|
1 | 1 | import EmployeeVerificationForm from '@/components/employeeVerificationForm' |
| 2 | +import ImageVerificationSingleEmployee from '@/components/imageVerificationSingleEmployee' |
2 | 3 | import OTPVerificationSingleEmployee from '@/components/otpVerificationSingleEmployee' |
| 4 | +import { SERVER_URL } from '@/constants/config' |
| 5 | +import axios from 'axios' |
3 | 6 | import React, { useState } from 'react' |
| 7 | +import { toast } from 'react-toastify' |
4 | 8 |
|
5 | 9 | const SingleEmployee = () => { |
6 | 10 | const [stage, setStage] = useState('details') //details || verifyOTP || verifyImage |
7 | 11 | const [employeeData, setEmployeeData] = useState({}) |
| 12 | + // const [employeeData, setEmployeeData] = useState({name: 'rupesh', gender: 'male', phone: '9137357003'}) |
8 | 13 | const [otp, setOtp] = useState(''); |
| 14 | + const [mobileNumber, setMobileNumber] = useState(null) |
9 | 15 |
|
10 | | - const onProceedHandler = (formData) => { |
| 16 | + const onProceedHandler = async (formData) => { |
11 | 17 | setEmployeeData(formData) |
12 | | - setStage('verifyOTP') |
| 18 | + const mob = await getMobileNumberFromCardNumber(formData.cardNumber) |
| 19 | + setMobileNumber(mob) |
| 20 | + // sendOTP(mob) |
| 21 | + sendOTP(9137357003) |
| 22 | + // setStage('verifyOTP') |
| 23 | + } |
| 24 | + |
| 25 | + const getMobileNumberFromCardNumber = async (cardNumber) => { |
| 26 | + // setMobileNumber(8383238282) |
| 27 | + return 8383238282 |
| 28 | + } |
| 29 | + |
| 30 | + const sendOTP = async (phoneNumber) => { |
| 31 | + axios |
| 32 | + .post(`${SERVER_URL}/apis/sendOTP`, { phone: phoneNumber }) |
| 33 | + .then(() => setStage("verifyOTP")) |
| 34 | + .catch((err) => { |
| 35 | + console.error(err); |
| 36 | + toast.error("Some error sending OTP") |
| 37 | + }); |
13 | 38 | } |
14 | 39 |
|
15 | 40 | const verifyOTPHandler = () => { |
16 | 41 | console.log(otp) |
| 42 | + |
| 43 | + const phone = 9137357003 |
| 44 | + axios |
| 45 | + .post(`${SERVER_URL}/apis/verifyOTP`, { phone: phone, code: otp }) |
| 46 | + .then((res) => { |
| 47 | + if(res.data.success){ |
| 48 | + toast.success("Verified OTP successfuly !"); |
| 49 | + // props.postVerification(); |
| 50 | + } else { |
| 51 | + toast.error("Invalid OTP !"); |
| 52 | + } |
| 53 | + }) |
| 54 | + |
17 | 55 | setStage('verifyImage') |
18 | 56 | } |
19 | 57 |
|
@@ -102,7 +140,8 @@ const SingleEmployee = () => { |
102 | 140 |
|
103 | 141 | <div className='w-[60%] mx-auto'> |
104 | 142 | {stage == 'details' && <EmployeeVerificationForm onProceedHandler={onProceedHandler}/>} |
105 | | - {stage == 'verifyOTP' && <OTPVerificationSingleEmployee otp={otp} setOtp={setOtp} verifyOTPHandler={verifyOTPHandler}/>} |
| 143 | + {stage == 'verifyOTP' && <OTPVerificationSingleEmployee otp={otp} setOtp={setOtp} verifyOTPHandler={verifyOTPHandler} mobileNumber={mobileNumber}/>} |
| 144 | + {stage == 'verifyImage' && <ImageVerificationSingleEmployee/>} |
106 | 145 | </div> |
107 | 146 | </div> |
108 | 147 | ) |
|
0 commit comments