Skip to content

Commit

Permalink
Added login page
Browse files Browse the repository at this point in the history
  • Loading branch information
erland-syafiq committed Jun 5, 2024
1 parent eaab54a commit 42b329a
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 5 deletions.
18 changes: 18 additions & 0 deletions site/app/login/LoginPage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
main .login {
background-color: #F2F1E8;
}

section.login {
height: calc(100vh - 61px);
}

.loginBox {
border: 2px solid #630031;
background: #EFE9E7;
box-shadow: -20px 16px 0px 0px #DEBB8F;
padding: 100px
}

.loginBox > h5 {
color: grey;
}
116 changes: 116 additions & 0 deletions site/app/login/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
"use client"

import React, { useState } from 'react';
import './LoginPage.css';
import { isValidEmail } from '../utils/validation';

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;
}

return (
<section className="container login d-flex justify-content-center align-items-center">
<div className="row">
<div className="loginBox">
<h1>Staff Sign In</h1>
<form id="account" method="post" onSubmit={handleSubmit}>
<h4>Log In for staff</h4>
<hr />
<div className="form-floating">
<label>Email</label>
<input
type="email"
name="email"
className="form-control"
autoComplete="username"
aria-required="true"
value={formData.email}
onChange={handleInputChange}
placeholder="Email"
/>
<span className="text-danger">{errors.email}</span>
</div>
<div className="form-floating">
<label>Password</label>
<input
type="password"
name="password"
className="form-control"
autoComplete="current-password"
aria-required="true"
value={formData.password}
onChange={handleInputChange}
placeholder="Password"
/>
<span className="text-danger">{errors.password}</span>
</div>
<div className="form-group custom-control custom-checkbox">
<input
type="checkbox"
className="custom-control-input"
id="rememberMe"
checked={rememberMe}
onChange={(e) => setRememberMe(e.target.checked)}
/>
<label className="custom-control-label" htmlFor="rememberMe">
Remember me?
</label>
</div>
<div>
<button id="login-submit" type="submit" className="w-100 btn btn-lg btn-primary">
Log in
</button>
</div>
<div>
<p>
<a id="forgot-password" href="/forgot-password">
Forgot your password?
</a>{' '}
|{' '}
<a href="/staff-register">
Register as a new user
</a>{' '}
|{' '}
<a id="resend-confirmation" href="/resend-email-confirmation">
Resend email confirmation
</a>
</p>
</div>
</form>
<h5>For any issues, contact [email protected]</h5>
</div>
</div>
</section>
);
};
6 changes: 1 addition & 5 deletions site/app/register/RegisterForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import React, { useState } from 'react';
import { useRouter } from 'next/navigation';

function isValidEmail(email) {
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return emailRegex.test(email);
}
import { isValidEmail } from '../utils/validation';

export default function RegisterForm() {

Expand Down
4 changes: 4 additions & 0 deletions site/app/utils/validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function isValidEmail(email) {
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return emailRegex.test(email);
}

0 comments on commit 42b329a

Please sign in to comment.