feat:delete button on edit article
This commit is contained in:
parent
b785c0a2c2
commit
407566899f
|
|
@ -15,6 +15,7 @@ import Image from "next/image";
|
|||
import { Switch } from "@heroui/switch";
|
||||
import {
|
||||
createArticle,
|
||||
deleteArticle,
|
||||
deleteArticleFiles,
|
||||
getArticleByCategory,
|
||||
getArticleById,
|
||||
|
|
@ -573,6 +574,33 @@ export default function EditArticleForm(props: { isDetail: boolean }) {
|
|||
});
|
||||
};
|
||||
|
||||
const handleDelete = (id: any) => {
|
||||
MySwal.fire({
|
||||
title: "Hapus Artikel",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
cancelButtonColor: "#3085d6",
|
||||
confirmButtonColor: "#d33",
|
||||
confirmButtonText: "Hapus",
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
doDelete(id);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
async function doDelete(id: any) {
|
||||
// loading();
|
||||
const resDelete = await deleteArticle(id);
|
||||
|
||||
if (resDelete?.error) {
|
||||
error(resDelete.message);
|
||||
return false;
|
||||
}
|
||||
close();
|
||||
router.push("/admin/article");
|
||||
}
|
||||
|
||||
return (
|
||||
<form
|
||||
className="flex flex-col lg:flex-row gap-8 text-black"
|
||||
|
|
@ -1150,11 +1178,15 @@ export default function EditArticleForm(props: { isDetail: boolean }) {
|
|||
Publish
|
||||
</Button>
|
||||
)}
|
||||
{/* {!isDetail && (
|
||||
<Button color="success" type="button">
|
||||
<p className="text-white">Draft</p>
|
||||
{!isDetail && (
|
||||
<Button
|
||||
onPress={() => handleDelete(id)}
|
||||
color="danger"
|
||||
type="button"
|
||||
>
|
||||
<p className="text-white">Delete</p>
|
||||
</Button>
|
||||
)} */}
|
||||
)}
|
||||
|
||||
<Link href="/admin/article">
|
||||
<Button color="danger" variant="bordered" type="button">
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ export default function ArticleTable() {
|
|||
};
|
||||
|
||||
async function doDelete(id: any) {
|
||||
// loading();
|
||||
loading();
|
||||
const resDelete = await deleteArticle(id);
|
||||
|
||||
if (resDelete?.error) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue