Skip to content

Commit

Permalink
touch up styles and add basic email regex
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPereira committed Oct 14, 2023
1 parent 991722d commit b8a2755
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
12 changes: 8 additions & 4 deletions frontend/src/pages/Authentication/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ type Inputs = {
};

/** Login Form Component
*
* @dev used on the Authentication page
* @dev noValidate on form to disable browser vaildation so we can use react-hook-form validations instead
*
*/

export default function LoginForm() {
const {
register,
Expand All @@ -33,7 +31,13 @@ export default function LoginForm() {
id="email"
type="email"
register={register}
validations={{ required: "Please enter your email address" }}
validations={{
required: "Please enter your email address",
pattern: {
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
message: "Please enter a valid email address",
},
}}
errors={errors.email}
/>
<TextField
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/pages/Authentication/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ type Inputs = {
password: string;
};

/** Signup Form Component
* @dev used on the Authentication page
* @dev noValidate on form to disable browser vaildation so we can use react-hook-form validations instead
*/
export default function SignupForm() {
const {
register,
Expand All @@ -19,6 +23,7 @@ export default function SignupForm() {
const onSubmit: SubmitHandler<Inputs> = (data) => {
console.log("Sending form data to server...", data);
};

return (
<div>
<h3 className="mb-10 text-4xl font-bold">Sign up</h3>
Expand Down Expand Up @@ -47,7 +52,13 @@ export default function SignupForm() {
type="email"
register={register}
errors={errors.email}
validations={{ required: "Please enter your email address" }}
validations={{
required: "Please enter your email address",
pattern: {
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
message: "Please enter a valid email address",
},
}}
/>
<TextField
label="Password"
Expand Down
1 change: 0 additions & 1 deletion frontend/src/pages/Authentication/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import SignupForm from "./SignupForm";
/** AuthenticationPage
* @dev handles both "/login" and "/signup" paths
*/

export default function AuthenticationPage() {
const { pathname } = useLocation();

Expand Down
13 changes: 6 additions & 7 deletions frontend/src/tw-components/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ interface TextFieldProps extends React.PropsWithChildren {
* @prop register -> React Hook Form's register function
* @prop validations -> React Hook Form's validation object
* @prop errors -> React Hook Form's errors object
*
* @TODO The password input's "Forgot password" and toggle visibility functionality
*/

export default function TextField({
Expand All @@ -32,8 +30,8 @@ export default function TextField({
errors,
}: TextFieldProps) {
return (
<div className="w-full mb-3">
<div className="mb-2 font-bold text-base">
<div className="w-full">
<div className="mb-1 font-bold text-base">
<label htmlFor={id}>{label}</label>
{type === "password" && (
<span className="text-blue-dark font-bold underline float-right cursor-pointer">
Expand All @@ -58,9 +56,10 @@ export default function TextField({
</div>
)}
</div>
{errors && (
<p className="mt-1 text-red font-gothic font-bold">{errors.message}</p>
)}

<div className="h-8 text-red font-gothic font-bold flex flex-col justify-center">
{errors && errors.message}
</div>
</div>
);
}

0 comments on commit b8a2755

Please sign in to comment.