fix error

This commit is contained in:
2025-12-04 10:56:36 -03:00
parent 2f76bd611c
commit c3917addfa
17 changed files with 127 additions and 52 deletions

View File

@@ -2,7 +2,7 @@ import type { Route } from '../+types'
import { PatternFormat } from 'react-number-format'
import { zodResolver } from '@hookform/resolvers/zod'
import { useState } from 'react'
import { useEffect, useState } from 'react'
import { CheckCircle2Icon } from 'lucide-react'
import { useForm } from 'react-hook-form'
import { redirect, useFetcher } from 'react-router'
@@ -44,7 +44,11 @@ export async function action({ request, context }: Route.ActionArgs) {
signal: request.signal
})
throw redirect('/authorize', { headers: r.headers })
if (r.ok) {
throw redirect('/authorize', { headers: r.headers })
}
return { ok: false, error: await r.json() }
}
export default function Signup({}: Route.ComponentProps) {
@@ -63,6 +67,16 @@ export default function Signup({}: Route.ComponentProps) {
})
}
useEffect(() => {
switch (fetcher.data?.error?.type) {
case 'EmailConflictError':
return setError('email', {
message: 'O endereço de email já está em uso',
type: 'manual'
})
}
}, [fetcher.data, setError])
return (
<RegisterContext value={{ user, setUser }}>
{user ? (