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

81 lines
2.8 KiB
TypeScript
Raw Normal View History

import type { Metadata } from "next";
import { ROLE_LABELS, formatDate } from "@/lib/astro";
import { backendGet, requireMe } from "@/lib/server";
import type { Chart } from "@/lib/types";
import { BirthEditor } from "./BirthEditor";
import { ProfileForm } from "./ProfileForm";
export const metadata: Metadata = { title: "Profil" };
const PROVIDERS: Record<string, string> = { google: "Google", password: "E-mail és jelszó" };
export default async function ProfilePage() {
const me = await requireMe("/profil");
const chart = me.primary_chart_id ? await backendGet<Chart>(`/v1/charts/${me.primary_chart_id}`) : null;
const { user } = me;
return (
<main className="page">
<div className="page-head">
<h1>Profil</h1>
<p className="muted">A fiókod és a születési adataid.</p>
</div>
<section className="card" aria-labelledby="account">
<div className="card-head">
<h2 id="account">Fiók</h2>
<div className="row" style={{ gap: 6 }}>
{user.roles.map((r) => (
<span key={r} className={r === "user" ? "badge" : "badge badge-gold"}>
{ROLE_LABELS[r] ?? r}
</span>
))}
</div>
</div>
<div className="grid-2">
<dl className="facts">
<dt>E-mail</dt>
<dd>
{user.email} {user.email_verified && <span className="badge">megerősítve</span>}
</dd>
<dt>Belépés</dt>
<dd>{me.providers.map((p) => PROVIDERS[p] ?? p).join(", ") || "–"}</dd>
<dt>Részletes elemzések</dt>
<dd>
{me.analyses_left.natal} képlet, {me.analyses_left.synastry} szinasztria
</dd>
<dt>Tag óta</dt>
<dd>{formatDate(user.created_at)}</dd>
</dl>
<ProfileForm displayName={user.display_name ?? ""} locale={user.locale} />
</div>
</section>
<section className="card" aria-labelledby="birth">
<div className="card-head">
<h2 id="birth">Születési adataim</h2>
{chart && !chart.highlights.time_known && <span className="badge">ismeretlen születési idő</span>}
</div>
<BirthEditor
chart={
chart
? {
birth: chart.birth_data,
placeName: chart.chart.location.place?.name ?? null,
region: chart.chart.location.place?.region ?? null,
countryCode: chart.chart.location.place?.country_code ?? chart.birth_data.country ?? null,
zone: chart.chart.time.zone,
utcOffset: chart.chart.time.utc_offset,
dst: chart.chart.time.dst,
}
: null
}
chartId={chart?.id ?? null}
/>
</section>
</main>
);
}