@@ -6,13 +6,16 @@ import React from "react";
66import { useState } from "react" ;
77// import { useMetamaskAuth, withConnectedRoute } from "../auth/authConfig";
88import { JUST_LOGGED_IN } from "../constants/routes" ;
9+ import axios from "axios" ;
910import AddImages from "./addImages" ;
10- import { sendOTP , verifyOTP } from "./api/otpVerification ";
11+ const API_URL = process . env . SERVER_URL || " ";
1112
1213// import { ToastContainer, toast } from "react-toastify";
1314// import "react-toastify/dist/ReactToastify.css";
1415
15- const invalidNumber = ( ) => { toast ( "Enter a Valid No." ) } ;
16+ const invalidNumber = ( ) => {
17+ toast ( "Enter a Valid No." ) ;
18+ } ;
1619
1720// import { sendOTP, verifyOTP } from "../pages/api/otpVerification.js";
1821
@@ -21,18 +24,59 @@ const Registration = () => {
2124
2225 const router = useRouter ( ) ;
2326 const [ date , setDate ] = useState ( null ) ;
27+ const [ receivedOtp , setReceivedOtp ] = useState ( "" ) ;
28+ // const [inputOtp, setInputOTP] = useState('');
29+ const [ successVerify , setSuccessVerify ] = useState ( "" ) ;
2430 const [ otp , setOTP ] = useState ( "" ) ;
2531 const [ isDisabled , setIsDisabled ] = useState ( false ) ;
2632 const [ phone , setPhone ] = useState ( "" ) ;
2733 const [ isOtpVerified , setIsOtpVerified ] = useState ( false ) ;
2834 const [ correctOtp , setCorrectOtp ] = useState ( false ) ;
2935
36+ const customAxios = axios . create ( {
37+ baseURL : API_URL ,
38+ } ) ;
39+
40+ const sendOTP = async ( phone ) => {
41+ console . log ( "Hii" ) ;
42+
43+ const response = await customAxios . post ( "/apis/sendOTP" , { phone } ) ;
44+ setReceivedOtp ( response . data . data ) ;
45+ console . log ( response . data . data ) ;
46+
47+ if ( response . status === 400 || response . status === 500 ) return false ;
48+ return true ;
49+ } ;
50+
51+ const verifyOTP = async ( phone , code ) => {
52+ const response = await customAxios . post ( "/apis/verifyOTP" , { phone, code } ) ;
53+ console . log ( response . data . success ) ;
54+ setSuccessVerify ( response . data . success ) ;
55+ console . log ( "Check" )
56+
57+ // console.log (inputOtp === receivedOtp)
58+ if ( response . status === 400 || response . data . success === false )
59+ return false ;
60+ return true ;
61+ } ;
62+
63+ if ( typeof window !== "undefined" ) {
64+ window . sendOTP = sendOTP ;
65+ window . verifyOTP = verifyOTP ;
66+ }
67+
3068 const onClickOtp = ( ) => {
3169 sendOTP ( phone ) ;
3270 } ;
3371
3472 const onCreateAccountHandler = ( e ) => {
3573 e . preventDefault ( ) ;
74+ if ( e . target . firstName . value . trim ( ) === undefined || e . target . lastName . value . trim ( ) === undefined ) {
75+ return ;
76+ }
77+ else {
78+ console . log ( "SUCCESS LOGIN" ) ;
79+ }
3680 console . log ( e . target . firstName . value ) ;
3781 console . log ( e . target . lastName . value ) ;
3882
@@ -48,6 +92,7 @@ const Registration = () => {
4892
4993 const onClickVerify = ( ) => {
5094 verifyOTP ( phone , otp ) ;
95+ // setInputOTP(otp);
5196 if ( verifyOTP ) {
5297 setCorrectOtp ( true ) ;
5398 }
@@ -165,9 +210,9 @@ const Registration = () => {
165210 < div className = "flex flex-row mt-[40px] items-center font-medium" >
166211 < button
167212 type = "submit"
168- disabled = { ! correctOtp }
213+ disabled = { ! successVerify }
169214 className = {
170- correctOtp
215+ successVerify
171216 ? "bg-blue py-[8px] px-[24px] rounded-lg text-white"
172217 : "bg-gray-400 py-[8px] px-[24px] rounded-lg text-white"
173218 }
0 commit comments