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

@@ -109,7 +109,7 @@ export default function Index({}: Route.ComponentProps) {
type: 'manual'
})
}
}, [fetcher.data])
}, [fetcher.data, setError])
return (
<>

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 ? (

View File

@@ -1,5 +1,5 @@
/* eslint-disable */
// Generated by Wrangler by running `wrangler types` (hash: 20d12d2cb42a565d117b277533ca85a9)
// Generated by Wrangler by running `wrangler types` (hash: 7e2e7bff7e69c3350947dfc5bad66ee7)
// Runtime types generated with workerd@1.20251118.0 2025-04-04
declare namespace Cloudflare {
interface GlobalProps {
@@ -7,6 +7,7 @@ declare namespace Cloudflare {
}
interface Env {
ISSUER_URL: "https://58tkjsb308.execute-api.sa-east-1.amazonaws.com";
APP_URL: string;
}
}
interface Env extends Cloudflare.Env {}