fix error
This commit is contained in:
@@ -109,7 +109,7 @@ export default function Index({}: Route.ComponentProps) {
|
||||
type: 'manual'
|
||||
})
|
||||
}
|
||||
}, [fetcher.data])
|
||||
}, [fetcher.data, setError])
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -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 ? (
|
||||
|
||||
Reference in New Issue
Block a user