Skip to content

Commit

Permalink
fixed email type and added toast message
Browse files Browse the repository at this point in the history
Fix Email Input Type and Improve Error Messaging on Signup and Login Pages
  • Loading branch information
Aniket-2504 committed Jun 14, 2024
1 parent 05a2783 commit 80b6cf4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
13 changes: 13 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"react-dom": "^18",
"react-icons": "^5.2.1",
"react-markdown": "^9.0.1",
"react-toastify": "^10.0.5",
"tailwind-merge": "^2.2.1",
"tailwindcss-animate": "^1.0.7"
},
Expand Down
23 changes: 14 additions & 9 deletions frontend/src/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ import Link from "next/link";
import axios from "axios";
import { useRouter } from "next/navigation";
import { useDataContext } from "@/context/dataContext";
import { ToastContainer, toast } from "react-toastify";
import 'react-toastify/dist/ReactToastify.css';

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

return (
<>
{(authState === "loading" || authState === "notloggedin") && (
<LoginInner />
)}
{authState === "loggedin" && router.push("/")}
</>
);
<ToastContainer />
{(authState === "loading" || authState === "notloggedin") && (
<LoginInner />
)}
{authState === "loggedin" && router.push("/")}
</>
);

}

function LoginInner() {
Expand All @@ -26,13 +30,13 @@ function LoginInner() {
const [loggingIn, setLogginIn] = useState<boolean>(false);
const router = useRouter();
const handleLogin= async (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.preventDefault();
// e.preventDefault();
if (email.length == 0) {
setError("*Email can't be empty");
toast.error("Email can't be empty");
return;
}
if (password.length == 0) {
setError("*Password can't be empty");
toast.error("Password can't be empty");
return;
}
//call the api here
Expand Down Expand Up @@ -89,6 +93,7 @@ function LoginInner() {
className="block px-3 w-full rounded-md border-0 py-1.5 text-gray-900 placeholder:text-gray-400 text-sm sm:leading-6"
style={{ outline: 'none' }}
/>

</div>
</div>

Expand Down
13 changes: 8 additions & 5 deletions frontend/src/app/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Link from "next/link";
import axios from "axios";
import { useDataContext } from "@/context/dataContext";
import { useRouter } from "next/navigation";
import { ToastContainer, toast } from "react-toastify";
import 'react-toastify/dist/ReactToastify.css';

export default function Signup() {
const router = useRouter();
Expand All @@ -29,21 +31,21 @@ function SignupInner() {
const [Signingup, setSigningUp] = useState<boolean>(false);

const handleSignup = async (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.preventDefault();
// 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;
}
if (password !== confirmPassword) {
setError("* Passwords do not match");
toast.error("Passwords do not match");
return;
}

Expand All @@ -67,6 +69,7 @@ function SignupInner() {

return (
<>
<ToastContainer />
<div className="flex min-h-full flex-1 flex-col justify-center px-6 py-12 lg:px-8 homepage">
<div className="text-xs text-red-900 h-2">{error}</div>
<div className="sm:mx-auto sm:w-full sm:max-w-sm">
Expand Down

0 comments on commit 80b6cf4

Please sign in to comment.