- Translated comments from Spanish to English in vite.config.ts, docker-compose.yml, attendance-risk.ts, analytics.ts, attendance.ts, attendees.ts, enums.ts, groups.ts, and onboarding.ts. - Improved descriptions for better understanding of code functionality and purpose. - Ensured uniformity in terminology and phrasing throughout the codebase.
143 lines
4.7 KiB
TypeScript
143 lines
4.7 KiB
TypeScript
import { useForm } from 'react-hook-form'
|
|
import { z } from 'zod'
|
|
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { Link, useNavigate } from '@tanstack/react-router'
|
|
import { Loader2 } from 'lucide-react'
|
|
import { authClient } from '../../lib/auth-client'
|
|
import { Button, Input, Label } from '../../components/ui'
|
|
import { AuthShell } from './AuthShell'
|
|
|
|
const schema = z
|
|
.object({
|
|
name: z.string().min(2, 'Ingresá tu nombre'),
|
|
email: z.string().email('Ingresá un email válido'),
|
|
password: z.string().min(8, 'La contraseña debe tener al menos 8 caracteres'),
|
|
confirmPassword: z.string(),
|
|
})
|
|
.refine((v) => v.password === v.confirmPassword, {
|
|
message: 'Las contraseñas no coinciden',
|
|
path: ['confirmPassword'],
|
|
})
|
|
|
|
type FormValues = z.infer<typeof schema>
|
|
|
|
export function SignupPage() {
|
|
const navigate = useNavigate()
|
|
const {
|
|
register,
|
|
handleSubmit,
|
|
setError,
|
|
formState: { errors, isSubmitting },
|
|
} = useForm<FormValues>({ resolver: zodResolver(schema) })
|
|
|
|
const onSubmit = handleSubmit(async ({ name, email, password }) => {
|
|
const { error, data } = await authClient.signUp.email(
|
|
{ name, email, password },
|
|
{
|
|
onSuccess: async () => {
|
|
await authClient.getSession()
|
|
},
|
|
},
|
|
)
|
|
if (error) {
|
|
setError('root', { message: error.message ?? 'No se pudo registrar' })
|
|
return
|
|
}
|
|
if (data?.token) {
|
|
// With email verification on, the session is not created until it is
|
|
// verified.
|
|
navigate({ to: '/verify-email', search: { email } })
|
|
}
|
|
})
|
|
|
|
const handleGoogle = async () => {
|
|
await authClient.signIn.social({ provider: 'google', callbackURL: '/' })
|
|
}
|
|
|
|
return (
|
|
<AuthShell title="Crear cuenta" subtitle="Empezá a cobrar en grupo en minutos">
|
|
<div className="space-y-4">
|
|
<form onSubmit={onSubmit} className="space-y-4">
|
|
<div>
|
|
<Label htmlFor="name">Nombre</Label>
|
|
<Input
|
|
id="name"
|
|
autoComplete="name"
|
|
placeholder="Nombre completo"
|
|
invalid={!!errors.name}
|
|
{...register('name')}
|
|
/>
|
|
{errors.name ? <p className="mt-1 text-sm text-danger">{errors.name.message}</p> : null}
|
|
</div>
|
|
|
|
<div>
|
|
<Label htmlFor="email">Email</Label>
|
|
<Input
|
|
id="email"
|
|
type="email"
|
|
autoComplete="email"
|
|
placeholder="vos@ejemplo.com"
|
|
invalid={!!errors.email}
|
|
{...register('email')}
|
|
/>
|
|
{errors.email ? <p className="mt-1 text-sm text-danger">{errors.email.message}</p> : null}
|
|
</div>
|
|
|
|
<div>
|
|
<Label htmlFor="password">Contraseña</Label>
|
|
<Input
|
|
id="password"
|
|
type="password"
|
|
autoComplete="new-password"
|
|
placeholder="Mínimo 8 caracteres"
|
|
invalid={!!errors.password}
|
|
{...register('password')}
|
|
/>
|
|
{errors.password ? (
|
|
<p className="mt-1 text-sm text-danger">{errors.password.message}</p>
|
|
) : null}
|
|
</div>
|
|
|
|
<div>
|
|
<Label htmlFor="confirmPassword">Repetí la contraseña</Label>
|
|
<Input
|
|
id="confirmPassword"
|
|
type="password"
|
|
autoComplete="new-password"
|
|
placeholder="••••••••"
|
|
invalid={!!errors.confirmPassword}
|
|
{...register('confirmPassword')}
|
|
/>
|
|
{errors.confirmPassword ? (
|
|
<p className="mt-1 text-sm text-danger">{errors.confirmPassword.message}</p>
|
|
) : null}
|
|
</div>
|
|
|
|
{errors.root ? <p className="text-sm text-danger">{errors.root.message}</p> : null}
|
|
|
|
<Button type="submit" variant="primary" className="w-full" disabled={isSubmitting}>
|
|
{isSubmitting ? <Loader2 className="size-4 animate-spin" /> : null}
|
|
{isSubmitting ? 'Creando…' : 'Crear cuenta'}
|
|
</Button>
|
|
</form>
|
|
|
|
<div className="flex items-center gap-3">
|
|
<div className="h-px flex-1 bg-border" />
|
|
<span className="text-xs uppercase tracking-wide text-foreground/40">o</span>
|
|
<div className="h-px flex-1 bg-border" />
|
|
</div>
|
|
|
|
<Button variant="outline" className="w-full" onClick={handleGoogle}>
|
|
Continuar con Google
|
|
</Button>
|
|
|
|
<p className="text-center text-sm text-foreground/60">
|
|
¿Ya tenés cuenta?{' '}
|
|
<Link to="/login" className="font-medium text-accent hover:underline">
|
|
Iniciá sesión
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
</AuthShell>
|
|
)
|
|
} |