This repository has been archived on 2026-11-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
hope-events/frontend/src/app/legal/privacy/page.tsx
T

121 lines
6.2 KiB
TypeScript

"use client";
import { Suspense, useEffect, useMemo, useState } from "react";
import Link from "next/link";
import { useSearchParams } from "next/navigation";
import { Navbar } from "@/components/layout/Navbar";
import { Footer } from "@/components/layout/Footer";
import { useScrollSpy } from "@/hooks/useScrollSpy";
import { useSiteSettings } from "@/contexts/SiteSettingsContext";
import { ApiError } from "@/lib/api";
import { apiV2Data } from "@/lib/apiV2";
import { PrivacyNoticeSection, type PublicNotice } from "@/components/shared/PrivacyNoticeSection";
const fmtDate = (d: string) => new Date(d).toLocaleDateString(undefined, { day: "numeric", month: "long", year: "numeric" });
/**
* The privacy notice. Its text comes from the backend: the published version edited in
* Admin → Privacy (or the built-in notice before one is published), with the organisation's
* details and operator register filled in. ?version=N shows an earlier version.
*/
function PrivacyNotice() {
const versionParam = useSearchParams().get("version");
const { settings } = useSiteSettings();
const [notice, setNotice] = useState<PublicNotice | null>(null);
const [error, setError] = useState<string | null>(null);
const sectionIds = useMemo(() => (notice?.sections || []).map(s => s.id), [notice]);
const activeId = useScrollSpy(sectionIds);
useEffect(() => {
setNotice(null);
setError(null);
(apiV2Data("get", "/privacy/notice", { query: { version: versionParam || undefined } }) as Promise<PublicNotice>)
.then(setNotice)
.catch(e => setError(e instanceof ApiError ? e.message : "The privacy notice couldn't be loaded. Please try again."));
}, [versionParam]);
const orgName = settings.org_name || "Cross Code";
const orgEmail = settings.org_email || "privacy@example.com";
const websiteUrl = settings.legal_website_url || "example.com";
const past = (notice?.versions || []).filter(v => v.version !== notice?.versions[0]?.version);
return (
<main className="flex-1 max-w-6xl mx-auto px-6 py-12 grid grid-cols-1 lg:grid-cols-[250px_1fr] gap-10 w-full">
<aside className="hidden lg:block text-sm text-gray-600 space-y-2 self-start sticky top-24 h-fit">
<h3 className="font-semibold text-gray-800 mb-3">On this page</h3>
<ul className="space-y-2 border-l border-gray-300 pl-3">
{(notice?.sections || []).map(s => (
<li key={s.id}>
<a href={`#${s.id}`} className={`block hover:text-brand-600 transition-colors ${activeId === s.id ? "text-brand-600 font-semibold" : ""}`}>
{s.title}
</a>
</li>
))}
</ul>
</aside>
<article className="bg-white rounded-2xl shadow p-8 text-gray-700 leading-relaxed">
<h1 className="text-4xl font-bold text-brand-700 mb-2">Privacy Policy</h1>
{error && <p className="text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg p-3">{error}</p>}
{!notice && !error && <p className="text-sm text-gray-500">Loading…</p>}
{notice && (
<>
<p className="text-sm text-gray-500 mb-6">
Effective Date: {notice.effectiveDate}
{!notice.builtIn && <> · Version {notice.version}</>}
</p>
{!notice.current && (
<div className="mb-6 p-3 rounded-lg bg-amber-50 border border-amber-200 text-sm text-amber-900">
This is an earlier version of our privacy notice. <Link href="/legal/privacy" className="font-medium underline">Read the current version</Link>.
</div>
)}
<div className="border-l-4 border-brand-600 pl-4 mb-8 text-gray-700">
<p>
<strong>Website:</strong>{" "}
<a href={`https://${websiteUrl}`} className="text-brand-600 hover:underline">{websiteUrl}</a>
</p>
<p><strong>Responsible Party:</strong> {orgName}</p>
<p>
<strong>Email:</strong>{" "}
<a href={`mailto:${orgEmail}`} className="text-brand-600 hover:underline">{orgEmail}</a>
</p>
</div>
{notice.sections.map((s, i) => <PrivacyNoticeSection key={s.id} section={s} first={i === 0} />)}
{past.length > 0 && (
<section className="mt-12 pt-6 border-t text-sm">
<h3 className="font-semibold text-gray-800 mb-2">Earlier versions</h3>
<ul className="space-y-1">
{notice.versions.map(v => (
<li key={v.version}>
<Link href={v.version === notice.versions[0].version ? "/legal/privacy" : `/legal/privacy?version=${v.version}`} className={`hover:underline ${v.version === notice.version ? "font-semibold text-gray-900" : "text-brand-600"}`}>
Version {v.version}
</Link>{" "}
<span className="text-gray-500">— {fmtDate(v.publishedAt)}{v.changeSummary ? `: ${v.changeSummary}` : ""}</span>
</li>
))}
</ul>
</section>
)}
</>
)}
</article>
</main>
);
}
export default function PrivacyPolicyPage() {
return (
<div className="min-h-screen flex flex-col bg-gray-50">
<Navbar />
<Suspense fallback={<main className="flex-1" />}>
<PrivacyNotice />
</Suspense>
<Footer />
</div>
);
}