From 1c9a3d21cc3479d299181d98fb895614e0aaf649 Mon Sep 17 00:00:00 2001
From: rohan09-raj <rajrohan1914@gmail.com>
Date: Tue, 16 Aug 2022 12:15:55 +0530
Subject: random bullshit

---
 .../src/pages/Update/Demographic/Demographic.jsx   | 77 ++++++++++------------
 1 file changed, 33 insertions(+), 44 deletions(-)

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

diff --git a/client/src/pages/Update/Demographic/Demographic.jsx b/client/src/pages/Update/Demographic/Demographic.jsx
index 8ec9e82..27a162a 100644
--- a/client/src/pages/Update/Demographic/Demographic.jsx
+++ b/client/src/pages/Update/Demographic/Demographic.jsx
@@ -3,10 +3,17 @@ import Address from '../Address/Address'
 import DocumentScanner from '../DocumentScanner/DocumentScanner'
 import SubmitButton from '../../../components/SubmitButton/SubmitButton'
 import FormOne from '../FormOne/FormOne'
-import { validEmail, validMobileNumber, validPincode } from '../../../components/RegEx/RegEx'
+import {
+  validEmail,
+  validMobileNumber,
+  validPincode,
+  validString
+} from '../../../components/RegEx/RegEx'
 import UpdateSelect from '../UpdateSelect/UpdateSelect'
+import { useTranslation } from 'react-i18next'
 
 const Demographic = () => {
+  const { t } = useTranslation()
   const [page, setPage] = useState(0)
 
   const [formData, setFormData] = useState({
@@ -28,58 +35,48 @@ const Demographic = () => {
     address: ''
   })
 
-  function handleSubmit () {
+  const handleSubmit = () => {
     if (page === 0) {
-        if (formData.name === '' || formData.name.length < 1) {
-        return alert('Please enter your name')
+      if (formData.name === '' || formData.name.length < 1) {
+        return alert(t('PLEASE_ENTER_YOUR_NAME'))
+      } else if (!validString.test(formData.name)) {
+        return alert(t('PLEASE_ENTER_VALID_NAME'))
       } else if (formData.gender === '') {
-        return alert('Please select your gender')
+        return alert(t('PLEASE_SELECT_YOUR_GENDER'))
       } else if (formData.mobile === '') {
-        return alert('Please enter your mobile number')
+        return alert(t('PLEASE_ENTER_YOUR_MOBILE_NUMBER'))
       } else if (!validMobileNumber.test(formData.mobile)) {
-        return alert('Please enter valid mobile number')
+        return alert(t('PLEASE_ENTER_VALID_MOBILE_NUMBER'))
       } else if (formData.email === '') {
-        return alert('Please enter your email')
+        return alert(t('PLEASE_ENTER_YOUR_EMAIL'))
       } else if (!validEmail.test(formData.email)) {
-        return alert('Please enter valid email')
+        return alert(t('PLEASE_ENTER_VALID_EMAIL'))
       } else {
         setPage(page + 1)
       }
     } else if (page === 1) {
-      if (formData.mobile === '') {
-        return alert('Please enter your mobile number')
-      } else if (!validMobileNumber.test(formData.mobile)) {
-        return alert('Please enter valid mobile number')
-      } else if (formData.email === '') {
-        return alert('Please enter your email')
-      } else if (!validEmail.test(formData.email)) {
-        return alert('Please enter valid email')
-      } else {
-        setPage(page + 1)
-      }
-    } else if (page === 2) {
       if (formData.country === '') {
-        return alert('Please select your country')
+        return alert(t('PLEASE_SELECT_YOUR_COUNTRY'))
       } else if (formData.state === '') {
-        return alert('Please select your state')
+        return alert(t('PLEASE_SELECT_YOUR_STATE'))
       } else if (formData.district === '') {
-        return alert('Please select your district')
+        return alert(t('PLEASE_SELECT_YOUR_DISTRICT'))
       } else if (formData.village === '') {
-        return alert('Please enter your village')
+        return alert(t('PLEASE_ENTER_YOUR_VILLAGE'))
       } else if (formData.houseNo === '') {
-        return alert('Please enter your house number')
+        return alert(t('PLEASE_ENTER_YOUR_HOUSE_NUMBER'))
       } else if (formData.street === '') {
-        return alert('Please enter your street')
+        return alert(t('PLEASE_ENTER_YOUR_STREET'))
       } else if (formData.locality === '') {
-        return alert('Please enter your locality')
+        return alert(t('PLEASE_ENTER_YOUR_LOCALITY'))
       } else if (formData.postOffice === '') {
-        return alert('Please enter your post office')
+        return alert(t('PLEASE_ENTER_YOUR_AREA_POST_OFFICE'))
       } else if (formData.landmark === '') {
-        return alert('Please enter your landmark')
+        return alert(t('PLEASE_ENTER_NEAREST_LANDMARK'))
       } else if (formData.pincode === '') {
-        return alert('Please enter your pincode')
+        return alert(t('PLEASE_ENTER_YOUR_AREA_PINCODE'))
       } else if (!validPincode.test(formData.pincode)) {
-        return alert('Please enter valid pincode')
+        return alert(t('PLEASE_ENTER_VALID_PINCODE'))
       } else {
         setFormData({
           ...formData,
@@ -108,21 +105,13 @@ const Demographic = () => {
   const conditionalButton = () => {
     switch (page) {
       case 0:
-        return <SubmitButton onClick={handleSubmit}>
-            Next
-          </SubmitButton>
+        return <SubmitButton onClick={handleSubmit}>Next</SubmitButton>
       case 1:
-        return <SubmitButton onClick={handleSubmit}>
-            Next
-          </SubmitButton>
+        return <SubmitButton onClick={handleSubmit}>Next</SubmitButton>
       case 2:
-        return <SubmitButton onClick={handleSubmit}>
-            Next
-          </SubmitButton>
+        return <SubmitButton onClick={handleSubmit}>Next</SubmitButton>
       default:
-        return <SubmitButton onClick={handleSubmit}>
-            Next
-          </SubmitButton>
+        return <SubmitButton onClick={handleSubmit}>Next</SubmitButton>
     }
   }
   return (
-- 
cgit 

