1
0
Fork 0

feat(banking): redesign banking overview with wallet hero, activity feed, and tabs

This commit is contained in:
Jason Fraley 2026-08-12 23:13:27 -04:00
parent 9210b7bbec
commit 4a2e0d5406
3 changed files with 162 additions and 105 deletions

View file

@ -1,7 +1,7 @@
import config from "@payload-config"; import config from "@payload-config";
import { getPayload } from "payload"; import { getPayload } from "payload";
import { headers as nextHeaders } from "next/headers"; import { headers as nextHeaders } from "next/headers";
import type { BankAccount, Faction } from "@/payload-types"; import type { BankAccount, BankTransaction, Faction, Resource } from "@/payload-types";
import { LandmarkIcon } from "lucide-react"; import { LandmarkIcon } from "lucide-react";
import { BankingOverview } from "@/components/frontend/banking/BankingOverview"; import { BankingOverview } from "@/components/frontend/banking/BankingOverview";
import hasRoles from "@/utils/access-control/hasRoles"; import hasRoles from "@/utils/access-control/hasRoles";
@ -26,6 +26,14 @@ export default async function BankingPage() {
}); });
const accounts = accountsRes.docs as unknown as BankAccount[]; const accounts = accountsRes.docs as unknown as BankAccount[];
const transactionsRes = await payload.find({
collection: "bank-transactions",
sort: "-timestamp",
limit: 25,
depth: 1,
});
const recentTransactions = transactionsRes.docs as unknown as BankTransaction[];
const factionsRes = await payload.find({ const factionsRes = await payload.find({
collection: "factions", collection: "factions",
limit: 100, limit: 100,
@ -41,6 +49,21 @@ export default async function BankingPage() {
(await hasLogisticsQualification(payload, user).catch(() => false)) (await hasLogisticsQualification(payload, user).catch(() => false))
: false; : false;
const currentUser = user
? {
id: user.id as number,
username: user.username,
displayName: user.displayName ?? user.username,
}
: null;
// Currency is shared across all accounts (main currency set in Game Rules).
// Resolve from the first account whose currency populated at depth 1.
const currencyResource =
accounts.length > 0 && typeof accounts[0].currency === "object"
? (accounts[0].currency as Resource)
: null;
return ( return (
<div className="p-5 flex flex-col gap-6"> <div className="p-5 flex flex-col gap-6">
<div className="flex flex-col gap-1"> <div className="flex flex-col gap-1">
@ -55,7 +78,9 @@ export default async function BankingPage() {
<BankingOverview <BankingOverview
accounts={accounts} accounts={accounts}
currentUserId={user?.id as number} recentTransactions={recentTransactions}
currentUser={currentUser}
currencyResource={currencyResource}
isManager={isManager} isManager={isManager}
factions={factions} factions={factions}
/> />

View file

@ -124,6 +124,7 @@ export function BankTransactionDialog({
size="sm" size="sm"
variant={mode === m ? "default" : "outline"} variant={mode === m ? "default" : "outline"}
onClick={() => openMode(m)} onClick={() => openMode(m)}
className="font-mono text-xs uppercase tracking-wider"
> >
<Mc className="size-4" /> <Mc className="size-4" />
{M.label} {M.label}

View file

@ -1,18 +1,25 @@
"use client"; "use client";
import type { ReactNode } from "react"; import type { ReactNode } from "react";
import Link from "next/link"; import type { BankAccount, BankTransaction, Resource } from "@/payload-types";
import type { BankAccount } from "@/payload-types"; import { LandmarkIcon } from "lucide-react";
import { LandmarkIcon, WalletIcon } from "lucide-react"; import {
import { Item, ItemContent, ItemHeader, ItemMedia, ItemTitle } from "@/components/ui/item"; Tabs,
import { formatAmount } from "@/lib/banking/format"; TabsList,
TabsTrigger,
TabsContent,
} from "@/components/ui/tabs";
import { AccountCard } from "@/components/frontend/banking/AccountCard"; import { AccountCard } from "@/components/frontend/banking/AccountCard";
import { CreateAccountDialog } from "@/components/frontend/banking/CreateAccountDialog"; import { CreateAccountDialog } from "@/components/frontend/banking/CreateAccountDialog";
import { MyWalletCard } from "@/components/frontend/banking/MyWalletCard"; import { WalletHero } from "@/components/frontend/banking/WalletHero";
import { ActivityFeed } from "@/components/frontend/banking/ActivityFeed";
import { currencyLabel, formatAmount } from "@/lib/banking/format";
interface BankingOverviewProps { interface BankingOverviewProps {
accounts: BankAccount[]; accounts: BankAccount[];
currentUserId: number; recentTransactions: BankTransaction[];
currentUser: { id: number; username: string; displayName?: string } | null;
currencyResource: Resource | null;
isManager: boolean; isManager: boolean;
factions: { id: number; name: string }[]; factions: { id: number; name: string }[];
} }
@ -29,10 +36,10 @@ function Section({
return ( return (
<section className="flex flex-col gap-3"> <section className="flex flex-col gap-3">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<h2 className="text-sm font-semibold uppercase tracking-wider text-muted-foreground"> <h3 className="font-mono text-[11px] font-medium uppercase tracking-wider text-muted-foreground/80">
{title} {title}
</h2> </h3>
<span className="text-xs text-muted-foreground"> <span className="font-mono text-[10px] text-muted-foreground/50">
{count} account{count !== 1 ? "s" : ""} {count} account{count !== 1 ? "s" : ""}
</span> </span>
</div> </div>
@ -49,123 +56,147 @@ function Section({
export function BankingOverview({ export function BankingOverview({
accounts, accounts,
currentUserId, recentTransactions,
currentUser,
currencyResource,
isManager, isManager,
factions, factions,
}: BankingOverviewProps) { }: BankingOverviewProps) {
const treasury = accounts.filter((a) => a.accountType === "treasury"); const treasury = accounts.filter((a) => a.accountType === "treasury");
const faction = accounts.filter((a) => a.accountType === "faction"); const factionAccounts = accounts.filter((a) => a.accountType === "faction");
const personal = accounts.filter((a) => a.accountType === "personal"); const personal = accounts.filter((a) => a.accountType === "personal");
const myAccount = personal.find((a) => { const myAccount = currentUser
const ownerId = typeof a.ownerUser === "object" ? a.ownerUser?.id : a.ownerUser; ? personal.find((a) => {
return ownerId === currentUserId; if (!a.ownerUser) return false;
}); const ownerId =
typeof a.ownerUser === "object" ? a.ownerUser.id : a.ownerUser;
return ownerId === currentUser.id;
})
: undefined;
const unitFunds = [...treasury, ...faction].reduce( // Regular users see only their own personal account; managers see everything.
const visiblePersonal = isManager
? personal
: myAccount
? [myAccount]
: [];
const unitFundsTotal = [...treasury, ...factionAccounts].reduce(
(sum, a) => sum + (a.balance ?? 0), (sum, a) => sum + (a.balance ?? 0),
0, 0,
); );
const currency =
accounts.length > 0 && typeof accounts[0].currency === "object"
? accounts[0].currency
: null;
const accountTypeLabels: Record<string, string> = { const visibleAccountsCount =
treasury: "Treasury", (isManager ? treasury.length + factionAccounts.length : 0) +
faction: "Faction", visiblePersonal.length;
personal: "Personal",
}; const tickerCurrency = (label: string): string =>
label.length > 8 ? `${label.slice(0, 8)}…` : label;
return ( return (
<div className="flex flex-col gap-8"> <div className="flex flex-col gap-6">
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4"> <WalletHero
<Item variant="outline"> account={myAccount ?? null}
<ItemMedia variant="icon" className="bg-blue-500/10"> currentUser={currentUser}
<LandmarkIcon className="text-blue-400" /> currencyResource={currencyResource}
</ItemMedia> />
<ItemContent>
<ItemHeader>
<ItemTitle>Unit funds</ItemTitle>
</ItemHeader>
<span className="text-lg font-semibold font-mono">
{formatAmount(unitFunds, currency)}
</span>
</ItemContent>
</Item>
<Item variant="outline"> <Tabs defaultValue="activity" className="gap-4">
<ItemMedia variant="icon" className="bg-muted"> <div className="flex flex-wrap items-end justify-between gap-2">
<LandmarkIcon className="text-muted-foreground" /> <TabsList
</ItemMedia> variant="line"
<ItemContent> className="grid w-full max-w-sm grid-cols-2"
<ItemHeader> >
<ItemTitle>Accounts</ItemTitle> <TabsTrigger
</ItemHeader> value="activity"
<span className="text-lg font-semibold font-mono"> className="font-mono text-[10px] uppercase tracking-wider"
{accounts.length} >
</span> Activity
</ItemContent> </TabsTrigger>
</Item> <TabsTrigger
value="accounts"
className="font-mono text-[10px] uppercase tracking-wider"
>
Accounts
</TabsTrigger>
</TabsList>
{myAccount ? ( {isManager && (
<Link href={`/logistics/banking/${myAccount.id}`} className="block"> <p className="font-mono text-[10px] uppercase tracking-wider text-muted-foreground/70">
<Item variant="outline" className="transition-colors"> UNIT FUNDS&nbsp;
<ItemMedia variant="icon" className="bg-emerald-500/10"> {formatAmount(unitFundsTotal, currencyResource)}
<WalletIcon className="text-emerald-400" /> </p>
</ItemMedia>
<ItemContent>
<ItemHeader>
<ItemTitle>My wallet</ItemTitle>
</ItemHeader>
<span className="text-lg font-semibold font-mono">
{formatAmount(myAccount.balance ?? 0, currency)}
</span>
</ItemContent>
</Item>
</Link>
) : (
<MyWalletCard />
)} )}
</div> </div>
<TabsContent value="activity" className="m-0">
<ActivityFeed
transactions={recentTransactions}
currencyResource={currencyResource}
/>
</TabsContent>
<TabsContent value="accounts" className="m-0 flex flex-col gap-6">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<h2 className="text-sm font-semibold uppercase tracking-wider text-muted-foreground"> <LandmarkIcon className="size-4 text-muted-foreground" />
Accounts <h2 className="font-mono text-xs font-semibold uppercase tracking-wider text-muted-foreground">
Unit Accounts
</h2> </h2>
<span className="font-mono text-[10px] text-muted-foreground/50">
{visibleAccountsCount}
</span>
</div> </div>
<CreateAccountDialog isManager={isManager} factions={factions} /> <CreateAccountDialog isManager={isManager} factions={factions} />
</div> </div>
{visibleAccountsCount === 0 ? (
<p className="text-sm text-muted-foreground italic">
No accessible accounts.{" "}
{!isManager && "Ask logistics personnel to set up the unit treasury."}
</p>
) : (
<>
{isManager && treasury.length > 0 && (
<Section title="Treasury" count={treasury.length}> <Section title="Treasury" count={treasury.length}>
{treasury.map((account) => ( {treasury.map((account) => (
<AccountCard key={account.id} account={account} /> <AccountCard key={account.id} account={account} />
))} ))}
</Section> </Section>
)}
<Section title="Factions" count={faction.length}> {isManager && factionAccounts.length > 0 && (
{faction.map((account) => ( <Section title="Factions" count={factionAccounts.length}>
{factionAccounts.map((account) => (
<AccountCard key={account.id} account={account} /> <AccountCard key={account.id} account={account} />
))} ))}
</Section> </Section>
)}
<Section title="Personal" count={personal.length}> {visiblePersonal.length > 0 && (
{personal.map((account) => ( <Section
title={isManager ? "Personal" : "My Account"}
count={visiblePersonal.length}
>
{visiblePersonal.map((account) => (
<AccountCard key={account.id} account={account} /> <AccountCard key={account.id} account={account} />
))} ))}
</Section> </Section>
)}
</>
)}
</TabsContent>
</Tabs>
{accounts.length === 0 && ( {accounts.length === 0 && (
<p className="text-sm text-muted-foreground italic"> <p className="text-sm text-muted-foreground italic">
No accounts yet. Create your first account to get started. No accounts yet. Create your first account to get started.
{isManager ? "" : " (Ask logistics personnel to set up the unit treasury.)"}
</p> </p>
)} )}
<p className="text-xs text-muted-foreground"> <p className="font-mono text-[10px] uppercase tracking-wider text-muted-foreground/40">
Account types: {Object.values(accountTypeLabels).join(" · ")}. SYS.BANKING / currency={tickerCurrency(currencyLabel(currencyResource))}
Balances are denominated in the main currency set in Game Rules.
</p> </p>
</div> </div>
); );