From b898fc3069e99ab2007943a6d32f3fd53cf74ed7 Mon Sep 17 00:00:00 2001 From: Sabda Yagra Date: Tue, 21 Apr 2026 18:45:06 +0700 Subject: [PATCH] fixing --- .../(admin)/admin/categories/page.tsx | 42 +++++++++++-------- app/[locale]/globals.css | 2 + .../categories/categories-detail-form.tsx | 4 +- global.d.ts | 1 + tsconfig.json | 2 +- 5 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 global.d.ts diff --git a/app/[locale]/(admin)/admin/categories/page.tsx b/app/[locale]/(admin)/admin/categories/page.tsx index 5b4ae77..ca9262c 100644 --- a/app/[locale]/(admin)/admin/categories/page.tsx +++ b/app/[locale]/(admin)/admin/categories/page.tsx @@ -34,10 +34,10 @@ import { createCategories } from "@/service/categories/categories"; const FormSchema = z.object({ title: z.string().min(1, "Nama kategori wajib diisi"), - slug: z.string().min(1, "Slug wajib diisi"), + slug: z.string().optional(), description: z.string().min(1, "Deskripsi wajib diisi"), - statusId: z.coerce.number().default(1), // biar default aktif - tags: z.string().optional(), // opsional aja kalau belum wajib + statusId: z.coerce.number().default(1), + tags: z.string().optional(), }); // helper untuk bikin slug otomatis @@ -64,22 +64,30 @@ const ReactTableImagePage = () => { }, }); + // const handleTitleChange = (value: string) => { + // form.setValue("title", value); + // const autoSlug = slugify(value); + // if ( + // !form.getValues("slug") || + // form.getValues("slug") === + // slugify(form.formState.defaultValues?.title || "") + // ) { + // form.setValue("slug", autoSlug); + // } + // }; const handleTitleChange = (value: string) => { form.setValue("title", value); - const autoSlug = slugify(value); - if ( - !form.getValues("slug") || - form.getValues("slug") === - slugify(form.formState.defaultValues?.title || "") - ) { - form.setValue("slug", autoSlug); - } + form.setValue("slug", slugify(value)); }; const onSubmit = async (data: z.infer) => { loading(); try { - const response = await createCategories(data); + const payload = { + ...data, + slug: slugify(data.title), + }; + const response = await createCategories(payload); MySwal.close(); if (response?.error) { @@ -87,8 +95,8 @@ const ReactTableImagePage = () => { typeof response.message === "string" ? response.message : Array.isArray(response.message) - ? response.message.join(", ") - : JSON.stringify(response.message); + ? response.message.join(", ") + : JSON.stringify(response.message); await MySwal.fire({ icon: "error", @@ -128,7 +136,7 @@ const ReactTableImagePage = () => { return (
- {/* */} +
@@ -184,7 +192,7 @@ const ReactTableImagePage = () => { /> {/* Slug */} - ( @@ -199,7 +207,7 @@ const ReactTableImagePage = () => { )} - /> + /> */} {/* Deskripsi */}
-
+ {/*

{formatDateToIndonesian(new Date(detail.updatedAt))}

-
+
*/} {/* Back Button */}