fix
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { Route } from './+types/index'
|
||||
|
||||
import { useToggle } from 'ahooks'
|
||||
import { PatternFormat } from 'react-number-format'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { useEffect, useState } from 'react'
|
||||
@@ -53,7 +54,7 @@ export async function action({ request, context }: Route.ActionArgs) {
|
||||
|
||||
export default function Signup({}: Route.ComponentProps) {
|
||||
const fetcher = useFetcher()
|
||||
const [show, setShow] = useState(false)
|
||||
const [show, { toggle: setShow }] = useToggle(false)
|
||||
const [user, setUser] = useState<User | null>(null)
|
||||
const form = useForm({
|
||||
resolver: zodResolver(formSchema)
|
||||
@@ -185,10 +186,12 @@ export default function Signup({}: Route.ComponentProps) {
|
||||
<div className="flex items-center gap-3">
|
||||
<Checkbox
|
||||
id="showPassword"
|
||||
onClick={() => setShow((x) => !x)}
|
||||
onClick={setShow}
|
||||
tabIndex={-1}
|
||||
/>
|
||||
<Label htmlFor="showPassword">Mostrar senha</Label>
|
||||
<Label htmlFor="showPassword" className="cursor-pointer">
|
||||
Mostrar senha
|
||||
</Label>
|
||||
</div>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { Route } from './+types/reset'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { AlertCircleIcon } from 'lucide-react'
|
||||
import { useToggle } from 'ahooks'
|
||||
import { useEffect } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { useFetcher, redirect } from 'react-router'
|
||||
@@ -21,6 +23,12 @@ import {
|
||||
import { Label } from '@repo/ui/components/ui/label'
|
||||
import { Spinner } from '@repo/ui/components/ui/spinner'
|
||||
import { request as req } from '@repo/util/request'
|
||||
import {
|
||||
Alert,
|
||||
AlertDescription,
|
||||
AlertTitle
|
||||
} from '@repo/ui/components/ui/alert'
|
||||
import { Link } from 'react-router'
|
||||
|
||||
export const formSchema = z
|
||||
.object({
|
||||
@@ -46,30 +54,26 @@ export async function action({ params, request, context }: Route.ActionArgs) {
|
||||
const url = new URL(`/reset/${token}`, context.cloudflare.env.ISSUER_URL)
|
||||
const body = await request.json()
|
||||
|
||||
console.log(url.toString())
|
||||
const r = await fetch(url.toString(), {
|
||||
method: 'POST',
|
||||
headers: new Headers({ 'Content-Type': 'application/json' }),
|
||||
body: JSON.stringify(body),
|
||||
signal: request.signal
|
||||
})
|
||||
|
||||
// const r = await fetch(issuerUrl.toString(), {
|
||||
// method: 'POST',
|
||||
// headers: new Headers({ 'Content-Type': 'application/json' }),
|
||||
// body: JSON.stringify(body),
|
||||
// signal: request.signal
|
||||
// })
|
||||
if (r.ok) {
|
||||
throw redirect('/authorize', { headers: r.headers })
|
||||
}
|
||||
|
||||
// if (r.ok) {
|
||||
// throw redirect('/authorize', { headers: r.headers })
|
||||
// }
|
||||
|
||||
// return { ok: false, error: await r.json() }
|
||||
|
||||
await new Promise((r) => setTimeout(r, 2000))
|
||||
return { ok: true }
|
||||
return { ok: false, error: await r.json() }
|
||||
}
|
||||
|
||||
export default function Route({}: Route.ComponentProps) {
|
||||
const fetcher = useFetcher()
|
||||
const [show, setShow] = useState(false)
|
||||
const form = useForm({ resolver: zodResolver(formSchema) })
|
||||
const { handleSubmit, control, formState } = form
|
||||
const [invalidCode, { set: setInvalidCode }] = useToggle(false)
|
||||
const [show, { toggle: setShow }] = useToggle(false)
|
||||
|
||||
const onSubmit = async ({ password }: Schema) => {
|
||||
await fetcher.submit(JSON.stringify({ new_password: password }), {
|
||||
@@ -78,6 +82,13 @@ export default function Route({}: Route.ComponentProps) {
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
switch (fetcher.data?.error?.type) {
|
||||
case 'InvalidCodeError':
|
||||
setInvalidCode(true)
|
||||
}
|
||||
}, [fetcher.data])
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex justify-center">
|
||||
@@ -94,6 +105,24 @@ export default function Route({}: Route.ComponentProps) {
|
||||
Defina uma nova senha para manter sua conta sempre segura.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{invalidCode && (
|
||||
<Alert variant="destructive">
|
||||
<AlertCircleIcon />
|
||||
<AlertTitle>O link para redefinição expirou.</AlertTitle>
|
||||
<AlertDescription>
|
||||
<p>Por favor, siga as instruções abaixo para continuar:</p>
|
||||
<ul className="list-disc text-sm [&_a]:underline [&_a]:hover:no-underline">
|
||||
<li>
|
||||
<Link to="/forgot" className="underline hover:no-underline">
|
||||
Gerar um novo link de redefinição de senha
|
||||
</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<Form {...form}>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6">
|
||||
<FormField
|
||||
@@ -130,12 +159,10 @@ export default function Route({}: Route.ComponentProps) {
|
||||
/>
|
||||
</FormControl>
|
||||
<div className="flex items-center gap-3">
|
||||
<Checkbox
|
||||
id="showPassword"
|
||||
onClick={() => setShow((x) => !x)}
|
||||
tabIndex={-1}
|
||||
/>
|
||||
<Label htmlFor="showPassword">Mostrar senha</Label>
|
||||
<Checkbox id="showPassword" onClick={setShow} tabIndex={-1} />
|
||||
<Label htmlFor="showPassword" className="cursor-pointer">
|
||||
Mostrar senha
|
||||
</Label>
|
||||
</div>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
||||
@@ -82,7 +82,7 @@ Resources:
|
||||
Reset:
|
||||
Type: HttpApi
|
||||
Properties:
|
||||
Path: /reset
|
||||
Path: /reset/{token}
|
||||
Method: POST
|
||||
ApiId: !Ref HttpApi
|
||||
Lookup:
|
||||
|
||||
Reference in New Issue
Block a user