import { useEffect, useState } from 'react' import { Link } from 'react-router-dom' import { catalog, finance, inventory, partners, production, purchaseOrders, salesOrders, } from '@/api/client' import { PageHeader } from '@/components/PageHeader' import { Loading } from '@/components/Loading' import { ErrorBox } from '@/components/ErrorBox' import { useAuth } from '@/auth/AuthContext' interface DashboardCounts { items: number partners: number locations: number salesOrders: number purchaseOrders: number workOrders: number journalEntries: number inProgressWorkOrders: number } export function DashboardPage() { const { username } = useAuth() const [counts, setCounts] = useState(null) const [error, setError] = useState(null) const [loading, setLoading] = useState(true) useEffect(() => { let active = true setLoading(true) Promise.all([ catalog.listItems(), partners.list(), inventory.listLocations(), salesOrders.list(), purchaseOrders.list(), production.listWorkOrders(), finance.listJournalEntries(), production.shopFloor(), ]) .then(([items, parts, locs, sos, pos, wos, jes, sf]) => { if (!active) return setCounts({ items: items.length, partners: parts.length, locations: locs.length, salesOrders: sos.length, purchaseOrders: pos.length, workOrders: wos.length, journalEntries: jes.length, inProgressWorkOrders: sf.length, }) }) .catch((e: unknown) => { if (active) setError(e instanceof Error ? e : new Error(String(e))) }) .finally(() => active && setLoading(false)) return () => { active = false } }, []) return (
{loading && } {error && } {counts && (
)}

Try the demo

  1. Open a sales order{' '} in DRAFT, click Confirm.
  2. With the same sales order CONFIRMED, click Ship. The framework atomically debits stock, flips status to SHIPPED, and emits a domain event.
  3. Watch stock balances{' '} drop, movements{' '} grow by one row, and{' '} journal entries {' '} settle from POSTED to SETTLED — all from the cross-PBC event subscriber in pbc-finance.
) } function DashboardCard({ label, value, to, highlight = false, }: { label: string value: number to: string highlight?: boolean }) { return (
{label}
{value}
) }