48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { deleteArticleAction } from '@/actions/articles/deleteArticleAction';
|
||
import { useModalStore } from '@/stores/useModalStore';
|
||
import { Button } from '@/ui/Button';
|
||
import { useApolloClient } from '@apollo/client';
|
||
import { CloseIcon } from '../icons/CloseIcon';
|
||
|
||
export function DeleteArticleModal({ id }: { id: number }) {
|
||
const { setModal } = useModalStore();
|
||
|
||
// const [deleteArticle] = useDeleteArticleMutation({
|
||
// variables: { id },
|
||
// refetchQueries: ['GetArticleById', 'GetArticlesCount'],
|
||
// onCompleted: () => {
|
||
// setModal(null, '');
|
||
// window.location.href = '/blog';
|
||
// },
|
||
// });
|
||
|
||
const client = useApolloClient();
|
||
|
||
async function handleDeleteArticle() {
|
||
await deleteArticleAction(id);
|
||
setModal(null, '');
|
||
client.refetchQueries({ include: ['GetArticlesCount'] });
|
||
}
|
||
|
||
return (
|
||
<div className="bg-white shadow-lg text-black p-8 rounded-xl flex flex-col gap-4">
|
||
<div className="flex justify-between items-center border-b border-[#ccc] pb-4 gap-4">
|
||
<p className="text-xl">Удаление статьи</p>
|
||
<button
|
||
onClick={() => setModal(null, '')}
|
||
className="p-2 hover:bg-white hover:bg-opacity-10 transition-colors rounded-full"
|
||
>
|
||
<CloseIcon />
|
||
</button>
|
||
</div>
|
||
|
||
<Button
|
||
onClick={handleDeleteArticle}
|
||
className="text-white self-end outline-none"
|
||
>
|
||
Удалить статью
|
||
</Button>
|
||
</div>
|
||
);
|
||
}
|