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,160 +1,98 @@
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { ActivityIcon, CircleCheckIcon, ServerIcon, UsersIcon } from 'lucide-react'
|
||||
import { Area, AreaChart, CartesianGrid, ResponsiveContainer, XAxis, YAxis } from 'recharts'
|
||||
import type { ShoppingListSummary } from '@superlist/shared'
|
||||
import { createFileRoute, Link } from '@tanstack/react-router'
|
||||
import { PlusIcon, ShoppingCartIcon } from 'lucide-react'
|
||||
|
||||
import { CreateItemForm } from '@/components/items/create-item-form'
|
||||
import { ItemList } from '@/components/items/item-list'
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { useHealth } from '@/hooks/use-health'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { listsQueryOptions, useLists } from '@/hooks/use-lists'
|
||||
import { ApiError } from '@/lib/api-client'
|
||||
|
||||
const TRAFFIC = [
|
||||
{ day: 'Mon', requests: 420 },
|
||||
{ day: 'Tue', requests: 512 },
|
||||
{ day: 'Wed', requests: 388 },
|
||||
{ day: 'Thu', requests: 640 },
|
||||
{ day: 'Fri', requests: 731 },
|
||||
{ day: 'Sat', requests: 254 },
|
||||
{ day: 'Sun', requests: 198 },
|
||||
]
|
||||
|
||||
export const Route = createFileRoute('/_authenticated/')({
|
||||
component: DashboardPage,
|
||||
loader: ({ context }) => context.queryClient.ensureQueryData(listsQueryOptions()),
|
||||
component: HomePage,
|
||||
})
|
||||
|
||||
function DashboardPage() {
|
||||
/** The list a user lands on: their primary one, falling back to the first. */
|
||||
function pickPrimaryList(lists: ShoppingListSummary[]): ShoppingListSummary | undefined {
|
||||
return lists.find((list) => list.isPrimary) ?? lists[0]
|
||||
}
|
||||
|
||||
function HomePage() {
|
||||
const { data: lists, isPending, error } = useLists()
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="mx-auto w-full max-w-2xl">
|
||||
<Alert variant="destructive">
|
||||
<AlertTitle>No pudimos cargar tu lista</AlertTitle>
|
||||
<AlertDescription>
|
||||
{error instanceof ApiError
|
||||
? (error.problem.detail ?? error.problem.title)
|
||||
: 'Inténtalo de nuevo en unos segundos.'}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isPending || !lists) {
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-2xl flex-col gap-4">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<Skeleton className="h-12 w-full" />
|
||||
<Skeleton className="h-12 w-full" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const primaryList = pickPrimaryList(lists)
|
||||
|
||||
if (!primaryList) {
|
||||
return <NoLists />
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 md:gap-6">
|
||||
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<StatCard title="Users" value="2,481" description="+12% vs last month" icon={UsersIcon} />
|
||||
<StatCard title="Active lists" value="318" description="+4 this week" icon={ActivityIcon} />
|
||||
<StatCard
|
||||
title="Tasks done"
|
||||
value="9,204"
|
||||
description="+18% vs last month"
|
||||
icon={CircleCheckIcon}
|
||||
/>
|
||||
<ApiStatusCard />
|
||||
<div className="mx-auto flex w-full max-w-2xl flex-col gap-4 md:gap-6">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<h1 className="text-lg font-semibold">{primaryList.name}</h1>
|
||||
{primaryList.isPrimary && <Badge>Principal</Badge>}
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 lg:grid-cols-2">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Requests</CardTitle>
|
||||
<CardDescription>API requests over the last 7 days</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="h-72 pl-0">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<AreaChart data={TRAFFIC} margin={{ left: 12, right: 12, top: 8 }}>
|
||||
<defs>
|
||||
<linearGradient id="fillRequests" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="5%" stopColor="var(--color-primary)" stopOpacity={0.7} />
|
||||
<stop offset="95%" stopColor="var(--color-primary)" stopOpacity={0.05} />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<CartesianGrid vertical={false} strokeDasharray="3 3" />
|
||||
<XAxis dataKey="day" tickLine={false} axisLine={false} />
|
||||
<YAxis tickLine={false} axisLine={false} width={40} />
|
||||
<Area
|
||||
dataKey="requests"
|
||||
type="monotone"
|
||||
stroke="var(--color-primary)"
|
||||
fill="url(#fillRequests)"
|
||||
strokeWidth={2}
|
||||
/>
|
||||
</AreaChart>
|
||||
</ResponsiveContainer>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<CreateItemForm listId={primaryList.id} />
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Recent activity</CardTitle>
|
||||
<CardDescription>What your team has been doing</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{[
|
||||
{ who: 'Ada Lovelace', what: 'created list "Q4 roadmap"', when: '2h ago' },
|
||||
{ who: 'Alan Turing', what: 'completed 12 tasks', when: '5h ago' },
|
||||
{ who: 'Grace Hopper', what: 'invited 3 teammates', when: 'yesterday' },
|
||||
{ who: 'Linus Torvalds', what: 'archived "Sprint 41"', when: '2 days ago' },
|
||||
].map((item) => (
|
||||
<div key={item.what} className="flex items-start gap-3">
|
||||
<div className="bg-muted text-muted-foreground flex size-9 shrink-0 items-center justify-center rounded-full text-xs font-medium">
|
||||
{item.who.slice(0, 2).toUpperCase()}
|
||||
</div>
|
||||
<div className="flex-1 text-sm">
|
||||
<p>
|
||||
<span className="font-medium">{item.who}</span> {item.what}
|
||||
</p>
|
||||
<p className="text-muted-foreground text-xs">{item.when}</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
<ItemList listId={primaryList.id} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function StatCard({
|
||||
title,
|
||||
value,
|
||||
description,
|
||||
icon: Icon,
|
||||
}: {
|
||||
title: string
|
||||
value: string
|
||||
description: string
|
||||
icon: typeof UsersIcon
|
||||
}) {
|
||||
function NoLists() {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">{title}</CardTitle>
|
||||
<Icon className="text-muted-foreground size-4" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-semibold">{value}</div>
|
||||
<p className="text-muted-foreground text-xs">{description}</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
/** Pings `GET /health` through TanStack Query, proving the API wiring works. */
|
||||
function ApiStatusCard() {
|
||||
const { data, isPending, error } = useHealth()
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">API</CardTitle>
|
||||
<ServerIcon className="text-muted-foreground size-4" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isPending && <div className="text-2xl font-semibold">…</div>}
|
||||
{data && (
|
||||
<>
|
||||
<div className="text-2xl font-semibold">
|
||||
<Badge variant="secondary">online</Badge>
|
||||
</div>
|
||||
<p className="text-muted-foreground text-xs">up {data.uptimeSeconds}s</p>
|
||||
</>
|
||||
)}
|
||||
{error && (
|
||||
<>
|
||||
<div className="text-2xl font-semibold">
|
||||
<Badge variant="destructive">offline</Badge>
|
||||
</div>
|
||||
<p className="text-muted-foreground truncate text-xs">
|
||||
{error instanceof ApiError
|
||||
? (error.problem.detail ?? error.message)
|
||||
: 'API unreachable'}
|
||||
<div className="mx-auto w-full max-w-2xl">
|
||||
<Card>
|
||||
<CardContent className="flex flex-col items-center gap-3 py-10 text-center">
|
||||
<div className="bg-muted text-muted-foreground flex size-12 items-center justify-center rounded-full">
|
||||
<ShoppingCartIcon className="size-6" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-medium">Todavía no tienes listas</p>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
Crea tu primera lista para empezar a añadir artículos.
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
<Button asChild>
|
||||
<Link to="/lists">
|
||||
<PlusIcon className="size-4" />
|
||||
Crear lista
|
||||
</Link>
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
86
apps/web/src/routes/_authenticated/lists/$listId/index.tsx
Normal file
86
apps/web/src/routes/_authenticated/lists/$listId/index.tsx
Normal file
@@ -0,0 +1,86 @@
|
||||
import { createFileRoute, Link } from '@tanstack/react-router'
|
||||
import { ArrowLeftIcon, SettingsIcon } from 'lucide-react'
|
||||
|
||||
import { CreateItemForm } from '@/components/items/create-item-form'
|
||||
import { ItemList } from '@/components/items/item-list'
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { itemsQueryOptions } from '@/hooks/use-items'
|
||||
import { listQueryOptions, useList } from '@/hooks/use-list'
|
||||
import { ApiError } from '@/lib/api-client'
|
||||
|
||||
export const Route = createFileRoute('/_authenticated/lists/$listId/')({
|
||||
loader: ({ context, params }) =>
|
||||
Promise.all([
|
||||
context.queryClient.ensureQueryData(listQueryOptions(params.listId)),
|
||||
context.queryClient.ensureQueryData(itemsQueryOptions(params.listId)),
|
||||
]),
|
||||
component: ListItemsPage,
|
||||
})
|
||||
|
||||
function problemMessage(error: unknown, fallback: string) {
|
||||
return error instanceof ApiError ? (error.problem.detail ?? error.problem.title) : fallback
|
||||
}
|
||||
|
||||
/** A list's items: the default view when a list is opened from the overview. */
|
||||
function ListItemsPage() {
|
||||
const { listId } = Route.useParams()
|
||||
const { data: list, isPending, error } = useList(listId)
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="mx-auto w-full max-w-2xl">
|
||||
<Alert variant="destructive">
|
||||
<AlertTitle>No pudimos abrir la lista</AlertTitle>
|
||||
<AlertDescription>{problemMessage(error, 'Inténtalo de nuevo.')}</AlertDescription>
|
||||
</Alert>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isPending || !list) {
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-2xl flex-col gap-4">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<Skeleton className="h-12 w-full" />
|
||||
<Skeleton className="h-12 w-full" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-2xl flex-col gap-4 md:gap-6">
|
||||
<div className="flex flex-col gap-2">
|
||||
<Link
|
||||
to="/lists"
|
||||
className="text-muted-foreground hover:text-foreground inline-flex items-center gap-1 text-sm"
|
||||
>
|
||||
<ArrowLeftIcon className="size-4" />
|
||||
Listas
|
||||
</Link>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<h1 className="text-lg font-semibold break-words">{list.name}</h1>
|
||||
{list.isPrimary && <Badge>Principal</Badge>}
|
||||
<Badge variant="secondary">
|
||||
{list.role === 'owner' ? 'Propietario' : 'Colaborador'}
|
||||
</Badge>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" asChild>
|
||||
<Link to="/lists/$listId/settings" params={{ listId: list.id }}>
|
||||
<SettingsIcon className="size-4" />
|
||||
Gestionar
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<CreateItemForm listId={list.id} autoFocus />
|
||||
|
||||
<ItemList listId={list.id} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
300
apps/web/src/routes/_authenticated/lists/$listId/settings.tsx
Normal file
300
apps/web/src/routes/_authenticated/lists/$listId/settings.tsx
Normal file
@@ -0,0 +1,300 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import type { ListMember, ShoppingListDetail } from '@superlist/shared'
|
||||
import { createFileRoute, Link } from '@tanstack/react-router'
|
||||
import { ArrowLeftIcon, CheckIcon, MailIcon, StarIcon, UserPlusIcon } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { z } from 'zod'
|
||||
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
||||
import { Avatar, AvatarFallback } from '@/components/ui/avatar'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Field, FieldError, FieldGroup, FieldLabel } from '@/components/ui/field'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { useCreateInvitation } from '@/hooks/use-invitations'
|
||||
import { listQueryOptions, useList } from '@/hooks/use-list'
|
||||
import { useRenameList, useSetPrimaryList } from '@/hooks/use-lists'
|
||||
import { ApiError } from '@/lib/api-client'
|
||||
|
||||
export const Route = createFileRoute('/_authenticated/lists/$listId/settings')({
|
||||
loader: ({ context, params }) =>
|
||||
context.queryClient.ensureQueryData(listQueryOptions(params.listId)),
|
||||
component: ListSettingsPage,
|
||||
})
|
||||
|
||||
function problemMessage(error: unknown, fallback: string) {
|
||||
return error instanceof ApiError ? (error.problem.detail ?? error.problem.title) : fallback
|
||||
}
|
||||
|
||||
function ListSettingsPage() {
|
||||
const { listId } = Route.useParams()
|
||||
const { data: list, isPending, error } = useList(listId)
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="mx-auto w-full max-w-2xl">
|
||||
<Alert variant="destructive">
|
||||
<AlertTitle>No pudimos abrir la lista</AlertTitle>
|
||||
<AlertDescription>{problemMessage(error, 'Inténtalo de nuevo.')}</AlertDescription>
|
||||
</Alert>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isPending || !list) {
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-2xl flex-col gap-4">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-32 w-full" />
|
||||
<Skeleton className="h-32 w-full" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-2xl flex-col gap-4 md:gap-6">
|
||||
<div className="flex flex-col gap-2">
|
||||
<Link
|
||||
to="/lists/$listId"
|
||||
params={{ listId: list.id }}
|
||||
className="text-muted-foreground hover:text-foreground inline-flex items-center gap-1 text-sm"
|
||||
>
|
||||
<ArrowLeftIcon className="size-4" />
|
||||
{list.name}
|
||||
</Link>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<h1 className="text-lg font-semibold break-words">Gestionar lista</h1>
|
||||
<Badge variant="secondary">{list.role === 'owner' ? 'Propietario' : 'Colaborador'}</Badge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!list.isPrimary && <SetPrimaryButton listId={list.id} />}
|
||||
|
||||
{list.role === 'owner' && <RenameListCard list={list} />}
|
||||
|
||||
{list.role === 'owner' && <InviteCollaboratorCard listId={list.id} />}
|
||||
|
||||
<MembersCard members={list.members} />
|
||||
|
||||
{list.invitations.length > 0 && <PendingInvitationsCard list={list} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SetPrimaryButton({ listId }: { listId: string }) {
|
||||
const setPrimary = useSetPrimaryList()
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="outline"
|
||||
className="w-full sm:w-auto sm:self-start"
|
||||
disabled={setPrimary.isPending}
|
||||
onClick={() => setPrimary.mutate(listId)}
|
||||
>
|
||||
<StarIcon className="size-4" />
|
||||
{setPrimary.isPending ? 'Marcando…' : 'Marcar como lista principal'}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
const renameSchema = z.object({
|
||||
name: z.string().trim().min(1, 'El nombre es obligatorio').max(80, 'Máximo 80 caracteres'),
|
||||
})
|
||||
|
||||
function RenameListCard({ list }: { list: ShoppingListDetail }) {
|
||||
const [saved, setSaved] = useState(false)
|
||||
const renameList = useRenameList(list.id)
|
||||
|
||||
const form = useForm<z.infer<typeof renameSchema>>({
|
||||
resolver: zodResolver(renameSchema),
|
||||
defaultValues: { name: list.name },
|
||||
})
|
||||
|
||||
const onSubmit = form.handleSubmit((values) => {
|
||||
setSaved(false)
|
||||
renameList.mutate(values, { onSuccess: () => setSaved(true) })
|
||||
})
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Nombre de la lista</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={onSubmit} className="flex flex-col gap-4">
|
||||
{renameList.error && (
|
||||
<Alert variant="destructive">
|
||||
<AlertDescription>
|
||||
{problemMessage(renameList.error, 'No pudimos renombrar la lista.')}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<FieldGroup>
|
||||
<Field data-invalid={!!form.formState.errors.name}>
|
||||
<FieldLabel htmlFor="rename-list">Nombre</FieldLabel>
|
||||
<Input id="rename-list" {...form.register('name')} />
|
||||
<FieldError errors={[form.formState.errors.name]} />
|
||||
</Field>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<Button type="submit" className="w-full sm:w-auto" disabled={renameList.isPending}>
|
||||
{renameList.isPending ? 'Guardando…' : 'Guardar'}
|
||||
</Button>
|
||||
{saved && (
|
||||
<span className="text-muted-foreground inline-flex items-center gap-1 text-sm">
|
||||
<CheckIcon className="size-4" />
|
||||
Guardado
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
const inviteSchema = z.object({
|
||||
email: z.email('Introduce un correo electrónico válido'),
|
||||
})
|
||||
|
||||
function InviteCollaboratorCard({ listId }: { listId: string }) {
|
||||
const [message, setMessage] = useState<string | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const createInvitation = useCreateInvitation(listId)
|
||||
|
||||
const form = useForm<z.infer<typeof inviteSchema>>({
|
||||
resolver: zodResolver(inviteSchema),
|
||||
defaultValues: { email: '' },
|
||||
})
|
||||
|
||||
const onSubmit = form.handleSubmit((values) => {
|
||||
setMessage(null)
|
||||
setError(null)
|
||||
|
||||
createInvitation.mutate(values, {
|
||||
onSuccess: (result) => {
|
||||
form.reset()
|
||||
setMessage(
|
||||
result.status === 'added'
|
||||
? `${result.email} ya tenía cuenta y ahora colabora en la lista.`
|
||||
: `Invitación enviada a ${result.email}.`,
|
||||
)
|
||||
},
|
||||
onError: (mutationError) => {
|
||||
setError(problemMessage(mutationError, 'No pudimos enviar la invitación.'))
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Invitar a colaborar</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={onSubmit} className="flex flex-col gap-4">
|
||||
{error && (
|
||||
<Alert variant="destructive">
|
||||
<AlertDescription>{error}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
{message && (
|
||||
<Alert>
|
||||
<AlertDescription>{message}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<FieldGroup>
|
||||
<Field data-invalid={!!form.formState.errors.email}>
|
||||
<FieldLabel htmlFor="invite-email">Correo electrónico</FieldLabel>
|
||||
<Input
|
||||
id="invite-email"
|
||||
type="email"
|
||||
placeholder="persona@ejemplo.com"
|
||||
autoComplete="off"
|
||||
{...form.register('email')}
|
||||
/>
|
||||
<FieldError errors={[form.formState.errors.email]} />
|
||||
</Field>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full sm:w-auto sm:self-start"
|
||||
disabled={createInvitation.isPending}
|
||||
>
|
||||
<UserPlusIcon className="size-4" />
|
||||
{createInvitation.isPending ? 'Enviando…' : 'Enviar invitación'}
|
||||
</Button>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
function initials(name: string) {
|
||||
return (
|
||||
name
|
||||
.split(' ')
|
||||
.map((part) => part[0])
|
||||
.filter(Boolean)
|
||||
.slice(0, 2)
|
||||
.join('')
|
||||
.toUpperCase() || '?'
|
||||
)
|
||||
}
|
||||
|
||||
function MembersCard({ members }: { members: ListMember[] }) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Colaboradores ({members.length})</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
{members.map((member) => (
|
||||
<div key={member.id} className="flex items-center gap-3">
|
||||
<Avatar className="size-9">
|
||||
<AvatarFallback>{initials(member.user.name)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-medium">{member.user.name}</p>
|
||||
<p className="text-muted-foreground truncate text-xs">{member.user.email}</p>
|
||||
</div>
|
||||
{member.role === 'owner' && <Badge variant="secondary">Propietario</Badge>}
|
||||
</div>
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
function PendingInvitationsCard({ list }: { list: ShoppingListDetail }) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Invitaciones pendientes</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
{list.invitations.map((invitation) => (
|
||||
<div key={invitation.id} className="flex items-center gap-3">
|
||||
<div className="bg-muted text-muted-foreground flex size-9 items-center justify-center rounded-full">
|
||||
<MailIcon className="size-4" />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-medium">{invitation.email}</p>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
Caduca el {new Date(invitation.expiresAt).toLocaleDateString('es')}
|
||||
</p>
|
||||
</div>
|
||||
<Badge variant="outline">Pendiente</Badge>
|
||||
</div>
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
87
apps/web/src/routes/_authenticated/lists/index.tsx
Normal file
87
apps/web/src/routes/_authenticated/lists/index.tsx
Normal file
@@ -0,0 +1,87 @@
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { PlusIcon, ShoppingCartIcon } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
|
||||
import { CreateListForm } from '@/components/lists/create-list-form'
|
||||
import { ListCard } from '@/components/lists/list-card'
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { listsQueryOptions, useLists } from '@/hooks/use-lists'
|
||||
import { ApiError } from '@/lib/api-client'
|
||||
|
||||
export const Route = createFileRoute('/_authenticated/lists/')({
|
||||
loader: ({ context }) => context.queryClient.ensureQueryData(listsQueryOptions()),
|
||||
component: ListsPage,
|
||||
})
|
||||
|
||||
function ListsPage() {
|
||||
const [showCreate, setShowCreate] = useState(false)
|
||||
const { data: lists, isPending, error } = useLists()
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-2xl flex-col gap-4 md:gap-6">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div>
|
||||
<h1 className="text-lg font-semibold">Listas de compras</h1>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
Tuyas y las que compartes con otras personas.
|
||||
</p>
|
||||
</div>
|
||||
<Button size="sm" onClick={() => setShowCreate((open) => !open)} aria-expanded={showCreate}>
|
||||
<PlusIcon className="size-4" />
|
||||
Nueva
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{showCreate && (
|
||||
<Card>
|
||||
<CardContent className="p-4">
|
||||
<CreateListForm onCreated={() => setShowCreate(false)} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{error ? (
|
||||
<Alert variant="destructive">
|
||||
<AlertTitle>No pudimos cargar tus listas</AlertTitle>
|
||||
<AlertDescription>
|
||||
{error instanceof ApiError
|
||||
? (error.problem.detail ?? error.problem.title)
|
||||
: 'Inténtalo de nuevo en unos segundos.'}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
) : isPending ? (
|
||||
<div className="flex flex-col gap-3">
|
||||
<Skeleton className="h-20 w-full" />
|
||||
<Skeleton className="h-20 w-full" />
|
||||
</div>
|
||||
) : lists && lists.length > 0 ? (
|
||||
<div className="flex flex-col gap-3">
|
||||
{lists.map((list) => (
|
||||
<ListCard key={list.id} list={list} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<Card>
|
||||
<CardContent className="flex flex-col items-center gap-3 py-10 text-center">
|
||||
<div className="bg-muted text-muted-foreground flex size-12 items-center justify-center rounded-full">
|
||||
<ShoppingCartIcon className="size-6" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-medium">Todavía no tienes listas</p>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
Crea tu primera lista para empezar a organizar tus compras.
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={() => setShowCreate(true)}>
|
||||
<PlusIcon className="size-4" />
|
||||
Crear lista
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createFileRoute, Navigate, Outlet } from '@tanstack/react-router'
|
||||
import { createFileRoute, Navigate, Outlet, useRouterState } from '@tanstack/react-router'
|
||||
|
||||
import { AppHeader } from '@/components/layout/app-header'
|
||||
import { AppSidebar } from '@/components/layout/app-sidebar'
|
||||
@@ -13,17 +13,18 @@ export const Route = createFileRoute('/_authenticated')({
|
||||
/**
|
||||
* Layout for every authenticated page. The session lives in BetterAuth (Hono
|
||||
* API); while it resolves we render a loader, and without a session we bounce
|
||||
* the user to `/sign-in`.
|
||||
* the user to `/sign-in`, keeping the current URL so we can return after login.
|
||||
*/
|
||||
function AuthenticatedLayout() {
|
||||
const { data: session, isPending } = useSession()
|
||||
const href = useRouterState({ select: (state) => state.location.href })
|
||||
|
||||
if (isPending) {
|
||||
return <SessionLoading />
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
return <Navigate to="/sign-in" replace />
|
||||
return <Navigate to="/sign-in" search={{ redirect: href }} replace />
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -16,8 +16,8 @@ export const Route = createFileRoute('/_authenticated/settings')({
|
||||
})
|
||||
|
||||
const profileSchema = z.object({
|
||||
name: z.string().min(1, 'Name is required').max(80),
|
||||
email: z.email('Enter a valid email address'),
|
||||
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>
|
||||
@@ -38,8 +38,8 @@ function SettingsPage() {
|
||||
<div className="grid max-w-3xl gap-4 md:gap-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Profile</CardTitle>
|
||||
<CardDescription>This is how other people will see you.</CardDescription>
|
||||
<CardTitle>Perfil</CardTitle>
|
||||
<CardDescription>Así es como te verán las demás personas.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form
|
||||
@@ -50,28 +50,30 @@ function SettingsPage() {
|
||||
>
|
||||
<FieldGroup>
|
||||
<Field data-invalid={!!form.formState.errors.name}>
|
||||
<FieldLabel htmlFor="name">Name</FieldLabel>
|
||||
<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">Email</FieldLabel>
|
||||
<FieldLabel htmlFor="email">Correo electrónico</FieldLabel>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
placeholder="ada@example.com"
|
||||
placeholder="ada@ejemplo.com"
|
||||
{...form.register('email')}
|
||||
/>
|
||||
<FieldDescription>We only use it to sign you in.</FieldDescription>
|
||||
<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}>
|
||||
Save changes
|
||||
Guardar cambios
|
||||
</Button>
|
||||
{saved && <span className="text-muted-foreground text-sm">Saved locally.</span>}
|
||||
{saved && (
|
||||
<span className="text-muted-foreground text-sm">Guardado localmente.</span>
|
||||
)}
|
||||
</div>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
@@ -80,13 +82,21 @@ function SettingsPage() {
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Appearance</CardTitle>
|
||||
<CardDescription>Notifications and display preferences.</CardDescription>
|
||||
<CardTitle>Apariencia</CardTitle>
|
||||
<CardDescription>Notificaciones y preferencias de visualización.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{[
|
||||
{ id: 'digest', label: 'Weekly digest', hint: 'A summary of your lists every Monday.' },
|
||||
{ id: 'mentions', label: 'Mentions', hint: 'Ping me when someone mentions my name.' },
|
||||
{
|
||||
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>
|
||||
|
||||
@@ -22,17 +22,37 @@ export const Route = createFileRoute('/_authenticated/tasks')({
|
||||
type Task = {
|
||||
title: string
|
||||
list: string
|
||||
status: 'todo' | 'in progress' | 'done'
|
||||
priority: 'low' | 'medium' | 'high'
|
||||
status: 'pendiente' | 'en curso' | 'hecha'
|
||||
priority: 'baja' | 'media' | 'alta'
|
||||
}
|
||||
|
||||
const TASKS: Task[] = [
|
||||
{ title: 'Design onboarding flow', list: 'Q4 roadmap', status: 'in progress', priority: 'high' },
|
||||
{ title: 'Write API docs', list: 'Docs', status: 'todo', priority: 'medium' },
|
||||
{ title: 'Review Prisma migrations', list: 'Backend', status: 'todo', priority: 'high' },
|
||||
{ title: 'Ship dark mode', list: 'Design system', status: 'done', priority: 'low' },
|
||||
{ title: 'Migrate to Turborepo', list: 'Infra', status: 'done', priority: 'medium' },
|
||||
{ title: 'Add e2e smoke test', list: 'Quality', status: 'in progress', priority: 'low' },
|
||||
{
|
||||
title: 'Diseñar el flujo de registro',
|
||||
list: 'Hoja de ruta Q4',
|
||||
status: 'en curso',
|
||||
priority: 'alta',
|
||||
},
|
||||
{
|
||||
title: 'Escribir la documentación de la API',
|
||||
list: 'Docs',
|
||||
status: 'pendiente',
|
||||
priority: 'media',
|
||||
},
|
||||
{
|
||||
title: 'Revisar migraciones de Prisma',
|
||||
list: 'Backend',
|
||||
status: 'pendiente',
|
||||
priority: 'alta',
|
||||
},
|
||||
{
|
||||
title: 'Publicar el modo oscuro',
|
||||
list: 'Sistema de diseño',
|
||||
status: 'hecha',
|
||||
priority: 'baja',
|
||||
},
|
||||
{ title: 'Migrar a Turborepo', list: 'Infra', status: 'hecha', priority: 'media' },
|
||||
{ title: 'Añadir prueba e2e', list: 'Calidad', status: 'en curso', priority: 'baja' },
|
||||
]
|
||||
|
||||
// `tableFeatures` and the columns live at module scope so row models stay stable.
|
||||
@@ -40,16 +60,16 @@ const features = tableFeatures({})
|
||||
const columnHelper = createColumnHelper<typeof features, Task>()
|
||||
|
||||
const columns = columnHelper.columns([
|
||||
columnHelper.accessor('title', { header: 'Task' }),
|
||||
columnHelper.accessor('list', { header: 'List' }),
|
||||
columnHelper.accessor('status', { header: 'Status' }),
|
||||
columnHelper.accessor('priority', { header: 'Priority' }),
|
||||
columnHelper.accessor('title', { header: 'Tarea' }),
|
||||
columnHelper.accessor('list', { header: 'Lista' }),
|
||||
columnHelper.accessor('status', { header: 'Estado' }),
|
||||
columnHelper.accessor('priority', { header: 'Prioridad' }),
|
||||
])
|
||||
|
||||
const STATUS_VARIANT = {
|
||||
todo: 'outline',
|
||||
'in progress': 'secondary',
|
||||
done: 'default',
|
||||
pendiente: 'outline',
|
||||
'en curso': 'secondary',
|
||||
hecha: 'default',
|
||||
} as const
|
||||
|
||||
function TasksPage() {
|
||||
@@ -68,21 +88,21 @@ function TasksPage() {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Tasks</CardTitle>
|
||||
<CardDescription>Every task across your lists.</CardDescription>
|
||||
<CardTitle>Tareas</CardTitle>
|
||||
<CardDescription>Todas las tareas de tus listas.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="relative max-w-sm">
|
||||
<div className="relative w-full sm:max-w-sm">
|
||||
<SearchIcon className="text-muted-foreground absolute top-2.5 left-2.5 size-4" />
|
||||
<Input
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder="Filter tasks…"
|
||||
placeholder="Filtrar tareas…"
|
||||
className="pl-8"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border">
|
||||
<div className="overflow-x-auto rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
@@ -102,7 +122,7 @@ function TasksPage() {
|
||||
colSpan={columns.length}
|
||||
className="text-muted-foreground h-24 text-center"
|
||||
>
|
||||
No tasks match your filter.
|
||||
Ninguna tarea coincide con el filtro.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user