refactor: update article deletion and retrieval methods to use external ID
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { deleteArticle } from '@/lib/feature/article/article.external';
|
||||
import { deleteArticleByExternalId } from '@/lib/feature/article/article.external';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
@@ -13,24 +13,25 @@ import {
|
||||
AlertDialogTrigger,
|
||||
} from '@/ui/components/shadcn/alert-dialog';
|
||||
import { Button } from '@/ui/components/shadcn/button';
|
||||
import { UUIDv4 } from '@/utils/types/uuid';
|
||||
import { Trash2Icon } from 'lucide-react';
|
||||
import { useTransition } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
interface DeleteArticleButtonProps {
|
||||
articleId: string;
|
||||
articleTitle: string;
|
||||
externalID: UUIDv4;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export const DeleteArticleButton = ({
|
||||
articleId,
|
||||
articleTitle,
|
||||
externalID,
|
||||
title,
|
||||
}: DeleteArticleButtonProps) => {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
const handleDelete = () => {
|
||||
startTransition(async () => {
|
||||
const result = await deleteArticle(articleId);
|
||||
const result = await deleteArticleByExternalId(externalID);
|
||||
if (!result.ok) {
|
||||
toast.error('Failed to delete article', {
|
||||
description: result.error.message,
|
||||
@@ -39,7 +40,7 @@ export const DeleteArticleButton = ({
|
||||
return;
|
||||
}
|
||||
toast.success('Article deleted', {
|
||||
description: `"${articleTitle}" has been removed.`,
|
||||
description: `"${title}" has been removed.`,
|
||||
position: 'bottom-right',
|
||||
});
|
||||
});
|
||||
@@ -57,7 +58,7 @@ export const DeleteArticleButton = ({
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete article?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This will permanently delete “{articleTitle}
|
||||
This will permanently delete “{title}
|
||||
”. This action cannot be undone.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
|
||||
Reference in New Issue
Block a user