Compare commits
No commits in common. "ab6316ef56841ddf2b979222d20fc2006870f53c" and "40f4f2f254d1c815e15b5e5c0da8b2b4923da359" have entirely different histories.
ab6316ef56
...
40f4f2f254
@ -42,13 +42,13 @@ const Attendance = ({ attendance, getRole, handleModalData }) => {
|
|||||||
<>
|
<>
|
||||||
<table className="table ">
|
<table className="table ">
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="border-none" style={{ textAlign: 'left' }}>
|
<tr className="border-top-0" style={{ textAlign: 'left' }}>
|
||||||
<td style={{ borderBottom: 'none' }}>
|
<td >
|
||||||
<strong>Date : {todayDate.toLocaleDateString('en-GB')}</strong>
|
<strong>Date : {todayDate.toLocaleDateString('en-GB')}</strong>
|
||||||
</td>
|
</td>
|
||||||
<td style={{ paddingLeft: '20px', borderBottom: 'none' }}></td>
|
<td style={{ paddingLeft: '20px' }}>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th className="border-top-0" colSpan={2}>
|
<th className="border-top-0" colSpan={2}>
|
||||||
Name
|
Name
|
||||||
|
|||||||
@ -122,7 +122,6 @@ const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className="dataTables_length text-start py-2 d-flex justify-content-between"
|
className="dataTables_length text-start py-2 d-flex justify-content-between"
|
||||||
id="DataTables_Table_0_length"
|
id="DataTables_Table_0_length"
|
||||||
@ -139,7 +138,7 @@ const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="table-responsive text-nowrap" style={{ minHeight: "250px" }}>
|
<div className="table-responsive text-nowrap">
|
||||||
{data && data.length > 0 && (
|
{data && data.length > 0 && (
|
||||||
<table className="table mb-0">
|
<table className="table mb-0">
|
||||||
<thead>
|
<thead>
|
||||||
@ -218,8 +217,6 @@ const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => {
|
|||||||
}, [])}
|
}, [])}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
)}
|
)}
|
||||||
{!loading && !isRefreshing && data.length === 0 && <span>No employee logs</span>}
|
{!loading && !isRefreshing && data.length === 0 && <span>No employee logs</span>}
|
||||||
{error && !loading && !isRefreshing && (
|
{error && !loading && !isRefreshing && (
|
||||||
|
|||||||
@ -31,7 +31,7 @@ const Regularization = ({ handleRequest }) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="table-responsive text-nowrap" style={{minHeight:"300px"}}>
|
<div className="table-responsive text-nowrap">
|
||||||
<table className="table mb-0">
|
<table className="table mb-0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -47,7 +47,7 @@ const Regularization = ({ handleRequest }) => {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{loading && <td colSpan={6} className="text-center py-5">Loading...</td>}
|
{loading && <td colSpan={5}>Loading...</td>}
|
||||||
|
|
||||||
{!loading &&
|
{!loading &&
|
||||||
(regularizes?.length > 0 ? (
|
(regularizes?.length > 0 ? (
|
||||||
@ -88,17 +88,12 @@ const Regularization = ({ handleRequest }) => {
|
|||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={6}
|
<td colSpan={5}>No Record Found</td>
|
||||||
className="text-center" style={{
|
|
||||||
height: "200px",
|
|
||||||
verticalAlign: "middle",
|
|
||||||
borderBottom: "none",
|
|
||||||
}}>No Record Found</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{!loading >10 && (
|
{!loading && (
|
||||||
<nav aria-label="Page ">
|
<nav aria-label="Page ">
|
||||||
<ul className="pagination pagination-sm justify-content-end py-1">
|
<ul className="pagination pagination-sm justify-content-end py-1">
|
||||||
<li className={`page-item ${currentPage === 1 ? "disabled" : ""}`}>
|
<li className={`page-item ${currentPage === 1 ? "disabled" : ""}`}>
|
||||||
@ -112,7 +107,8 @@ const Regularization = ({ handleRequest }) => {
|
|||||||
{[...Array(totalPages)].map((_, index) => (
|
{[...Array(totalPages)].map((_, index) => (
|
||||||
<li
|
<li
|
||||||
key={index}
|
key={index}
|
||||||
className={`page-item ${currentPage === index + 1 ? "active" : ""
|
className={`page-item ${
|
||||||
|
currentPage === index + 1 ? "active" : ""
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
@ -124,7 +120,8 @@ const Regularization = ({ handleRequest }) => {
|
|||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
<li
|
<li
|
||||||
className={`page-item ${currentPage === totalPages ? "disabled" : ""
|
className={`page-item ${
|
||||||
|
currentPage === totalPages ? "disabled" : ""
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
|
|||||||
@ -86,7 +86,7 @@ const TaskModel = ({
|
|||||||
...prev,
|
...prev,
|
||||||
floorId: value,
|
floorId: value,
|
||||||
workAreaId: 0,
|
workAreaId: 0,
|
||||||
activityID: "",
|
activityID: 0,
|
||||||
workCategoryId: categoryData?.[0]?.id?.toString() ?? "",
|
workCategoryId: categoryData?.[0]?.id?.toString() ?? "",
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
@ -291,7 +291,7 @@ const TaskModel = ({
|
|||||||
{...register("activityID")}
|
{...register("activityID")}
|
||||||
onChange={handleActivityChange}
|
onChange={handleActivityChange}
|
||||||
>
|
>
|
||||||
<option value="">Select Activity</option>
|
<option value="0">Select Activity</option>
|
||||||
{activityData &&
|
{activityData &&
|
||||||
activityData.length > 0 &&
|
activityData.length > 0 &&
|
||||||
activityData
|
activityData
|
||||||
|
|||||||
@ -1,27 +1,21 @@
|
|||||||
import React, { useEffect, useRef } from "react";
|
import React, { useEffect, useRef } from "react";
|
||||||
|
|
||||||
const DateRangePicker = ({
|
const DateRangePicker = ({ onRangeChange, DateDifference = 7, defaultStartDate = new Date() - 1 }) => {
|
||||||
onRangeChange,
|
|
||||||
DateDifference = 7,
|
|
||||||
endDateMode = "yesterday", // "today" or "yesterday"
|
|
||||||
}) => {
|
|
||||||
const inputRef = useRef(null);
|
const inputRef = useRef(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const endDate = new Date();
|
const today = new Date();;
|
||||||
if (endDateMode === "yesterday") {
|
today.setDate(today.getDate() - 1);
|
||||||
endDate.setDate(endDate.getDate() - 1);
|
const fifteenDaysAgo = new Date();
|
||||||
}
|
|
||||||
|
|
||||||
const startDate = new Date();
|
fifteenDaysAgo.setDate(today.getDate() - DateDifference);
|
||||||
startDate.setDate(endDate.getDate() - DateDifference);
|
|
||||||
|
|
||||||
const fp = flatpickr(inputRef.current, {
|
const fp = flatpickr(inputRef.current, {
|
||||||
mode: "range",
|
mode: "range",
|
||||||
dateFormat: "Y-m-d",
|
dateFormat: "Y-m-d", // Format for backend (actual input value)
|
||||||
altInput: true,
|
altInput: true, // Enables a visually different field
|
||||||
altFormat: "d-m-Y",
|
altFormat: "d-m-Y",
|
||||||
defaultDate: [startDate, endDate],
|
defaultDate: [fifteenDaysAgo, today],
|
||||||
static: true,
|
static: true,
|
||||||
clickOpens: true,
|
clickOpens: true,
|
||||||
onChange: (selectedDates, dateStr) => {
|
onChange: (selectedDates, dateStr) => {
|
||||||
@ -31,14 +25,16 @@ const DateRangePicker = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
onRangeChange?.({
|
onRangeChange?.({
|
||||||
startDate: startDate.toLocaleDateString("en-CA"),
|
// startDate: fifteenDaysAgo.toISOString().split("T")[0],
|
||||||
endDate: endDate.toLocaleDateString("en-CA"),
|
// endDate: today.toISOString().split("T")[0],
|
||||||
|
startDate: fifteenDaysAgo.toLocaleDateString("en-CA"),
|
||||||
|
endDate: today.toLocaleDateString("en-CA"),
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
fp.destroy();
|
fp.destroy();
|
||||||
};
|
};
|
||||||
}, [onRangeChange, DateDifference, endDateMode]);
|
}, [onRangeChange]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
|
|||||||
@ -141,7 +141,6 @@ const DailyTask = () => {
|
|||||||
<div className="col-6 text-start">
|
<div className="col-6 text-start">
|
||||||
<DateRangePicker
|
<DateRangePicker
|
||||||
onRangeChange={setDateRange}
|
onRangeChange={setDateRange}
|
||||||
endDateMode="today"
|
|
||||||
DateDifference="6"
|
DateDifference="6"
|
||||||
dateFormat="DD-MM-YYYY"
|
dateFormat="DD-MM-YYYY"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { AuthWrapper } from "./AuthWrapper";
|
import { AuthWrapper } from "./AuthWrapper";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
@ -9,23 +9,16 @@ import { useForm } from "react-hook-form";
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const loginScheam = z.object({
|
||||||
|
username: z.string().email(),
|
||||||
|
password: z.string().min(1, { message: "Password required" }),
|
||||||
|
rememberMe: z.boolean(),
|
||||||
|
});
|
||||||
|
|
||||||
const LoginPage = () => {
|
const LoginPage = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [hidepass, setHidepass] = useState(true);
|
const [hidepass, setHidepass] = useState(true);
|
||||||
const [IsLoginWithOTP, setLoginWithOtp] = useState(false);
|
|
||||||
const [IsTriedOTPThrough, setIsTriedOTPThrough] = useState(false);
|
|
||||||
const now = Date.now();
|
|
||||||
|
|
||||||
const loginSchema = IsLoginWithOTP
|
|
||||||
? z.object({
|
|
||||||
username: z.string().email({ message: "Valid email required" }),
|
|
||||||
})
|
|
||||||
: z.object({
|
|
||||||
username: z.string().email({ message: "Valid email required" }),
|
|
||||||
password: z.string().min(1, { message: "Password required" }),
|
|
||||||
rememberMe: z.boolean(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
@ -34,15 +27,14 @@ const LoginPage = () => {
|
|||||||
reset,
|
reset,
|
||||||
getValues,
|
getValues,
|
||||||
} = useForm({
|
} = useForm({
|
||||||
resolver: zodResolver(loginSchema),
|
resolver: zodResolver(loginScheam),
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit = async (data) => {
|
const onSubmit = async (data) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!IsLoginWithOTP) {
|
let userCredential = {
|
||||||
const userCredential = {
|
|
||||||
username: data.username,
|
username: data.username,
|
||||||
password: data.password,
|
password: data.password,
|
||||||
};
|
};
|
||||||
@ -51,32 +43,19 @@ const LoginPage = () => {
|
|||||||
localStorage.setItem("refreshToken", response.data.refreshToken);
|
localStorage.setItem("refreshToken", response.data.refreshToken);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
navigate("/dashboard");
|
navigate("/dashboard");
|
||||||
} else {
|
|
||||||
await AuthRepository.sendOTP({ email: data.username });
|
|
||||||
localStorage.setItem("otpUsername", data.username);
|
|
||||||
localStorage.setItem("otpSentTime", now.toString());
|
|
||||||
navigate("/auth/login-otp");
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showToast("Invalid username or password.", "error");
|
showToast("Invalid username or password.","error")
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect( () =>
|
|
||||||
{ const otpSentTime = localStorage.getItem("otpSentTime");
|
|
||||||
if (localStorage.getItem("otpUsername") && IsLoginWithOTP && now - Number(otpSentTime) < 10 * 60 * 1000) {
|
|
||||||
navigate("/auth/login-otp");
|
|
||||||
}
|
|
||||||
}, [IsLoginWithOTP]);
|
|
||||||
return (
|
return (
|
||||||
<AuthWrapper>
|
<AuthWrapper>
|
||||||
<h4 className="mb-2">Welcome to PMS!</h4>
|
<h4 className="mb-2">Welcome to PMS!</h4>
|
||||||
<p className="mb-4">
|
<p className="mb-4">
|
||||||
{IsLoginWithOTP
|
Please sign-in to your account and start the adventure
|
||||||
? "Enter your email to receive a one-time password (OTP)."
|
|
||||||
: "Please sign-in to your account and start the adventure."}
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
id="formAuthentication"
|
id="formAuthentication"
|
||||||
className="mb-3"
|
className="mb-3"
|
||||||
@ -91,6 +70,7 @@ const LoginPage = () => {
|
|||||||
className="form-control"
|
className="form-control"
|
||||||
id="username"
|
id="username"
|
||||||
{...register("username")}
|
{...register("username")}
|
||||||
|
name="username"
|
||||||
placeholder="Enter your email or username"
|
placeholder="Enter your email or username"
|
||||||
autoFocus
|
autoFocus
|
||||||
/>
|
/>
|
||||||
@ -103,13 +83,12 @@ const LoginPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!IsLoginWithOTP && (
|
|
||||||
<>
|
|
||||||
<div className="mb-3 form-password-toggle">
|
<div className="mb-3 form-password-toggle">
|
||||||
|
<div className="d-flex justify-content-center">
|
||||||
<label className="form-label" htmlFor="password">
|
<label className="form-label" htmlFor="password">
|
||||||
Password
|
Password
|
||||||
</label>
|
</label>
|
||||||
|
</div>
|
||||||
<div className="input-group input-group-merge">
|
<div className="input-group input-group-merge">
|
||||||
<input
|
<input
|
||||||
type={hidepass ? "password" : "text"}
|
type={hidepass ? "password" : "text"}
|
||||||
@ -117,7 +96,9 @@ const LoginPage = () => {
|
|||||||
id="password"
|
id="password"
|
||||||
{...register("password")}
|
{...register("password")}
|
||||||
className="form-control"
|
className="form-control"
|
||||||
placeholder="••••••••••••"
|
name="password"
|
||||||
|
placeholder="············"
|
||||||
|
aria-describedby="password"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@ -145,61 +126,44 @@ const LoginPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mb-3 d-flex justify-content-between">
|
<div className="mb-3 d-flex justify-content-between">
|
||||||
<div className="form-check d-flex">
|
<div className="form-check d-flex">
|
||||||
<input
|
<input
|
||||||
className="form-check-input"
|
className="form-check-input"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="remember-me"
|
id="remember-me"
|
||||||
|
name="rememberMe"
|
||||||
{...register("rememberMe")}
|
{...register("rememberMe")}
|
||||||
/>
|
/>
|
||||||
<label className="form-check-label ms-2">Remember Me</label>
|
<label className="form-check-label ms-2">Remember Me</label>
|
||||||
</div>
|
</div>
|
||||||
<Link to="/auth/forgot-password">Forgot Password?</Link>
|
<Link
|
||||||
|
aria-label="Go to Forgot Password Page"
|
||||||
|
to="/auth/forgot-password"
|
||||||
|
>
|
||||||
|
<span>Forgot Password?</span>
|
||||||
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="mb-3">
|
<div className="mb-3">
|
||||||
<button
|
<button
|
||||||
aria-label="Submit form"
|
aria-label="Click me"
|
||||||
className="btn btn-primary d-grid w-100 mb-2"
|
className="btn btn-primary d-grid w-100"
|
||||||
type="submit"
|
type="submit"
|
||||||
>
|
>
|
||||||
{loading
|
{loading ? "Please Wait" : " Sign in"}
|
||||||
? "Please Wait"
|
|
||||||
: IsLoginWithOTP
|
|
||||||
? "Continue with OTP"
|
|
||||||
: "Sign In"}
|
|
||||||
</button>
|
</button>
|
||||||
{!IsLoginWithOTP && (
|
|
||||||
<button
|
|
||||||
aria-label="loginwithotp"
|
|
||||||
type="button"
|
|
||||||
onClick={() => setLoginWithOtp(true)}
|
|
||||||
className="btn btn-primary w-100"
|
|
||||||
>
|
|
||||||
login With OTP
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<p className="text-center">
|
<p className="text-center">
|
||||||
<span>New on our platform? </span>
|
<span>New on our platform? </span>
|
||||||
{IsLoginWithOTP ? (
|
<Link
|
||||||
<a
|
aria-label="Go to Register Page"
|
||||||
className="text-primary cursor-pointer"
|
to="/auth/reqest/demo"
|
||||||
onClick={() => setLoginWithOtp(false)}
|
className="registration-link"
|
||||||
>
|
>
|
||||||
Login With Password
|
<span>Request a Demo</span>
|
||||||
</a>
|
|
||||||
) : (
|
|
||||||
<Link to="/auth/reqest/demo" className="registration-link">
|
|
||||||
Request a Demo
|
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
|
||||||
</p>
|
</p>
|
||||||
</AuthWrapper>
|
</AuthWrapper>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,185 +0,0 @@
|
|||||||
import { useForm } from "react-hook-form";
|
|
||||||
import { z } from "zod";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
|
||||||
import { useState, useRef, useEffect } from "react";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import showToast from "../../services/toastService";
|
|
||||||
import { AuthWrapper } from "./AuthWrapper";
|
|
||||||
import { OTP_EXPIRY_SECONDS } from "../../utils/constants";
|
|
||||||
import AuthRepository from "../../repositories/AuthRepository";
|
|
||||||
|
|
||||||
const otpSchema = z.object({
|
|
||||||
otp1: z.string().min(1, "Required"),
|
|
||||||
otp2: z.string().min(1, "Required"),
|
|
||||||
otp3: z.string().min(1, "Required"),
|
|
||||||
otp4: z.string().min(1, "Required"),
|
|
||||||
});
|
|
||||||
|
|
||||||
const LoginWithOtp = () => {
|
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
const [ loading, setLoading ] = useState( false );
|
|
||||||
const [ timeLeft, setTimeLeft ] = useState( 0 );
|
|
||||||
|
|
||||||
|
|
||||||
const inputRefs = useRef([]);
|
|
||||||
|
|
||||||
const {
|
|
||||||
register,
|
|
||||||
handleSubmit,
|
|
||||||
formState: { errors, isSubmitted },
|
|
||||||
getValues,
|
|
||||||
} = useForm({
|
|
||||||
resolver: zodResolver(otpSchema),
|
|
||||||
});
|
|
||||||
|
|
||||||
const onSubmit = async (data) => {
|
|
||||||
const finalOtp = data.otp1 + data.otp2 + data.otp3 + data.otp4;
|
|
||||||
const username = localStorage.getItem( "otpUsername" );
|
|
||||||
console.log(username)
|
|
||||||
setLoading(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
let requestedData = {
|
|
||||||
email: username,
|
|
||||||
otp:finalOtp
|
|
||||||
}
|
|
||||||
const response = await AuthRepository.verifyOTP( requestedData )
|
|
||||||
|
|
||||||
localStorage.setItem("jwtToken", response.data.token);
|
|
||||||
localStorage.setItem("refreshToken", response.data.refreshToken);
|
|
||||||
setLoading( false );
|
|
||||||
localStorage.removeItem( "otpUsername" );
|
|
||||||
localStorage.removeItem( "otpSentTime" );
|
|
||||||
navigate( "/dashboard" );
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
showToast( "Invalid or expired OTP.", "error" );
|
|
||||||
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const formatTime = (seconds) => {
|
|
||||||
const min = Math.floor(seconds / 60).toString().padStart(2, "0");
|
|
||||||
const sec = (seconds % 60).toString().padStart(2, "0");
|
|
||||||
return `${min}:${sec}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const otpSentTime = localStorage.getItem("otpSentTime");
|
|
||||||
const now = Date.now();
|
|
||||||
|
|
||||||
if (otpSentTime) {
|
|
||||||
const elapsed = Math.floor((now - Number(otpSentTime)) / 1000); // in seconds
|
|
||||||
const remaining = Math.max(OTP_EXPIRY_SECONDS - elapsed, 0); // prevent negatives
|
|
||||||
setTimeLeft(remaining);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
useEffect(() => {
|
|
||||||
if (timeLeft <= 0) return;
|
|
||||||
|
|
||||||
const timer = setInterval(() => {
|
|
||||||
setTimeLeft((prev) => {
|
|
||||||
if (prev <= 1) {
|
|
||||||
clearInterval(timer);
|
|
||||||
localStorage.removeItem( "otpSentTime" );
|
|
||||||
localStorage.removeItem("otpUsername");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return prev - 1;
|
|
||||||
});
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
return () => clearInterval(timer);
|
|
||||||
}, [timeLeft]);
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
|
||||||
<AuthWrapper>
|
|
||||||
<div className="otp-verification-wrapper">
|
|
||||||
<h4>Verify Your OTP</h4>
|
|
||||||
<p className="mb-4">Please enter the 4-digit code sent to your email.</p>
|
|
||||||
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
|
||||||
<div className="d-flex justify-content-center gap-6 mb-3">
|
|
||||||
{[1, 2, 3, 4].map((num, idx) => {
|
|
||||||
const { ref, onChange, ...rest } = register(`otp${num}`);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<input
|
|
||||||
key={num}
|
|
||||||
type="text"
|
|
||||||
maxLength={1}
|
|
||||||
className={`form-control text-center ${
|
|
||||||
errors[`otp${num}`] ? "is-invalid" : ""
|
|
||||||
}`}
|
|
||||||
ref={(el) => {
|
|
||||||
inputRefs.current[idx] = el;
|
|
||||||
ref(el);
|
|
||||||
}}
|
|
||||||
onChange={(e) => {
|
|
||||||
const val = e.target.value;
|
|
||||||
onChange(e);
|
|
||||||
if (/^\d$/.test(val) && idx < 3) {
|
|
||||||
inputRefs.current[idx + 1]?.focus();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onKeyDown={(e) => {
|
|
||||||
if (
|
|
||||||
e.key === "Backspace" &&
|
|
||||||
!getValues()[`otp${num}`] &&
|
|
||||||
idx > 0
|
|
||||||
) {
|
|
||||||
inputRefs.current[idx - 1]?.focus();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
style={{ width: "40px", height: "40px", fontSize: "15px" }}
|
|
||||||
{...rest}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{isSubmitted && Object.values(errors).some((e) => e?.message) && (
|
|
||||||
<div
|
|
||||||
className="text-danger text-center mb-3"
|
|
||||||
style={{ fontSize: "12px" }}
|
|
||||||
>
|
|
||||||
Please fill all four digits.
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
className="btn btn-primary d-grid w-100"
|
|
||||||
disabled={loading}
|
|
||||||
>
|
|
||||||
{loading ? "Verifying..." : "Verify OTP"}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{timeLeft > 0 ? (
|
|
||||||
<p
|
|
||||||
className="text-center text-muted mt-2"
|
|
||||||
style={{ fontSize: "14px" }}
|
|
||||||
>
|
|
||||||
This OTP will expire in <strong>{formatTime(timeLeft)}</strong>
|
|
||||||
</p>
|
|
||||||
) : (
|
|
||||||
<div>
|
|
||||||
<p
|
|
||||||
className="text-center text-danger mt-2 text small-text m-0"
|
|
||||||
|
|
||||||
>
|
|
||||||
OTP has expired. Please request a new one.
|
|
||||||
</p>
|
|
||||||
<a className="text-primary cursor-pointer" onClick={()=>navigate('/auth/login')}>Try Again</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
)}
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</AuthWrapper>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default LoginWithOtp;
|
|
||||||
@ -141,7 +141,7 @@ const AttendancesEmployeeRecords = ({ employee }) => {
|
|||||||
id="DataTables_Table_0_length"
|
id="DataTables_Table_0_length"
|
||||||
>
|
>
|
||||||
<div className="col-md-3 my-0 ">
|
<div className="col-md-3 my-0 ">
|
||||||
<DateRangePicker onRangeChange={setDateRange} endDateMode="yesterday"/>
|
<DateRangePicker onRangeChange={setDateRange} />
|
||||||
</div>
|
</div>
|
||||||
<div className="col-md-2 m-0 text-end">
|
<div className="col-md-2 m-0 text-end">
|
||||||
<i
|
<i
|
||||||
|
|||||||
@ -10,9 +10,7 @@ const AuthRepository = {
|
|||||||
resetPassword: (data) => api.post("/api/auth/reset-password", data),
|
resetPassword: (data) => api.post("/api/auth/reset-password", data),
|
||||||
forgotPassword: (data) => api.post("/api/auth/forgot-password", data),
|
forgotPassword: (data) => api.post("/api/auth/forgot-password", data),
|
||||||
sendMail: (data) => api.post("/api/auth/sendmail", data),
|
sendMail: (data) => api.post("/api/auth/sendmail", data),
|
||||||
changepassword: ( data ) => api.post( "/api/auth/change-password", data ),
|
changepassword: (data) => api.post("/api/auth/change-password", data),
|
||||||
sendOTP: ( data ) => api.post( 'api/auth/send-otp', data ),
|
|
||||||
verifyOTP:(data)=>api.post("api/auth/login-otp",data)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AuthRepository;
|
export default AuthRepository;
|
||||||
|
|||||||
@ -37,15 +37,13 @@ import LegalInfoCard from "../pages/TermsAndConditions/LegalInfoCard";
|
|||||||
// Protected Route Wrapper
|
// Protected Route Wrapper
|
||||||
import ProtectedRoute from "./ProtectedRoute";
|
import ProtectedRoute from "./ProtectedRoute";
|
||||||
import Directory from "../pages/Directory/Directory";
|
import Directory from "../pages/Directory/Directory";
|
||||||
import LoginWithOtp from "../pages/authentication/LoginWithOtp";
|
|
||||||
|
|
||||||
const router = createBrowserRouter(
|
const router = createBrowserRouter(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
element: <AuthLayout />,
|
element: <AuthLayout />,
|
||||||
children: [
|
children: [
|
||||||
{path: "/auth/login", element: <LoginPage />},
|
{ path: "/auth/login", element: <LoginPage /> },
|
||||||
{path: "/auth/login-otp", element: <LoginWithOtp />},
|
|
||||||
{ path: "/auth/reqest/demo", element: <RegisterPage /> },
|
{ path: "/auth/reqest/demo", element: <RegisterPage /> },
|
||||||
{ path: "/auth/forgot-password", element: <ForgotPasswordPage /> },
|
{ path: "/auth/forgot-password", element: <ForgotPasswordPage /> },
|
||||||
{ path: "/reset-password", element: <ResetPasswordPage /> },
|
{ path: "/reset-password", element: <ResetPasswordPage /> },
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
export const THRESH_HOLD = 48; // hours
|
export const THRESH_HOLD = 48; // hours
|
||||||
export const DURATION_TIME = 10; // minutes
|
export const DURATION_TIME = 10; // minutes
|
||||||
export const OTP_EXPIRY_SECONDS = 600 // OTP time
|
|
||||||
|
|
||||||
export const MANAGE_MASTER = "588a8824-f924-4955-82d8-fc51956cf323";
|
export const MANAGE_MASTER = "588a8824-f924-4955-82d8-fc51956cf323";
|
||||||
|
|
||||||
@ -26,4 +25,3 @@ export const MANAGE_TASK = "08752f33-3b29-4816-b76b-ea8a968ed3c5"
|
|||||||
export const VIEW_TASK = "9fcc5f87-25e3-4846-90ac-67a71ab92e3c"
|
export const VIEW_TASK = "9fcc5f87-25e3-4846-90ac-67a71ab92e3c"
|
||||||
|
|
||||||
export const ASSIGN_REPORT_TASK = "6a32379b-8b3f-49a6-8c48-4b7ac1b55dc2"
|
export const ASSIGN_REPORT_TASK = "6a32379b-8b3f-49a6-8c48-4b7ac1b55dc2"
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user