-
Notifications
You must be signed in to change notification settings - Fork 23
Implemented a countdown timer with automatic redirection to the login… #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import React, { useState, useEffect } from 'react'; | ||
|
|
||
| const CountdownTimer = () => { | ||
| const [timeLeft, setTimeLeft] = useState(5); | ||
|
|
||
| useEffect(() => { | ||
| const timer = setInterval(() => { | ||
| setTimeLeft(prevTimeLeft => prevTimeLeft - 1); | ||
| }, 1000); | ||
|
|
||
| return () => clearInterval(timer); | ||
|
|
||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| if (timeLeft <= 0) { | ||
| window.location.href = "/login"; | ||
| } | ||
| }, [timeLeft]); | ||
|
|
||
| return ( | ||
| <div className="text-sm text-green mt-2"> | ||
| {timeLeft > 0 ? `You will be redirected to the login page in ${timeLeft} seconds.` : "Redirecting to login page..."} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default CountdownTimer; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import React, { useRef, useEffect, useState } from "react"; | ||
| import { Link } from "react-router-dom"; | ||
| import { Link, Navigate } from "react-router-dom"; | ||
| import axios from "../../../api/axios"; | ||
| import { IoMdEyeOff, IoMdEye } from "react-icons/io"; | ||
| import { FaTimesCircle } from "react-icons/fa"; | ||
|
|
@@ -9,6 +9,8 @@ import ErrorToast from "../toast/ErrorToast"; | |
| import { useErrorToast } from "../toast/useErrorToast"; | ||
| import SuccessToast from "../toast/SuccessToast"; | ||
| import { useSuccessToast } from "../toast/useSuccessToast"; | ||
| // import CountdownTimer | ||
| import CountdownTimer from "./CountdownTimer"; | ||
|
|
||
| // REGEX for validation | ||
| const NAME_REGEX = /^[a-zA-Z][a-zA-Z- ]{1,50}$/; | ||
|
|
@@ -73,6 +75,9 @@ const Register = () => { | |
|
|
||
| const [buttonStatus, setButtonStatus] = useState("Sign Up"); | ||
|
|
||
| // For countdowntimer | ||
| const isCountdownTimer = success; | ||
|
|
||
| useEffect(() => { | ||
| firstNameRef.current.focus(); | ||
| }, []); | ||
|
|
@@ -138,7 +143,7 @@ const Register = () => { | |
| headers: { "Content-Type": "application/json" }, | ||
| withCredentials: true, | ||
| }); | ||
|
|
||
| showSuccess("Registration Successful! You can now log in."); | ||
| setSuccess(true); | ||
| // Optionally: navigate to login page | ||
|
|
@@ -824,6 +829,9 @@ const Register = () => { | |
| </form> | ||
| )} | ||
| </div> | ||
| <div className="countdown-timer"> | ||
| {isCountdownTimer && <CountdownTimer className="text-green-600 text-4xl" />} | ||
| </div> | ||
|
Comment on lines
+829
to
+831
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's have this replace lines 204 - 209 that you currently have. Basically replacing: That way the new message is just your countdown and redirects inside of the same block as the success message.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The replacement is complete! |
||
| </div> | ||
| <SuccessToast | ||
| message={successMessage} | ||
|
|
@@ -841,6 +849,6 @@ const Register = () => { | |
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
| } | ||
|
|
||
| export default Register; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please uncomment this as we have had someone recently add a feature with the success on login page.