changes added in company profile
This commit is contained in:
parent
a13ea7ffef
commit
e00e7a1a38
@ -15,6 +15,20 @@ import HeaderBar from '@/components/layout/HeaderBar';
|
||||
// return { quarter, year };
|
||||
// };
|
||||
|
||||
const formatName = (name = '') => {
|
||||
return name
|
||||
// camelCase → add space
|
||||
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
||||
// split by space
|
||||
.split(' ')
|
||||
// capitalize each word
|
||||
.map(
|
||||
word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
|
||||
)
|
||||
.join(' ');
|
||||
};
|
||||
|
||||
|
||||
export const WelcomeSection = ({ data = null, loading = false, error = '' }) => {
|
||||
// const { quarter: currentQuarter, year: currentYear } = getCurrentQuarterAndYear();
|
||||
|
||||
@ -32,18 +46,20 @@ export const WelcomeSection = ({ data = null, loading = false, error = '' }) =>
|
||||
<HeaderBar />
|
||||
<div className="max-w-[1280px] mx-auto px-4 pt-2 pb-1">
|
||||
<div className="space-y-1">
|
||||
<h2 className="w-[360px] text-[18px] pt-2 leading-[28px] font-medium text-[#232528]">
|
||||
Welcome{' '}
|
||||
{(() => {
|
||||
try {
|
||||
const userProfile = JSON.parse(localStorage.getItem('user_profile'));
|
||||
return userProfile?.name ? userProfile.name : '';
|
||||
} catch (error) {
|
||||
console.error('Error reading user_profile from sessionStorage:', error);
|
||||
return '';
|
||||
}
|
||||
})()}!
|
||||
</h2>
|
||||
<h2 className="w-[360px] text-[18px] pt-2 leading-[28px] font-medium text-[#232528]">
|
||||
Welcome{' '}
|
||||
{(() => {
|
||||
try {
|
||||
const userProfile = JSON.parse(localStorage.getItem('user_profile'));
|
||||
return userProfile?.name ? formatName(userProfile.name) : '';
|
||||
} catch (error) {
|
||||
console.error('Error reading user_profile from localStorage:', error);
|
||||
return '';
|
||||
}
|
||||
})()}
|
||||
!
|
||||
</h2>
|
||||
|
||||
{/* <p
|
||||
className={`w-[360px] text-[14px] leading-[24px] font-normal ${
|
||||
error ? 'text-red-600' : 'text-[#5F646D]'
|
||||
|
||||
@ -6,6 +6,8 @@ import apiClient from '@/services/api/apiClient';
|
||||
import { getBeforePreviousData, getQuarterPeriods } from '@/services/submissions/submissionService';
|
||||
import { getProductSubmissionHistory } from '@/services/submissions/submissionService';
|
||||
import { Line } from 'react-chartjs-2';
|
||||
import { IoIosArrowBack } from "react-icons/io";
|
||||
|
||||
|
||||
// Helper function to get months for quarter
|
||||
const getMonthsForQuarter = (quarter, year) => {
|
||||
@ -931,12 +933,29 @@ setAdditionalForecastMonths([
|
||||
<AdminHeader />
|
||||
|
||||
<div className="max-w-[1280px] mx-auto px-4 py-6 space-y-6">
|
||||
<nav className="flex items-center gap-2 text-sm text-[#8F9299] mb-6">
|
||||
<Link to="/admin/validations" className="flex items-center gap-2 text-[#232528] hover:underline">
|
||||
Manage Submissions <img src={caretUpSrc} alt="" className="h-3 w-3 " />
|
||||
</Link>
|
||||
<span className="text-[#7A7F87] font-medium">View Submission</span>
|
||||
</nav>
|
||||
<nav className="flex items-center px-3 justify-between text-sm ">
|
||||
{/* LEFT SIDE */}
|
||||
<div className="flex items-center gap-2 text-[#8F9299]">
|
||||
<Link
|
||||
to="/admin/validations"
|
||||
className="flex items-center gap-2 text-[#232528] hover:underline"
|
||||
>
|
||||
Manage Submissions
|
||||
<img src={caretUpSrc} alt="" className="h-3 w-3" />
|
||||
</Link>
|
||||
<span className="text-[#7A7F87] font-medium">
|
||||
View Submission
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* RIGHT SIDE */}
|
||||
{/* <button
|
||||
onClick={() => navigate(-1)}
|
||||
className="flex items-center gap-1 text-sm text-white px-2 py-1 rounded-md bg-[#B68A35] hover:underline"
|
||||
>
|
||||
← Back
|
||||
</button> */}
|
||||
</nav>
|
||||
|
||||
<section className="min-h-[219px] rounded-[16px] border border-[#E6EAF5] bg-white px-0 py-6 shadow-[0_16px_32px_rgba(15,23,42,0.08)]">
|
||||
<div className="grid gap-1 lg:grid-cols-2">
|
||||
@ -1888,25 +1907,52 @@ setAdditionalForecastMonths([
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="border-t border-[#E5E7EB] bg-white pt-2 pb-4 px-6 max-w-[1240px] mx-auto">
|
||||
<div className="mx-auto flex max-w-[1280px] justify-end gap-4">
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex h-11 items-center justify-center rounded-[10px] border border-[#B52520] px-6 text-sm font-semibold text-[#B52520] transition-colors hover:bg-[#FEE2E2] disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
onClick={() => setIsRejectOpen(true)}
|
||||
disabled={actionLoading || submissionData?.status === 'Rejected' || submissionData?.status === 'Approved'}
|
||||
>
|
||||
{submissionData?.status === 'Rejected' ? 'Already Rejected' : 'Reject'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex h-11 items-center justify-center rounded-[10px] bg-[#92722A] px-6 text-sm font-semibold text-white transition-colors hover:bg-[#B68A35] disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
onClick={() => setIsApproveOpen(true)}
|
||||
disabled={actionLoading || submissionData?.status === 'Approved' || submissionData?.status === 'Rejected'}
|
||||
>
|
||||
{actionLoading ? 'Processing...' : submissionData?.status === 'Approved' ? 'Already Approved' : 'Approve'}
|
||||
</button>
|
||||
</div>
|
||||
<div className="border-t border-[#E5E7EB] bg-white pt-2 pb-4 px-6 max-w-[1240px] mx-auto my-auto">
|
||||
<div className="mx-auto flex max-w-[1280px] items-center justify-between">
|
||||
{/* LEFT SIDE - Back */}
|
||||
<button
|
||||
onClick={() => navigate(-1)}
|
||||
className="flex items-center gap-1 text-[#B68A35] px-4 py-1 rounded-md border border-[#B68A35] hover:underline"
|
||||
>
|
||||
<IoIosArrowBack /> Back
|
||||
</button>
|
||||
|
||||
{/* RIGHT SIDE - Actions */}
|
||||
<div className="flex gap-4">
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex h-11 items-center justify-center rounded-[10px] border border-[#B52520] px-6 text-sm font-semibold text-[#B52520] transition-colors hover:bg-[#FEE2E2] disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
onClick={() => setIsRejectOpen(true)}
|
||||
disabled={
|
||||
actionLoading ||
|
||||
submissionData?.status === 'Rejected' ||
|
||||
submissionData?.status === 'Approved'
|
||||
}
|
||||
>
|
||||
{submissionData?.status === 'Rejected'
|
||||
? 'Already Rejected'
|
||||
: 'Reject'}
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex h-11 items-center justify-center rounded-[10px] bg-[#92722A] px-6 text-sm font-semibold text-white transition-colors hover:bg-[#B68A35] disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
onClick={() => setIsApproveOpen(true)}
|
||||
disabled={
|
||||
actionLoading ||
|
||||
submissionData?.status === 'Approved' ||
|
||||
submissionData?.status === 'Rejected'
|
||||
}
|
||||
>
|
||||
{actionLoading
|
||||
? 'Processing...'
|
||||
: submissionData?.status === 'Approved'
|
||||
? 'Already Approved'
|
||||
: 'Approve'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{isApproveOpen && (
|
||||
@ -1938,11 +1984,16 @@ setAdditionalForecastMonths([
|
||||
>
|
||||
{actionLoading ? 'Processing...' : 'Approve'}
|
||||
</button>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@ -66,18 +66,18 @@ const ManageSubmissions = () => {
|
||||
const [loading, setLoading] = React.useState(true);
|
||||
const [error, setError] = React.useState(null);
|
||||
const [search, setSearch] = React.useState('');
|
||||
const [year, setYear] = React.useState('');
|
||||
const [year, setYear] = React.useState('All');
|
||||
// Function to get current quarter (1-4)
|
||||
const getCurrentQuarter = () => {
|
||||
const month = new Date().getMonth();
|
||||
return `Q${Math.floor(month / 3) + 1}`;
|
||||
};
|
||||
|
||||
const [quarter, setQuarter] = React.useState(getCurrentQuarter());
|
||||
const [quarter, setQuarter] = React.useState('All');
|
||||
const [emirate, setEmirate] = React.useState('All');
|
||||
const [status, setStatus] = React.useState('All');
|
||||
const [selectedQuarter, setSelectedQuarter] = React.useState(getCurrentQuarter());
|
||||
const [selectedYear, setSelectedYear] = React.useState(new Date().getFullYear().toString());
|
||||
const [selectedQuarter, setSelectedQuarter] = React.useState('All');
|
||||
const [selectedYear, setSelectedYear] = React.useState('All');
|
||||
const [currentPage, setCurrentPage] = React.useState(1);
|
||||
const [toast, setToast] = React.useState(null);
|
||||
const [showApproveModal, setShowApproveModal] = React.useState(false);
|
||||
@ -91,7 +91,7 @@ const ManageSubmissions = () => {
|
||||
const [isInitialLoad, setIsInitialLoad] = React.useState(true);
|
||||
const [filters, setFilters] = React.useState({
|
||||
search: '',
|
||||
year: '',
|
||||
year: 'All',
|
||||
quarter: 'All',
|
||||
emirate: 'All',
|
||||
status: 'All'
|
||||
@ -330,10 +330,9 @@ React.useEffect(() => {
|
||||
params,
|
||||
withCredentials: true
|
||||
});
|
||||
const currentQuarter = response?.data?.selected_quarter ;
|
||||
// const currentQuarter = 'All';
|
||||
const currentYear = response?.data?.selected_year || new Date().getFullYear().toString();
|
||||
// const currentYear = 'All';
|
||||
// Always use 'All' as default for both quarter and year
|
||||
const currentQuarter = 'All';
|
||||
const currentYear = 'All';
|
||||
// Set the filter states
|
||||
setSelectedQuarter(currentQuarter);
|
||||
setSelectedYear(currentYear);
|
||||
|
||||
@ -3324,6 +3324,23 @@ const handleImport = async () => {
|
||||
};
|
||||
})}
|
||||
rows={displayedRows}
|
||||
renderCell={(value, rowIndex, colIndex) => {
|
||||
// ISIC Code column is at index 3 (0-based)
|
||||
if (colIndex === 3 && value) {
|
||||
const truncated = value.length > 10 ? `${value.substring(0, 10)}…` : value;
|
||||
return (
|
||||
<div className="group relative">
|
||||
<div className="truncate cursor-pointer hover:no-underline">{truncated}</div>
|
||||
{value.length > 10 && (
|
||||
<div className="absolute z-10 hidden group-hover:block bg-gray-800 text-white text-xs rounded px-2 py-1 -top-8 left-1/2 transform -translate-x-1/2 whitespace-nowrap">
|
||||
{value}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return value;
|
||||
}}
|
||||
columnWidths={[
|
||||
300, // Establishment Name (increased from 250)
|
||||
180, // Contact Name (increased from 150)
|
||||
|
||||
@ -4,28 +4,52 @@ import { useNavigate, useLocation } from 'react-router-dom';
|
||||
import { AlertCircle, Clock, CheckCircle } from "lucide-react";
|
||||
|
||||
const logoSrc = '/assets/images/FCSCLogo.svg';
|
||||
|
||||
|
||||
const OTPVerification = () => {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
|
||||
const [otp, setOtp] = useState(['', '', '', '', '', '']);
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [toast, setToast] = useState(null);
|
||||
const [resendDisabled, setResendDisabled] = useState(false);
|
||||
const [countdown, setCountdown] = useState(600);
|
||||
const [resendDisabled, setResendDisabled] = useState(false); // Resend is enabled by default
|
||||
const [otpExpiryCountdown, setOtpExpiryCountdown] = useState(600); // 10 minutes countdown
|
||||
const [resendCooldown, setResendCooldown] = useState(0); // No initial cooldown
|
||||
const [showResendCooldown, setShowResendCooldown] = useState(false); // Only show cooldown after first click
|
||||
const [attemptsRemaining, setAttemptsRemaining] = useState(3);
|
||||
|
||||
|
||||
const inputRefs = useRef(Array(6).fill(null).map(() => React.createRef()));
|
||||
const toastTimeoutRef = useRef(null);
|
||||
const countdownRef = useRef(null);
|
||||
|
||||
|
||||
// Get email from location state or use a default
|
||||
const maskedEmail = location.state?.email ?
|
||||
`${location.state.email.split('@')[0].substring(0, 2)}***@${location.state.email.split('@')[1]}` :
|
||||
'na***@company.com';
|
||||
|
||||
const maskedEmail = (() => {
|
||||
const email = location.state?.email;
|
||||
if (!email) return 'na***@company.com';
|
||||
|
||||
const [local, domain] = email.split('@');
|
||||
|
||||
// local part masking
|
||||
const maskedLocal =
|
||||
local.length > 3
|
||||
? `${local.slice(0, 2)}*****${local.slice(-1)}`
|
||||
: `${local.slice(0, 1)}***`;
|
||||
|
||||
// domain name + extension
|
||||
const domainParts = domain.split('.');
|
||||
const domainName = domainParts[0];
|
||||
const extension = domainParts.slice(1).join('.');
|
||||
|
||||
const maskedDomain =
|
||||
domainName.length > 3
|
||||
? `${domainName.slice(0, 2)}****${domainName.slice(-1)}`
|
||||
: `${domainName.slice(0, 1)}***`;
|
||||
|
||||
return `${maskedLocal}@${maskedDomain}.${extension}`;
|
||||
})();
|
||||
|
||||
|
||||
// Toast handling
|
||||
const closeToast = useCallback(() => {
|
||||
if (toastTimeoutRef.current) {
|
||||
@ -34,7 +58,7 @@ const OTPVerification = () => {
|
||||
}
|
||||
setToast(null);
|
||||
}, []);
|
||||
|
||||
|
||||
const showToast = useCallback((type, message) => {
|
||||
if (!message) return;
|
||||
if (toastTimeoutRef.current) {
|
||||
@ -47,24 +71,24 @@ const OTPVerification = () => {
|
||||
toastTimeoutRef.current = null;
|
||||
}, 4000);
|
||||
}, []);
|
||||
|
||||
|
||||
// Handle OTP input change
|
||||
const handleOtpChange = (e, index) => {
|
||||
const value = e.target.value;
|
||||
|
||||
|
||||
// Only allow numbers and limit to 1 character
|
||||
if (value && !/^\d*$/.test(value)) return;
|
||||
|
||||
|
||||
const newOtp = [...otp];
|
||||
newOtp[index] = value.slice(-1);
|
||||
setOtp(newOtp);
|
||||
|
||||
|
||||
// Move to next input if there's a value and we're not on the last input
|
||||
if (value && index < 5 && inputRefs.current[index + 1]?.current) {
|
||||
inputRefs.current[index + 1].current.focus();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Handle backspace
|
||||
const handleKeyDown = (e, index) => {
|
||||
if (e.key === 'Backspace' && !otp[index] && index > 0 && inputRefs.current[index - 1]?.current) {
|
||||
@ -72,7 +96,7 @@ const OTPVerification = () => {
|
||||
inputRefs.current[index - 1].current.focus();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Handle paste
|
||||
const handlePaste = (e) => {
|
||||
e.preventDefault();
|
||||
@ -82,40 +106,40 @@ const OTPVerification = () => {
|
||||
setOtp([...newOtp, ...Array(6 - newOtp.length).fill('')]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Handle verify OTP
|
||||
const handleVerify = async (e) => {
|
||||
e.preventDefault();
|
||||
const otpValue = otp.join('');
|
||||
|
||||
|
||||
if (otpValue.length !== 6) {
|
||||
setError('Please enter a valid 6-digit code');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
setLoading(true);
|
||||
setError('');
|
||||
|
||||
|
||||
try {
|
||||
const response = await verifyOtp({
|
||||
registered_email: location.state?.email,
|
||||
otp: otpValue
|
||||
const response = await verifyOtp({
|
||||
registered_email: location.state?.email,
|
||||
otp: otpValue
|
||||
});
|
||||
|
||||
|
||||
if (response?.status === 'success') {
|
||||
// Show success message immediately
|
||||
showToast('success', 'Verified! You are signed in. Redirecting to your dashboard.');
|
||||
|
||||
|
||||
// Get the user role from the most reliable source
|
||||
const userRole = response?.data?.user?.role ||
|
||||
response?.data?.role ||
|
||||
const userRole = response?.data?.user?.role ||
|
||||
response?.data?.role ||
|
||||
localStorage.getItem('user_role');
|
||||
|
||||
|
||||
// Set the role in localStorage if not already set
|
||||
if (userRole && !localStorage.getItem('user_role')) {
|
||||
localStorage.setItem('user_role', userRole);
|
||||
}
|
||||
|
||||
|
||||
// Update user profile in local storage with OTP verification status
|
||||
try {
|
||||
const userProfile = JSON.parse(localStorage.getItem('user_profile') || '{}');
|
||||
@ -128,22 +152,22 @@ const OTPVerification = () => {
|
||||
} catch (error) {
|
||||
console.error('Failed to update user profile:', error);
|
||||
}
|
||||
|
||||
|
||||
// Determine the appropriate dashboard based on user role
|
||||
let redirectPath = '/dashboard';
|
||||
|
||||
|
||||
// Check if user is admin (case-insensitive check)
|
||||
if (userRole && userRole.toLowerCase() === 'admin') {
|
||||
redirectPath = '/admin/dashboard';
|
||||
console.log('Admin user detected, redirecting to admin dashboard');
|
||||
}
|
||||
|
||||
|
||||
// If there's a saved path from before login, use that
|
||||
const savedPath = location.state?.from?.pathname;
|
||||
if (savedPath) {
|
||||
redirectPath = savedPath;
|
||||
}
|
||||
|
||||
|
||||
// Redirect after a short delay
|
||||
setLoading(true);
|
||||
setTimeout(() => {
|
||||
@ -152,20 +176,20 @@ const OTPVerification = () => {
|
||||
} else {
|
||||
throw new Error(response?.message || 'Invalid OTP');
|
||||
}
|
||||
|
||||
|
||||
} catch (err) {
|
||||
console.error('OTP verification failed', err);
|
||||
const errorMessage = err.response?.data?.message ||
|
||||
err.message ||
|
||||
const errorMessage = err.response?.data?.message ||
|
||||
err.message ||
|
||||
'An error occurred during OTP verification. Please try again.';
|
||||
|
||||
|
||||
const newAttempts = attemptsRemaining - 1;
|
||||
setAttemptsRemaining(newAttempts);
|
||||
|
||||
|
||||
// Set the error message for incorrect OTP
|
||||
const displayError = errorMessage || 'Invalid verification code';
|
||||
setError(displayError);
|
||||
|
||||
|
||||
if (newAttempts <= 0) {
|
||||
setOtp(Array(6).fill(''));
|
||||
// Show error message and redirect to login after a short delay
|
||||
@ -184,76 +208,85 @@ const OTPVerification = () => {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Handle OTP expiry countdown
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => {
|
||||
setOtpExpiryCountdown(prev => {
|
||||
if (prev <= 0) {
|
||||
clearInterval(timer);
|
||||
// Redirect to login when OTP expires
|
||||
navigate('/login', {
|
||||
state: {
|
||||
message: 'OTP has expired. Please try again.',
|
||||
messageType: 'error'
|
||||
},
|
||||
replace: true
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
return prev - 1;
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
return () => clearInterval(timer);
|
||||
}, [navigate]);
|
||||
|
||||
// Handle resend cooldown timer
|
||||
useEffect(() => {
|
||||
if (resendCooldown <= 0) {
|
||||
setResendDisabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setResendDisabled(true);
|
||||
const cooldownTimer = setInterval(() => {
|
||||
setResendCooldown(prev => {
|
||||
if (prev <= 1) {
|
||||
clearInterval(cooldownTimer);
|
||||
setResendDisabled(false);
|
||||
return 0;
|
||||
}
|
||||
return prev - 1;
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
return () => clearInterval(cooldownTimer);
|
||||
}, [resendCooldown]);
|
||||
|
||||
// Handle resend OTP
|
||||
const handleResend = async () => {
|
||||
if (resendDisabled) return;
|
||||
|
||||
|
||||
// Show loading state immediately
|
||||
setResendDisabled(true);
|
||||
setLoading(true);
|
||||
|
||||
|
||||
try {
|
||||
// Call the API to resend OTP
|
||||
const response = await requestOtp(location.state?.email);
|
||||
|
||||
// Update state and show success toast immediately
|
||||
const tenMinutesInSeconds = 10 * 60;
|
||||
setCountdown(tenMinutesInSeconds);
|
||||
|
||||
// Reset timers
|
||||
setOtpExpiryCountdown(600); // Reset to 10 minutes
|
||||
setResendCooldown(60); // Start 60 seconds cooldown
|
||||
setShowResendCooldown(true); // Show the cooldown timer
|
||||
setAttemptsRemaining(3);
|
||||
setError('');
|
||||
setOtp(Array(6).fill(''));
|
||||
|
||||
// Use setTimeout to ensure the toast shows up in the next tick
|
||||
setTimeout(() => {
|
||||
showToast('success', response.message || 'A new OTP has been sent to your email.');
|
||||
}, 0);
|
||||
|
||||
|
||||
// Show success message immediately
|
||||
showToast('success', response.message || 'A new OTP has been sent to your email.');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error resending OTP:', error);
|
||||
showToast('error', 'An error occurred while sending OTP. Please try again.');
|
||||
setResendDisabled(false);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
// Re-enable resend after 60 seconds
|
||||
const timer = setTimeout(() => {
|
||||
setResendDisabled(false);
|
||||
}, 60000);
|
||||
|
||||
// Cleanup timer on component unmount
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
};
|
||||
|
||||
// Start countdown on component mount
|
||||
useEffect(() => {
|
||||
// Always use 10 minutes for the countdown
|
||||
const tenMinutesInMs = 10 * 60 * 1000;
|
||||
const expiryTime = Date.now() + tenMinutesInMs;
|
||||
|
||||
const updateCountdown = () => {
|
||||
const now = Date.now();
|
||||
const remainingSeconds = Math.max(0, Math.floor((expiryTime - now) / 1000));
|
||||
|
||||
setCountdown(remainingSeconds);
|
||||
|
||||
if (remainingSeconds <= 0) {
|
||||
clearInterval(countdownRef.current);
|
||||
setResendDisabled(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Initial update
|
||||
updateCountdown();
|
||||
|
||||
// Set up interval for countdown updates
|
||||
countdownRef.current = setInterval(updateCountdown, 1000);
|
||||
|
||||
return () => {
|
||||
if (countdownRef.current) clearInterval(countdownRef.current);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
|
||||
// Cleanup on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
@ -261,10 +294,13 @@ const OTPVerification = () => {
|
||||
if (countdownRef.current) clearInterval(countdownRef.current);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const minutes = Math.floor(countdown / 60);
|
||||
const seconds = countdown % 60;
|
||||
|
||||
|
||||
const expiryMinutes = Math.floor(otpExpiryCountdown / 60);
|
||||
const expirySeconds = otpExpiryCountdown % 60;
|
||||
|
||||
// Format time for display (MM:SS)
|
||||
const formatTime = (time) => time < 10 ? `0${time}` : time;
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#F7F7F7] flex items-center justify-center px-4">
|
||||
{/* Toast Notification */}
|
||||
@ -297,7 +333,7 @@ const OTPVerification = () => {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
<div className="w-full max-w-md">
|
||||
<div className="bg-white rounded-lg shadow-sm ring-1 ring-gray-200 overflow-hidden">
|
||||
{/* Logo Section */}
|
||||
@ -309,13 +345,13 @@ const OTPVerification = () => {
|
||||
IIP (Index of Industrial Production)
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="p-7">
|
||||
{/* <div className="text-center mb-6">
|
||||
<h2 className="text-xl font-bold text-gray-800">Email OTP</h2>
|
||||
<p className="text-gray-600 mt-1">Step 2 of 2</p>
|
||||
</div> */}
|
||||
|
||||
|
||||
<form onSubmit={handleVerify}>
|
||||
<div className="space-y-6">
|
||||
<div className="text-center">
|
||||
@ -324,7 +360,7 @@ const OTPVerification = () => {
|
||||
We sent a 6-digit authentication code to <span className="font-medium">{maskedEmail}</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
{/* OTP Inputs */}
|
||||
<div className="space-y-4">
|
||||
<div className="flex justify-center space-x-3">
|
||||
@ -341,8 +377,8 @@ const OTPVerification = () => {
|
||||
onKeyDown={(e) => handleKeyDown(e, index)}
|
||||
onPaste={handlePaste}
|
||||
className={`w-12 h-12 text-center text-xl bg-transparent border-2 rounded focus:outline-none focus:ring-0 ${
|
||||
error ? 'border-red-500' :
|
||||
digit ? 'border-[#92722A]' :
|
||||
error ? 'border-red-500' :
|
||||
digit ? 'border-[#92722A]' :
|
||||
'border-gray-300 hover:border-gray-400 focus:border-[#92722A] focus:border-b-2 focus:border-b-[#92722A]'
|
||||
}`}
|
||||
autoFocus={index === 0}
|
||||
@ -350,25 +386,25 @@ const OTPVerification = () => {
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
|
||||
{error && (
|
||||
<div className="text-red-600 text-sm flex items-center justify-center">
|
||||
<AlertCircle className="h-4 w-4 mr-1" />
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
<div className="flex justify-between items-center text-sm text-gray-600">
|
||||
<div className="flex items-center space-x-2 leading-none">
|
||||
<Clock className="h-4 w-4 flex-shrink-0 -mt-0.5" />
|
||||
<span className="text-sm -ml-1">
|
||||
Code expires in {minutes}:{seconds < 10 ? `0${seconds}` : seconds}
|
||||
Code expires in {formatTime(expiryMinutes)}:{formatTime(expirySeconds)}
|
||||
</span>
|
||||
</div>
|
||||
<span>Attempts: {attemptsRemaining} of 3</span>
|
||||
<span>Attempts used: {attemptsRemaining}/3</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<button
|
||||
type="submit"
|
||||
@ -388,28 +424,30 @@ const OTPVerification = () => {
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
|
||||
|
||||
<div className="text-center">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleResend}
|
||||
disabled={resendDisabled}
|
||||
className={`text-sm font-medium ${
|
||||
resendDisabled ? 'text-gray-400' : 'text-[#92722A] hover:text-[#7a5e23]'
|
||||
resendDisabled ? 'text-gray-400 cursor-not-allowed' : 'text-[#92722A] hover:text-[#7a5e23] cursor-pointer'
|
||||
}`}
|
||||
>
|
||||
{resendDisabled ? `Resend code (${Math.ceil(countdown/60)}:${(countdown%60).toString().padStart(2, '0')})` : 'Resend code'}
|
||||
{showResendCooldown && resendCooldown > 0
|
||||
? `Resend code (${formatTime(Math.floor(resendCooldown / 60))}:${formatTime(resendCooldown % 60)})`
|
||||
: 'Resend code'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
<div className="mt-6 pt-6 border-t border-gray-200 text-center">
|
||||
|
||||
<p className="mt-2 text-sm text-gray-600">
|
||||
Having trouble?{' '}
|
||||
<button
|
||||
<button
|
||||
onClick={() => navigate('/')}
|
||||
className="text-[#92722A] hover:text-[#7a5e23] font-medium focus:outline-none"
|
||||
>
|
||||
@ -423,5 +461,5 @@ const OTPVerification = () => {
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default OTPVerification;
|
||||
|
||||
export default OTPVerification;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user