-
Notifications
You must be signed in to change notification settings - Fork 8
feat(admin): require expiration for credit grants unless 'Never expires' is checked #15
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -45,6 +45,7 @@ export function UserAdminCreditGrant({ | |||||
| const [customDescription, setCustomDescription] = useState<string>(''); | ||||||
| const [expirationDate, setExpirationDate] = useState<string>(''); | ||||||
| const [expiryHours, setExpiryHours] = useState<string>(''); | ||||||
| const [neverExpires, setNeverExpires] = useState(false); | ||||||
|
|
||||||
| // API state | ||||||
| const [isGrantingCredit, setIsGrantingCredit] = useState(false); | ||||||
|
|
@@ -55,8 +56,17 @@ export function UserAdminCreditGrant({ | |||||
| ); | ||||||
| const expectNegative = selectedCreditCategory?.expect_negative_amount ?? false; | ||||||
|
|
||||||
| // Form validation - credit category required; description required for negative amount categories | ||||||
| const isFormValid = selectedCredit && (!expectNegative || customDescription.trim().length > 0); | ||||||
| // Check if expiration is set (either via date or hours) | ||||||
| const hasExpiration = expirationDate.trim() !== '' || expiryHours.trim() !== ''; | ||||||
|
|
||||||
| // Form validation: | ||||||
| // - credit category required | ||||||
| // - description required for negative amount categories | ||||||
| // - expiration required unless "Never expires" is checked (only for non-negative categories) | ||||||
| const isFormValid = | ||||||
| selectedCredit && | ||||||
| (!expectNegative || customDescription.trim().length > 0) && | ||||||
| (expectNegative || neverExpires || hasExpiration); | ||||||
|
|
||||||
| const handleCreditTypeChange = (value: string) => { | ||||||
| setSelectedCredit(value); | ||||||
|
|
@@ -65,6 +75,7 @@ export function UserAdminCreditGrant({ | |||||
| setCustomDescription(''); | ||||||
| setExpirationDate(''); | ||||||
| setExpiryHours(''); | ||||||
| setNeverExpires(false); | ||||||
| }; | ||||||
|
|
||||||
| const handleGrantCredit = async () => { | ||||||
|
|
@@ -109,6 +120,7 @@ export function UserAdminCreditGrant({ | |||||
| setCustomDescription(''); | ||||||
| setExpirationDate(''); | ||||||
| setExpiryHours(''); | ||||||
| setNeverExpires(false); | ||||||
| await queryClient.invalidateQueries({ queryKey: ['admin-user-credit-transactions', id] }); | ||||||
| } else { | ||||||
| setCreditMessage({ | ||||||
|
|
@@ -220,7 +232,7 @@ export function UserAdminCreditGrant({ | |||||
| <> | ||||||
| <div> | ||||||
| <Label className="text-sm font-medium" htmlFor="expiry-hours"> | ||||||
| Expiry Hours | ||||||
| Expiry Hours{!neverExpires && !expirationDate ? ' (required)' : ''} | ||||||
| </Label> | ||||||
| <Input | ||||||
| type="number" | ||||||
|
|
@@ -230,12 +242,12 @@ export function UserAdminCreditGrant({ | |||||
| min="0" | ||||||
| step="0.01" | ||||||
| id="expiry-hours" | ||||||
| disabled={!selectedCredit} | ||||||
| disabled={!selectedCredit || neverExpires} | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING: Required indicator condition is incorrect for "Expiration Date" This shows "(required)" whenever
Suggested change
|
||||||
| /> | ||||||
| </div> | ||||||
| <div> | ||||||
| <Label className="text-sm font-medium" htmlFor="date"> | ||||||
| Expiration Date | ||||||
| Expiration Date{!neverExpires && !expiryHours ? ' (required)' : ''} | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: Date input value fallback likely never triggers + format mismatch
Consider using something like |
||||||
| </Label> | ||||||
| <Input | ||||||
| type="date" | ||||||
|
|
@@ -244,8 +256,26 @@ export function UserAdminCreditGrant({ | |||||
| } | ||||||
| onChange={e => setExpirationDate(e.target.value)} | ||||||
| id="date" | ||||||
| disabled={!selectedCredit || neverExpires} | ||||||
| /> | ||||||
| </div> | ||||||
| <div className="flex items-end"> | ||||||
| <Label className="flex items-center gap-2 text-sm font-medium"> | ||||||
| <input | ||||||
| type="checkbox" | ||||||
| checked={neverExpires} | ||||||
| onChange={e => { | ||||||
| setNeverExpires(e.target.checked); | ||||||
| if (e.target.checked) { | ||||||
| setExpirationDate(''); | ||||||
| setExpiryHours(''); | ||||||
| } | ||||||
| }} | ||||||
| disabled={!selectedCredit} | ||||||
| /> | ||||||
| Never expires | ||||||
| </Label> | ||||||
| </div> | ||||||
| </> | ||||||
| )} | ||||||
| </div> | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Required indicator condition is incorrect for "Expiry Hours"
This shows "(required)" whenever
expirationDateis empty, even if the user already enteredexpiryHours. Consider only showing required when neither expiration field is set.