From 1b48cc3dc624b85b8e22e475769453e767d5a36b Mon Sep 17 00:00:00 2001
From: rohan09-raj <rajrohan1914@gmail.com>
Date: Mon, 8 Aug 2022 13:09:01 +0530
Subject: integrated react webcam

---
 .../pages/Enrollment/PhotoCapture/PhotoCapture.jsx | 46 +++++++++++++++++++---
 1 file changed, 41 insertions(+), 5 deletions(-)

(limited to 'client/src/pages/Enrollment/PhotoCapture/PhotoCapture.jsx')

diff --git a/client/src/pages/Enrollment/PhotoCapture/PhotoCapture.jsx b/client/src/pages/Enrollment/PhotoCapture/PhotoCapture.jsx
index 0b30848..c4960c2 100644
--- a/client/src/pages/Enrollment/PhotoCapture/PhotoCapture.jsx
+++ b/client/src/pages/Enrollment/PhotoCapture/PhotoCapture.jsx
@@ -1,17 +1,44 @@
-import React from 'react'
+/* eslint-disable multiline-ternary */
+import React, { useState } from 'react'
+import Webcam from 'react-webcam'
+import { useNavigate } from 'react-router-dom'
 import Header from '../../../components/Header/Header'
-import CardScanner from '../../../components/Card/CardScanner'
+import SubmitButton from '../../../components/SubmitButton/SubmitButton'
 import styles from './PhotoCapture.module.css'
 import { Button, Grid, Typography } from '@mui/material'
 
 const PhotoCapture = () => {
+  const [photo, setPhoto] = useState()
+
+  const navigate = useNavigate()
+
+  const webcamRef = React.useRef(null)
+
+  const capture = React.useCallback(() => {
+    const imageSrc = webcamRef.current.getScreenshot()
+    setPhoto(imageSrc)
+  })
+
   return (
     <>
       <Header subheading="Enrollment" />
       <div className={styles.card__container}>
-        <CardScanner
-          image={`${process.env.PUBLIC_URL}/assets/images/capture.svg`}
-        />
+        {photo === '' ? (
+          <Webcam
+            audio={false}
+            height={300}
+            ref={webcamRef}
+            screenshotFormat="image/jpeg"
+            width={500}
+            videoConstraints={{
+              height: 300,
+              width: 500,
+              facingMode: 'user'
+            }}
+          />
+        ) : (
+          <img src={photo} />
+        )}
       </div>
       <Grid container columnSpacing={10} justifyContent="center">
         <Grid item>
@@ -20,6 +47,10 @@ const PhotoCapture = () => {
             size="large"
             type="submit"
             variant="contained"
+            onClick={(e) => {
+              e.preventDefault()
+              capture()
+            }}
           >
             Capture
           </Button>
@@ -30,6 +61,10 @@ const PhotoCapture = () => {
             size="large"
             type="submit"
             variant="contained"
+            onClick={(e) => {
+              e.preventDefault()
+              setPhoto('')
+            }}
           >
             Reset
           </Button>
@@ -45,6 +80,7 @@ const PhotoCapture = () => {
           </Typography>
         </Grid>
       </div>
+      <SubmitButton onClick={() => navigate('/enrollment/documents')} />
     </>
   )
 }
-- 
cgit 

