From 7619fd6dd396255e3b60779c18e2f67d7de7152c Mon Sep 17 00:00:00 2001 From: anikaahmed114 Date: Fri, 1 Mar 2024 19:40:01 -0500 Subject: [PATCH] progress on forgot password --- compass/app/auth/forgot_password/page.tsx | 72 +++++++++++++++++++++++ compass/components/Button.tsx | 16 ++--- compass/components/InlineLink.tsx | 2 +- compass/package-lock.json | 2 +- compass/package.json | 2 +- compass/tsconfig.json | 2 +- 6 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 compass/app/auth/forgot_password/page.tsx diff --git a/compass/app/auth/forgot_password/page.tsx b/compass/app/auth/forgot_password/page.tsx new file mode 100644 index 0000000..554e98a --- /dev/null +++ b/compass/app/auth/forgot_password/page.tsx @@ -0,0 +1,72 @@ +"use client" +import Button from '@/components/Button'; +import Input from '@/components/Input' +import InlineLink from '@/components/InlineLink'; +import Paper from '@/components/auth/Paper'; +import { useState, useEffect } from 'react'; + +function isValidEmail(email: string) { + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + + if (email.trim() === '') { + return 'Email cannot be empty'; + } else if (!emailRegex.test(email)) { + return 'Invalid email format'; + } + else{ + return 'If your email exists in the database, you should receive a password reset in your inbox.' + } + +} + +export default function Page() { + const [isButtonDisabled, setIsButtonDisabled] = useState(true); + const [confirmEmail, setconfirmEmail] = useState(''); + const [emailError, setEmailError] = useState(''); + + useEffect(() => { + const error = isValidEmail(confirmEmail); + setEmailError(error); + setIsButtonDisabled(error !== null && !error.includes('exists in the database')); + }, [confirmEmail]); + + return ( + <> + +
+

Forgot password

+
+ { + setconfirmEmail(e.target.value); + setEmailError(''); // Reset the error when the user types + }}/> + {emailError && ( +

+ {emailError} +

+ )} +
+
+ + Back to Sign In + + + +
+
+

+ © 2024 Compass Center +

+
+ + ); +}; + diff --git a/compass/components/Button.tsx b/compass/components/Button.tsx index 72c47f9..2436359 100644 --- a/compass/components/Button.tsx +++ b/compass/components/Button.tsx @@ -3,18 +3,18 @@ import { FunctionComponent, ReactNode } from 'react'; type ButtonProps = { children: ReactNode; onClick?: () => void; // make the onClick handler optional + type?: "button" | "submit" | "reset"; // specify possible values for type + disabled?: boolean; }; -const Button: FunctionComponent = ({ children, onClick }) => { +const Button: FunctionComponent = ({ children, type, disabled, onClick}) => { + const buttonClassName = `inline-block rounded border ${disabled ? 'bg-gray-400 text-gray-600 cursor-not-allowed' : 'border-purple-600 bg-purple-600 text-white hover:bg-transparent hover:text-purple-600 focus:outline-none focus:ring active:text-purple-500'} px-4 py-1 text-md font-semibold w-20 h-10 text-center`; return ( diff --git a/compass/components/InlineLink.tsx b/compass/components/InlineLink.tsx index a913ff4..f2e45ef 100644 --- a/compass/components/InlineLink.tsx +++ b/compass/components/InlineLink.tsx @@ -7,7 +7,7 @@ interface Link { const InlineLink: React.FC = ({href = '#', children}) => { return ( - + {children} ) diff --git a/compass/package-lock.json b/compass/package-lock.json index aa9dab8..de4e361 100644 --- a/compass/package-lock.json +++ b/compass/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "dependencies": { "@heroicons/react": "^2.1.1", - "next": "13.5.6", + "next": "^13.5.6", "react": "^18", "react-dom": "^18" }, diff --git a/compass/package.json b/compass/package.json index a748bbe..8fac3f3 100644 --- a/compass/package.json +++ b/compass/package.json @@ -10,7 +10,7 @@ }, "dependencies": { "@heroicons/react": "^2.1.1", - "next": "13.5.6", + "next": "^13.5.6", "react": "^18", "react-dom": "^18" }, diff --git a/compass/tsconfig.json b/compass/tsconfig.json index c714696..1acc222 100644 --- a/compass/tsconfig.json +++ b/compass/tsconfig.json @@ -8,7 +8,7 @@ "noEmit": true, "esModuleInterop": true, "module": "esnext", - "moduleResolution": "bundler", + "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve",