From 96b3e62554bb28344b6c831c7cdd1edc4f5e5acf Mon Sep 17 00:00:00 2001 From: Andy Chan Date: Tue, 27 Feb 2024 15:47:10 -0500 Subject: [PATCH] Add error messages to login page Modifies the Button component, may break some things. I hope not. --- compass/app/page.tsx | 52 ++++++++++++++++++++++++++++++----- compass/components/Button.tsx | 2 +- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/compass/app/page.tsx b/compass/app/page.tsx index 8cc4be6..3ab3991 100644 --- a/compass/app/page.tsx +++ b/compass/app/page.tsx @@ -1,17 +1,52 @@ // pages/index.tsx +"use client"; import Button from '@/components/Button'; import Input from '@/components/Input' import InlineLink from '@/components/InlineLink'; import Paper from '@/components/auth/Paper'; -import { Metadata } from 'next' +// import { Metadata } from 'next' import Image from 'next/image'; +import {ChangeEvent, useState} from "react"; -export const metadata: Metadata = { - title: 'Login', -} +// export const metadata: Metadata = { +// title: 'Login', +// } export default function Page() { + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [error, setError] = useState(""); + + const handleEmailChange = (event: React.ChangeEvent) => { + setEmail(event.currentTarget.value); + console.log("email " + email); + } + + const handlePasswordChange = (event: React.ChangeEvent) => { + setPassword(event.currentTarget.value); + console.log("password " + password) + } + + const handleClick = (event: React.MouseEvent) => { + event.preventDefault(); + // Priority: Incorrect combo > Missing email > Missing password + + if (password.trim().length === 0) { + setError("Please enter your password.") + } + // This shouldn't happen, already provides validation, but just in case. + if (email.trim().length === 0) { + setError("Please enter your email.") + } + // Placeholder for incorrect email + password combo. + if (email === "incorrect@gmail.com" && password) { + setError("Incorrect password.") + } + } + + + return ( <> @@ -24,18 +59,21 @@ export default function Page() { />

Login

- +
- +
Forgot password? - +
diff --git a/compass/components/Button.tsx b/compass/components/Button.tsx index 72c47f9..597c082 100644 --- a/compass/components/Button.tsx +++ b/compass/components/Button.tsx @@ -2,7 +2,7 @@ import { FunctionComponent, ReactNode } from 'react'; type ButtonProps = { children: ReactNode; - onClick?: () => void; // make the onClick handler optional + onClick?: (event: React.MouseEvent) => void; }; const Button: FunctionComponent = ({ children, onClick }) => {