import { SecurityKey } from '@definitions/user'; import { useFlashKey } from '@/plugins/useFlash'; import { Form, Formik, FormikHelpers } from 'formik'; import { registerSecurityKey } from '@/api/account/security-keys'; import { object, string } from 'yup'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import Field from '@/components/elements/Field'; import tw from 'twin.macro'; import Button from '@/components/elements/Button'; import React from 'react'; interface Values { name: string; } export default ({ onKeyAdded }: { onKeyAdded: (key: SecurityKey) => void }) => { const { clearAndAddHttpError } = useFlashKey('security_keys'); const submit = ({ name }: Values, { setSubmitting, resetForm }: FormikHelpers) => { registerSecurityKey(name) .then(key => { resetForm(); onKeyAdded(key); }) .catch(clearAndAddHttpError) .then(() => setSubmitting(false)); }; return ( {({ isSubmitting }) => (
)}
); };