import type { Actions } from 'easy-peasy'; import { useStoreActions } from 'easy-peasy'; import { useState } from 'react'; import tw from 'twin.macro'; import deleteAllocation from '@/api/admin/nodes/allocations/deleteAllocation'; import Button from '@/components/elements/Button'; import ConfirmationModal from '@/components/elements/ConfirmationModal'; import type { ApplicationStore } from '@/state'; interface Props { nodeId: number; allocationId: number; onDeleted?: () => void; } export default ({ nodeId, allocationId, 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('allocation'); deleteAllocation(nodeId, allocationId) .then(() => { setLoading(false); setVisible(false); if (onDeleted !== undefined) { onDeleted(); } }) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'allocation', error }); setLoading(false); setVisible(false); }); }; return ( <> setVisible(false)} > Are you sure you want to delete this allocation? ); };