feat: add first and last name to register form

This commit is contained in:
Juan Di Toro 2024-03-13 19:06:43 +01:00
parent 99ac9533f0
commit d07dbff31f
1 changed files with 47 additions and 38 deletions

View File

@ -1,21 +1,23 @@
import type { MetaFunction } from "@remix-run/node" import type { MetaFunction } from "@remix-run/node";
import { Link } from "@remix-run/react" import { Link } from "@remix-run/react";
import { Button } from "~/components/ui/button" import { Button } from "~/components/ui/button";
import logoPng from "~/images/lume-logo.png?url" import logoPng from "~/images/lume-logo.png?url";
import lumeColorLogoPng from "~/images/lume-color-logo.png?url" import lumeColorLogoPng from "~/images/lume-color-logo.png?url";
import discordLogoPng from "~/images/discord-logo.png?url" import discordLogoPng from "~/images/discord-logo.png?url";
import lumeBgPng from "~/images/lume-bg-image.png?url" import lumeBgPng from "~/images/lume-bg-image.png?url";
import { Field, FieldCheckbox } from "~/components/forms" import { Field, FieldCheckbox } from "~/components/forms";
import { getFormProps, useForm } from "@conform-to/react" import { getFormProps, useForm } from "@conform-to/react";
import { z } from "zod" import { z } from "zod";
import { getZodConstraint, parseWithZod } from "@conform-to/zod" import { getZodConstraint, parseWithZod } from "@conform-to/zod";
export const meta: MetaFunction = () => { export const meta: MetaFunction = () => {
return [{ title: "Sign Up" }] return [{ title: "Sign Up" }];
} };
const RegisterSchema = z const RegisterSchema = z
.object({ .object({
firstName: z.string().min(1),
lastName: z.string().min(1),
email: z.string().email(), email: z.string().email(),
password: z password: z
.string() .string()
@ -24,28 +26,28 @@ const RegisterSchema = z
.string() .string()
.min(8, { message: "Password must be at least 8 characters" }), .min(8, { message: "Password must be at least 8 characters" }),
termsOfService: z.boolean({ termsOfService: z.boolean({
required_error: "You must agree to the terms of service" required_error: "You must agree to the terms of service",
}) }),
}) })
.superRefine((data, ctx) => { .superRefine((data, ctx) => {
if (data.password !== data.confirmPassword) { if (data.password !== data.confirmPassword) {
return ctx.addIssue({ return ctx.addIssue({
code: z.ZodIssueCode.custom, code: z.ZodIssueCode.custom,
path: ["confirmPassword"], path: ["confirmPassword"],
message: "Passwords do not match" message: "Passwords do not match",
}) });
} }
return true return true;
}) });
export default function Register() { export default function Register() {
const [form, fields] = useForm({ const [form, fields] = useForm({
id: "register", id: "register",
constraint: getZodConstraint(RegisterSchema), constraint: getZodConstraint(RegisterSchema),
onValidate({ formData }) { onValidate({ formData }) {
return parseWithZod(formData, { schema: RegisterSchema }) return parseWithZod(formData, { schema: RegisterSchema });
} },
}) });
return ( return (
<div className="p-10 h-screen relative"> <div className="p-10 h-screen relative">
@ -54,21 +56,33 @@ export default function Register() {
</header> </header>
<form <form
className="w-full p-2 max-w-md space-y-4 mt-12 bg-background" className="w-full p-2 max-w-md space-y-4 mt-12 bg-background"
{...getFormProps(form)} {...getFormProps(form)}>
>
<span className="!mb-12 space-y-2"> <span className="!mb-12 space-y-2">
<h2 className="text-3xl font-bold">All roads lead to Lume</h2> <h2 className="text-3xl font-bold">All roads lead to Lume</h2>
<p className="text-input-placeholder"> <p className="text-input-placeholder">
🤘 Get 50 GB free storage and download for free,{" "} 🤘 Get 50 GB free storage and download for free,{" "}
<b <b
className="text-primar className="text-primar
y-2" y-2">
>
forever forever
</b> </b>
.{" "} .{" "}
</p> </p>
</span> </span>
<div className="flex gap-4">
<Field
className="flex-1"
inputProps={{ name: fields.firstName.name }}
labelProps={{ children: "First Name" }}
errors={fields.firstName.errors}
/>
<Field
className="flex-1"
inputProps={{ name: fields.lastName.name }}
labelProps={{ children: "Last Name" }}
errors={fields.lastName.errors}
/>
</div>
<Field <Field
inputProps={{ name: fields.email.name }} inputProps={{ name: fields.email.name }}
labelProps={{ children: "Email" }} labelProps={{ children: "Email" }}
@ -92,19 +106,17 @@ export default function Register() {
I agree to the I agree to the
<Link <Link
to="/terms-of-service" to="/terms-of-service"
className="text-primary-1 text-md hover:underline hover:underline-offset-4 mx-1" className="text-primary-1 text-md hover:underline hover:underline-offset-4 mx-1">
>
Terms of Service Terms of Service
</Link> </Link>
and and
<Link <Link
to="/privacy-policy" to="/privacy-policy"
className="text-primary-1 text-md hover:underline hover:underline-offset-4 mx-1" className="text-primary-1 text-md hover:underline hover:underline-offset-4 mx-1">
>
Privacy Policy Privacy Policy
</Link> </Link>
</span> </span>
) ),
}} }}
errors={fields.termsOfService.errors} errors={fields.termsOfService.errors}
/> />
@ -113,8 +125,7 @@ export default function Register() {
Already have an account?{" "} Already have an account?{" "}
<Link <Link
to="/login" to="/login"
className="text-primary-1 text-md hover:underline hover:underline-offset-4" className="text-primary-1 text-md hover:underline hover:underline-offset-4">
>
Login here instead Login here instead
</Link> </Link>
</p> </p>
@ -132,8 +143,7 @@ export default function Register() {
<Link to="https://discord.lumeweb.com"> <Link to="https://discord.lumeweb.com">
<Button <Button
variant={"link"} variant={"link"}
className="flex flex-row gap-x-2 text-input-placeholder" className="flex flex-row gap-x-2 text-input-placeholder">
>
<img className="h-5" src={discordLogoPng} alt="Discord Logo" /> <img className="h-5" src={discordLogoPng} alt="Discord Logo" />
Connect with us Connect with us
</Button> </Button>
@ -143,8 +153,7 @@ export default function Register() {
<Link to="https://lumeweb.com"> <Link to="https://lumeweb.com">
<Button <Button
variant={"link"} variant={"link"}
className="flex flex-row gap-x-2 text-input-placeholder" className="flex flex-row gap-x-2 text-input-placeholder">
>
<img className="h-5" src={lumeColorLogoPng} alt="Lume Logo" /> <img className="h-5" src={lumeColorLogoPng} alt="Lume Logo" />
Connect with us Connect with us
</Button> </Button>
@ -153,5 +162,5 @@ export default function Register() {
</ul> </ul>
</footer> </footer>
</div> </div>
) );
} }