From 83eae371a68d5b1bffaeab29a8367c55762a3a2d Mon Sep 17 00:00:00 2001 From: Anang Yusman Date: Wed, 28 Jan 2026 01:21:50 +0800 Subject: [PATCH] fix:bugs dialog --- components/dialog/galery-detail-dialog.tsx | 44 +++--- components/dialog/promo-dialog.tsx | 138 ++++------------- .../form/product/create-product-form.tsx | 144 ++++++++++++++---- 3 files changed, 170 insertions(+), 156 deletions(-) diff --git a/components/dialog/galery-detail-dialog.tsx b/components/dialog/galery-detail-dialog.tsx index 6069cc5..9449e0d 100644 --- a/components/dialog/galery-detail-dialog.tsx +++ b/components/dialog/galery-detail-dialog.tsx @@ -115,7 +115,7 @@ export function DialogDetailGaleri({ open, onClose, data }: any) { const res = await commentGalery(id, message || undefined); if (res?.error) { - error(res.message || "Gagal komentar promotion"); + error(res.message || "Gagal komentar galeri"); close(); return; } @@ -161,11 +161,24 @@ export function DialogDetailGaleri({ open, onClose, data }: any) { return ( <> - - - {/* Header */} -
- Detail Galeri +
+
e.stopPropagation()} + > + {/* HEADER */} +
+ + +

Detail Galeri

{/* Images List */} -
+

{data.title}

@@ -240,7 +253,7 @@ export function DialogDetailGaleri({ open, onClose, data }: any) { {/* Deskripsi */} {/* Tanggal Upload */} -
+

Tanggal Upload

@@ -250,7 +263,7 @@ export function DialogDetailGaleri({ open, onClose, data }: any) {
{/* Timeline */} -
+

Status Timeline

@@ -374,17 +387,8 @@ export function DialogDetailGaleri({ open, onClose, data }: any) {
)}
- - {/* - - */} - -
+ + {openApproverHistory && (
- - +
onOpenChange(false)} + > +
e.stopPropagation()} + > {/* HEADER */} -
- - - Detail Promoaa - - +
+ +

Detail Promo

-

Ukuran File

-

{promo.fileSize}

+
+ Profile +
@@ -418,104 +434,6 @@ export default function PromoDetailDialog({ )}
)} - {openApproverHistory && ( -
setOpenApproverHistory(false)} - > -
e.stopPropagation()} - > - {/* HEADER */} -
- - -

Approver History

- -
- - Menunggu - - - Banner - - - 1 - -
-
- - {/* BODY */} -
- {/* LEFT TIMELINE */} -
- {/* Upload */} -
- - Upload - -
-
- - {/* Diterima */} -
-

Diterima

- - Direview oleh: approver-jaecoo1 - -
- -
- - {/* Pending */} -
-

Pending

- - Direview oleh: approver-jaecoo1 - -
-
- - {/* ARROW */} -
- > - > -
- - {/* RIGHT NOTES */} -
-
-
- Catatan: -
-
- -
-
- Catatan: -
-
-
-
- - {/* FOOTER */} -
- -
-
-
- )} {/* FOOTER
*/} - -
+
+ {openApproverHistory && (
([{ id: 1, name: "", file: null }]); + const [selectedColor, setSelectedColor] = useState(null); - const [specs, setSpecs] = useState([{ id: 1 }]); + const [specs, setSpecs] = useState< + { id: number; title: string; file: File | null }[] + >([{ id: 1, title: "", file: null }]); + const [file, setFile] = useState(null); const router = useRouter(); const MySwal = withReactContent(Swal); @@ -37,9 +43,9 @@ export default function AddProductForm() { if (selected) setFile(selected); }; - const handleAddSpec = () => { - setSpecs((prev) => [...prev, { id: prev.length + 1 }]); - }; + // const handleAddSpec = () => { + // setSpecs((prev) => [...prev, { id: prev.length + 1 }]); + // }; const { register, handleSubmit, @@ -49,29 +55,67 @@ export default function AddProductForm() { resolver: zodResolver(formSchema), }); + const handleSpecTitleChange = (index: number, value: string) => { + const updated = [...specs]; + updated[index].title = value; + setSpecs(updated); + }; + + const handleSpecFileChange = ( + index: number, + e: React.ChangeEvent, + ) => { + const file = e.target.files?.[0] || null; + const updated = [...specs]; + updated[index].file = file; + setSpecs(updated); + }; + const onSubmit = async (data: z.infer) => { try { const formData = new FormData(); formData.append("title", data.name); formData.append("variant", data.variant); - formData.append("is_active", "1"); formData.append("price", data.price.toString()); - // if (data.banner && data.banner.length > 0) { - // formData.append("thumbnail_path", data.banner[0]); - // } + formData.append("status", "1"); + formData.append("is_active", "1"); + + // banner if (file) { formData.append("file", file); } - const colorsArray = colors.map((c) => selectedColor || ""); - formData.append("colors", JSON.stringify(colorsArray)); - const res = await createProduct(formData); + // 🔥 colors JSON (object) + const colorsPayload = colors.map((c) => ({ + name: c.name, + })); + formData.append("colors", JSON.stringify(colorsPayload)); - console.log("API Success:", res); + // 🔥 color images + colors.forEach((c) => { + if (c.file) { + formData.append("color_images", c.file); + } + }); + + // 🔥 specifications JSON + const specificationsPayload = specs.map((s) => ({ + title: s.title, + })); + formData.append("specifications", JSON.stringify(specificationsPayload)); + + // 🔥 imagespecification_url (files) + specs.forEach((s) => { + if (s.file) { + formData.append("imagespecification_url", s.file); + } + }); + + await createProduct(formData); successSubmit("/admin/product"); - } catch (error) { - console.error("Submit Error:", error); + } catch (err) { + console.error(err); alert("Gagal mengirim produk"); } }; @@ -96,7 +140,20 @@ export default function AddProductForm() { }; const handleAddColor = () => { - setColors((prev) => [...prev, { id: prev.length + 1 }]); + setColors((prev) => [ + ...prev, + { id: prev.length + 1, name: "", file: null }, + ]); + }; + + const handleColorFileChange = ( + index: number, + e: React.ChangeEvent, + ) => { + const file = e.target.files?.[0] || null; + const updated = [...colors]; + updated[index].file = file; + setColors(updated); }; const formatRupiah = (value: string) => { @@ -192,7 +249,14 @@ export default function AddProductForm() { - + { + const updated = [...colors]; + updated[index].name = e.target.value; + setColors(updated); + }} + /> {/* Pilihan Warna */}
@@ -214,7 +278,12 @@ export default function AddProductForm() {
))} @@ -264,36 +343,49 @@ export default function AddProductForm() { Judul Spesifikasi {index + 1} handleSpecTitleChange(index, e.target.value)} /> -
+ +
+ + + {spec.file && ( +

{spec.file.name}

+ )}
))} - + */}