From 0a1a985de6e9a53896d2ba17e26d042009b3e1b4 Mon Sep 17 00:00:00 2001
From: rohan09-raj <rajrohan1914@gmail.com>
Date: Thu, 18 Aug 2022 16:12:35 +0530
Subject: Condtional update handling

---
 client/src/pages/Update/Biometric/Biometric.jsx | 38 +++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 3 deletions(-)

(limited to 'client/src/pages/Update/Biometric/Biometric.jsx')

diff --git a/client/src/pages/Update/Biometric/Biometric.jsx b/client/src/pages/Update/Biometric/Biometric.jsx
index c105ad8..72aa1b7 100644
--- a/client/src/pages/Update/Biometric/Biometric.jsx
+++ b/client/src/pages/Update/Biometric/Biometric.jsx
@@ -4,9 +4,12 @@ import PhotoCapture from '../PhotoCapture/PhotoCapture'
 import Fingerprint from '../Fingerprint/Fingerprint'
 import IrisScan from '../IrisScan/IrisScan'
 import BiometricSelect from '../BiometricSelect/BiometricSelect'
+import BackButton from '../../../components/BackButton/BackButton'
+import { userContext } from '../../../context/User'
 
 const Biometric = () => {
   const [page, setPage] = useState(4)
+  const { userData, oriUserData, setUserData } = userContext()
 
   const [formData, setFormData] = useState({
     photo: '',
@@ -27,14 +30,43 @@ const Biometric = () => {
     }
   }
 
+  const handleBack = () => {
+    if (!userData.photo) {
+      setUserData({ ...userData, photo: oriUserData.photo })
+    }
+    setPage(page - 1)
+  }
+
+  const handleSubmit = () => {
+    if (!userData.photo) {
+      setUserData({ ...userData, photo: oriUserData.photo })
+    }
+    setPage(page + 1)
+  }
+
   const conditionalButton = () => {
     switch (page) {
       case 0:
-        return <SubmitButton onClick={() => setPage(4)}>Next</SubmitButton>
+        return (
+          <>
+            <SubmitButton onClick={() => handleSubmit()}> Next</SubmitButton>
+            <BackButton onClick={() => handleBack()} />
+          </>
+        )
       case 1:
-        return <SubmitButton onClick={() => setPage(4)}>Next</SubmitButton>
+        return (
+          <>
+            <SubmitButton onClick={() => setPage(4)}> Next</SubmitButton>
+            <BackButton onClick={() => setPage(page - 1)} />
+          </>
+        )
       case 2:
-        return <SubmitButton onClick={() => setPage(4)}>Next</SubmitButton>
+        return (
+          <>
+            <SubmitButton onClick={() => setPage(4)}> Next</SubmitButton>
+            <BackButton onClick={() => setPage(page - 1)} />
+          </>
+        )
     }
   }
   return (
-- 
cgit 

