From f47c3f4349cb68460dadf1fc381e3ceb52fe009a Mon Sep 17 00:00:00 2001
From: rohan09-raj <rajrohan1914@gmail.com>
Date: Fri, 19 Aug 2022 21:06:48 +0530
Subject: minor fixes

---
 .../src/pages/Enrollment/Agreement/Agreement.jsx   | 110 +++++++++++++--------
 1 file changed, 71 insertions(+), 39 deletions(-)

(limited to 'client/src/pages/Enrollment/Agreement/Agreement.jsx')

diff --git a/client/src/pages/Enrollment/Agreement/Agreement.jsx b/client/src/pages/Enrollment/Agreement/Agreement.jsx
index d5690f3..cf74d46 100644
--- a/client/src/pages/Enrollment/Agreement/Agreement.jsx
+++ b/client/src/pages/Enrollment/Agreement/Agreement.jsx
@@ -3,71 +3,103 @@ import Header from '../../../components/Header/Header'
 import CardAgreement from '../../../components/Card/CardAgreement'
 import styles from './Agreement.module.css'
 import Input from '../../../components/Input/Input'
-import { Grid, Button } from '@mui/material'
+import { Button, Typography } from '@mui/material'
 import { useTranslation } from 'react-i18next'
 import { sendOTP } from '../../../services/apiservice'
 import { userContext } from '../../../context/User'
 import { useMutation } from 'react-query'
+import { ToastContainer, toast } from 'react-toastify'
+import 'react-toastify/dist/ReactToastify.css'
 
-const Agreement = () => {
+const Agreement = ({ unverified, setUnverified }) => {
   const { t } = useTranslation()
-  const [otp, setOtp] = useState(0)
+  const [otp, setOtp] = useState()
+  const [disabled, setDisabled] = useState(false)
+  const [finalDisable, setFinalDisable] = useState(false)
+  const [show, setShow] = useState(false)
   const { userData } = userContext()
   console.log(userData)
   const { data, mutate } = useMutation(() =>
     sendOTP({ mobile: `+91${userData?.mobile}` })
   )
 
+  console.log('Disabled: ', disabled, 'Final Disable: ', finalDisable)
+
   const verifyOTP = () => {
     if (data?.data?.otpCode === Number(otp)) {
-      console.log('Verified', data?.data?.otpCode, otp)
+      console.log('Disabled: ', disabled, 'Final Disable: ', finalDisable)
+      setFinalDisable(true)
+      setDisabled(true)
+      setShow(false)
+      setUnverified(false)
+      toast.success(t('OTP_VERIFIED!'))
     } else {
-      console.log(typeof otp)
-      console.log(typeof data?.data?.otpCode)
-      console.log('Incorrect OTP', data?.data?.otpCode, otp)
+      toast.error(t('INCORRECT_OTP!'))
     }
   }
 
+  const sendResendOTP = () => {
+    setTimeout(() => {
+      if (finalDisable === false) {
+        console.log('Disabled: ', disabled, 'Final Disable: ', finalDisable)
+        setDisabled(false)
+      }
+    }, 30000)
+  }
+
   return (
     <>
+      <ToastContainer
+        autoClose={1000}
+        hideProgressBar={true}
+        theme={'colored'}
+      />
       <Header subheading={t('ENROLLMENT')} />
       <div className={styles.card__container}>
         <CardAgreement
           image={`${process.env.PUBLIC_URL}/assets/images/agreement.svg`}
         />
       </div>
-      <Input
-        type="number"
-        id="otp"
-        value={otp}
-        label={t('PLEASE_VERIFY_YOUR_IDENTITY')}
-        onChange={(e) => setOtp(e.target.value)}
-        placeholder="XXXXXX"
-      />
-      <Grid container columnSpacing={10} justifyContent="center">
-        <Grid item>
-          <Button
-            color="primary"
-            size="large"
-            type="submit"
-            variant="contained"
-            onClick={() => mutate()}
-          >
-            {t('SEND_OTP')}
-          </Button>
-        </Grid>
-        <Grid item>
-          <Button
-            color="primary"
-            size="large"
-            type="submit"
-            variant="contained"
-            onClick={() => verifyOTP()}
-          >
-            {t('VERIFY_OTP')}
-          </Button>
-        </Grid>
-      </Grid>
+      <div className={styles.card__elements}>
+        <Typography>{t('PLEASE_VERIFY_YOUR_IDENTITY')}</Typography>
+        <Button
+          color="primary"
+          size="large"
+          type="submit"
+          variant="contained"
+          disabled={disabled}
+          onClick={() => {
+            mutate()
+            setDisabled(true)
+            setShow(true)
+            sendResendOTP()
+          }}
+        >
+          {show ? t('RESEND') : t('SEND_OTP')}
+        </Button>
+        {show && (
+          <>
+            <Input
+              type="number"
+              id="otp"
+              value={otp}
+              onChange={(e) => setOtp(e.target.value)}
+              placeholder="XXXXXX"
+            />
+            <Button
+              color="primary"
+              size="large"
+              type="submit"
+              variant="contained"
+              onClick={() => {
+                verifyOTP()
+              }}
+            >
+              {t('VERIFY_OTP')}
+            </Button>
+          </>
+        )}
+      </div>
     </>
   )
 }
-- 
cgit 

