diff --git a/src/App.tsx b/src/App.tsx index fa6affb..7b53971 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,24 +1,42 @@ -import { useContext } from 'react'; +import { useContext } from "react"; import { Route, BrowserRouter as Router, Routes } from "react-router-dom"; -import GlobalStateContext from './Contexts/GlobalStateContext'; -import DefaultLayout from './Layouts/DefaultLayout'; -import Login from './Pages/Login'; -import { RouteLink } from './Routes/Routes'; +import GlobalStateContext from "./Contexts/GlobalStateContext"; +import DefaultLayout from "./Layouts/DefaultLayout"; +import Login from "./Pages/Login"; +import { RouteLink } from "./Routes/Routes"; +import LoginOtp from "./Pages/OnBoarding/LoginOtp"; -function App() { - const context = useContext(GlobalStateContext); - if (!context) throw new Error('App must be used within a GlobalStateProvider'); - const { isAuthenticate } = context; +function App() { + const context = useContext(GlobalStateContext); + if (!context) + throw new Error("App must be used within a GlobalStateProvider"); + const { isAuthenticate } = context; - return ( - - - } /> - {RouteLink.map(({ path, Component }, index) => (} />))}) : ()} /> - } /> - - - ); -} + return ( + + + } /> + } /> + + + {RouteLink.map(({ path, Component }, index) => ( + } /> + ))} + + + ) : ( + + ) + } + /> + } /> + + + ); +} export default App; diff --git a/src/Contexts/GlobalStateProvider.tsx b/src/Contexts/GlobalStateProvider.tsx index 1f2c713..9a839de 100644 --- a/src/Contexts/GlobalStateProvider.tsx +++ b/src/Contexts/GlobalStateProvider.tsx @@ -5,7 +5,7 @@ import GlobalStateContext from './GlobalStateContext'; const GlobalStateProvider = ({ children }:{children:ReactNode}) => { - const [isAuthenticate, setIsAuthenticate] = useState(true); + const [isAuthenticate, setIsAuthenticate] = useState(false); return ( diff --git a/src/Pages/OnBoarding/LoginOtp.tsx b/src/Pages/OnBoarding/LoginOtp.tsx new file mode 100644 index 0000000..3fa635a --- /dev/null +++ b/src/Pages/OnBoarding/LoginOtp.tsx @@ -0,0 +1,132 @@ +import { Center, HStack, Image, Input, Text, VStack } from "@chakra-ui/react"; +import { useContext, useState } from "react"; +import { useForm } from "react-hook-form"; +import GlobalStateContext from "../../Contexts/GlobalStateContext"; +import logo from "../../assets/logo.svg"; +import uiEdit from "../../assets/icons/edit.png"; +import { Button } from "../../components/ui/button"; +import { Field } from "../../components/ui/field"; +import { Toaster, toaster } from "../../components/ui/toaster"; +import { PinInput } from "../../components/ui/pin-input"; + +interface FormValues { + mobileNumber: number; +} + +const LoginOtp = () => { + const [isLoading, setIsLoading] = useState(false); + const context = useContext(GlobalStateContext); + if (!context) { + throw new Error("App must be used within a GlobalStateProvider"); + } + const { setIsAuthenticate } = context; + const { + register, + handleSubmit, + formState: { errors }, + } = useForm(); + + const onSubmit = handleSubmit((data) => { + setIsLoading(true); + if (data?.mobileNumber === 1234567890) { + setTimeout(() => { + setIsAuthenticate(true); + setIsLoading(false); + }, 3000); // 3-second delay + } else { + toaster.create({ + title: `Invalid Credentials`, + type: "error", + }); + setIsLoading(false); + } + }); + + return ( + + + + + + +
+ +
+ +
+ + + Enter otp + + + OTP has been send to your E-mail Address + + + + + 9619565889 + + + + + + + + Forgot password + + +
+ +
+
+ ); +}; + +export default LoginOtp; diff --git a/src/assets/icons/edit.png b/src/assets/icons/edit.png new file mode 100644 index 0000000..2aeaad0 Binary files /dev/null and b/src/assets/icons/edit.png differ diff --git a/src/components/ui/pin-input.tsx b/src/components/ui/pin-input.tsx new file mode 100644 index 0000000..93e013c --- /dev/null +++ b/src/components/ui/pin-input.tsx @@ -0,0 +1,27 @@ +import { PinInput as ChakraPinInput, Group } from "@chakra-ui/react" +import * as React from "react" + +export interface PinInputProps extends ChakraPinInput.RootProps { + rootRef?: React.Ref + count?: number + inputProps?: React.InputHTMLAttributes + attached?: boolean +} + +export const PinInput = React.forwardRef( + function PinInput(props, ref) { + const { count = 4, inputProps, rootRef, attached, ...rest } = props + return ( + + + + + {Array.from({ length: count }).map((_, index) => ( + + ))} + + + + ) + }, +)