diff --git a/site/app/login/LoginForm.jsx b/site/app/login/LoginForm.jsx new file mode 100644 index 0000000..eb2a530 --- /dev/null +++ b/site/app/login/LoginForm.jsx @@ -0,0 +1,109 @@ +"use client" + + +import { isValidEmail } from '../utils/validation'; + +import React, { useState } from 'react'; + +export default function LoginForm() { + const [formData, setFormData] = useState({ email: '', password: '' }); + const [rememberMe, setRememberMe] = useState(false); + const [errors, setErrors] = useState([]); + + const handleInputChange = (e) => { + const { name, value } = e.target; + setFormData({ ...formData, [name]: value }); + }; + + const handleSubmit = (e) => { + e.preventDefault(); + + if (!validateForm()) return; + + try { + // Attempt login + } + catch(e) { + console.error("There was an error submitting the form!", e); + } + + }; + + function validateForm() { + const newErrors = {}; + + if (!formData.advisorEmail) newErrors.email = "Email is required"; + if (!isValidEmail(formData.advisorEmail)) newErrors.email = "Email is invalid"; + if (!formData.password) newErrors.password = "Password is required"; + + setErrors(newErrors); + return Object.keys(newErrors).length === 0; + } + + return ( +
+ ) +} \ No newline at end of file diff --git a/site/app/login/page.jsx b/site/app/login/page.jsx index 0512fad..e19f20c 100644 --- a/site/app/login/page.jsx +++ b/site/app/login/page.jsx @@ -1,8 +1,6 @@ -"use client" - -import React, { useState } from 'react'; +import React from "react"; import './LoginPage.css'; -import { isValidEmail } from '../utils/validation'; +import LoginForm from "./LoginForm"; export const metadata = { title: "Staff login", @@ -10,110 +8,14 @@ export const metadata = { noindex: true } -export default function Login () { - const [formData, setFormData] = useState({ email: '', password: '' }); - const [rememberMe, setRememberMe] = useState(false); - const [errors, setErrors] = useState([]); - - const handleInputChange = (e) => { - const { name, value } = e.target; - setFormData({ ...formData, [name]: value }); - }; - - const handleSubmit = (e) => { - e.preventDefault(); - - if (!validateForm()) return; - - try { - // Attempt login - } - catch(e) { - console.error("There was an error submitting the form!", e); - } - - }; - - function validateForm() { - const newErrors = {}; - - if (!formData.advisorEmail) newErrors.email = "Email is required"; - if (!isValidEmail(formData.advisorEmail)) newErrors.email = "Email is invalid"; - if (!formData.password) newErrors.password = "Password is required"; - - setErrors(newErrors); - return Object.keys(newErrors).length === 0; - } +export default function LoginPage () { return (