Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (#273): a11y audit signup page #303

Merged
merged 58 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
04ac51b
feat (#273): import and apply LinkCustom component
CorinaMurg Jun 8, 2024
fa8eb8b
feat (#273): update <title>
CorinaMurg Jun 8, 2024
7c03632
fix: register page.tsx to be a server component
chris-nowicki Jun 10, 2024
e006e55
fix(#273): update title and description
CorinaMurg Jun 10, 2024
7469ddd
fix(#273): remove Link import
CorinaMurg Jul 6, 2024
652a260
fix(#273): add font-bold and text classes to LinkCustom
CorinaMurg Jul 6, 2024
8fba3a6
fix(#273): update text of second Login link
CorinaMurg Jul 6, 2024
be6cf89
fix(#273): merge develop
CorinaMurg Jul 6, 2024
eb7a990
fix(#273): add return type to RegisterPage function
CorinaMurg Jul 7, 2024
9777134
fix(#273): add JSDoc comment
CorinaMurg Jul 7, 2024
a1efcba
fix(#273): remove the hard-coded data-testid
CorinaMurg Jul 7, 2024
4d33119
fix(#273): create label variants
CorinaMurg Jul 10, 2024
2319374
fix(#273): wrap input fields in Label component
CorinaMurg Jul 10, 2024
8b41dd6
Merge branch 'develop' into corina/a11y-audit-signup-page
CorinaMurg Jul 10, 2024
f0777a9
fix(#273): remove unused code
CorinaMurg Jul 10, 2024
3b3929d
fix(#273): update data-testid in unit test for LinkCustom
CorinaMurg Jul 16, 2024
e99e554
fix(#273): merge develop
CorinaMurg Jul 16, 2024
8916bc8
fix(#273): add Label variant to WeeklyPickButton
CorinaMurg Jul 16, 2024
6382386
fix(#273): add unit test for Label
CorinaMurg Jul 17, 2024
8b17c88
fix(#273): update placeholder text
CorinaMurg Jul 17, 2024
54e31c3
fix(#273): update text size for Label
CorinaMurg Jul 17, 2024
a0d13ce
fix(#273): update gap values for Label variants
CorinaMurg Jul 17, 2024
b2f46ab
fix(#273): create interface export for LinkCustom
CorinaMurg Jul 17, 2024
ff1f640
fix(#273): remove interface file for LinkCustom
CorinaMurg Jul 18, 2024
c639f72
fix(#273): add Label.tsx file
CorinaMurg Jul 18, 2024
d189719
fix(#273): merge develop
CorinaMurg Jul 18, 2024
0a9c881
Merge branch 'develop' into corina/a11y-audit-signup-page
CorinaMurg Jul 18, 2024
29fa949
fix(#273): fix spelling mistake
CorinaMurg Jul 18, 2024
2a84095
fix(#273): hyphenate data-testid and custom classes
CorinaMurg Jul 18, 2024
892934e
Merge branch 'develop' into corina/a11y-audit-signup-page
CorinaMurg Jul 19, 2024
f419421
fix(#273): update variant names for Label
CorinaMurg Jul 22, 2024
88a3bfd
fix(#273): update variants name in Label test
CorinaMurg Jul 22, 2024
96cc8a6
fix(#273): merge develop
CorinaMurg Jul 25, 2024
c7e9c22
fix(#273): added back the data-testid to LinkCustom
CorinaMurg Jul 25, 2024
caf8de3
fix(#273): remove data-testid from LinkCustom test
CorinaMurg Jul 25, 2024
56d4843
fix(#273): create file with Label variant types
CorinaMurg Jul 25, 2024
c749ace
fix(#273): merge develop
CorinaMurg Aug 12, 2024
b985de1
fix(#273): update test with correct name for Register page
CorinaMurg Aug 13, 2024
de0b89d
Merge branch 'develop' into corina/a11y-audit-signup-page
CorinaMurg Aug 13, 2024
d5b9267
Merge branch 'develop' into corina/a11y-audit-signup-page
CorinaMurg Aug 13, 2024
79480b7
fix(#273): merge develop
CorinaMurg Aug 13, 2024
61973e3
fix(#273): change label text color
CorinaMurg Aug 13, 2024
a3c6480
fix(#273): remove punctuation from LinkCustom
CorinaMurg Aug 13, 2024
2f90856
fix(#273): update variant classes
CorinaMurg Aug 15, 2024
8a661db
Merge branch 'develop' into corina/a11y-audit-signup-page
CorinaMurg Aug 23, 2024
0b2630c
Merge branch 'develop' into corina/a11y-audit-signup-page
ryandotfurrer Aug 23, 2024
8cf9b62
Merge branch 'corina/a11y-audit-signup-page' of https://github.com/Le…
CorinaMurg Sep 19, 2024
9371d6d
fix(#273): Merge changes from develop except in Label and WeeklyPickB…
CorinaMurg Sep 19, 2024
2ca6306
fix(#273): Merge changes from develop
CorinaMurg Sep 19, 2024
0789402
Merge branch 'develop' into corina/a11y-audit-signup-page
CorinaMurg Oct 18, 2024
f79a31c
Merge 'develop' into corina/a11y-audit-signup-page
CorinaMurg Oct 18, 2024
5e155f8
fix (#273): update Labal unit test after merging develop
CorinaMurg Oct 18, 2024
0d380b2
fix(#273): add labels to registration input fields
CorinaMurg Oct 21, 2024
8429c4a
fix(#273): update placeholder values for registration input fields
CorinaMurg Oct 21, 2024
2640e7d
fix(#273): wrap the link only around the Link word
CorinaMurg Oct 21, 2024
4bc7c76
fix(#273): remove extra lines
CorinaMurg Oct 21, 2024
883b84e
fix(#273): add missing new line at the end of the file
CorinaMurg Oct 21, 2024
252e1b9
Merge branch 'develop' into corina/a11y-audit-signup-page
shashilo Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
261 changes: 261 additions & 0 deletions app/(main)/register/Register.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
// Copyright (c) Gridiron Survivor.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have a new register page in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Register.tsx is now the client component, and page.tsx is the server component (with the meta data) for the registration page. This breakdown is necessary in order for nextJS to render a page with the correct meta data.

I’m tagging @chris-nowicki here just to make sure I’m explaining this correctly. He’s the one who took care of this fix.

// Licensed under the MIT License.

'use client';
import { AlertVariants } from '@/components/AlertNotification/Alerts.enum';
import { Button } from '@/components/Button/Button';
import { Control, useForm, useWatch, SubmitHandler } from 'react-hook-form';
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from '../../../components/Form/Form';
import { Input } from '@/components/Input/Input';
import { registerAccount } from '@/api/apiFunctions';
import { toast } from 'react-hot-toast';
import { useAuthContext } from '@/context/AuthContextProvider';
import { useRouter } from 'next/navigation';
import { z } from 'zod';
import { zodResolver } from '@hookform/resolvers/zod';
import Alert from '@/components/AlertNotification/AlertNotification';
import LinkCustom from '@/components/LinkCustom/LinkCustom';
import Logo from '@/components/Logo/Logo';
import logo from '/public/assets/logo-colored-outline.svg';
import React, { JSX, useEffect, useState } from 'react';
import LoadingSpinner from '@/components/LoadingSpinner/LoadingSpinner';

const RegisterUserSchema = z
.object({
email: z
.string()
.min(1, { message: 'Please enter an email address' })
.email({ message: 'Please enter a valid email address' }),
password: z
.string()
.min(1, { message: 'Please enter a password' })
.min(8, { message: 'Password must be at least 8 characters' }),
confirmPassword: z
.string()
.min(1, { message: 'Please confirm your password' })
.min(8, { message: 'Password must be at least 8 characters' }),
})
.refine((data) => data.password === data.confirmPassword, {
message: "Passwords don't match",
path: ['confirmPassword'],
});

type RegisterUserSchemaType = z.infer<typeof RegisterUserSchema>;

/**
* Renders the registration page.
* @returns {JSX.Element} The rendered registration page.
*/
const Register = (): JSX.Element => {
const router = useRouter();
const { login, isSignedIn } = useAuthContext();
const [isLoading, setIsLoading] = useState(false);

useEffect(() => {
if (isSignedIn) {
router.push('/league/all');
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSignedIn]);

const form = useForm<RegisterUserSchemaType>({
resolver: zodResolver(RegisterUserSchema),
});

/**
* The current value of the 'email' field in the form.
* @type {string}
*/
const email: string = useWatch({
control: form.control,
name: 'email',
defaultValue: '',
});

/**
* The current value of the 'password' field in the form.
* @type {string}
*/
const password: string = useWatch({
control: form.control,
name: 'password',
defaultValue: '',
});

/**
* The current value of the 'confirmPassword' field in the form.
* @type {string}
*/
const confirmPassword: string = useWatch({
control: form.control,
name: 'confirmPassword',
defaultValue: '',
});

/**
* A function that handles form submission.
* @param {RegisterUserSchemaType} data - The data submitted in the form.
* @returns {Promise<void>} Promise that resolves after form submission is processed.
*/
const onSubmit: SubmitHandler<RegisterUserSchemaType> = async (
data: RegisterUserSchemaType,
): Promise<void> => {
try {
setIsLoading(true);
await registerAccount(data);
await login(data);
toast.custom(
<Alert
variant={AlertVariants.Success}
message="You have successfully registered your account."
/>,
);
} catch (error) {
console.error('Registration Failed', error);
toast.custom(
<Alert variant={AlertVariants.Error} message="Something went wrong!" />,
);
} finally {
setIsLoading(false);
}
};

const isDisabled = !email || !password || password !== confirmPassword;

return (
<section className="grid xl:grid-cols-2 xl:grid-rows-none">
<div
data-testid="dark-mode-section"
className="row-span-1 grid w-full place-items-center from-[#4E160E] to-zinc-950 bg-gradient-to-b xl:h-screen xl:bg-gradient-to-b"
>
<Logo className="mx-auto w-52 xl:w-64 xl:place-self-end" src={logo} />
<div className="mx-auto grid gap-4 place-self-end px-8 pb-8 text-foreground">
<p className="hidden leading-7 xl:block">
Thank you... fantasy football draft, for letting me know that even
in my fantasies, I am bad at sports.
</p>
<p className="hidden leading-7 xl:block">Jimmy Fallon</p>
</div>
</div>
<div className="row-span-1 mx-auto grid max-w-sm justify-center space-y-4 px-4 xl:flex xl:flex-col">
<div>
<h1 className="text-5xl font-extrabold tracking-tight text-foreground">
Register A New Account
</h1>
<p className="pb-4 font-normal leading-7 text-muted-foreground">
If you have an existing account{' '}
<LinkCustom href="/login">Login!</LinkCustom>
</p>
</div>

<Form {...form}>
<form
id="input-container"
className="grid gap-3"
data-testid="register-form"
onSubmit={form.handleSubmit(onSubmit)}
>
<FormField
control={form.control as Control<object>}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel className="border-none px-0 py-0 pb-2 pl-1">
Email
</FormLabel>
<FormControl>
<Input
data-testid="email"
type="email"
placeholder="Your email"
{...field}
/>
</FormControl>
{form.formState.errors?.email && (
<FormMessage>
{form.formState.errors?.email.message}
</FormMessage>
)}
</FormItem>
)}
/>
<FormField
control={form.control as Control<object>}
name="password"
render={({ field }) => (
<FormItem>
<FormLabel className="border-none px-0 py-0 pb-2 pl-1">
Password
</FormLabel>
<FormControl>
<Input
data-testid="password"
type="password"
placeholder="Your password"
{...field}
/>
</FormControl>
{form.formState.errors?.password && (
<FormMessage>
{form.formState.errors?.password.message}
</FormMessage>
)}
</FormItem>
)}
/>
<FormField
control={form.control as Control<object>}
name="confirmPassword"
render={({ field }) => (
<FormItem>
<FormLabel className="border-none px-0 py-0 pb-2 pl-1">
Confirm Password
</FormLabel>
<FormControl>
<Input
data-testid="confirm-password"
type="password"
placeholder="Confirm your password"
{...field}
/>
</FormControl>
{form.formState.errors?.confirmPassword && (
<FormMessage>
{form.formState.errors?.confirmPassword.message}
</FormMessage>
)}
</FormItem>
)}
/>

<Button
data-testid="continue-button"
label={
isLoading ? (
<LoadingSpinner data-testid="loading-spinner" />
) : (
'Continue'
)
}
type="submit"
disabled={isDisabled}
/>
<p className="pb-4 font-normal leading-7 text-muted-foreground">
<LinkCustom href="/login">Login</LinkCustom>
{' '} to get started playing.
</p>
</form>
</Form>
</div>
</section>
);
};

export default Register;
10 changes: 5 additions & 5 deletions app/(main)/register/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { toast } from 'react-hot-toast';
import Alert from '@/components/AlertNotification/AlertNotification';
import React, { useState as useStateMock } from 'react';
import Register from './page';
import RegisterPage from './page';

const mockLogin = jest.fn();
const mockPush = jest.fn();
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('Register', () => {
.spyOn(React, 'useState')
.mockImplementation(() => [false, setIsLoading]);

render(<Register />);
render(<RegisterPage />);

confirmPasswordInput = screen.getByTestId('confirm-password');
continueButton = screen.getByTestId('continue-button');
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('Register', () => {
it('redirects to /league/all when the button is clicked', async () => {
mockUseAuthContext.isSignedIn = true;

render(<Register />);
render(<RegisterPage />);

await waitFor(() => {
expect(mockPush).toHaveBeenCalledWith('/league/all');
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('Register loading spinner', () => {
setIsLoading,
]);

render(<Register />);
render(<RegisterPage />);

await waitFor(() => {
expect(screen.queryByTestId('loading-spinner')).toBeInTheDocument();
Expand All @@ -189,7 +189,7 @@ describe('Register loading spinner', () => {
setIsLoading,
]);

render(<Register />);
render(<RegisterPage />);

await waitFor(() => {
expect(screen.queryByTestId('loading-spinner')).not.toBeInTheDocument();
Expand Down
Loading