feat(web): UI quick wins for items, navigation and settings
- Toggling an item only disables that row, so several items can be marked in a row; failures roll back just that item and show a toast, and the list refetches once the last toggle settles. - Sidebar, bottom nav and header share one set of sections (Inicio / Listas / Ajustes); the bottom nav drops the duplicated "Cuenta" link and the header drops the non-functional search button. - Settings: the name is saved through BetterAuth, the email is shown read-only, and the fake notification switches are replaced by a real theme picker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,113 +1,27 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
||||
import { useState } from 'react'
|
||||
import { MonitorIcon, MoonIcon, SunIcon } from 'lucide-react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { toast } from 'sonner'
|
||||
import { z } from 'zod'
|
||||
import { type Theme, useTheme } from '@/components/theme-provider'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel } from '@/components/ui/field'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { signOut, useSession } from '@/lib/auth-client'
|
||||
import { authClient, signOut, useSession } from '@/lib/auth-client'
|
||||
|
||||
export const Route = createFileRoute('/_authenticated/settings')({
|
||||
component: SettingsPage,
|
||||
})
|
||||
|
||||
const profileSchema = z.object({
|
||||
name: z.string().min(1, 'El nombre es obligatorio').max(80),
|
||||
email: z.email('Introduce un correo electrónico válido'),
|
||||
})
|
||||
|
||||
type ProfileValues = z.infer<typeof profileSchema>
|
||||
|
||||
function SettingsPage() {
|
||||
const { data: session } = useSession()
|
||||
const navigate = useNavigate()
|
||||
const [saved, setSaved] = useState(false)
|
||||
|
||||
const form = useForm<ProfileValues>({
|
||||
resolver: zodResolver(profileSchema),
|
||||
defaultValues: {
|
||||
name: session?.user.name ?? '',
|
||||
email: session?.user.email ?? '',
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="grid max-w-3xl gap-4 md:gap-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Perfil</CardTitle>
|
||||
<CardDescription>Así es como te verán las demás personas.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(() => {
|
||||
// Wire this to a `PATCH /users/me` feature on the API.
|
||||
setSaved(true)
|
||||
})}
|
||||
>
|
||||
<FieldGroup>
|
||||
<Field data-invalid={!!form.formState.errors.name}>
|
||||
<FieldLabel htmlFor="name">Nombre</FieldLabel>
|
||||
<Input id="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"
|
||||
placeholder="ada@ejemplo.com"
|
||||
{...form.register('email')}
|
||||
/>
|
||||
<FieldDescription>Solo lo usamos para iniciar tu sesión.</FieldDescription>
|
||||
<FieldError errors={[form.formState.errors.email]} />
|
||||
</Field>
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
<Button type="submit" disabled={form.formState.isSubmitting}>
|
||||
Guardar cambios
|
||||
</Button>
|
||||
{saved && (
|
||||
<span className="text-muted-foreground text-sm">Guardado localmente.</span>
|
||||
)}
|
||||
</div>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Apariencia</CardTitle>
|
||||
<CardDescription>Notificaciones y preferencias de visualización.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{[
|
||||
{
|
||||
id: 'digest',
|
||||
label: 'Resumen semanal',
|
||||
hint: 'Un resumen de tus listas cada lunes.',
|
||||
},
|
||||
{
|
||||
id: 'mentions',
|
||||
label: 'Menciones',
|
||||
hint: 'Avísame cuando alguien mencione mi nombre.',
|
||||
},
|
||||
].map((option) => (
|
||||
<div key={option.id} className="flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<p className="text-sm font-medium">{option.label}</p>
|
||||
<p className="text-muted-foreground text-sm">{option.hint}</p>
|
||||
</div>
|
||||
<Switch defaultChecked aria-label={option.label} />
|
||||
</div>
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
<div className="mx-auto grid w-full max-w-2xl gap-4 md:gap-6">
|
||||
<ProfileCard />
|
||||
<AppearanceCard />
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
@@ -129,3 +43,103 @@ function SettingsPage() {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const profileSchema = z.object({
|
||||
name: z.string().trim().min(1, 'El nombre es obligatorio').max(80, 'Máximo 80 caracteres'),
|
||||
})
|
||||
|
||||
type ProfileValues = z.infer<typeof profileSchema>
|
||||
|
||||
function ProfileCard() {
|
||||
const { data: session } = useSession()
|
||||
|
||||
const form = useForm<ProfileValues>({
|
||||
resolver: zodResolver(profileSchema),
|
||||
defaultValues: { name: session?.user.name ?? '' },
|
||||
})
|
||||
|
||||
const onSubmit = form.handleSubmit(async (values) => {
|
||||
const { error } = await authClient.updateUser({ name: values.name })
|
||||
|
||||
if (error) {
|
||||
toast.error(error.message ?? 'No pudimos guardar tu nombre.')
|
||||
return
|
||||
}
|
||||
|
||||
form.reset(values)
|
||||
toast.success('Nombre actualizado.')
|
||||
})
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Perfil</CardTitle>
|
||||
<CardDescription>Así te ven las personas con las que compartes listas.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={onSubmit}>
|
||||
<FieldGroup>
|
||||
<Field data-invalid={!!form.formState.errors.name}>
|
||||
<FieldLabel htmlFor="name">Nombre</FieldLabel>
|
||||
<Input id="name" autoComplete="name" {...form.register('name')} />
|
||||
<FieldError errors={[form.formState.errors.name]} />
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel htmlFor="email">Correo electrónico</FieldLabel>
|
||||
<Input id="email" type="email" value={session?.user.email ?? ''} readOnly disabled />
|
||||
<FieldDescription>
|
||||
Lo usas para iniciar sesión y recibir invitaciones.
|
||||
</FieldDescription>
|
||||
</Field>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full sm:w-auto sm:self-start"
|
||||
disabled={!form.formState.isDirty || form.formState.isSubmitting}
|
||||
>
|
||||
{form.formState.isSubmitting ? 'Guardando…' : 'Guardar cambios'}
|
||||
</Button>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
const THEME_OPTIONS: { value: Theme; label: string; icon: typeof SunIcon }[] = [
|
||||
{ value: 'light', label: 'Claro', icon: SunIcon },
|
||||
{ value: 'dark', label: 'Oscuro', icon: MoonIcon },
|
||||
{ value: 'system', label: 'Sistema', icon: MonitorIcon },
|
||||
]
|
||||
|
||||
function AppearanceCard() {
|
||||
const { theme, setTheme } = useTheme()
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Apariencia</CardTitle>
|
||||
<CardDescription>Elige el tema de la app en este dispositivo.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<fieldset className="grid grid-cols-3 gap-2">
|
||||
<legend className="sr-only">Tema</legend>
|
||||
{THEME_OPTIONS.map((option) => (
|
||||
<Button
|
||||
key={option.value}
|
||||
type="button"
|
||||
variant={theme === option.value ? 'default' : 'outline'}
|
||||
aria-pressed={theme === option.value}
|
||||
onClick={() => setTheme(option.value)}
|
||||
className="h-auto flex-col gap-1.5 py-3"
|
||||
>
|
||||
<option.icon className="size-5" />
|
||||
{option.label}
|
||||
</Button>
|
||||
))}
|
||||
</fieldset>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user