-
Notifications
You must be signed in to change notification settings - Fork 66
Refactor Limits page #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Refactor Limits page #296
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
e3ce03b
Replace limits cards with inline limit and alert controls
sarimrmalik 151d688
Refactor each icon into its own file with a common wrapper for shared…
sarimrmalik e25ca40
Refactor Alert and Limit ASCII icons to use div wrappers instead of S…
sarimrmalik a2ec03e
Rollback icon refactor since out of scope of this branch
sarimrmalik adee037
Add ASCII icon components for alert and limit with styled text repres…
sarimrmalik 80f766d
Refactor billing limits management by removing the old LimitForm comp…
sarimrmalik f8c7998
Refactor dashboard limits management by removing the old limit-sectio…
sarimrmalik fa3856c
Enhance UsageAlertForm and UsageLimitForm to improve cancel functiona…
sarimrmalik a510283
Add SetUsageLimitDialog component for setting API usage limits
sarimrmalik 65c7b0c
Refactor UsageAlertForm and UsageLimitForm to use Input components fo…
sarimrmalik 262247b
Refactor RemoveUsageLimitDialog and UsageLimitForm to enhance user in…
sarimrmalik 039e670
Refactor UsageLimits component to improve loading state handling. Con…
sarimrmalik 7189e3d
Run biome format
sarimrmalik 85c4cc7
Add mount check in UsageAlertForm to prevent initial effect execution
sarimrmalik 307ef38
Add currency validation and formatting utilities with comprehensive t…
sarimrmalik 58f76f7
Refactor currency-related tests and forms for improved consistency an…
sarimrmalik ab005a1
Fix top padding
sarimrmalik 05220fe
Refactor dialog components and forms for improved user experience and…
sarimrmalik 3d5758a
Enhance hover effects in UsageAlertSection and UsageLimitSection for …
sarimrmalik a9896ee
Add focus behavior for input fields in UsageAlertForm and UsageLimitForm
sarimrmalik 34d823b
Update dialog positioning and overflow behavior for improved layout a…
sarimrmalik b83fa3c
Refactor AlertAsciiIcon and LimitAsciiIcon components to utilize a ne…
sarimrmalik a0e6d06
Reduce gap between items in UsageAlertForm and UsageLimitForm for imp…
sarimrmalik c424e39
Update success toast messages in usage limit and alert forms for impr…
sarimrmalik 0213f76
Merge remote-tracking branch 'origin/main' into refactor/limits-page
sarimrmalik e3cc931
Merge remote-tracking branch 'origin/main' into refactor/limits-page
sarimrmalik 770fc1b
refactor: update button variants and loading states in usage limit an…
sarimrmalik 0ac36aa
refactor: remove early return for team check in UsageLimits component
sarimrmalik 7bd5c58
refactor: reorganize currency input utilities and update usage forms
sarimrmalik 2495346
fix: adjust dialog content width for better responsiveness
sarimrmalik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ next-env.d.ts | |
|
|
||
| # AI agents and related files | ||
| CLAUDE.md | ||
| .cursor | ||
| .agent | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { | ||
| CurrencyInputSchema, | ||
| sanitizeCurrencyInput, | ||
| } from '@/features/dashboard/limits/currency-input' | ||
|
|
||
| describe('sanitizeCurrencyInput', () => { | ||
| it.each([ | ||
| ['$1,250', '1250'], | ||
| ['1250', '1250'], | ||
| ['abc', ''], | ||
| ['', ''], | ||
| ])('returns %p -> %p', (value: string, expected: string) => { | ||
| expect(sanitizeCurrencyInput(value)).toBe(expected) | ||
| }) | ||
| }) | ||
|
|
||
| describe('CurrencyInputSchema', () => { | ||
| it.each(['100', '1', ' 100 ', '999999'])('accepts %p', (value: string) => { | ||
| expect(CurrencyInputSchema.safeParse(value).success).toBe(true) | ||
| }) | ||
|
|
||
| it.each([ | ||
| '', | ||
| ' ', | ||
| '12.50', | ||
| '1,250', | ||
| 'abc', | ||
| '0', | ||
| ])('rejects %p', (value: string) => { | ||
| expect(CurrencyInputSchema.safeParse(value).success).toBe(false) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { AsciiIcon } from './ascii-icon' | ||
|
|
||
| const INACTIVE_LINES = [ | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ' -********- ', | ||
| ' -*-- -*- ', | ||
| ' -*- -*- ', | ||
| ' **- -** ', | ||
| ' -*- -*- ', | ||
| ' -**----------**- ', | ||
| ' ----**----**---- ', | ||
| ' -******- ', | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ] | ||
|
|
||
| const ACTIVE_LINES = [ | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ' -********- ', | ||
| [ | ||
| { text: ' -*-- ' }, | ||
| { className: 'text-accent-main-highlight', text: '-' }, | ||
| { text: '*- ' }, | ||
| ], | ||
| ' -*- -*- ', | ||
| [ | ||
| { text: ' *' }, | ||
| { className: 'text-accent-main-highlight', text: '*' }, | ||
| { text: '- -' }, | ||
| { className: 'text-accent-main-highlight', text: '*' }, | ||
| { text: '* ' }, | ||
| ], | ||
| ' -*- -*- ', | ||
| [ | ||
| { text: ' -*' }, | ||
| { className: 'text-accent-main-highlight', text: '*' }, | ||
| { text: '----------**- ' }, | ||
| ], | ||
| [ | ||
| { text: ' ----**' }, | ||
| { className: 'text-accent-main-highlight', text: '-' }, | ||
| { text: '---**---- ' }, | ||
| ], | ||
| ' -******- ', | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ] | ||
|
|
||
| interface AlertAsciiIconProps { | ||
| active?: boolean | ||
| className?: string | ||
| } | ||
|
|
||
| export const AlertAsciiIcon = ({ | ||
| active = false, | ||
| className, | ||
| }: AlertAsciiIconProps) => ( | ||
| <AsciiIcon | ||
| className={className} | ||
| lines={active ? ACTIVE_LINES : INACTIVE_LINES} | ||
| /> | ||
| ) |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { type CSSProperties, Fragment } from 'react' | ||
| import { cn } from '@/lib/utils' | ||
|
|
||
| type AsciiLineSegment = { | ||
| className?: string | ||
| text: string | ||
| } | ||
|
|
||
| type AsciiLine = string | readonly AsciiLineSegment[] | ||
|
|
||
| const TEXT_STYLE = { | ||
| fontFamily: 'var(--font-mono)', | ||
| fontFeatureSettings: "'ss03' 1", | ||
| fontSize: '3.802px', | ||
| fontWeight: 600, | ||
| letterSpacing: '-0.038px', | ||
| lineHeight: '4px', | ||
| } satisfies CSSProperties | ||
|
|
||
| interface AsciiIconProps { | ||
| className?: string | ||
| lines: readonly AsciiLine[] | ||
| } | ||
|
|
||
| const renderAsciiLine = (line: AsciiLine) => { | ||
| if (typeof line === 'string') return line | ||
|
|
||
| return line.map((segment, index) => ( | ||
| <Fragment key={`${segment.text}-${index}`}> | ||
| {segment.className ? ( | ||
| <span className={segment.className}>{segment.text}</span> | ||
| ) : ( | ||
| segment.text | ||
| )} | ||
| </Fragment> | ||
| )) | ||
| } | ||
|
|
||
| export const AsciiIcon = ({ className, lines }: AsciiIconProps) => ( | ||
| <div className={cn('relative size-[72px]', className)}> | ||
| <div | ||
| className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 whitespace-nowrap text-fg uppercase" | ||
| style={TEXT_STYLE} | ||
| > | ||
| {lines.map((line, index) => ( | ||
| <p key={index} className="m-0 whitespace-pre"> | ||
| {renderAsciiLine(line)} | ||
| </p> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { z } from 'zod' | ||
|
|
||
| // Validates a string as a positive whole USD amount. Example: "1250" -> valid, "abc" -> invalid. | ||
| const CurrencyInputSchema = z | ||
| .string() | ||
| .trim() | ||
| .min(1, 'Enter a value.') | ||
| .regex(/^\d+$/, 'Enter a whole USD amount.') | ||
| .refine((value) => Number(value) >= 1, 'Value must be at least 1.') | ||
|
|
||
| // Removes non-digits from a USD draft value. Example: "$1,250" -> "1250". | ||
| const sanitizeCurrencyInput = (value: string) => value.replace(/\D+/g, '') | ||
|
|
||
| export { CurrencyInputSchema, sanitizeCurrencyInput } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import type { MouseEvent } from 'react' | ||
|
|
||
| const INTERACTIVE_ELEMENT_SELECTOR = | ||
| 'button, input, textarea, select, a, [role="button"], [data-no-input-focus]' | ||
|
|
||
| // Focuses the first editable input in a block, e.g. block click -> input focused, button click -> unchanged. | ||
| const focusBlockInputOnMouseDown = (event: MouseEvent<HTMLElement>) => { | ||
| if (!(event.target instanceof Element)) return | ||
| if (event.target.closest(INTERACTIVE_ELEMENT_SELECTOR)) return | ||
|
|
||
| const input = event.currentTarget.querySelector('input') | ||
| if (!(input instanceof HTMLInputElement)) return | ||
| if (input.disabled || input.readOnly) return | ||
|
|
||
| event.preventDefault() | ||
| input.focus() | ||
|
|
||
| const cursorPosition = input.value.length | ||
| input.setSelectionRange(cursorPosition, cursorPosition) | ||
| } | ||
|
|
||
| export { focusBlockInputOnMouseDown } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { AsciiIcon } from './ascii-icon' | ||
|
|
||
| const INACTIVE_LINES = [ | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ' ---**--- ', | ||
| ' -**------**- ', | ||
| ' -**- - -**- ', | ||
| ' ** -**- ** ', | ||
| ' *- --- -* ', | ||
| ' ** ** ', | ||
| ' -**- -**- ', | ||
| ' -- -- ', | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ] | ||
|
|
||
| const ACTIVE_LINES = [ | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ' ---**--- ', | ||
| [ | ||
| { text: ' -**-----' }, | ||
| { className: 'text-accent-secondary-error-highlight', text: '-' }, | ||
| { text: '**- ' }, | ||
| ], | ||
| ' -**- - -**- ', | ||
| [ | ||
| { text: ' ' }, | ||
| { className: 'text-accent-main-highlight', text: '**' }, | ||
| { text: ' -**- ** ' }, | ||
| ], | ||
| [ | ||
| { text: ' *- -' }, | ||
| { className: 'text-accent-main-highlight', text: '-' }, | ||
| { text: '- -* ' }, | ||
| ], | ||
| ' ** ** ', | ||
| ' -**- -**- ', | ||
| [ | ||
| { text: ' -- ' }, | ||
| { className: 'text-accent-main-highlight', text: '-' }, | ||
| { text: '- ' }, | ||
| ], | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ' ', | ||
| ] | ||
|
|
||
| interface LimitAsciiIconProps { | ||
| active?: boolean | ||
| className?: string | ||
| } | ||
|
|
||
| export const LimitAsciiIcon = ({ | ||
| active = false, | ||
| className, | ||
| }: LimitAsciiIconProps) => ( | ||
| <AsciiIcon | ||
| className={className} | ||
| lines={active ? ACTIVE_LINES : INACTIVE_LINES} | ||
| /> | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.