/* 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, Typography, StepLabel, Step, Stepper } from '@mui/material' import PopUpModal from '../../../components/Modal/Modal' import { useTranslation } from 'react-i18next' import { userContext } from '../../../context/User' import { toast } from 'react-toastify' import { useStyles } from './styles' import AudioAutoplay from '../../../components/AudioAutoplay/AudioAutoplay' const DocumentScanner = () => { const { userData, oriUserData, setUserData } = userContext() const { t } = useTranslation() let steps 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: '' }) const classes = useStyles() 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 && documents.POI !== '' && documents.POA !== '' && documents.DOB !== '' ) { setUserData({ ...userData, documents: documents }) } else if (documents.POI !== '' && documents.POA !== '') { toast.error(t('SCAN_YOUR_DOCUMENT')) } else if (documents.POI !== '' && documents.DOB !== '') { toast.error(t('SCAN_YOUR_DOCUMENT')) } else if (documents.POA !== '' && documents.DOB !== '') { toast.error(t('SCAN_YOUR_DOCUMENT')) } else if (documents.POI !== '') { toast.error(t('SCAN_YOUR_DOCUMENT')) } else if (documents.POA !== '') { toast.error(t('SCAN_YOUR_DOCUMENT')) } else if (documents.DOB !== '') { toast.error(t('SCAN_YOUR_DOCUMENT')) } else { toast.error(t('SCAN_YOUR_DOCUMENT')) } if ( (!documents.POI && activeStep === 0) || (!documents.POA && activeStep === 1) || (!documents.DOB && activeStep === 2) ) { toast.error(t('SCAN_YOUR_DOCUMENT')) } else { 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.length !== 0 && (
  • {t('CONSISTS_OF_3_STEPS')}
    • {t('PROOF_OF_IDENTITY')}
    • {t(t('PROOF_OF_ADDRESS'))}
    • {t('PROOF_OF_DOB')}
  • {t( 'ENSURE_THAT_YOUR_DOCUMENTS_ARE_IN_THE_CENTER_OF_THE_FRAME' )}
  • {t( 'YOU_WONT_BE_ABLE_TO_PROCEED_UNTIL_YOU_HAVE_SCANNED_ALL_THE_REQUIRED_DOCUMENTS' )}
} /> )}
{steps.map((label, index) => { const stepProps = {} const labelProps = {} return ( {label} ) })} {activeStep === steps.length ? ( steps.length === 0 ? (
{t("YOU_HAVEN'T_UPDATED_ANYTHING")} {t('YOU_MAY_EITHER_UPDATE_OR_MOVE_TO_NEXT_STEP')}
) : ( {t('ALL_STEPS_COMPLETED')} ) ) : ( {activeStep === 0 ? ( ) : activeStep === 1 ? ( ) : ( activeStep === 2 && )} )}
) } export default DocumentScanner