diff --git a/.env.example b/.env.example index 4900783..b7c8ade 100644 --- a/.env.example +++ b/.env.example @@ -13,6 +13,12 @@ BETTER_AUTH_URL="http://localhost:4100" NODE_ENV="development" # Optional: Pino log level (defaults to "debug" outside production, "info" in production) # LOG_LEVEL="info" +# Resend API key used to send invitation emails. Without it, emails are logged instead. +# RESEND_API_KEY="re_xxxxxxxx" +# From address for outgoing email (must be a verified Resend sender) +# MAIL_FROM="Superlist " +# Public URL of the web app, used to build the accept-invitation links +WEB_APP_URL="http://localhost:7153" # --- apps/web --- # Public URL of the API consumed by the frontend diff --git a/.gitignore b/.gitignore index 869b83b..86a353f 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ logs/ # generated apps/web/src/routeTree.gen.ts +apps/web/.tanstack/ apps/api/src/generated/ diff --git a/AGENTS.md b/AGENTS.md index d5c8c87..584dc24 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,8 +5,8 @@ Scaffold is in place and verified: Turborepo monorepo with `apps/api`, `apps/web` and `packages/shared`, CI on GitHub Actions, Biome as the only JS/TS tool and the text Bun lockfile committed. -Not done yet: no database migrations (`prisma/migrations` does not exist — no Postgres has been run against -the schema) and no product features. The only backend module is `health`, used as the reference example. +Not done yet: product features are just starting (sign-up, shopping lists, list items and invitations exist; +there is no Google login and no email verification). The `health` module is the reference example. ## Stack (source of truth: `STACK.md`) @@ -82,6 +82,12 @@ Run from the repo root. Verification order is `build`, then `lint` → `typechec - **TypeScript 6 specifics:** `baseUrl` no longer exists (aliases are declared with `paths` only), and `apps/web/tsconfig.app.json` enables `erasableSyntaxOnly` — no enums, namespaces or constructor parameter properties in the web app. Both apps use `@/*` → `src/*` and `verbatimModuleSyntax` (use `import type`). +- **Database naming (Prisma):** tables are **plural snake_case** (`shopping_lists`, `users`), + columns are **snake_case** (`owner_id`, `created_at`) and enum types are **snake_case** (`list_role`) — all + declared with `@@map` / `@map` in `schema.prisma`. The Prisma *model* and *field* names stay + PascalCase/camelCase, because BetterAuth and the generated client address models by those names, so a column + rename never changes the TypeScript API. Default constraint/index names follow the mapped names, so do not + set `map:` unless you have a reason to. - CI (`.github/workflows/ci.yml`) runs on PRs and pushes to `main`: `bun install --frozen-lockfile` → `db:generate` → `lint:ci` → `typecheck` → `test` → `build`, with Bun 1.4.0 and Node 22 for the Prisma CLI. - Generated files are gitignored and must never be edited by hand: `apps/web/src/routeTree.gen.ts`, @@ -191,8 +197,9 @@ export class CreateAlert { the generated migration under `apps/api/prisma/migrations` — never edit migration files by hand. The datasource has no `url` in the schema: it comes from `prisma.config.ts` (`env('DATABASE_URL')`). For production, `apps/api` also has `db:deploy` (`prisma migrate deploy`), which is not wired to a turbo task yet. -- The BetterAuth models (`User`, `Session`, `Account`, `Verification`) are already in the schema with lowercase - `@@map`ed table names; regenerate them with the BetterAuth CLI rather than by hand if the auth config changes. +- The BetterAuth models (`User`, `Session`, `Account`, `Verification`) are already in the schema and follow the + naming convention above (`users`, `sessions`, `accounts`, `verifications` with snake_case columns); regenerate + them with the BetterAuth CLI rather than by hand if the auth config changes, then re-apply the mapping. ## Shared package (`@superlist/shared`) @@ -227,6 +234,11 @@ apps/web/src/ prefetch), renders `QueryClientProvider` + `RouterProvider`, and registers the router type. `__root.tsx` wraps everything in `ThemeProvider` + `TooltipProvider`, mounts the Sonner `Toaster` and lazy-loads the router and query devtools in development only. +- **Theme**: hand-rolled in `src/components/theme-provider.tsx` — `useTheme()` exposes `theme`, `resolvedTheme` + and `setTheme`, and the provider toggles the `.dark` class and `color-scheme` on ``. The pre-paint script + in `apps/web/index.html` applies the stored theme before React mounts; both share the `superlist-theme` + storage key, so keep them in sync. Do not swap this for `next-themes`: it renders a `
diff --git a/apps/web/package.json b/apps/web/package.json index 0628d1a..cd255fe 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -25,7 +25,6 @@ "clsx": "^2.1.1", "cn": "^0.4.0", "lucide-react": "^1.55.0", - "next-themes": "^0.4.6", "radix-ui": "^1.8.0", "react": "^19.2.8", "react-dom": "^19.2.8", diff --git a/apps/web/src/components/items/create-item-form.tsx b/apps/web/src/components/items/create-item-form.tsx new file mode 100644 index 0000000..965211e --- /dev/null +++ b/apps/web/src/components/items/create-item-form.tsx @@ -0,0 +1,55 @@ +import { zodResolver } from '@hookform/resolvers/zod' +import { PlusIcon } from 'lucide-react' +import { useForm } from 'react-hook-form' +import { z } from 'zod' + +import { Button } from '@/components/ui/button' +import { Field, FieldError } from '@/components/ui/field' +import { Input } from '@/components/ui/input' +import { useCreateItem } from '@/hooks/use-items' + +const createItemSchema = z.object({ + name: z.string().trim().min(1, 'Escribe un artículo').max(120, 'Máximo 120 caracteres'), +}) + +type CreateItemValues = z.infer + +type CreateItemFormProps = { + listId: string + /** Focus the input when the form mounts, so the user can type right away. */ + autoFocus?: boolean +} + +/** Input to add an item to a list. Submits with Enter or the button. */ +export function CreateItemForm({ listId, autoFocus = false }: CreateItemFormProps) { + const createItem = useCreateItem(listId) + + const form = useForm({ + resolver: zodResolver(createItemSchema), + defaultValues: { name: '' }, + }) + + const onSubmit = form.handleSubmit((values) => { + createItem.mutate(values, { onSuccess: () => form.reset() }) + }) + + return ( +
+ + + + + + +
+ ) +} diff --git a/apps/web/src/components/items/item-list.tsx b/apps/web/src/components/items/item-list.tsx new file mode 100644 index 0000000..d6074c2 --- /dev/null +++ b/apps/web/src/components/items/item-list.tsx @@ -0,0 +1,93 @@ +import { CheckIcon, ShoppingBasketIcon } from 'lucide-react' + +import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert' +import { Card, CardContent } from '@/components/ui/card' +import { Skeleton } from '@/components/ui/skeleton' +import { useItems } from '@/hooks/use-items' +import { ApiError } from '@/lib/api-client' +import { cn } from '@/lib/utils' + +type ItemListProps = { + listId: string +} + +/** Items loaded from the API, pending ones first. */ +export function ItemList({ listId }: ItemListProps) { + const { data: items, isPending, error } = useItems(listId) + + if (error) { + return ( + + No pudimos cargar los artículos + + {error instanceof ApiError + ? (error.problem.detail ?? error.problem.title) + : 'Inténtalo de nuevo en unos segundos.'} + + + ) + } + + if (isPending) { + return ( +
+ + + +
+ ) + } + + if (items.length === 0) { + return ( + + +
+ +
+
+

La lista está vacía

+

+ Usa el campo de arriba para añadir tu primer artículo. +

+
+
+
+ ) + } + + return ( +
    + {items.map((item) => ( +
  • + + + + + + + {item.name} + + {item.quantity && ( + {item.quantity} + )} + + +
  • + ))} +
+ ) +} diff --git a/apps/web/src/components/layout/app-header.tsx b/apps/web/src/components/layout/app-header.tsx index 5773a5d..914522c 100644 --- a/apps/web/src/components/layout/app-header.tsx +++ b/apps/web/src/components/layout/app-header.tsx @@ -1,34 +1,35 @@ import { useRouterState } from '@tanstack/react-router' import { SearchIcon } from 'lucide-react' + import { ThemeToggle } from '@/components/theme-toggle' import { Separator } from '@/components/ui/separator' import { SidebarTrigger } from '@/components/ui/sidebar' -function usePageTitle() { - const pathname = useRouterState({ select: (state) => state.location.pathname }) - - if (pathname === '/') return 'Dashboard' - - const segment = pathname.split('/').filter(Boolean).at(0) ?? '' - return segment.charAt(0).toUpperCase() + segment.slice(1) +function titleFor(pathname: string) { + if (pathname === '/') return 'Panel' + if (pathname.startsWith('/lists')) return 'Listas' + if (pathname.startsWith('/tasks')) return 'Tareas' + if (pathname.startsWith('/settings')) return 'Ajustes' + return 'Superlist' } export function AppHeader() { - const title = usePageTitle() + const pathname = useRouterState({ select: (state) => state.location.pathname }) + const title = titleFor(pathname) return (
-

{title}

+

{title}

Superlist - Admin + Listas compartidas
@@ -53,11 +59,15 @@ export function AppSidebar() { - Platform + Plataforma {NAV_ITEMS.map((item) => ( - + {item.title} diff --git a/apps/web/src/components/layout/nav-user.tsx b/apps/web/src/components/layout/nav-user.tsx index f8df1c5..389d167 100644 --- a/apps/web/src/components/layout/nav-user.tsx +++ b/apps/web/src/components/layout/nav-user.tsx @@ -35,7 +35,7 @@ export function NavUser() { const navigate = useNavigate() const user = session?.user - const name = user?.name ?? 'Signed out' + const name = user?.name ?? 'Sin sesión' const email = user?.email ?? '' return ( @@ -79,7 +79,7 @@ export function NavUser() { void navigate({ to: '/settings' })}> - Account + Cuenta @@ -90,7 +90,7 @@ export function NavUser() { }} > - Sign out + Cerrar sesión diff --git a/apps/web/src/components/lists/create-list-form.tsx b/apps/web/src/components/lists/create-list-form.tsx new file mode 100644 index 0000000..1869f1e --- /dev/null +++ b/apps/web/src/components/lists/create-list-form.tsx @@ -0,0 +1,81 @@ +import { zodResolver } from '@hookform/resolvers/zod' +import { useState } from 'react' +import { useForm } from 'react-hook-form' +import { z } from 'zod' + +import { Alert, AlertDescription } from '@/components/ui/alert' +import { Button } from '@/components/ui/button' +import { Field, FieldError, FieldGroup, FieldLabel } from '@/components/ui/field' +import { Input } from '@/components/ui/input' +import { useCreateList } from '@/hooks/use-lists' +import { ApiError } from '@/lib/api-client' + +const createListSchema = z.object({ + name: z.string().trim().min(1, 'El nombre es obligatorio').max(80, 'Máximo 80 caracteres'), +}) + +type CreateListValues = z.infer + +type CreateListFormProps = { + onCreated?: () => void +} + +/** Inline form to create a shopping list. Used by the lists page. */ +export function CreateListForm({ onCreated }: CreateListFormProps) { + const [error, setError] = useState(null) + const createList = useCreateList() + + const form = useForm({ + resolver: zodResolver(createListSchema), + defaultValues: { name: '' }, + }) + + const onSubmit = form.handleSubmit((values) => { + setError(null) + + createList.mutate(values, { + onSuccess: () => { + form.reset() + onCreated?.() + }, + onError: (mutationError) => { + setError( + mutationError instanceof ApiError + ? (mutationError.problem.detail ?? mutationError.problem.title) + : 'No pudimos crear la lista.', + ) + }, + }) + }) + + return ( +
+ {error && ( + + {error} + + )} + + + + Nombre de la lista + + + + + + +
+ ) +} diff --git a/apps/web/src/components/lists/list-card.tsx b/apps/web/src/components/lists/list-card.tsx new file mode 100644 index 0000000..33b2013 --- /dev/null +++ b/apps/web/src/components/lists/list-card.tsx @@ -0,0 +1,55 @@ +import type { ShoppingListSummary } from '@superlist/shared' +import { Link } from '@tanstack/react-router' +import { SettingsIcon, StarIcon, UsersIcon } from 'lucide-react' + +import { Badge } from '@/components/ui/badge' +import { Button } from '@/components/ui/button' +import { Card, CardContent } from '@/components/ui/card' +import { useSetPrimaryList } from '@/hooks/use-lists' + +type ListCardProps = { + list: ShoppingListSummary +} + +/** A single list in the lists overview. Tapping it opens the list's items. */ +export function ListCard({ list }: ListCardProps) { + const setPrimary = useSetPrimaryList() + + return ( + + + +
+ {list.name} + {list.isPrimary && Principal} +
+
+ + + {list.memberCount} {list.memberCount === 1 ? 'persona' : 'personas'} + + {list.role === 'owner' ? 'Propietario' : 'Colaborador'} +
+ + + {!list.isPrimary && ( + + )} + + +
+
+ ) +} diff --git a/apps/web/src/components/theme-provider.tsx b/apps/web/src/components/theme-provider.tsx index 1028b06..f41369b 100644 --- a/apps/web/src/components/theme-provider.tsx +++ b/apps/web/src/components/theme-provider.tsx @@ -1,11 +1,84 @@ -import { ThemeProvider as NextThemesProvider } from 'next-themes' -import type { ComponentProps } from 'react' +import type { ReactNode } from 'react' +import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react' -/** Wraps `next-themes` so the theme is toggled by a class on ``. */ -export function ThemeProvider({ children, ...props }: ComponentProps) { - return ( - - {children} - - ) +export type Theme = 'light' | 'dark' | 'system' + +type ResolvedTheme = Exclude + +type ThemeContextValue = { + /** The preference the user picked, `system` included. */ + theme: Theme + /** The preference already resolved against the OS setting. */ + resolvedTheme: ResolvedTheme + setTheme: (theme: Theme) => void +} + +const STORAGE_KEY = 'superlist-theme' +const DARK_QUERY = '(prefers-color-scheme: dark)' + +/** + * This theme handling is hand-rolled on purpose. Libraries such as `next-themes` + * avoid the pre-paint flash by rendering a `