import React, { useState } from 'react'; import { FormattedMessage } from 'react-intl'; import { useRouter } from 'next/router'; import { Formik, Form, Field } from 'formik'; import { del } from 'lib/web'; import Button from 'components/common/Button'; import FormLayout, { FormButtons, FormError, FormMessage, FormRow, } from 'components/layout/FormLayout'; const CONFIRMATION_WORD = 'DELETE'; const validate = ({ confirmation }) => { const errors = {}; if (confirmation !== CONFIRMATION_WORD) { errors.confirmation = !confirmation ? ( ) : ( ); } return errors; }; export default function DeleteForm({ values, onSave, onClose }) { const { basePath } = useRouter(); const [message, setMessage] = useState(); const handleSubmit = async ({ type, id }) => { const { ok, data } = await del(`${basePath}/api/${type}/${id}`); if (ok) { onSave(); } else { setMessage( data || , ); } }; return ( {props => (
{values.name} }} />

{CONFIRMATION_WORD} }} />

{message}
)}
); }