import React, { useState } from 'react'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationStore } from '@/state'; import tw from 'twin.macro'; import Button from '@/components/elements/Button'; import ConfirmationModal from '@/components/elements/ConfirmationModal'; import deleteDatabase from '@/api/admin/databases/deleteDatabase'; interface Props { databaseId: number; onDeleted: () => void; } export default ({ databaseId, 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('database'); deleteDatabase(databaseId) .then(() => { setLoading(false); onDeleted(); }) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'database', error }); setLoading(false); setVisible(false); }); }; return ( <> setVisible(false)} > Are you sure you want to delete this database host? This action will delete all knowledge of databases created on this host but not the databases themselves. ); };