/* eslint-disable multiline-ternary */ import React, { useState } from 'react' import Webcam from 'react-webcam' import Header from '../../../components/Header/Header' import styles from './DocumentScanner.module.css' import { Button, Grid, Typography, StepLabel, Step, Stepper, Box } from '@mui/material' import SubmitButton from '../../../components/SubmitButton/SubmitButton' import { useTranslation } from 'react-i18next' import { userContext } from '../../../context/User' const DocumentScanner = () => { const { userData, oriUserData, setUserData } = userContext() const { t } = useTranslation() // JSON.stringify(oriUserData?.address) === let steps // use conditional statements to compare userData and oriUserData to determine the steps // 1st case: if only address is changed, then step=['POA'] // 2nd case: if only either name or gender is changed, then step=['POI'] // 3rd case: if only dob is changed, then step=['DOB'] // 4th case: If only address and name or gender is changed, then step=['POA', 'POI'] // 5th case: If only address and dob is changed, then step=['POA', 'DOB'] // 6th case: If only name or gender and dob is changed, then step=['POI', 'DOB'] // 7th case: If everything is changed, then step=['POA', 'POI', 'DOB'] if ( (userData.address !== oriUserData.address && userData.dob !== oriUserData.dob && userData.name !== oriUserData.name) || userData.gender !== oriUserData.gender ) { steps = ['POA', 'POI', 'DOB'] } else { if (userData.address !== oriUserData.address) { if ( userData.name !== oriUserData.name || userData.gender !== oriUserData.gender ) { steps = ['POA', 'POI'] } else if (userData.dob !== oriUserData.dob) { steps = ['POA', 'DOB'] } else { steps = ['POA'] } } else if ( userData.name !== oriUserData.name || userData.gender !== oriUserData.gender ) { if (userData.dob !== oriUserData.dob) { steps = ['POI', 'DOB'] } else { steps = ['POI'] } } else if (userData.dob !== oriUserData.dob) { steps = ['DOB'] } else { steps = [] } } const [documents, setDocuments] = useState({ POI: '', POA: '', DOB: '' }) const [activeStep, setActiveStep] = React.useState(0) const [doccu] = useState({ POI: '', POA: '', DOB: '' }) console.log(documents) const webcamRef = React.useRef(null) const capture = React.useCallback((doc) => { const imageSrc = webcamRef.current.getScreenshot() doccu[doc] = imageSrc setDocuments({ ...documents, POI: doccu.POI, POA: doccu.POA, DOB: doccu.DOB }) }) const handleNext = () => { if (activeStep === steps.length - 1) { setUserData({ ...userData, documents: documents }) } setActiveStep((prevActiveStep) => prevActiveStep + 1) } const handleBack = () => { setActiveStep((prevActiveStep) => prevActiveStep - 1) } const WebcamComponent = ({ doc }) => { return ( <>
{documents[doc] === '' ? ( ) : ( )}


{t('KINDLY_CLICK_THE_PICTURE_OF_YOUR_DOCUMENTS')}
) } return ( <>
{steps.map((label, index) => { const stepProps = {} const labelProps = {} return ( {label} ) })} {activeStep === steps.length ? ( {t('ALL_STEPS_COMPLETED')} ) : ( {activeStep === 0 ? ( ) : activeStep === 1 ? ( ) : ( activeStep === 2 && )} )} ) } export default DocumentScanner