2026-10-05 18:10:18 -04:00
|
|
|
import { useStore } from '@tanstack/react-form';
|
|
|
|
|
import { useAppForm, Form } from '@/components/form';
|
2022-05-14 17:31:53 -04:00
|
|
|
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
2026-10-05 18:10:18 -04:00
|
|
|
import { useCreateSSHKey } from '@/api/account/ssh-keys/queries';
|
2022-05-14 17:31:53 -04:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
export default function CreateSSHKeyForm() {
|
|
|
|
|
const createSshKey = useCreateSSHKey();
|
2022-05-14 17:31:53 -04:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
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.
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-05-14 17:31:53 -04:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
const isSubmitting = useStore(form.store, (state) => state.isSubmitting);
|
2022-05-14 17:31:53 -04:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2026-10-05 18:10:18 -04:00
|
|
|
<Form form={form}>
|
|
|
|
|
<SpinnerOverlay visible={isSubmitting} />
|
|
|
|
|
<div className={'mb-6'}>
|
|
|
|
|
<form.AppField
|
|
|
|
|
name={'name'}
|
|
|
|
|
validators={{
|
|
|
|
|
onChange: ({ value }) => (value.length >= 1 ? undefined : 'A key name must be provided.'),
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{(field) => <field.TextField label={'SSH Key Name'} />}
|
|
|
|
|
</form.AppField>
|
|
|
|
|
</div>
|
|
|
|
|
<form.AppField
|
|
|
|
|
name={'publicKey'}
|
|
|
|
|
validators={{
|
|
|
|
|
onChange: ({ value }) => (value.length >= 1 ? undefined : 'A public key must be provided.'),
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{(field) => (
|
|
|
|
|
<field.TextAreaField label={'Public Key'} rows={6} description={'Enter your public SSH key.'} />
|
|
|
|
|
)}
|
|
|
|
|
</form.AppField>
|
|
|
|
|
<div className={'flex justify-end mt-6'}>
|
|
|
|
|
<form.AppForm>
|
|
|
|
|
<form.SubmitButton>Save</form.SubmitButton>
|
|
|
|
|
</form.AppForm>
|
|
|
|
|
</div>
|
|
|
|
|
</Form>
|
2022-05-14 17:31:53 -04:00
|
|
|
</>
|
|
|
|
|
);
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|