import React, { useState } from 'react'; import { FormattedMessage } from 'react-intl'; import { Formik, Form, Field } from 'formik'; import Button from 'components/common/Button'; import FormLayout, { FormButtons, FormError, FormMessage, FormRow, } from 'components/layout/FormLayout'; import Loading from 'components/common/Loading'; import useApi from 'hooks/useApi'; 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 { del } = useApi(); const [message, setMessage] = useState(); const [deleting, setDeleting] = useState(false); const handleSubmit = async ({ type, id }) => { setDeleting(true); const { ok, data } = await del(`/${type}/${id}`); if (ok) { onSave(); } else { setMessage( data || , ); setDeleting(false); } }; return ( {deleting && } {props => (
{values.name} }} />

{CONFIRMATION_WORD} }} />

{message}
)}
); }