feat: add collaborative shopping lists with items and invitations
Some checks failed
CI / Verify (push) Has been cancelled
Some checks failed
CI / Verify (push) Has been cancelled
API: lists, items and invitations modules (list, create, get, update, set-primary, items create/list, invitation create/accept/list-pending), BetterAuth session helper, list membership, mailer and Prisma schema plus migrations. Web: lists overview, list detail (items) and list management (settings) views, item and invitation forms/hooks, sign-up and invitation accept pages. Shared: shopping list DTOs. Tooling: ignore the generated TanStack Router cache (apps/web/.tanstack).
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
||||
import { createFileRoute, Link, useNavigate } from '@tanstack/react-router'
|
||||
import { useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { z } from 'zod'
|
||||
@@ -12,18 +12,22 @@ import { Input } from '@/components/ui/input'
|
||||
import { signIn } from '@/lib/auth-client'
|
||||
|
||||
export const Route = createFileRoute('/(auth)/sign-in')({
|
||||
validateSearch: (search: Record<string, unknown>): { redirect?: string } => ({
|
||||
redirect: typeof search.redirect === 'string' ? search.redirect : undefined,
|
||||
}),
|
||||
component: SignInPage,
|
||||
})
|
||||
|
||||
const signInSchema = z.object({
|
||||
email: z.email('Enter a valid email address'),
|
||||
password: z.string().min(8, 'Passwords are at least 8 characters long'),
|
||||
email: z.email('Introduce un correo electrónico válido'),
|
||||
password: z.string().min(8, 'La contraseña debe tener al menos 8 caracteres'),
|
||||
})
|
||||
|
||||
type SignInValues = z.infer<typeof signInSchema>
|
||||
|
||||
function SignInPage() {
|
||||
const navigate = useNavigate()
|
||||
const { redirect } = Route.useSearch()
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const form = useForm<SignInValues>({
|
||||
@@ -37,7 +41,12 @@ function SignInPage() {
|
||||
const { error: signInError } = await signIn.email(values)
|
||||
|
||||
if (signInError) {
|
||||
setError(signInError.message ?? 'Could not sign you in')
|
||||
setError(signInError.message ?? 'No pudimos iniciar tu sesión')
|
||||
return
|
||||
}
|
||||
|
||||
if (redirect) {
|
||||
window.location.assign(redirect)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -48,33 +57,33 @@ function SignInPage() {
|
||||
<div className="flex min-h-svh items-center justify-center p-6">
|
||||
<Card className="w-full max-w-sm">
|
||||
<CardHeader>
|
||||
<CardTitle>Sign in</CardTitle>
|
||||
<CardDescription>Use your Superlist account to continue.</CardDescription>
|
||||
<CardTitle>Iniciar sesión</CardTitle>
|
||||
<CardDescription>Usa tu cuenta de Superlist para continuar.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={onSubmit} className="flex flex-col gap-6">
|
||||
{error && (
|
||||
<Alert variant="destructive">
|
||||
<AlertTitle>Sign in failed</AlertTitle>
|
||||
<AlertTitle>No pudimos iniciar tu sesión</AlertTitle>
|
||||
<AlertDescription>{error}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<FieldGroup>
|
||||
<Field data-invalid={!!form.formState.errors.email}>
|
||||
<FieldLabel htmlFor="email">Email</FieldLabel>
|
||||
<FieldLabel htmlFor="email">Correo electrónico</FieldLabel>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
placeholder="ada@example.com"
|
||||
placeholder="ada@ejemplo.com"
|
||||
{...form.register('email')}
|
||||
/>
|
||||
<FieldError errors={[form.formState.errors.email]} />
|
||||
</Field>
|
||||
|
||||
<Field data-invalid={!!form.formState.errors.password}>
|
||||
<FieldLabel htmlFor="password">Password</FieldLabel>
|
||||
<FieldLabel htmlFor="password">Contraseña</FieldLabel>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
@@ -85,9 +94,20 @@ function SignInPage() {
|
||||
</Field>
|
||||
|
||||
<Button type="submit" disabled={form.formState.isSubmitting}>
|
||||
{form.formState.isSubmitting ? 'Signing in…' : 'Sign in'}
|
||||
{form.formState.isSubmitting ? 'Iniciando sesión…' : 'Iniciar sesión'}
|
||||
</Button>
|
||||
</FieldGroup>
|
||||
|
||||
<p className="text-muted-foreground text-center text-sm">
|
||||
¿Todavía no tienes cuenta?{' '}
|
||||
<Link
|
||||
to="/sign-up"
|
||||
search={redirect ? { redirect } : {}}
|
||||
className="text-foreground font-medium underline-offset-4 hover:underline"
|
||||
>
|
||||
Crea una
|
||||
</Link>
|
||||
</p>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
128
apps/web/src/routes/(auth)/sign-up.tsx
Normal file
128
apps/web/src/routes/(auth)/sign-up.tsx
Normal file
@@ -0,0 +1,128 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { createFileRoute, Link, useNavigate } from '@tanstack/react-router'
|
||||
import { useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { z } from 'zod'
|
||||
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Field, FieldError, FieldGroup, FieldLabel } from '@/components/ui/field'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { signUp } from '@/lib/auth-client'
|
||||
|
||||
export const Route = createFileRoute('/(auth)/sign-up')({
|
||||
validateSearch: (search: Record<string, unknown>): { redirect?: string } => ({
|
||||
redirect: typeof search.redirect === 'string' ? search.redirect : undefined,
|
||||
}),
|
||||
component: SignUpPage,
|
||||
})
|
||||
|
||||
const signUpSchema = z.object({
|
||||
name: z.string().trim().min(1, 'Escribe tu nombre').max(80),
|
||||
email: z.email('Introduce un correo electrónico válido'),
|
||||
password: z.string().min(8, 'La contraseña debe tener al menos 8 caracteres'),
|
||||
})
|
||||
|
||||
type SignUpValues = z.infer<typeof signUpSchema>
|
||||
|
||||
function SignUpPage() {
|
||||
const navigate = useNavigate()
|
||||
const { redirect } = Route.useSearch()
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const form = useForm<SignUpValues>({
|
||||
resolver: zodResolver(signUpSchema),
|
||||
defaultValues: { name: '', email: '', password: '' },
|
||||
})
|
||||
|
||||
const onSubmit = form.handleSubmit(async (values) => {
|
||||
setError(null)
|
||||
|
||||
const { error: signUpError } = await signUp.email(values)
|
||||
|
||||
if (signUpError) {
|
||||
setError(signUpError.message ?? 'No pudimos crear tu cuenta')
|
||||
return
|
||||
}
|
||||
|
||||
if (redirect) {
|
||||
window.location.assign(redirect)
|
||||
return
|
||||
}
|
||||
|
||||
await navigate({ to: '/' })
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="flex min-h-svh items-center justify-center p-6">
|
||||
<Card className="w-full max-w-sm">
|
||||
<CardHeader>
|
||||
<CardTitle>Crear cuenta</CardTitle>
|
||||
<CardDescription>Empieza a compartir tus listas de compras.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={onSubmit} className="flex flex-col gap-6">
|
||||
{error && (
|
||||
<Alert variant="destructive">
|
||||
<AlertTitle>No pudimos crear tu cuenta</AlertTitle>
|
||||
<AlertDescription>{error}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<FieldGroup>
|
||||
<Field data-invalid={!!form.formState.errors.name}>
|
||||
<FieldLabel htmlFor="name">Nombre</FieldLabel>
|
||||
<Input
|
||||
id="name"
|
||||
autoComplete="name"
|
||||
placeholder="Ada Lovelace"
|
||||
{...form.register('name')}
|
||||
/>
|
||||
<FieldError errors={[form.formState.errors.name]} />
|
||||
</Field>
|
||||
|
||||
<Field data-invalid={!!form.formState.errors.email}>
|
||||
<FieldLabel htmlFor="email">Correo electrónico</FieldLabel>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
placeholder="ada@ejemplo.com"
|
||||
{...form.register('email')}
|
||||
/>
|
||||
<FieldError errors={[form.formState.errors.email]} />
|
||||
</Field>
|
||||
|
||||
<Field data-invalid={!!form.formState.errors.password}>
|
||||
<FieldLabel htmlFor="password">Contraseña</FieldLabel>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
{...form.register('password')}
|
||||
/>
|
||||
<FieldError errors={[form.formState.errors.password]} />
|
||||
</Field>
|
||||
|
||||
<Button type="submit" disabled={form.formState.isSubmitting}>
|
||||
{form.formState.isSubmitting ? 'Creando cuenta…' : 'Crear cuenta'}
|
||||
</Button>
|
||||
</FieldGroup>
|
||||
|
||||
<p className="text-muted-foreground text-center text-sm">
|
||||
¿Ya tienes cuenta?{' '}
|
||||
<Link
|
||||
to="/sign-in"
|
||||
search={redirect ? { redirect } : {}}
|
||||
className="text-foreground font-medium underline-offset-4 hover:underline"
|
||||
>
|
||||
Inicia sesión
|
||||
</Link>
|
||||
</p>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user