diff options
author | rohan09-raj <rajrohan1914@gmail.com> | 2022-08-19 00:10:29 +0530 |
---|---|---|
committer | rohan09-raj <rajrohan1914@gmail.com> | 2022-08-19 00:10:42 +0530 |
commit | 953dd3c954411d92811415cc9be4a7c7d76ab185 (patch) | |
tree | 0bd2aa118361bbe70f0ac0b62da3c12fa1cb902f /client | |
parent | a9ed2c9daa5a3e065401996daf922f59de7f0101 (diff) |
added otp support
Diffstat (limited to 'client')
-rw-r--r-- | client/src/pages/Enrollment/Agreement/Agreement.jsx | 30 | ||||
-rw-r--r-- | client/src/services/apiservice.js | 5 |
2 files changed, 32 insertions, 3 deletions
diff --git a/client/src/pages/Enrollment/Agreement/Agreement.jsx b/client/src/pages/Enrollment/Agreement/Agreement.jsx index 9764110..d5690f3 100644 --- a/client/src/pages/Enrollment/Agreement/Agreement.jsx +++ b/client/src/pages/Enrollment/Agreement/Agreement.jsx @@ -1,13 +1,33 @@ -import React from 'react' +import React, { useState } from 'react' 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 { useTranslation } from 'react-i18next' +import { sendOTP } from '../../../services/apiservice' +import { userContext } from '../../../context/User' +import { useMutation } from 'react-query' const Agreement = () => { const { t } = useTranslation() + const [otp, setOtp] = useState(0) + const { userData } = userContext() + console.log(userData) + const { data, mutate } = useMutation(() => + sendOTP({ mobile: `+91${userData?.mobile}` }) + ) + + const verifyOTP = () => { + if (data?.data?.otpCode === Number(otp)) { + console.log('Verified', data?.data?.otpCode, otp) + } else { + console.log(typeof otp) + console.log(typeof data?.data?.otpCode) + console.log('Incorrect OTP', data?.data?.otpCode, otp) + } + } + return ( <> <Header subheading={t('ENROLLMENT')} /> @@ -17,9 +37,11 @@ const Agreement = () => { /> </div> <Input - type="text" + 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"> @@ -29,6 +51,7 @@ const Agreement = () => { size="large" type="submit" variant="contained" + onClick={() => mutate()} > {t('SEND_OTP')} </Button> @@ -39,8 +62,9 @@ const Agreement = () => { size="large" type="submit" variant="contained" + onClick={() => verifyOTP()} > - {t('RESEND')} + {t('VERIFY_OTP')} </Button> </Grid> </Grid> diff --git a/client/src/services/apiservice.js b/client/src/services/apiservice.js index 305d557..0aa9337 100644 --- a/client/src/services/apiservice.js +++ b/client/src/services/apiservice.js @@ -18,3 +18,8 @@ export const updateUser = async (id, payload) => { const response = await apiClient.patch(`/user/${id}`, payload) return response } + +export const sendOTP = async (payload) => { + const response = await apiClient.post('/otp', payload) + return response +} |