// import { gql, useQuery } from '@apollo/client';
import { Heading, Input, Stack } from '@chakra-ui/react';
import { Button } from '@client/components/ui/button';
import { Field } from '@client/components/ui/field';
import { valibotResolver } from '@hookform/resolvers/valibot';
import { createFileRoute } from '@tanstack/react-router';
import { useForm } from 'react-hook-form';
import * as v from 'valibot';
export const Route = createFileRoute('/register')({
component: RegisterComponent
});
function RegisterComponent() {
// const { data } = useQuery(getBooksQuery);
return (
Sign up
);
}
interface FormValues {
email: string;
username: string;
password: string;
confirm_password: string;
}
function Register() {
const schema = v.pipe(
v.object({
email: v.pipe(v.string(), v.nonEmpty('Email is required'), v.email('Invalid email')),
username: v.pipe(v.string(), v.nonEmpty('Username is required')),
password: v.pipe(
v.string(),
v.nonEmpty('Password is required'),
v.minLength(8, 'Needs to be at least 8 characters')
),
confirm_password: v.pipe(v.string(), v.nonEmpty('Confirm your password'))
}),
v.forward(
v.check(input => input.password === input.confirm_password, 'Passwords do not match'),
['confirm_password']
)
);
const {
register,
handleSubmit,
formState: { errors }
} = useForm({ resolver: valibotResolver(schema) });
const onSubmit = handleSubmit(data => alert(data));
return (
);
}
/* const getBooksQuery = gql`
query BooksMany {
booksMany {
id
author
title
}
}
`; */