import { useStore } from '@tanstack/react-form'; import { useAppForm, Form } from '@/components/form'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import { useCreateSSHKey } from '@/api/account/ssh-keys/queries'; export default function CreateSSHKeyForm() { const createSshKey = useCreateSSHKey(); const form = useAppForm({ defaultValues: { name: '', publicKey: '' }, onSubmit: async ({ value, formApi }) => { try { await createSshKey.mutateAsync({ body: { name: value.name, public_key: value.publicKey, }, }); formApi.reset(); } catch { // Error toast is handled by the mutation. } }, }); const isSubmitting = useStore(form.store, (state) => state.isSubmitting); return ( <>
(value.length >= 1 ? undefined : 'A key name must be provided.'), }} > {(field) => }
(value.length >= 1 ? undefined : 'A public key must be provided.'), }} > {(field) => ( )}
Save
); }