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 { Switch } from "@heroui/switch";
|
||||||
import {
|
import {
|
||||||
createArticle,
|
createArticle,
|
||||||
|
deleteArticle,
|
||||||
deleteArticleFiles,
|
deleteArticleFiles,
|
||||||
getArticleByCategory,
|
getArticleByCategory,
|
||||||
getArticleById,
|
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 (
|
return (
|
||||||
<form
|
<form
|
||||||
className="flex flex-col lg:flex-row gap-8 text-black"
|
className="flex flex-col lg:flex-row gap-8 text-black"
|
||||||
|
|
@ -1150,11 +1178,15 @@ export default function EditArticleForm(props: { isDetail: boolean }) {
|
||||||
Publish
|
Publish
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{/* {!isDetail && (
|
{!isDetail && (
|
||||||
<Button color="success" type="button">
|
<Button
|
||||||
<p className="text-white">Draft</p>
|
onPress={() => handleDelete(id)}
|
||||||
|
color="danger"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<p className="text-white">Delete</p>
|
||||||
</Button>
|
</Button>
|
||||||
)} */}
|
)}
|
||||||
|
|
||||||
<Link href="/admin/article">
|
<Link href="/admin/article">
|
||||||
<Button color="danger" variant="bordered" type="button">
|
<Button color="danger" variant="bordered" type="button">
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ export default function ArticleTable() {
|
||||||
};
|
};
|
||||||
|
|
||||||
async function doDelete(id: any) {
|
async function doDelete(id: any) {
|
||||||
// loading();
|
loading();
|
||||||
const resDelete = await deleteArticle(id);
|
const resDelete = await deleteArticle(id);
|
||||||
|
|
||||||
if (resDelete?.error) {
|
if (resDelete?.error) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue