fix: category in admin

This commit is contained in:
Sabda Yagra 2025-10-03 21:44:55 +07:00
parent 4a5bce9c24
commit ff44a3b837
1 changed files with 21 additions and 2 deletions

View File

@ -10,15 +10,34 @@ export default function StatusToogle(props: {
}) { }) {
const { id, initValue } = props; const { id, initValue } = props;
const router = useRouter(); const router = useRouter();
// const publishCategory = async (id: number, status: string) => {
// const response = await publishUnpublishCategory(id, status);
// console.log(response);
// if (response?.error) {
// error(response.message);
// return false;
// }
// router.push("/admin/settings/category?dataChange=true");
// };
const publishCategory = async (id: number, status: string) => { const publishCategory = async (id: number, status: string) => {
const response = await publishUnpublishCategory(id, status); const response = await publishUnpublishCategory(id, status);
console.log(response); console.log("API Response:", response);
// cek error interceptor
if (response?.error) { if (response?.error) {
error(response.message); error(response.message || "Terjadi kesalahan");
return false; return false;
} }
// cek flag success asli dari backend
if (response?.data?.success === false) {
error(response?.data?.message || "Terjadi kesalahan");
return false;
}
router.push("/admin/settings/category?dataChange=true"); router.push("/admin/settings/category?dataChange=true");
}; };
return ( return (
<Switch <Switch
id={String(id)} id={String(id)}