Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions apps/nextjs-app/src/components/ui/form/error.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { ComponentPropsWithoutRef } from 'react';

import { cn } from '@/utils/cn';

export type ErrorProps = {
errorMessage?: string | null;
};
} & ComponentPropsWithoutRef<'div'>;

export const Error = ({ errorMessage }: ErrorProps) => {
export const Error = ({ errorMessage, className }: ErrorProps) => {
if (!errorMessage) return null;

return (
<div
role="alert"
aria-label={errorMessage}
className="text-sm font-semibold text-red-500"
className={cn('text-sm font-semibold text-red-500', className)}
>
{errorMessage}
</div>
Expand Down
14 changes: 6 additions & 8 deletions apps/nextjs-app/src/features/auth/components/login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useSearchParams } from 'next/navigation';

import { Button } from '@/components/ui/button';
import { Form, Input } from '@/components/ui/form';
import { Error } from '@/components/ui/form/error';
import { paths } from '@/config/paths';
import { useLogin, loginInputSchema } from '@/lib/auth';

Expand All @@ -13,17 +14,17 @@ type LoginFormProps = {
};

export const LoginForm = ({ onSuccess }: LoginFormProps) => {
const login = useLogin({
const { mutate, isPending, error } = useLogin({
onSuccess,
});

const searchParams = useSearchParams();
const redirectTo = searchParams?.get('redirectTo');

return (
<div>
<Form
onSubmit={(values) => {
login.mutate(values);
mutate(values);
}}
schema={loginInputSchema}
>
Expand All @@ -42,11 +43,8 @@ export const LoginForm = ({ onSuccess }: LoginFormProps) => {
registration={register('password')}
/>
<div>
<Button
isLoading={login.isPending}
type="submit"
className="w-full"
>
{error && <Error className="mb-2" errorMessage={error.message} />}
<Button isLoading={isPending} type="submit" className="w-full">
Log in
</Button>
</div>
Expand Down
11 changes: 5 additions & 6 deletions apps/nextjs-app/src/features/auth/components/register-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as React from 'react';

import { Button } from '@/components/ui/button';
import { Form, Input, Select, Label, Switch } from '@/components/ui/form';
import { Error } from '@/components/ui/form/error';
import { paths } from '@/config/paths';
import { useRegister, registerInputSchema } from '@/lib/auth';
import { Team } from '@/types/api';
Expand All @@ -24,14 +25,15 @@ export const RegisterForm = ({
teams,
}: RegisterFormProps) => {
const registering = useRegister({ onSuccess });
const { mutate, isPending, error } = useRegister({ onSuccess });
const searchParams = useSearchParams();
const redirectTo = searchParams?.get('redirectTo');

return (
<div>
<Form
onSubmit={(values) => {
registering.mutate(values);
mutate(values);
}}
schema={registerInputSchema}
options={{
Expand Down Expand Up @@ -96,11 +98,8 @@ export const RegisterForm = ({
/>
)}
<div>
<Button
isLoading={registering.isPending}
type="submit"
className="w-full"
>
{error && <Error className="mb-2" errorMessage={error.message} />}
<Button isLoading={isPending} type="submit" className="w-full">
Register
</Button>
</div>
Expand Down