Skip to content

Commit

Permalink
add toast notifications in signup
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohitha-pudu committed May 17, 2024
1 parent 0b6cd3f commit a96aa62
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions frontend/src/app/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@ import Link from "next/link";
import axios from "axios";
import { useDataContext } from "@/context/dataContext";
import { redirect, useRouter } from "next/navigation";
import { toast, ToastContainer } from "react-toastify";
import 'react-toastify/dist/ReactToastify.css';

export default function Signup() {
const router = useRouter();
const { authState } = useDataContext();

return (
<>
<ToastContainer
position="top-center"
autoClose={5000}
hideProgressBar={true} // Hide the progress bar
newestOnTop={false}
closeOnClick
rtl={false}
pauseOnFocusLoss
draggable
pauseOnHover
theme="colored"
/>
{(authState === "loading" || authState === "notloggedin") && (
<SignupInner />
)}
Expand All @@ -30,14 +44,17 @@ function SignupInner() {
e.preventDefault();
if (email.length == 0) {
setError("*Email can't be empty");
toast.error("*Email can't be empty");
return;
}
if (username.length == 0) {
setError("*username can't be empty");
toast.error("*Username can't be empty");
return;
}
if (password.length == 0) {
setError("*Password can't be empty");
toast.error("*Password can't be empty");
return;
}
setSigningUp(true);
Expand All @@ -51,9 +68,11 @@ function SignupInner() {
}
);
setSigningUp(false);
toast.success("Signup successful!");
router.push("/login");
} catch (error) {
setSigningUp(false);
toast.error((error as Error).message);
setError((error as Error).message);
}
};
Expand Down

0 comments on commit a96aa62

Please sign in to comment.