|
| 1 | +import EmployeeVerificationForm from '@/components/employeeVerificationForm' |
| 2 | +import ImageVerificationSingleEmployee from '@/components/imageVerificationSingleEmployee' |
| 3 | +import OTPVerificationSingleEmployee from '@/components/otpVerificationSingleEmployee' |
| 4 | +import { SERVER_URL } from '@/constants/config' |
| 5 | +import axios from 'axios' |
| 6 | +import React, { useState } from 'react' |
| 7 | +import { toast } from 'react-toastify' |
| 8 | + |
| 9 | +const VerifyByLink = () => { |
| 10 | + const [stage, setStage] = useState('details') //details || verifyOTP || verifyImage |
| 11 | + const [employeeData, setEmployeeData] = useState({}) |
| 12 | + // const [employeeData, setEmployeeData] = useState({name: 'rupesh', gender: 'male', phone: '9137357003'}) |
| 13 | + const [otp, setOtp] = useState(''); |
| 14 | + const [mobileNumber, setMobileNumber] = useState(null) |
| 15 | + |
| 16 | + const onProceedHandler = async (formData) => { |
| 17 | + setEmployeeData(formData) |
| 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 | + }); |
| 38 | + } |
| 39 | + |
| 40 | + const verifyOTPHandler = () => { |
| 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 | + |
| 55 | + setStage('verifyImage') |
| 56 | + } |
| 57 | + |
| 58 | + return ( |
| 59 | + <div className='w-[100%] dark:text-white dark:bg-dark2 text-dark3'> |
| 60 | + <div className='flex flex-row items-center text-[26px] font-medium h-[70px] pl-[40px] border-b-[1px] dark:border-[#232830] border-[#DCE3EE] bg-'> |
| 61 | + Verify Employee |
| 62 | + </div> |
| 63 | + |
| 64 | + <div className="flex flex-row w-[40%] mt-[20px] mx-auto items-center justify-between text-[14px] font-[12px]"> |
| 65 | + <div className="flex flex-row items-center text-blue-600 dark:text-blue-500"> |
| 66 | + <svg |
| 67 | + aria-hidden="true" |
| 68 | + className="w-4 h-4 mr-2" |
| 69 | + fill="currentColor" |
| 70 | + viewBox="0 0 20 20" |
| 71 | + xmlns="http://www.w3.org/2000/svg" |
| 72 | + > |
| 73 | + <path |
| 74 | + fillRule="evenodd" |
| 75 | + d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" |
| 76 | + clipRule="evenodd" |
| 77 | + ></path> |
| 78 | + </svg> |
| 79 | + Employee Details |
| 80 | + </div> |
| 81 | + <div |
| 82 | + className={`h-[1px] w-[30px] sm:w-[30px] ${ |
| 83 | + stage == "verifyOTP" || stage == "verifyImage" |
| 84 | + ? "bg-blue-600 dark:bg-blue-500" |
| 85 | + : "bg-gray-500 dark:bg-gray-200" |
| 86 | + }`} |
| 87 | + ></div> |
| 88 | + <div |
| 89 | + className={`flex flex-row items-center ${ |
| 90 | + stage == "verifyOTP" || stage == "verifyImage" |
| 91 | + ? "text-blue-600 dark:text-blue-500" |
| 92 | + : "text-gray-500" |
| 93 | + }`} |
| 94 | + > |
| 95 | + <svg |
| 96 | + aria-hidden="true" |
| 97 | + className="w-4 h-4 mr-2" |
| 98 | + fill="currentColor" |
| 99 | + viewBox="0 0 20 20" |
| 100 | + xmlns="http://www.w3.org/2000/svg" |
| 101 | + > |
| 102 | + <path |
| 103 | + fillRule="evenodd" |
| 104 | + d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" |
| 105 | + clipRule="evenodd" |
| 106 | + ></path> |
| 107 | + </svg> |
| 108 | + OTP Verification |
| 109 | + </div> |
| 110 | + <div |
| 111 | + className={`h-[1px] w-[30px] sm:w-[30px] ${ |
| 112 | + stage == "verifyImage" |
| 113 | + ? "bg-blue-600 dark:bg-blue-500" |
| 114 | + : "bg-gray-500 dark:bg-gray-200" |
| 115 | + }`} |
| 116 | + ></div> |
| 117 | + <div |
| 118 | + className={`flex flex-row items-center ${ |
| 119 | + stage == "verifyImage" |
| 120 | + ? "text-blue-600 dark:text-blue-500" |
| 121 | + : "text-gray-500" |
| 122 | + }`} |
| 123 | + > |
| 124 | + <svg |
| 125 | + aria-hidden="true" |
| 126 | + className="w-4 h-4 mr-2" |
| 127 | + fill="currentColor" |
| 128 | + viewBox="0 0 20 20" |
| 129 | + xmlns="http://www.w3.org/2000/svg" |
| 130 | + > |
| 131 | + <path |
| 132 | + fillRule="evenodd" |
| 133 | + d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" |
| 134 | + clipRule="evenodd" |
| 135 | + ></path> |
| 136 | + </svg> |
| 137 | + Image Verification |
| 138 | + </div> |
| 139 | + </div> |
| 140 | + |
| 141 | + <div className='w-[50%] mx-auto'> |
| 142 | + {stage == 'details' && <EmployeeVerificationForm onProceedHandler={onProceedHandler}/>} |
| 143 | + {stage == 'verifyOTP' && <OTPVerificationSingleEmployee otp={otp} setOtp={setOtp} verifyOTPHandler={verifyOTPHandler} mobileNumber={mobileNumber}/>} |
| 144 | + {stage == 'verifyImage' && <ImageVerificationSingleEmployee/>} |
| 145 | + </div> |
| 146 | + </div> |
| 147 | + ) |
| 148 | +} |
| 149 | + |
| 150 | +export default VerifyByLink |
0 commit comments