Files
sorsfonalak/services/frontend/src/app/szemelyek/page.tsx
T

79 lines
2.8 KiB
TypeScript
Raw Normal View History

import type { Metadata } from "next";
import Link from "next/link";
import { ChartCard } from "@/components/ChartCard";
import { PersonActions } from "@/components/PersonActions";
import { PersonPacks } from "@/components/PersonPacks";
import { backendGet, requireMe } from "@/lib/server";
import type { ChartListItem, PublicConfig } from "@/lib/types";
export const metadata: Metadata = { title: "Személyek" };
/** The persons the user added, with room for a new one. */
export default async function PersonsPage() {
const me = await requireMe("/szemelyek");
const [list, config] = await Promise.all([
backendGet<{ charts: ChartListItem[] }>("/v1/charts"),
backendGet<PublicConfig>("/v1/config"),
]);
const charts = list?.charts ?? [];
const persons = charts.filter((c) => c.kind === "person");
const isAdmin = me.user.roles.includes("admin");
const slots = me.persons;
const full = slots.left === 0;
const now = Date.now();
return (
<main className="page" style={{ maxWidth: 1080 }}>
<div className="page-head">
<h1>Személyek</h1>
<p className="muted">
Társad, családtagjaid, barátaid képlete. Mindegyikhez kérhetsz részletes elemzést, és a képletoldal címére
kattintva válthatsz köztük.
</p>
</div>
<div className="chart-cards">
{persons.map((p) => (
<ChartCard key={p.id} chart={p} title={p.label}>
<PersonActions
id={p.id}
name={p.label}
editable={isAdmin || (p.editable_until !== null && Date.parse(p.editable_until) > now)}
/>
</ChartCard>
))}
{!full && (
<Link href="/szemelyek/uj" className="chart-card chart-card-new">
<span className="chart-card-plus" aria-hidden="true">
+
</span>
<strong className="chart-card-name">Új személy</strong>
<span className="muted">
{slots.unlimited ? "Korlátlan számú személy" : `Még ${slots.left} személyt vehetsz fel`}
</span>
</Link>
)}
</div>
{!slots.unlimited && (
<section className="card" aria-labelledby="slots-title">
<div className="card-head">
<h2 id="slots-title">Személyek</h2>
<span className="badge">
{slots.used} / {slots.limit} hely
</span>
</div>
<p className="muted">
{full
? "Elfogytak a helyeid. Újabb személyhez válassz csomagot."
: "A felvett személyek képletét és elemzéseit itt éred el. Egy törölt személy helye nem szabadul fel."}
</p>
<PersonPacks packSize={config?.person_pack_size ?? 5} canPay={config?.mock_payments ?? false} />
</section>
)}
</main>
);
}