From 83d1a1c558293e1b14c9a5847628e7661f749c66 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Mon, 21 Oct 2024 14:54:11 +0700 Subject: initial commit --- app/page.tsx | 248 +++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 156 insertions(+), 92 deletions(-) (limited to 'app/page.tsx') diff --git a/app/page.tsx b/app/page.tsx index 433c8aa..ccfb7f7 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,101 +1,165 @@ +"use client"; import Image from "next/image"; +import PackageCamera from "./lib/camera/component/pakageCamera"; +import BarcodeScanner from "./lib/camera/component/scannerBarcode"; +import SjCamera from "./lib/camera/component/sjCamera"; +import useCameraStore from "./lib/camera/hooks/useCameraStore"; +import Header from "./lib/camera/component/hedear"; +import { Button } from "@mui/material"; +import { SaveAsOutlined } from "@mui/icons-material"; +import axios from "axios"; +import odooApi from "./lib/api/odooApi"; +import { useEffect, useState } from "react"; +import { useRouter } from "next/navigation"; +import { getAuth } from "./lib/api/auth"; export default function Home() { + const [isLogin, setIsLogin] = useState(true); + const { + barcode, + imageSj, + imagePackage, + setBarcode, + setImageSj, + setImagePackage, + } = useCameraStore(); + const [isLoading, setIsLoading] = useState(false); + + const router = useRouter(); + + useEffect(() => { + const token = getAuth(); + + if (!token) { + router.push("/login"); + } else { + setIsLogin(true); + } + }, [router]); + + const handleSubmit = async (event: React.FormEvent) => { + event.preventDefault(); + setIsLoading(true); + + if (!barcode || !imageSj || !imagePackage) { + alert("Barcode dan gambar harus tersedia."); + setIsLoading(false); + return; + } + + try { + const newSjImage = imageSj.replace(/^.*?,/, ""); + const newPackageImage = imagePackage.replace(/^.*?,/, ""); + // const method = 'PUT'; + + const data = { + sj_document: newSjImage, // Kirim base64 lengkap dengan prefix + paket_document: newPackageImage, // Kirim base64 lengkap dengan prefix + }; + + const response = await odooApi( + "PUT", + `/api/v1/stock-picking/${barcode}/documentation`, + data + ); + console.log(response); + if (response.status.code == 200) { + alert("Berhasil Submit Data"); + setBarcode(""); + setImageSj(""); + setImagePackage(""); + setIsLoading(false); + } + return response.data; + } catch (error: unknown) { + if (error instanceof Error) { + console.error("Error mengirim data:", error.message); + } else if (axios.isAxiosError(error)) { + console.error("Error:", error.response?.data); + } else { + console.error("Unknown error:", error); + } + setIsLoading(false); + } + }; + return ( -
-
- Next.js logo -
    -
  1. - Get started by editing{" "} - - app/page.tsx - - . -
  2. -
  3. Save and see your changes instantly.
  4. -
+
+
+ {isLogin && ( +
+
+
+ +
+
+ +
+ + +
+
-
- - Vercel logomark - Deploy now - - - Read our docs - + {imageSj && ( + <> + +
+ Captured +
+ + )} + +
+ + {imagePackage && ( + <> + +
+ Captured +
+ + )} +
+
+ +
+ +
+ )} + {!isLogin && ( +
+
+

Loading...

+
-
- + )}
); } -- cgit v1.2.3