({
form,
maxTokenLifetime,
formError,
setFormError,
isCreating,
creationFailed,
now,
})
| 36 | } |
| 37 | |
| 38 | export const CreateTokenForm: FC<CreateTokenFormProps> = ({ |
| 39 | form, |
| 40 | maxTokenLifetime, |
| 41 | formError, |
| 42 | setFormError, |
| 43 | isCreating, |
| 44 | creationFailed, |
| 45 | now, |
| 46 | }) => { |
| 47 | const navigate = useNavigate(); |
| 48 | |
| 49 | const [expDays, setExpDays] = useState<number>(1); |
| 50 | const [lifetimeDays, setLifetimeDays] = useState<number | string>( |
| 51 | determineDefaultLtValue(maxTokenLifetime), |
| 52 | ); |
| 53 | const currentTime = dayjs(now ?? new Date()); |
| 54 | |
| 55 | // biome-ignore lint/correctness/useExhaustiveDependencies: adding form will cause an infinite loop |
| 56 | useEffect(() => { |
| 57 | if (lifetimeDays !== "custom") { |
| 58 | void form.setFieldValue("lifetime", lifetimeDays); |
| 59 | } else { |
| 60 | void form.setFieldValue("lifetime", expDays); |
| 61 | } |
| 62 | }, [lifetimeDays, expDays]); |
| 63 | |
| 64 | const getFieldHelpers = getFormHelpers<CreateTokenData>(form, formError); |
| 65 | |
| 66 | return ( |
| 67 | <HorizontalForm onSubmit={form.handleSubmit}> |
| 68 | <FormSection |
| 69 | title="Name" |
| 70 | description="What is this token for?" |
| 71 | classes={{ sectionInfo: classNames.sectionInfo }} |
| 72 | > |
| 73 | <FormFields> |
| 74 | <TextField |
| 75 | {...getFieldHelpers("name")} |
| 76 | label="Name" |
| 77 | required |
| 78 | onChange={onChangeTrimmed(form, () => setFormError(undefined))} |
| 79 | autoFocus |
| 80 | fullWidth |
| 81 | /> |
| 82 | </FormFields> |
| 83 | </FormSection> |
| 84 | <FormSection |
| 85 | title="Expiration" |
| 86 | description={ |
| 87 | form.values.lifetime ? ( |
| 88 | <> |
| 89 | The token will expire on{" "} |
| 90 | <span data-chromatic="ignore"> |
| 91 | {currentTime |
| 92 | .add(form.values.lifetime, "days") |
| 93 | .utc() |
| 94 | .format("MMMM DD, YYYY")} |
| 95 | </span> |
nothing calls this directly
no test coverage detected