Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 28 additions & 0 deletions client/src/assets/components/subcomponents/CountdownTimer.jsx
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;
2 changes: 1 addition & 1 deletion client/src/assets/components/subcomponents/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const Login = () => {
const {
message: successMessage,
show: showSuccessToast,
showSuccess,
//showSuccess,
Copy link
Owner

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.

} = useSuccessToast();

const handleChange = (e) => {
Expand Down
14 changes: 11 additions & 3 deletions client/src/assets/components/subcomponents/Register.jsx
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";
Expand All @@ -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}$/;
Expand Down Expand Up @@ -73,6 +75,9 @@ const Register = () => {

const [buttonStatus, setButtonStatus] = useState("Sign Up");

// For countdowntimer
const isCountdownTimer = success;

useEffect(() => {
firstNameRef.current.focus();
}, []);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The 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: <p className="text-md mt-1"> <Link to="/login" className="link link-primary"> Click here to log in </Link>{" "} and get started! </p>

That way the new message is just your countdown and redirects inside of the same block as the success message.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replacement is complete!

</div>
<SuccessToast
message={successMessage}
Expand All @@ -841,6 +849,6 @@ const Register = () => {
/>
</div>
);
};
}

export default Register;