import type { Actions } from 'easy-peasy'; import { useStoreActions } from 'easy-peasy'; import { useState } from 'react'; import tw from 'twin.macro'; import deleteMount from '@/api/admin/mounts/deleteMount'; import { Button } from '@/components/elements/button'; import ConfirmationModal from '@/components/elements/ConfirmationModal'; import type { ApplicationStore } from '@/state'; interface Props { mountId: number; onDeleted: () => void; } export default ({ mountId, 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('mount'); deleteMount(mountId) .then(() => { setLoading(false); onDeleted(); }) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'mount', error }); setLoading(false); setVisible(false); }); }; return ( <> setVisible(false)} > Are you sure you want to delete this mount? Deleting a mount will not delete files on any nodes. setVisible(true)}> ); };