import type { Actions } from 'easy-peasy'; import { useStoreActions } from 'easy-peasy'; import { useState } from 'react'; import tw from 'twin.macro'; import deleteEgg from '@/api/admin/eggs/deleteEgg'; import { Button } from '@/components/elements/button'; import { Shape } from '@/components/elements/button/types'; import ConfirmationModal from '@/components/elements/ConfirmationModal'; import type { ApplicationStore } from '@/state'; interface Props { eggId: number; onDeleted: () => void; } export default ({ eggId, onDeleted }: Props) => { const [visible, setVisible] = useState(false); const [loading, setLoading] = useState(false); const { clearFlashes, clearAndAddHttpError } = useStoreActions( (actions: Actions) => actions.flashes, ); const onDelete = () => { setLoading(true); clearFlashes('egg'); deleteEgg(eggId) .then(() => { setLoading(false); onDeleted(); }) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'egg', error }); setLoading(false); setVisible(false); }); }; return ( <> setVisible(false)} > Are you sure you want to delete this egg? You may only delete an egg with no servers using it. setVisible(true)}> ); };