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

---
 .../Update/DocumentScanner/DocumentScanner.jsx     | 54 +++++++++++++++++++---
 1 file changed, 48 insertions(+), 6 deletions(-)

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

diff --git a/client/src/pages/Update/DocumentScanner/DocumentScanner.jsx b/client/src/pages/Update/DocumentScanner/DocumentScanner.jsx
index 14fb769..f6fe0b5 100644
--- a/client/src/pages/Update/DocumentScanner/DocumentScanner.jsx
+++ b/client/src/pages/Update/DocumentScanner/DocumentScanner.jsx
@@ -17,13 +17,55 @@ import { useTranslation } from 'react-i18next'
 import { userContext } from '../../../context/User'
 
 const DocumentScanner = () => {
-  const { userData, setUserData } = userContext()
+  const { userData, oriUserData, setUserData } = userContext()
   const { t } = useTranslation()
-  const steps = [
-    t('PROOF_OF_IDENTITY'),
-    t('PROOF_OF_ADDRESS'),
-    t('PROOF_OF_DOB')
-  ]
+
+  // 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)
 
-- 
cgit 

