1
0
Fork 0
polaris-task-force/src/app/(frontend)/logistics/banking/[id]/page.tsx
Z8MB1E 52ecc4f3b6 refactor(banking): pass currency config through banking UI
Banking overview, cards, detail, and activity feed now render amounts from the full CurrencyConfig (symbol + singular/plural) fetched from Game Rules instead of a plain currency label.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-09-06 01:23:57 -04:00

87 lines
2.4 KiB
TypeScript

import config from "@payload-config";
import { getPayload } from "payload";
import { headers as nextHeaders } from "next/headers";
import { notFound } from "next/navigation";
import type { BankAccount, LedgerEntry } from "@/payload-types";
import { AccountDetail } from "@/components/frontend/banking/AccountDetail";
import { hasPermission } from "@/utils/access-control/hasPermission";
import { hasLogisticsQualification } from "@/utils/access-control/hasLogisticsQualification";
import { getCurrencyConfig } from "@/lib/banking";
export const metadata = {
title: "Account — Polaris Task Force",
};
interface AccountPageProps {
params: Promise<{ id: string }>;
}
export default async function AccountPage({ params }: AccountPageProps) {
const { id } = await params;
const payload = await getPayload({ config });
const { user } = await payload.auth({
headers: await nextHeaders(),
canSetHeaders: false,
});
const account = await payload
.findByID({
collection: "bank-accounts",
id: Number(id),
depth: 1,
})
.catch(() => null);
if (!account) {
notFound();
}
const typedAccount = account as unknown as BankAccount;
const isManager = user
? (await hasPermission(payload, user, "banking:manage")) ||
(await hasLogisticsQualification(payload, user).catch(() => false))
: false;
const ownerId =
typeof typedAccount.ownerUser === "object"
? typedAccount.ownerUser?.id
: typedAccount.ownerUser;
const isOwner = typedAccount.accountType === "personal" && user !== null && ownerId === user.id;
if (!isManager && !isOwner) {
notFound();
}
const ledgerRes = await payload.find({
collection: "ledger-entries",
where: { account: { equals: Number(id) } },
sort: "-timestamp",
limit: 200,
depth: 0,
});
const ledger = ledgerRes.docs as unknown as LedgerEntry[];
const allAccountsRes = await payload.find({
collection: "bank-accounts",
limit: 500,
depth: 0,
});
const otherAccounts = (allAccountsRes.docs as unknown as BankAccount[])
.filter((a) => a.id !== typedAccount.id)
.map((a) => ({ id: a.id, name: a.name }));
const currencyConfig = await getCurrencyConfig(payload);
return (
<div className="p-5 max-w-7xl">
<AccountDetail
account={typedAccount}
ledger={ledger}
otherAccounts={otherAccounts}
canTransact={isManager || isOwner}
currencyConfig={currencyConfig}
/>
</div>
);
}