From 352000c186a2765416cd2fab6693e68bb62e9e53 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 30 Sep 2025 16:20:05 +0700 Subject: done --- app/login/page.tsx | 2 +- app/page.tsx | 150 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 133 insertions(+), 19 deletions(-) diff --git a/app/login/page.tsx b/app/login/page.tsx index 3ccefa4..c0d7ab8 100644 --- a/app/login/page.tsx +++ b/app/login/page.tsx @@ -154,7 +154,7 @@ const Login = () => {
-
+
(true); const [isDriver, setIsDriver] = useState(false); const [isDispatch, setIsDispatch] = useState(false); + const [shippingMethod, setShippingMethod] = useState(""); + const [shipTouched, setShipTouched] = useState(false); + const { barcode, @@ -42,7 +46,6 @@ export default function Home() { router.push("/login"); return; } - // baca role dari cookie yang diset saat login const roleCookie = (getCookie("web_role") as string | undefined)?.toLowerCase() as Role | undefined; const role: Role | null = roleCookie === "driver" || roleCookie === "dispatch" ? roleCookie : null; @@ -61,16 +64,25 @@ export default function Home() { return; } - // Validasi sesuai role yang dipilih di login + // Dispatch: shipping method wajib + if (isDispatch) setShipTouched(true); + if (isDispatch && !shippingMethod) { + alert("Shipping Method wajib dipilih."); + setIsLoading(false); + return; + } + + + // Validasi foto sesuai role & shipping method if (isDispatch) { - // Dispatch: dispatch wajib, SJ opsional if (!imageDispatch) { alert("Foto Dispatch Wajib Diisi"); setIsLoading(false); return; } + // SJ opsional untuk self_pickup & ekspedisi → tidak divalidasi } else { - // Driver (atau non-dispatch): SJ & Penerima wajib + // Driver: SJ & Penerima wajib if (!imageSj || !imagePackage) { alert("Barcode, Foto SJ, dan Foto Penerima harus tersedia."); setIsLoading(false); @@ -79,7 +91,6 @@ export default function Home() { } try { - // siapkan base64 tanpa prefix, kalau kosong biarkan undefined const newSjImage = imageSj ? imageSj.replace(/^.*?,/, "") : undefined; const newPackageImage = imagePackage ? imagePackage.replace(/^.*?,/, "") : undefined; const newDispatchImage = @@ -87,15 +98,17 @@ export default function Home() { ? imageDispatch.replace(/^.*?,/, "") : imageDispatch || undefined; - // hanya kirim field yang ada + // Kirim hanya yang ada const submittedSj = !!newSjImage; const submittedPackage = !!newPackageImage; - const submittedDispatch = !!newDispatchImage && !isDriver; // dispatch hanya untuk non-driver + const submittedDispatch = !!newDispatchImage && !isDriver; const data: Record = {}; if (submittedSj) data.sj_document = newSjImage!; if (submittedPackage) data.paket_document = newPackageImage!; if (submittedDispatch) data.dispatch_document = newDispatchImage!; + // (opsional) kirim shippingMethod jika backend mau simpan + if (isDispatch && shippingMethod) data.shipping_method = shippingMethod; const response = (await odooApi( "PUT", @@ -106,7 +119,7 @@ export default function Home() { if (response?.status?.code === 200) { alert("Berhasil Submit Data"); setBarcode(""); - + // Bersihkan HANYA yang dikirim if (submittedSj) setImageSj(""); if (submittedPackage) setImagePackage(""); if (submittedDispatch) setImageDispatch(""); @@ -128,6 +141,19 @@ export default function Home() { } }; + // dispatch: SJ hanya utk self_pickup & ekspedisi + const showSjForDispatch = + isDispatch && (shippingMethod === "self_pickup" || shippingMethod === "ekspedisi"); + + // dispatch: kamera dispatch tampil utk semua method (asal sudah dipilih) + const showDispatchForDispatch = isDispatch && shippingMethod !== ""; + + // preview SJ: sembunyikan kalau dispatch belum pilih method + const showSjPreview = !!imageSj && (!isDispatch || showSjForDispatch); + + // preview Dispatch: sembunyikan kalau dispatch belum pilih method + const showDispatchPreview = !!imageDispatch && (!isDispatch || showDispatchForDispatch); + return (
@@ -138,27 +164,95 @@ export default function Home() {
+ {/* Shipping Method (khusus dispatch) */} + {isDispatch && ( +
+ + {/* shrink = kunci agar label tidak tumpuk dengan placeholder */} + Shipping Method + + {shipTouched && !shippingMethod && ( + Wajib pilih shipping method. + )} + +
+ )} + +
- {/* SJ: driver wajib, dispatch opsional → tampil untuk semua */} - - {/* Penerima: tidak diperlukan dispatch → sembunyikan saat dispatch */} - {!isDispatch && } - {/* Dispatch: wajib untuk dispatch; non-driver boleh tampil */} - {!isDriver && } + {isDispatch ? ( + <> + {showSjForDispatch && } + {showDispatchForDispatch && } + {/* dispatch TIDAK perlu kamera penerima */} + + ) : ( + <> + {/* driver / non-dispatch */} + + + {/* driver tidak menampilkan kamera dispatch */} + + )}
+
- {imageSj && ( + {/* Preview SJ */} + {showSjPreview && ( <>
Captured +
+ + )} + + {/* Preview Penerima (hanya non-dispatch) */} + {!isDispatch && imagePackage && ( + <> + +
+ Captured )} + {/* Preview Dispatch */} + {showDispatchPreview && ( + <> + +
+ Captured +
+ + )} + +
- {imagePackage && ( + {!isDispatch && imagePackage && ( <>