import type { Route } from '../+types' import { useRequest } from 'ahooks' import { PatternFormat } from 'react-number-format' import { zodResolver } from '@hookform/resolvers/zod' import { useState } from 'react' import { CheckCircle2Icon } from 'lucide-react' import { useForm } from 'react-hook-form' import { Button } from '@repo/ui/components/ui/button' import { Checkbox } from '@repo/ui/components/ui/checkbox' import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@repo/ui/components/ui/form' import { Input } from '@repo/ui/components/ui/input' import { Label } from '@repo/ui/components/ui/label' import { Cpf } from './cpf' import { formSchema, type Schema, RegisterContext, type User } from './data' import { Alert, AlertDescription, AlertTitle } from '@repo/ui/components/ui/alert' export function meta({}: Route.MetaArgs) { return [{ title: 'Criar conta · EDUSEG®' }] } export async function action({ request, context }: Route.ActionArgs) { const issuerUrl = new URL('/register', context.cloudflare.env.ISSUER_URL) const body = await request.json() const r = await fetch(issuerUrl.toString(), { method: 'POST', headers: new Headers({ 'Content-Type': 'application/json' }), body: JSON.stringify(body) }) console.log(await r.json()) } export default function Signup({}: Route.ComponentProps) { const [show, setShow] = useState(false) const [user, setUser] = useState(null) const form = useForm({ resolver: zodResolver(formSchema) }) const { control, handleSubmit, formState } = form const { runAsync } = useRequest( async (user) => { return await fetch(`/register`, { method: 'POST', headers: new Headers({ 'Content-Type': 'application/json' }), body: JSON.stringify(user) }) }, { manual: true } ) const onSubmit = async (data: Schema) => { await runAsync({ ...user, ...data }) } return ( {user ? (
{user?.never_logged && ( Confirme seus dados Revise suas informações e edite o que precisar antes de continuar. )} ( Nome )} /> ( Email )} /> ( CPF { onChange(value) }} {...props} /> )} /> ( Senha )} /> ( Confirmar senha
setShow((x) => !x)} tabIndex={-1} />
)} /> ) : ( )}
) }