From 83d1a1c558293e1b14c9a5847628e7661f749c66 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Mon, 21 Oct 2024 14:54:11 +0700 Subject: initial commit --- app/lib/camera/component/camera.tsx | 79 +++++++++++++++++++++++++++++ app/lib/camera/component/cardFoto.tsx | 27 ++++++++++ app/lib/camera/component/hedear.tsx | 21 ++++++++ app/lib/camera/component/pakageCamera.tsx | 44 ++++++++++++++++ app/lib/camera/component/scannerBarcode.tsx | 56 ++++++++++++++++++++ app/lib/camera/component/sjCamera.tsx | 48 ++++++++++++++++++ app/lib/camera/hooks/useCamera.ts | 32 ++++++++++++ app/lib/camera/hooks/useCameraStore.ts | 22 ++++++++ 8 files changed, 329 insertions(+) create mode 100644 app/lib/camera/component/camera.tsx create mode 100644 app/lib/camera/component/cardFoto.tsx create mode 100644 app/lib/camera/component/hedear.tsx create mode 100644 app/lib/camera/component/pakageCamera.tsx create mode 100644 app/lib/camera/component/scannerBarcode.tsx create mode 100644 app/lib/camera/component/sjCamera.tsx create mode 100644 app/lib/camera/hooks/useCamera.ts create mode 100644 app/lib/camera/hooks/useCameraStore.ts (limited to 'app/lib/camera') diff --git a/app/lib/camera/component/camera.tsx b/app/lib/camera/component/camera.tsx new file mode 100644 index 0000000..b398616 --- /dev/null +++ b/app/lib/camera/component/camera.tsx @@ -0,0 +1,79 @@ +import { CameraSharp } from "@mui/icons-material"; +import { Button, IconButton } from "@mui/material"; +import Image from "next/image"; +import React, { useRef } from "react"; +import Webcam from "react-webcam"; + +interface WebcamCaptureProps { + image: string | null; + setImage: (image: string | null) => void; + isWebcamVisible: boolean; + setIsWebcamVisible: (isVisible: boolean) => void; +} + +const WebcamCapture: React.FC = ({ + image, + setImage, + isWebcamVisible, + setIsWebcamVisible, +}) => { + const webcamRef = useRef(null); + + // Mengambil foto dari webcam + const capture = () => { + const image = webcamRef.current?.getScreenshot(); + setIsWebcamVisible(false); + setImage(image || null); + }; + + const takePicture = () => { + setImage(null); + setIsWebcamVisible(true); + }; + + // Mengatur ukuran webcam + const videoConstraints = { + width: 500, + height: 480, + facingMode: { + exact: "environment" // untuk kamera belakang + }, + }; + + return ( +
+ {!isWebcamVisible && ( + + )} + + {isWebcamVisible && ( +
+ + capture()}> + + +
+ )} + {image && ( +
+ Captured +
+ )} +
+ ); +}; + +export default WebcamCapture; diff --git a/app/lib/camera/component/cardFoto.tsx b/app/lib/camera/component/cardFoto.tsx new file mode 100644 index 0000000..34da216 --- /dev/null +++ b/app/lib/camera/component/cardFoto.tsx @@ -0,0 +1,27 @@ +import { Card, CardContent, Typography } from "@mui/material"; +import Image from "next/image"; +import React from "react"; +import useCameraStore from "../hooks/useCameraStore"; + +const CardFotos = () => { + const { imagePackage } = useCameraStore(); + return ( + + Captured + + + Lizard + + + + ); +} + +export default CardFotos diff --git a/app/lib/camera/component/hedear.tsx b/app/lib/camera/component/hedear.tsx new file mode 100644 index 0000000..5cf3f1d --- /dev/null +++ b/app/lib/camera/component/hedear.tsx @@ -0,0 +1,21 @@ +// components/Header.tsx +import Image from "next/image"; + +export default function Header() { + return ( + + ); +} diff --git a/app/lib/camera/component/pakageCamera.tsx b/app/lib/camera/component/pakageCamera.tsx new file mode 100644 index 0000000..e0c7158 --- /dev/null +++ b/app/lib/camera/component/pakageCamera.tsx @@ -0,0 +1,44 @@ +import React from "react"; +import useCameraStore from "../hooks/useCameraStore"; +import { IconButton } from "@mui/material"; +import { PhotoCameraFrontOutlined } from "@mui/icons-material"; + +const PackageCamera: React.FC = () => { + const { setImagePackage } = useCameraStore(); + const handleCapture = (event: React.ChangeEvent) => { + const file = event.target.files?.[0]; + if (file) { + const reader = new FileReader(); + reader.onloadend = () => { + setImagePackage(reader.result as string); + }; + reader.readAsDataURL(file); + } + }; + + return ( +
+ + +
+ ); +}; + +export default PackageCamera; diff --git a/app/lib/camera/component/scannerBarcode.tsx b/app/lib/camera/component/scannerBarcode.tsx new file mode 100644 index 0000000..3079e33 --- /dev/null +++ b/app/lib/camera/component/scannerBarcode.tsx @@ -0,0 +1,56 @@ +import { QrCode2 } from "@mui/icons-material"; +import { Button, TextField } from "@mui/material"; +import dynamic from "next/dynamic"; +import React, { useState } from "react"; +import useCameraStore from "../hooks/useCameraStore"; + +const BarcodeScannerComponent = dynamic( + () => import("react-qr-barcode-scanner"), + { ssr: false } +); +const BarcodeScanner: React.FC = () => { + const { barcode, setBarcode } = useCameraStore(); + const [isCameraActive, setIsCameraActive] = useState(false); + + return ( +
+ + + {isCameraActive && ( + { + if (result) { + setBarcode(result.getText()); + setIsCameraActive(false); + } + }} + /> + )} + +
+ setBarcode(e.target.value) } + InputLabelProps={{ + shrink: true, // Label akan selalu berada di atas (outline) + }} + /> +
+
+ ); +}; + +export default BarcodeScanner; diff --git a/app/lib/camera/component/sjCamera.tsx b/app/lib/camera/component/sjCamera.tsx new file mode 100644 index 0000000..5cc39ad --- /dev/null +++ b/app/lib/camera/component/sjCamera.tsx @@ -0,0 +1,48 @@ +import React from "react"; +import useCameraStore from "../hooks/useCameraStore"; +import { IconButton } from "@mui/material"; +import { PendingActions } from "@mui/icons-material"; + +const SjCamera: React.FC = () => { + const { setImageSj } = useCameraStore(); + const handleSuratJalanCapture = ( + event: React.ChangeEvent + ) => { + const file = event.target.files?.[0]; + if (file) { + const reader = new FileReader(); + reader.onloadend = () => { + setImageSj(reader.result as string); + }; + reader.readAsDataURL(file); + } + }; + + return ( + <> +
+ + +
+ + ); +}; + +export default SjCamera; diff --git a/app/lib/camera/hooks/useCamera.ts b/app/lib/camera/hooks/useCamera.ts new file mode 100644 index 0000000..d85d978 --- /dev/null +++ b/app/lib/camera/hooks/useCamera.ts @@ -0,0 +1,32 @@ +import { useState } from "react" + +const useCamera = () => { + + const [imageSJ, setImageSj] = useState(null) + const [imagePackage, setImagePackage] = useState(null) + const [barcode, setBarcode] = useState(null) + + const [isWebcamVisibleSj, setIsWebcamVisibleSJ] = useState(false) + const [isWebcamVisiblePackage, setIsWebcamVisiblePackage] = useState(false) + + const handleSubmit = () => { + setIsWebcamVisibleSJ(false) + } + + + return { + barcode, + setBarcode, + imageSJ, + imagePackage, + setImageSj, + setImagePackage, + isWebcamVisibleSj, + isWebcamVisiblePackage, + setIsWebcamVisibleSJ, + setIsWebcamVisiblePackage, + handleSubmit + } +} + +export default useCamera \ No newline at end of file diff --git a/app/lib/camera/hooks/useCameraStore.ts b/app/lib/camera/hooks/useCameraStore.ts new file mode 100644 index 0000000..c922d1c --- /dev/null +++ b/app/lib/camera/hooks/useCameraStore.ts @@ -0,0 +1,22 @@ +// store/useCameraStore.ts +import { create } from 'zustand' + +interface CameraStore { + barcode: string | null + setBarcode: (barcode: string) => void + imageSj: string | null + setImageSj: (image: string) => void + imagePackage: string | null + setImagePackage: (image: string) => void +} + +const useCameraStore = create((set) => ({ + barcode: null, + setBarcode: (barcode: string) => set({ barcode: barcode }), + imageSj: null, + setImageSj: (image: string) => set({ imageSj: image }), + imagePackage: null, + setImagePackage: (image: string) => set({ imagePackage: image }), +})) + +export default useCameraStore \ No newline at end of file -- cgit v1.2.3