import { Form, Formik, FormikHelpers } from 'formik'; import React, { useState } from 'react'; import tw from 'twin.macro'; import createEggVariable from '@/api/admin/eggs/createEggVariable'; import getEgg from '@/api/admin/eggs/getEgg'; import { EggVariableForm, validationSchema } from '@/components/admin/nests/eggs/EggVariablesContainer'; import Modal from '@/components/elements/Modal'; import FlashMessageRender from '@/components/FlashMessageRender'; import Button from '@/components/elements/Button'; import useFlash from '@/plugins/useFlash'; export default function NewVariableButton ({ eggId }: { eggId: number }) { const [ visible, setVisible ] = useState(false); const { clearFlashes, clearAndAddHttpError } = useFlash(); const { mutate } = getEgg(eggId); const submit = (values: any, { setSubmitting }: FormikHelpers) => { clearFlashes('variable:create'); createEggVariable(eggId, values) .then(async (v) => { await mutate(egg => ({ ...egg!, relations: { variables: [ ...egg!.relations.variables!, v ] } })); setVisible(false); }) .catch(error => { clearAndAddHttpError({ key: 'variable:create', error }); setSubmitting(false); }); }; return ( <> {({ isSubmitting, resetForm }) => ( { resetForm(); setVisible(false); }} >

New Variable

)}
); }