Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/components/Auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ const Login = (props: LoginProps) => {
const [otpError, setOtpError] = useState<string>("");
const [otpValidationError, setOtpValidationError] = useState<string>("");
const [resendOtpCountdown, setResendOtpCountdown] = useState(0);
const activeMode =
!disablePatientLogin && mode === "patient" ? "patient" : "staff";

// Timer Function for resend OTP
useEffect(() => {
Expand All @@ -127,6 +129,16 @@ const Login = (props: LoginProps) => {
localStorage.setItem(LocalStorageKeys.loginPreference, mode);
}, [mode]);

// Autofocuses when switching tabs
useEffect(() => {
const frame = requestAnimationFrame(() => {
document
.getElementById(activeMode === "staff" ? "username" : "phone")
?.focus();
});
return () => cancelAnimationFrame(frame);
}, [activeMode]);

// Send OTP Mutation
const { mutate: sendOtp, isPending: sendOtpPending } = useMutation({
mutationFn: mutate(otpApi.send),
Expand Down
Loading