wip: refresh design

This commit is contained in:
Mythie
2023-06-09 18:21:18 +10:00
parent 5ec97657c1
commit 803ebccee3
432 changed files with 19755 additions and 26866 deletions

View File

@ -0,0 +1,125 @@
'use client';
import { zodResolver } from '@hookform/resolvers/zod';
import { Loader } from 'lucide-react';
import { signIn } from 'next-auth/react';
import { useForm } from 'react-hook-form';
import { z } from 'zod';
import { TRPCClientError } from '@documenso/trpc/client';
import { trpc } from '@documenso/trpc/react';
import { cn } from '@documenso/ui/lib/utils';
import { Button } from '@documenso/ui/primitives/button';
import { Input } from '@documenso/ui/primitives/input';
import { Label } from '@documenso/ui/primitives/label';
import { useToast } from '@documenso/ui/primitives/use-toast';
import { SignaturePad } from '../signature-pad';
export const ZSignUpFormSchema = z.object({
name: z.string().min(1),
email: z.string().email().min(1),
password: z.string().min(1),
});
export type TSignUpFormSchema = z.infer<typeof ZSignUpFormSchema>;
export type SignUpFormProps = {
className?: string;
};
export const SignUpForm = ({ className }: SignUpFormProps) => {
const { toast } = useToast();
const {
register,
handleSubmit,
formState: { errors, isSubmitting },
} = useForm<TSignUpFormSchema>({
values: {
name: '',
email: '',
password: '',
},
resolver: zodResolver(ZSignUpFormSchema),
});
const { mutateAsync: signup } = trpc.auth.signup.useMutation();
const onFormSubmit = async ({ name, email, password }: TSignUpFormSchema) => {
try {
await signup({ name, email, password });
await signIn('credentials', {
email,
password,
callbackUrl: '/',
});
} catch (err) {
if (err instanceof TRPCClientError && err.data?.code === 'BAD_REQUEST') {
toast({
title: 'An error occurred',
description: err.message,
variant: 'destructive',
});
} else {
toast({
title: 'An unknown error occurred',
description:
'We encountered an unknown error while attempting to sign you up. Please try again later.',
variant: 'destructive',
});
}
}
};
return (
<form
className={cn('flex w-full flex-col gap-y-4', className)}
onSubmit={handleSubmit(onFormSubmit)}
>
<div>
<Label htmlFor="name" className="text-slate-500">
Name
</Label>
<Input id="name" type="text" className="mt-2 bg-white" {...register('name')} />
{errors.name && <span className="mt-1 text-xs text-red-500">{errors.name.message}</span>}
</div>
<div>
<Label htmlFor="email" className="text-slate-500">
Email
</Label>
<Input id="email" type="email" className="mt-2 bg-white" {...register('email')} />
{errors.email && <span className="mt-1 text-xs text-red-500">{errors.email.message}</span>}
</div>
<div>
<Label htmlFor="password" className="text-slate-500">
Password
</Label>
<Input id="password" type="password" className="mt-2 bg-white" {...register('password')} />
</div>
<div>
<Label htmlFor="password" className="text-slate-500">
Sign Here
</Label>
<div>
<SignaturePad className="mt-2 h-36 w-full rounded-lg border bg-white" />
</div>
</div>
<Button size="lg" disabled={isSubmitting}>
{isSubmitting && <Loader className="mr-2 h-5 w-5 animate-spin" />}
Sign Up
</Button>
</form>
);
};