0ad52757ad
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
import type { Metadata } from "next";
|
||
import { notFound } from "next/navigation";
|
||
import { hasHouseholdRole } from "@/features/households/roles";
|
||
import { StatementView } from "@/features/transactions/components/statement-view";
|
||
import { getCardSummary, getOverdraftSummary } from "@/features/transactions/card";
|
||
import { currentMonth, getAccountStatement } from "@/features/transactions/statement";
|
||
import { tr } from "@/i18n/tr";
|
||
import { requireActiveHousehold } from "@/lib/dal";
|
||
import { MONTH_PATTERN } from "@/shared/statement";
|
||
|
||
export const metadata: Metadata = { title: tr.statement.title };
|
||
|
||
/** /hesaplar/:id?ay=2026-11 — aylık hesap ekstresi (yürüyen bakiye) ve mutabakat. */
|
||
export default async function AccountStatementPage({
|
||
params,
|
||
searchParams,
|
||
}: PageProps<"/hesaplar/[id]">) {
|
||
const { user, household } = await requireActiveHousehold("viewer");
|
||
const [{ id }, sp] = await Promise.all([params, searchParams]);
|
||
const now = currentMonth();
|
||
const requested = typeof sp.ay === "string" && MONTH_PATTERN.test(sp.ay) ? sp.ay : now;
|
||
const month = requested > now ? now : requested;
|
||
const statement = await getAccountStatement(user.id, household.id, id, month);
|
||
if (!statement) notFound();
|
||
const [card, overdraft] = await Promise.all([
|
||
statement.account.type === "credit_card"
|
||
? getCardSummary(user.id, household.id, id)
|
||
: Promise.resolve(null),
|
||
statement.account.type === "bank"
|
||
? getOverdraftSummary(user.id, household.id, id)
|
||
: Promise.resolve(null),
|
||
]);
|
||
return (
|
||
<StatementView
|
||
key={`${id}-${month}`}
|
||
statement={statement}
|
||
card={card}
|
||
overdraft={overdraft}
|
||
canWrite={hasHouseholdRole(household.role, "member")}
|
||
/>
|
||
);
|
||
}
|