Merge branch 'otp-modal-update' of TEST/digifi-employer-starter into master
This commit is contained in:
@@ -6,4 +6,4 @@ TWITTER_URL=https://twitter.com
|
||||
INSTAGRAM_URL=https://www.instagram.com
|
||||
|
||||
# BACKEND END POINTS
|
||||
VITE_USERS_ENDPOINT='https://digifi-apidev.chiefsoft.net/digiusers/v1'
|
||||
VITE_USERS_ENDPOINT='https://digifi-apidev.chiefsoft.net/employment/v1'
|
||||
+1
-1
@@ -6,4 +6,4 @@ VITE_TWITTER_URL=https://twitter.com
|
||||
VITE_INSTAGRAM_URL=https://www.instagram.com
|
||||
|
||||
# BACKEND END POINTS
|
||||
VITE_USERS_ENDPOINT='https://digifi-apidev.chiefsoft.net/digiusers/v1'
|
||||
VITE_USERS_ENDPOINT='https://digifi-apidev.chiefsoft.net/employment/v1'
|
||||
+1
-1
@@ -6,4 +6,4 @@ TWITTER_URL=https://twitter.com
|
||||
INSTAGRAM_URL=https://www.instagram.com
|
||||
|
||||
# BACKEND END POINTS
|
||||
VITE_USERS_ENDPOINT='https://digifi-apidev.chiefsoft.net/digiusers/v1'
|
||||
VITE_USERS_ENDPOINT='https://digifi-apidev.chiefsoft.net/employment/v1'
|
||||
@@ -1,8 +1,10 @@
|
||||
import { useState } from "react";
|
||||
import { Button, FloatLabelInput } from "..";
|
||||
import { Button, CustomSpinner, FloatLabelInput } from "..";
|
||||
import CustomModal from "../modal/CustomModal";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useNavigate, useLocation } from "react-router-dom";
|
||||
import { RouteHandler } from "../../router/routes";
|
||||
import { RequestStatus } from "../../core/models";
|
||||
import { employerLogin } from "../../core/apiRequest";
|
||||
|
||||
|
||||
type FormType = {
|
||||
@@ -16,7 +18,13 @@ type HandleChange = {
|
||||
};
|
||||
|
||||
export default function Login() {
|
||||
const navigate = useNavigate()
|
||||
|
||||
const navigate = useNavigate()
|
||||
const {state} = useLocation()
|
||||
|
||||
const [modal, setModal] = useState<boolean>(false)
|
||||
|
||||
const [requestStatus, setRequestStatus] = useState<RequestStatus>({loading:false, status:null, message:'', data:{}})
|
||||
|
||||
let [formDetails, setFormDetails] = useState<FormType>({
|
||||
email: "",
|
||||
@@ -28,16 +36,41 @@ export default function Login() {
|
||||
}: {
|
||||
target: HandleChange;
|
||||
}): any => {
|
||||
setFormDetails((prev) => ({ ...prev, [name]: value }));
|
||||
setFormDetails((prev:FormType) => ({ ...prev, [name]: value }));
|
||||
};
|
||||
|
||||
const [modal, setModal] = useState<boolean>(false)
|
||||
const loginFxn = () => {
|
||||
let reqData = {
|
||||
application_uid: state?.application_uid,
|
||||
password: formDetails?.password,
|
||||
username: formDetails.email
|
||||
}
|
||||
|
||||
setRequestStatus((prev:RequestStatus) => ({...prev, loading:true}))
|
||||
employerLogin(reqData).then(res => {
|
||||
// console.log('RES', res)
|
||||
if(!res?.data?.call_return){
|
||||
setRequestStatus({loading:false, status:false, message:'Email/Password is wrong', data:{}})
|
||||
return setTimeout(()=>{
|
||||
setRequestStatus({loading:false, status:null, message:'', data:{}})
|
||||
},4000)
|
||||
}
|
||||
setRequestStatus({loading:false, status:true, message:'login successful', data:res?.data})
|
||||
setModal(true)
|
||||
}).catch(err =>{
|
||||
setRequestStatus({loading:false, status:false, message:'something went wrong', data:{}})
|
||||
console.log(err)
|
||||
return setTimeout(()=>{
|
||||
setRequestStatus({loading:false, status:null, message:'', data:{}})
|
||||
},4000)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={`w-full overflow-y-auto bg-top bg-cover`}>
|
||||
<div className="w-full flex justify-center">
|
||||
<div className="w-2/3 md:max-w-[570px]">
|
||||
<div className="w-full md:max-w-[570px]">
|
||||
<div className="bg-white w-full rounded-2xl border-2 border-black">
|
||||
<div className="w-full p-5 sm:p-10 lg:p-20 flex flex-col justify-between items-center h-full">
|
||||
<div className="mb-4">
|
||||
@@ -78,12 +111,16 @@ export default function Login() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-10 w-full sm:flex justify-between items-center gap-2">
|
||||
<div className="mt-10 w-full flex items-center gap-2">
|
||||
<Button
|
||||
text="Enter"
|
||||
className="rounded-md w-full sm:w-2/5 text-xl capitalize font-bold"
|
||||
onClick={()=>{setModal(true)}}
|
||||
onClick={loginFxn}
|
||||
disabled={!formDetails.password || !formDetails.email || requestStatus.loading}
|
||||
/>
|
||||
{requestStatus.loading &&
|
||||
<CustomSpinner />
|
||||
}
|
||||
{/* <Link to='' className='text-black text-sm'>Forget your password?</Link> */}
|
||||
</div>
|
||||
</div>
|
||||
@@ -94,12 +131,12 @@ export default function Login() {
|
||||
</div>
|
||||
{ modal &&
|
||||
<CustomModal>
|
||||
<div className="px-10 py-5 md:px-16 bg-white w-[90%] max-w-[420px] flex flex-col justify-center items-center rounded-xl">
|
||||
<p className="text-sm font-bold text-slate-700 text-center tracking-wide leading-normal">We have sent you a verification code to complete this Login. Please check your phone number</p>
|
||||
<div className="w-full flex justify-end">
|
||||
<div className="py-5 bg-white w-[90%] max-w-[420px] flex flex-col justify-center items-center rounded-xl">
|
||||
<p className="px-10 md:px-20 text-sm font-bold text-slate-700 text-center tracking-wide leading-normal">We have sent you a verification code to complete this Login. Please check your phone number</p>
|
||||
<div className="px-5 md:px-10 w-full flex justify-end">
|
||||
<button
|
||||
className="font-bold text-[11px] lg:text-[13px] text-[#5A2C82]"
|
||||
onClick={()=>{navigate(RouteHandler.otppage, { state: {continue: true }, replace:true })}}
|
||||
onClick={()=>{navigate(RouteHandler.otppage, { state: {verify_uid: requestStatus?.data?.verify_uid, application_uid: requestStatus?.data?.records?.application_uid }, replace:true })}}
|
||||
>
|
||||
Ok
|
||||
</button>
|
||||
|
||||
+100
-60
@@ -1,11 +1,14 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Button, FloatLabelInput } from "..";
|
||||
import { Button, CustomSpinner } from "..";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import { RouteHandler } from "../../router/routes";
|
||||
import { updateUserDetails } from "../../store/UserDetails";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { verifyOTP } from "../../core/apiRequest";
|
||||
import { RequestStatus } from "../../core/models";
|
||||
|
||||
type FormType = {
|
||||
email: string;
|
||||
password: string;
|
||||
[index: string] : string
|
||||
};
|
||||
|
||||
type HandleChange = {
|
||||
@@ -16,23 +19,51 @@ type HandleChange = {
|
||||
export default function Login() {
|
||||
const navigate = useNavigate()
|
||||
const { state } = useLocation();
|
||||
const dispatch = useDispatch()
|
||||
|
||||
let [formDetails, setFormDetails] = useState<FormType>({
|
||||
email: "",
|
||||
password: "",
|
||||
const [requestStatus, setRequestStatus] = useState<RequestStatus>({loading:false, status:null, message:'', data:{}})
|
||||
|
||||
let [values, setValues] = useState<FormType>({
|
||||
otp1: "",
|
||||
otp2: "",
|
||||
otp3: "",
|
||||
otp4: "",
|
||||
});
|
||||
|
||||
const handleFormChange = ({
|
||||
const handleChange = ({
|
||||
target: { name, value },
|
||||
}: {
|
||||
target: HandleChange;
|
||||
}): any => {
|
||||
setFormDetails((prev) => ({ ...prev, [name]: value }));
|
||||
setValues((prev:FormType) => ({ ...prev, [name]: value }));
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
localStorage.setItem('token', 'dummy')
|
||||
navigate(RouteHandler.homepage, {replace:true})
|
||||
let reqData = {
|
||||
verify_uid: state?.verify_uid,
|
||||
otp: values.otp1+values.otp2+values.otp3+values.otp4
|
||||
}
|
||||
|
||||
setRequestStatus((prev:RequestStatus) => ({...prev, loading:true}))
|
||||
verifyOTP(reqData).then(res => {
|
||||
if(!res?.data?.call_return){
|
||||
setRequestStatus({loading:false, status:false, message:'OTP is wrong', data:{}})
|
||||
return setTimeout(()=>{
|
||||
setRequestStatus({loading:false, status:null, message:'', data:{}})
|
||||
},4000)
|
||||
}
|
||||
setRequestStatus({loading:false, status:true, message:'OTP Verified', data:res?.data})
|
||||
localStorage.setItem('token', state?.verify_uid)
|
||||
let data = {firstname:'firstname', lastname:'lastname', uid:'28273737646466464'}
|
||||
dispatch(updateUserDetails(data));
|
||||
navigate(`/${state?.application_uid}`, {replace:true})
|
||||
}).catch(err =>{
|
||||
setRequestStatus({loading:false, status:false, message:'something went wrong', data:{}})
|
||||
console.log(err)
|
||||
return setTimeout(()=>{
|
||||
setRequestStatus({loading:false, status:null, message:'', data:{}})
|
||||
},4000)
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
@@ -42,10 +73,20 @@ export default function Login() {
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(()=>{
|
||||
const formOTP = document.querySelectorAll('input')
|
||||
for (const i of formOTP) {
|
||||
if (i.value === '') {
|
||||
i.focus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
},[values])
|
||||
|
||||
return (
|
||||
<div className={`w-full overflow-y-auto bg-top bg-cover`}>
|
||||
<div className="w-full flex justify-center">
|
||||
<div className="w-4/5 md:max-w-[570px]">
|
||||
<div className="w-full xs:max-w-[350px] md:max-w-[570px]">
|
||||
<div className="bg-white w-full rounded-2xl border-2 border-black">
|
||||
<div className="w-full p-5 sm:p-10 lg:p-20 flex flex-col justify-between items-center">
|
||||
<div className="mb-4">
|
||||
@@ -59,63 +100,62 @@ export default function Login() {
|
||||
|
||||
<div className="w-full sm:w-4/5">
|
||||
{/* INPUTS */}
|
||||
<div className="w-full flex justify-between gap-8">
|
||||
<div className="relative my-2 py-2">
|
||||
<FloatLabelInput
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
// placeHolder="Email"
|
||||
// labelName="Email"
|
||||
value={formDetails.email}
|
||||
inputClass=""
|
||||
onChange={handleFormChange}
|
||||
/>
|
||||
</div>
|
||||
<div className="relative my-2 py-2">
|
||||
<FloatLabelInput
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
// placeHolder="Password"
|
||||
// labelName="Password"
|
||||
value={formDetails.password}
|
||||
inputClass=""
|
||||
onChange={handleFormChange}
|
||||
/>
|
||||
</div>
|
||||
<div className="relative my-2 py-2">
|
||||
<FloatLabelInput
|
||||
id="passwor"
|
||||
name="passwor"
|
||||
type="password"
|
||||
// placeHolder="Password"
|
||||
// labelName="Password"
|
||||
value={formDetails.password}
|
||||
inputClass=""
|
||||
onChange={handleFormChange}
|
||||
/>
|
||||
</div>
|
||||
<div className="relative my-2 py-2">
|
||||
<FloatLabelInput
|
||||
id="passw"
|
||||
name="passw"
|
||||
type="password"
|
||||
// placeHolder="Password"
|
||||
// labelName="Password"
|
||||
value={formDetails.password}
|
||||
inputClass=""
|
||||
onChange={handleFormChange}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full flex justify-between gap-4">
|
||||
<input
|
||||
id='otp1'
|
||||
name='otp1'
|
||||
className={`custom-otp text-center w-12 h-12 outline-none border-b-2 border-b-[#5A2C82] placeholder:text-transparent transition-all duration-500`}
|
||||
type='text'
|
||||
placeholder=''
|
||||
value={values.otp1}
|
||||
onChange={handleChange}
|
||||
maxLength={1}
|
||||
/>
|
||||
<input
|
||||
id='otp2'
|
||||
name='otp2'
|
||||
className={`custom-otp text-center w-12 h-12 outline-none border-b-2 border-b-[#5A2C82] placeholder:text-transparent transition-all duration-500`}
|
||||
type='text'
|
||||
placeholder=''
|
||||
value={values.otp2}
|
||||
onChange={handleChange}
|
||||
maxLength={1}
|
||||
/>
|
||||
<input
|
||||
id='otp3'
|
||||
name='otp3'
|
||||
className={`custom-otp text-center w-12 h-12 outline-none border-b-2 border-b-[#5A2C82] placeholder:text-transparent transition-all duration-500`}
|
||||
type='text'
|
||||
placeholder=''
|
||||
value={values.otp3}
|
||||
onChange={handleChange}
|
||||
maxLength={1}
|
||||
/>
|
||||
<input
|
||||
id='otp4'
|
||||
name='otp4'
|
||||
className={`custom-otp text-center w-12 h-12 outline-none border-b-2 border-b-[#5A2C82] placeholder:text-transparent transition-all duration-500`}
|
||||
type='text'
|
||||
placeholder=''
|
||||
value={values.otp4}
|
||||
onChange={handleChange}
|
||||
maxLength={1}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-10 w-full">
|
||||
{requestStatus.loading ?
|
||||
<div className='w-full flex justify-center items-center'>
|
||||
<CustomSpinner />
|
||||
</div>
|
||||
:
|
||||
<Button
|
||||
text="Enter"
|
||||
className="rounded-md w-full text-xl capitalize font-bold"
|
||||
onClick={handleSubmit}
|
||||
disabled={!values.otp1 || !values.otp2 || !values.otp1 || !values.otp1}
|
||||
/>
|
||||
}
|
||||
{/* <Link to='#' className='text-black text-sm'>Forget your password?</Link> */}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@ interface ButtonProps {
|
||||
className?: string;
|
||||
type?: "button" | "submit" | "reset";
|
||||
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
const Button: React.FC<ButtonProps> = ({
|
||||
@@ -12,12 +13,14 @@ const Button: React.FC<ButtonProps> = ({
|
||||
className,
|
||||
onClick,
|
||||
type = "button",
|
||||
disabled = false
|
||||
}) => {
|
||||
return (
|
||||
<button
|
||||
className={`btn-primary uppercase text-[11px] lg:text-[13px] p-[6px] lg:px-[10px] ${className}`}
|
||||
onClick={onClick}
|
||||
type={type}
|
||||
disabled={disabled}
|
||||
>
|
||||
{text}
|
||||
</button>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import React from 'react'
|
||||
|
||||
type Props = {
|
||||
size?: string
|
||||
}
|
||||
|
||||
export default function CustomSpinner({size='8'}:Props) {
|
||||
let width = `w-${size}`
|
||||
let height = `h-${size}`
|
||||
return (
|
||||
<div role="status">
|
||||
<svg aria-hidden="true" className={`inline ${width} ${height} text-gray-200 animate-spin dark:text-gray-600 fill-blue-600`} viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
|
||||
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>
|
||||
</svg>
|
||||
<span className="sr-only">Loading...</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -2,5 +2,6 @@ import Button from "./Button";
|
||||
import InputCompOne from "./InputCompOne";
|
||||
import FloatLabelInput from "./FloatLabelInput";
|
||||
import Stepper from "./Stepper";
|
||||
import CustomSpinner from "./CustomSpinner";
|
||||
|
||||
export { Button, FloatLabelInput, InputCompOne, Stepper };
|
||||
export { Button, CustomSpinner, FloatLabelInput, InputCompOne, Stepper };
|
||||
|
||||
+13
-13
@@ -1,18 +1,18 @@
|
||||
import { postAuxEnd, getAuxEnd } from "./axiosCall";
|
||||
|
||||
// FUNCTION TO START BVN VALIDATION
|
||||
// export const validateBVN = (postData:any) => {
|
||||
// let reqData = {
|
||||
// ...postData
|
||||
// }
|
||||
// return postAuxEnd('/bvn', reqData)
|
||||
// }
|
||||
// FUNCTION TO LOGIN EMPLOYER
|
||||
export const employerLogin = (postData:any) => {
|
||||
let reqData = {
|
||||
...postData
|
||||
}
|
||||
return postAuxEnd('/auth', reqData)
|
||||
}
|
||||
|
||||
|
||||
// FUNCTION TO VERIFY OTP AND LOGIN
|
||||
// export const verifyOTP = (postData:any) => {
|
||||
// let reqData = {
|
||||
// ...postData
|
||||
// }
|
||||
// return postAuxEnd('/bvn/verify', reqData)
|
||||
// }
|
||||
export const verifyOTP = (postData:any) => {
|
||||
let reqData = {
|
||||
...postData
|
||||
}
|
||||
return postAuxEnd('/otp', reqData)
|
||||
}
|
||||
+13
-23
@@ -1,27 +1,17 @@
|
||||
export interface RequestStatus {
|
||||
loading?:boolean
|
||||
status?:boolean | undefined
|
||||
message?:string
|
||||
name?:string
|
||||
data?:{}[] | [any] | {}
|
||||
loading?: null | boolean
|
||||
status?: null | boolean
|
||||
message?: null | string
|
||||
data? : {[index:string]: string | {[index:string]: string}}
|
||||
}
|
||||
|
||||
|
||||
export interface User {
|
||||
firstname?:string
|
||||
lastname?:string
|
||||
last_login?:string
|
||||
message?:string
|
||||
token?:string
|
||||
customer_uid?:string
|
||||
call_return?:string
|
||||
}
|
||||
|
||||
|
||||
export type PendingTableList = {
|
||||
status?: string | boolean;
|
||||
application_uid?: string
|
||||
added?: string
|
||||
loan_amount?: string
|
||||
payment_month?: string
|
||||
}[];
|
||||
export interface APIResponse {
|
||||
call_return: string
|
||||
verify_uid: string
|
||||
records: {
|
||||
application_uid: string
|
||||
password: string
|
||||
username: string
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
import {useState, useEffect} from 'react'
|
||||
import Layout from '../Layout';
|
||||
// import DashboardLayout from "./DashboardLayout";
|
||||
import { Outlet, useNavigate } from "react-router-dom";
|
||||
import { Outlet, useNavigate, useParams } from "react-router-dom";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { updateUserDetails } from '../../store/UserDetails';
|
||||
import { RouteHandler } from '../../router/routes';
|
||||
@@ -13,6 +13,7 @@ export default function DashboardAuth() {
|
||||
|
||||
const navigate = useNavigate()
|
||||
const dispatch = useDispatch()
|
||||
const {application_uid} = useParams()
|
||||
|
||||
const { userDetails } = useSelector((state:any) => state?.userDetails); // CHECKS IF USER Details are avaliable
|
||||
|
||||
@@ -41,7 +42,7 @@ export default function DashboardAuth() {
|
||||
|
||||
let token = localStorage.getItem('token')
|
||||
if(!token){ // IF NO TOKEN || UID RETURN TO LOGIN PAGE
|
||||
navigate(RouteHandler.loginpage, {replace:true})
|
||||
navigate(RouteHandler.loginpage, {state:{application_uid}, replace:true})
|
||||
return
|
||||
}
|
||||
const getUser = () => { // FUNCTION TO GET USER BY ID
|
||||
@@ -51,6 +52,8 @@ export default function DashboardAuth() {
|
||||
}
|
||||
if(!Object.keys(userDetails).length){
|
||||
getUser()
|
||||
}else{
|
||||
setLoading(false)
|
||||
}
|
||||
},[])
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ import { StartValidation } from "../components";
|
||||
const StartValidationPage: React.FC = () => {
|
||||
|
||||
useEffect(()=>{ // remove this function later
|
||||
localStorage.clear()
|
||||
setTimeout(()=>{
|
||||
localStorage.clear()
|
||||
},2000)
|
||||
},[])
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export class RouteHandler {
|
||||
static homepage = "/";
|
||||
static homepage = "/:application_uid";
|
||||
static loginpage = "/auth/login";
|
||||
static otppage = "/auth/otp";
|
||||
}
|
||||
|
||||
+5
-1
@@ -5,7 +5,11 @@ export default {
|
||||
"./src/**/*.{js,ts,jsx,tsx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
extend: {
|
||||
screens:{
|
||||
xs: "400px",
|
||||
}
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user