feat: app shell, UI kit, data loading, recurring sync
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
23f3192cd0
commit
08f23f909f
14 files changed
+493
-7
No files matched your search
@@ -0,0 +1,56 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { logoutAction } from "@/server/actions/auth";
|
||||
import { isActive } from "./nav";
|
||||
|
||||
const tab = "flex flex-1 flex-col items-center gap-0.5 py-2 text-[11px] font-medium";
|
||||
|
||||
export function MobileNav() {
|
||||
const pathname = usePathname();
|
||||
const [more, setMore] = useState(false);
|
||||
const color = (href: string) => (isActive(pathname, href) ? "text-accent" : "text-muted");
|
||||
|
||||
return (
|
||||
<>
|
||||
{more && (
|
||||
<div className="fixed inset-0 z-30 bg-black/20 md:hidden" onClick={() => setMore(false)}>
|
||||
<div className="absolute bottom-[72px] right-3 w-56 rounded-card border border-line bg-white p-2 shadow-lg">
|
||||
{[
|
||||
["/budgets", "◔ Budgets"],
|
||||
["/credits", "⌂ Crédits & charges"],
|
||||
["/reglages", "⚙ Réglages"],
|
||||
].map(([href, label]) => (
|
||||
<Link key={href} href={href} className="block rounded-lg px-3 py-2.5 font-medium hover:bg-page">
|
||||
{label}
|
||||
</Link>
|
||||
))}
|
||||
<span className="block px-3 py-2.5 text-gray-400">∿ Simulateur (bientôt)</span>
|
||||
<form action={logoutAction}>
|
||||
<button className="w-full rounded-lg px-3 py-2.5 text-left font-medium text-neg hover:bg-neg-soft">Déconnexion</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<nav className="fixed inset-x-0 bottom-0 z-40 flex items-end border-t border-line bg-white pb-[env(safe-area-inset-bottom)] md:hidden">
|
||||
<Link href="/" className={`${tab} ${color("/")}`}>
|
||||
<span className="text-lg">◧</span>Accueil
|
||||
</Link>
|
||||
<Link href="/operations" className={`${tab} ${color("/operations")}`}>
|
||||
<span className="text-lg">≡</span>Opérations
|
||||
</Link>
|
||||
<Link href="/nouvelle" className="flex flex-1 justify-center py-1.5" aria-label="Nouvelle opération">
|
||||
<span className="grid h-12 w-12 place-items-center rounded-full bg-accent text-2xl text-white shadow-md">+</span>
|
||||
</Link>
|
||||
<Link href="/recurrents" className={`${tab} ${color("/recurrents")}`}>
|
||||
<span className="text-lg">↻</span>Récurrents
|
||||
</Link>
|
||||
<button type="button" onClick={() => setMore((v) => !v)} className={`${tab} text-muted`}>
|
||||
<span className="text-lg">⋯</span>Plus
|
||||
</button>
|
||||
</nav>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { logoutAction } from "@/server/actions/auth";
|
||||
import { Logo } from "./Logo";
|
||||
import { Avatar } from "./ui/Avatar";
|
||||
import { Chip } from "./ui/Chip";
|
||||
import { NAV, isActive } from "./nav";
|
||||
|
||||
const item = "flex items-center gap-2.5 rounded-lg px-2.5 py-2 font-medium";
|
||||
|
||||
export function Sidebar({ user }: { user: { firstName: string; color: string } }) {
|
||||
const pathname = usePathname();
|
||||
return (
|
||||
<aside className="sticky top-0 hidden h-dvh w-[210px] shrink-0 flex-col border-r border-line bg-white px-3.5 py-[22px] md:flex">
|
||||
<div className="mb-[26px] px-2">
|
||||
<Logo />
|
||||
</div>
|
||||
<nav className="space-y-0.5">
|
||||
{NAV.map((n) =>
|
||||
n.soon ? (
|
||||
<span key={n.href} className={`${item} cursor-default text-gray-400`}>
|
||||
<span className="w-[18px] text-center">{n.icon}</span>
|
||||
{n.label}
|
||||
<span className="ml-auto">
|
||||
<Chip tone="planned">bientôt</Chip>
|
||||
</span>
|
||||
</span>
|
||||
) : (
|
||||
<Link
|
||||
key={n.href}
|
||||
href={n.href}
|
||||
className={`${item} ${isActive(pathname, n.href) ? "bg-accent-soft text-accent" : "text-muted hover:text-ink"}`}
|
||||
>
|
||||
<span className="w-[18px] text-center">{n.icon}</span>
|
||||
{n.label}
|
||||
</Link>
|
||||
),
|
||||
)}
|
||||
<Link
|
||||
href="/reglages"
|
||||
className={`${item} mt-6 ${isActive(pathname, "/reglages") ? "bg-accent-soft text-accent" : "text-muted hover:text-ink"}`}
|
||||
>
|
||||
<span className="w-[18px] text-center">⚙</span>
|
||||
Réglages
|
||||
</Link>
|
||||
</nav>
|
||||
<div className="mt-auto flex items-center gap-2 border-t border-line px-2 pt-4">
|
||||
<Avatar user={user} size={28} />
|
||||
<span className="font-semibold">{user.firstName}</span>
|
||||
<form action={logoutAction} className="ml-auto">
|
||||
<button className="text-xs text-muted hover:text-neg" title="Déconnexion">
|
||||
Déconnexion
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
export interface NavItem {
|
||||
href: string;
|
||||
label: string;
|
||||
icon: string;
|
||||
soon?: boolean;
|
||||
}
|
||||
|
||||
export const NAV: NavItem[] = [
|
||||
{ href: "/", label: "Tableau de bord", icon: "◧" },
|
||||
{ href: "/operations", label: "Opérations", icon: "≡" },
|
||||
{ href: "/recurrents", label: "Récurrents & prévu", icon: "↻" },
|
||||
{ href: "/budgets", label: "Budgets", icon: "◔" },
|
||||
{ href: "/credits", label: "Crédits & charges", icon: "⌂" },
|
||||
{ href: "/simulateur", label: "Simulateur", icon: "∿", soon: true },
|
||||
];
|
||||
|
||||
export const isActive = (pathname: string, href: string) =>
|
||||
href === "/" ? pathname === "/" : pathname === href || pathname.startsWith(`${href}/`);
|
||||
@@ -0,0 +1,13 @@
|
||||
import { formatEuro } from "@/domain/money";
|
||||
import type { OpKind } from "@/domain/types";
|
||||
|
||||
/** Montant en vert (entrée) ou rouge (dépense), chiffres tabulaires. */
|
||||
export function Amount({ cents, kind, className = "" }: { cents: number; kind?: OpKind; className?: string }) {
|
||||
const signed = kind === "EXPENSE" ? -cents : cents;
|
||||
const color = kind === "INCOME" ? "text-pos" : kind === "EXPENSE" ? "text-neg" : "";
|
||||
return (
|
||||
<span className={`tabular whitespace-nowrap font-semibold ${color} ${className}`}>
|
||||
{formatEuro(signed, { sign: kind !== undefined })}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export function Avatar({ user, size = 34 }: { user: { firstName: string; color: string }; size?: number }) {
|
||||
return (
|
||||
<span
|
||||
className="inline-grid shrink-0 place-items-center rounded-full font-bold text-white"
|
||||
style={{ backgroundColor: user.color, width: size, height: size, fontSize: size * 0.38 }}
|
||||
>
|
||||
{user.firstName.slice(0, 1).toUpperCase()}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
type Tone = "accent" | "split" | "planned" | "link" | "danger";
|
||||
|
||||
const TONES: Record<Tone, string> = {
|
||||
accent: "bg-accent-soft text-accent",
|
||||
split: "bg-gray-100 text-gray-700",
|
||||
planned: "bg-warn-soft text-warn",
|
||||
link: "bg-pos-soft text-pos",
|
||||
danger: "bg-neg-soft text-neg",
|
||||
};
|
||||
|
||||
/** Pastille ; `color` (couleur d'une personne) remplace le ton. */
|
||||
export function Chip({ tone = "accent", color, children }: { tone?: Tone; color?: string; children: ReactNode }) {
|
||||
const style = color ? { backgroundColor: `${color}1a`, color } : undefined;
|
||||
return (
|
||||
<span
|
||||
className={`inline-block whitespace-nowrap rounded-full px-2 py-0.5 text-[11px] font-semibold ${color ? "" : TONES[tone]}`}
|
||||
style={style}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import Link from "next/link";
|
||||
import { addMonths, monthLabelFr } from "@/lib/dates";
|
||||
|
||||
/** ‹ Mois › : navigation par le paramètre ?m=YYYY-MM, en conservant les autres filtres. */
|
||||
export function MonthSwitcher({
|
||||
month,
|
||||
basePath,
|
||||
params = {},
|
||||
}: {
|
||||
month: string;
|
||||
basePath: string;
|
||||
params?: Record<string, string | undefined>;
|
||||
}) {
|
||||
const href = (m: string) => {
|
||||
const q = new URLSearchParams({ ...Object.fromEntries(Object.entries(params).filter(([, v]) => v)), m } as Record<string, string>);
|
||||
return `${basePath}?${q}`;
|
||||
};
|
||||
const arrow = "grid h-[30px] w-[30px] place-items-center rounded-lg border border-line bg-white text-muted hover:text-ink";
|
||||
return (
|
||||
<div className="flex items-center gap-3">
|
||||
<Link href={href(addMonths(month, -1))} className={arrow} aria-label="Mois précédent">
|
||||
‹
|
||||
</Link>
|
||||
<h1 className="min-w-[10ch] text-center text-xl font-bold md:text-[22px]">{monthLabelFr(month)}</h1>
|
||||
<Link href={href(addMonths(month, 1))} className={arrow} aria-label="Mois suivant">
|
||||
›
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
"use client";
|
||||
|
||||
export interface PillOption<T extends string> {
|
||||
value: T;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export function Pills<T extends string>({
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
options: PillOption<T>[];
|
||||
value: T | null;
|
||||
onChange: (v: T) => void;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{options.map((o) => (
|
||||
<button
|
||||
key={o.value}
|
||||
type="button"
|
||||
onClick={() => onChange(o.value)}
|
||||
className={`rounded-full border px-3 py-1.5 text-[13px] font-medium transition-colors ${
|
||||
value === o.value ? "border-accent bg-accent text-white" : "border-line bg-white text-ink hover:border-gray-300"
|
||||
}`}
|
||||
>
|
||||
{o.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user