Add default expires at and validation

This commit is contained in:
Hongbo Wu 2022-06-06 13:10:46 +08:00
parent 07c71da88e
commit c389a48209
2 changed files with 11 additions and 2 deletions

View file

@ -16,6 +16,7 @@ export interface FormInputProps {
required?: boolean
css?: any
options?: string[]
min?: any
}
export const FormInput = styled('input', {
@ -96,6 +97,7 @@ export function GeneralFormInput(props: FormInputProps): JSX.Element {
},
}}
name={input.name}
min={input.min}
/>
)
}

View file

@ -42,6 +42,11 @@ export default function ApiKeys(): JSX.Element {
return rows
}, [apiKeys])
// default expiry date is 1 year from now
const defaultExpiresAt = new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)
.toISOString()
.split('T')[0]
applyStoredTheme(false)
async function onDelete(id: string): Promise<void> {
@ -121,15 +126,17 @@ export default function ApiKeys(): JSX.Element {
required: true,
},
{
label: 'Expired at',
label: 'Expired on',
name: 'expiredAt',
required: true,
onChange: setExpiresAt,
type: 'date',
min: new Date().toISOString().split('T')[0], // today
value: defaultExpiresAt,
},
])
setName('')
setExpiresAt(new Date(Date.now() + 1000 * 60 * 60 * 24 * 365))
setExpiresAt(new Date(defaultExpiresAt))
setAddModelOpen(true)
}}
/>