import React, { useState } from 'react'; import createNest from '@/api/admin/nests/createNest'; import getNests from '@/api/admin/nests/getNests'; import Button from '@/components/elements/Button'; import Field from '@/components/elements/Field'; import Modal from '@/components/elements/Modal'; import FlashMessageRender from '@/components/FlashMessageRender'; import useFlash from '@/plugins/useFlash'; import { Form, Formik, FormikHelpers } from 'formik'; import { object, string } from 'yup'; import tw from 'twin.macro'; interface Values { name: string, description: string, } const schema = object().shape({ name: string() .required('A nest name must be provided.') .max(32, 'Nest name must not exceed 32 characters.'), description: string() .max(255, 'Nest description must not exceed 255 characters.'), }); export default () => { const [ visible, setVisible ] = useState(false); const { clearFlashes, clearAndAddHttpError } = useFlash(); const { mutate } = getNests(); const submit = ({ name, description }: Values, { setSubmitting }: FormikHelpers) => { clearFlashes('nest:create'); setSubmitting(true); createNest(name, description) .then(nest => { mutate(data => ({ ...data, items: data.items.concat(nest) }), false); setVisible(false); }) .catch(error => { clearAndAddHttpError({ key: 'nest:create', error }); setSubmitting(false); }); }; return ( <> { ({ isSubmitting, resetForm }) => ( { resetForm(); setVisible(false); }} >

New Nest

) }
); };