Simpl-Resultat/src/components/settings/DocsContent.tsx
le king fu 01da65c215 docs(gating): ADR 0017 + architecture + user guide + CHANGELOG
Document the edition-gating work (#297-#301):

- ADR 0017 (accepted): tier->features matrix, signed features[] override
  fail-closed in Free (CWE-863), UI-only enforcement as an assumed GPL
  soft-paywall (server-enforced price fetching stays the only hard gate),
  non-destructive downgrade, dev-override behind an explicit Cargo
  feature (CWE-489), rejected alternatives.
- architecture.md: new 'Gating par edition' section (entitlements matrix,
  LicenseContext, useEntitlement, RequireFeature/UpsellGate, NavLock,
  profileGate, Rust side), rewritten entitlements.rs section (auto-update
  now Base+, stale 'open to free' note removed), gated routes listed in
  the routing section, hooks table updated (useLicense removed in #297 ->
  useEntitlement/useIsPremium), ADR index + header refreshed.
- guide-utilisateur.md + docs.editions.* i18n keys (FR/EN) wired into
  DocsContent: new 'Editions' section with the Free/Base/Premium table,
  unlock flow and non-destructive locking tips.
- CHANGELOG.md + CHANGELOG.fr.md: one global [Unreleased] entry listing
  the modules now gated Base (Budget, Adjustments, advanced reports,
  multi-profile, auto-update) and Premium (Balance), the visible-but-
  locked upsell with disabled 'coming soon' purchase CTA, and the
  data-preserving behaviour.

Resolves #302

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-20 22:48:55 -04:00

203 lines
6.5 KiB
TypeScript

import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { useLocation } from "react-router-dom";
import {
Rocket,
LayoutDashboard,
Upload,
ArrowLeftRight,
Tags,
SlidersHorizontal,
PiggyBank,
BarChart3,
Wallet,
Settings,
Lightbulb,
ListChecks,
Footprints,
Printer,
Users,
KeyRound,
} from "lucide-react";
const SECTIONS = [
{ key: "gettingStarted", icon: Rocket },
{ key: "profiles", icon: Users },
{ key: "dashboard", icon: LayoutDashboard },
{ key: "import", icon: Upload },
{ key: "transactions", icon: ArrowLeftRight },
{ key: "categories", icon: Tags },
{ key: "adjustments", icon: SlidersHorizontal },
{ key: "budget", icon: PiggyBank },
{ key: "reports", icon: BarChart3 },
{ key: "balance", icon: Wallet },
{ key: "settings", icon: Settings },
{ key: "editions", icon: KeyRound },
] as const;
export default function DocsContent() {
const { t } = useTranslation();
const location = useLocation();
const sectionRefs = useRef<Record<string, HTMLElement | null>>({});
const [activeSection, setActiveSection] = useState<string>(SECTIONS[0].key);
useEffect(() => {
const observer = new IntersectionObserver(
(entries) => {
for (const entry of entries) {
if (entry.isIntersecting) {
setActiveSection(entry.target.id);
}
}
},
{ rootMargin: "-30% 0px -60% 0px", threshold: 0 },
);
for (const { key } of SECTIONS) {
const el = sectionRefs.current[key];
if (el) observer.observe(el);
}
return () => observer.disconnect();
}, []);
useEffect(() => {
const hash = location.hash.replace("#", "");
if (hash && sectionRefs.current[hash]) {
requestAnimationFrame(() => {
sectionRefs.current[hash]?.scrollIntoView({
behavior: "smooth",
block: "start",
});
});
}
}, [location.hash]);
const scrollToSection = (key: string) => {
sectionRefs.current[key]?.scrollIntoView({
behavior: "smooth",
block: "start",
});
};
return (
<div className="space-y-6">
<div className="flex items-center justify-between gap-3">
<h2 className="text-xl font-semibold">{t("docs.title")}</h2>
<button
onClick={() => window.print()}
className="print:hidden flex items-center gap-2 px-3 py-2 text-sm rounded-lg bg-[var(--card)] border border-[var(--border)] text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--muted)] transition-colors"
title={t("docs.print")}
>
<Printer size={16} />
{t("docs.print")}
</button>
</div>
<nav
className="print:hidden bg-[var(--card)] border border-[var(--border)] rounded-xl p-3"
aria-label={t("docs.title")}
>
<ul className="flex flex-wrap gap-1">
{SECTIONS.map(({ key, icon: Icon }) => (
<li key={key}>
<button
onClick={() => scrollToSection(key)}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs transition-colors ${
activeSection === key
? "bg-[var(--primary)] text-white font-medium"
: "text-[var(--muted-foreground)] hover:bg-[var(--border)] hover:text-[var(--foreground)]"
}`}
>
<Icon size={13} />
{t(`docs.${key}.title`)}
</button>
</li>
))}
</ul>
</nav>
{SECTIONS.map(({ key, icon: Icon }) => (
<section
key={key}
id={key}
ref={(el) => {
sectionRefs.current[key] = el;
}}
className="bg-[var(--card)] border border-[var(--border)] rounded-xl p-6 space-y-4 scroll-mt-4"
>
<div className="flex items-center gap-3">
<div className="w-9 h-9 rounded-lg bg-[var(--primary)]/10 flex items-center justify-center text-[var(--primary)]">
<Icon size={20} />
</div>
<h3 className="text-lg font-semibold">{t(`docs.${key}.title`)}</h3>
</div>
<p className="text-[var(--muted-foreground)]">
{t(`docs.${key}.overview`)}
</p>
<div>
<h4 className="flex items-center gap-2 text-sm font-semibold uppercase tracking-wider text-[var(--muted-foreground)] mb-2">
<ListChecks size={14} />
{t("docs.features")}
</h4>
<ul className="space-y-1">
{(
t(`docs.${key}.features`, { returnObjects: true }) as string[]
).map((item, i) => (
<li key={i} className="flex items-start gap-2 text-sm">
<span className="text-[var(--primary)] mt-0.5 shrink-0">
&bull;
</span>
{item}
</li>
))}
</ul>
</div>
<div>
<h4 className="flex items-center gap-2 text-sm font-semibold uppercase tracking-wider text-[var(--muted-foreground)] mb-2">
<Footprints size={14} />
{key === "gettingStarted"
? t("docs.quickStart")
: t("docs.howTo")}
</h4>
<ol className="space-y-1 list-decimal list-inside">
{(
t(`docs.${key}.steps`, { returnObjects: true }) as string[]
).map((item, i) => (
<li key={i} className="text-sm">
{item}
</li>
))}
</ol>
</div>
<div className="bg-[var(--background)] rounded-lg p-4">
<h4 className="flex items-center gap-2 text-sm font-semibold uppercase tracking-wider text-[var(--muted-foreground)] mb-2">
<Lightbulb size={14} />
{t("docs.tipsHeader")}
</h4>
<ul className="space-y-1">
{(
t(`docs.${key}.tips`, { returnObjects: true }) as string[]
).map((item, i) => (
<li
key={i}
className="flex items-start gap-2 text-sm text-[var(--muted-foreground)]"
>
<Lightbulb
size={13}
className="text-[var(--primary)] mt-0.5 shrink-0"
/>
{item}
</li>
))}
</ul>
</div>
</section>
))}
</div>
);
}