From d9a343b2b6b8fc2744fe38f4f7c67067877702ee Mon Sep 17 00:00:00 2001 From: Clarence Date: Wed, 2 Dec 2026 02:08:55 +0800 Subject: [PATCH] feat(dashboard): transactions, config, plan, profile and admin on shared merqo-ui Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 6 + src/app/admin/README.md | 6 +- src/app/admin/activity/activity-section.tsx | 2 +- src/app/admin/page.tsx | 118 ++++-------------- src/app/admin/recent-activity-table.tsx | 91 ++++++++++++++ src/app/admin/vendors/vendors-table.tsx | 3 +- src/app/dashboard/README.md | 1 - .../dashboard/config/payment-config-form.tsx | 6 +- src/app/dashboard/plan/page.tsx | 18 +-- src/app/dashboard/transactions/README.md | 4 +- .../transaction-table.dom.test.tsx | 83 +++--------- .../transactions/transaction-table.tsx | 50 ++------ 12 files changed, 172 insertions(+), 216 deletions(-) create mode 100644 src/app/admin/recent-activity-table.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index efa169d..947c14b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project are documented here. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Changed + +- Payments, Plan, payment setup and the admin overview, vendors and activity pages now use more of the shared `@merqo/ui` components (stat tiles, sections, cards, data tables). Payments shows one table at every width, with the Kit and Created columns hidden on phones. Behaviour, plan limits and copy are unchanged. + ## [0.11.3] - 2026-12-02 ### Changed diff --git a/src/app/admin/README.md b/src/app/admin/README.md index 7857d65..d81b0a8 100644 --- a/src/app/admin/README.md +++ b/src/app/admin/README.md @@ -35,8 +35,10 @@ figure-tile helper used by the overview and vendors screens. `securityStats()` in `@/lib/admin-data`), a recent cross-vendor activity feed (rows link to `/admin/vendors?q=`, or `EmptyState` when empty). Page titles use the shared `PageHeader`; statuses read Awaiting payment / Marked paid / Received. -- Overview figures use `@merqo/ui`'s shared `StatCard` (label/value plus optional - `caption` and a period-over-period `delta`/`deltaTooltip` pill, `deltaSize="xs"`). +- Overview figures use `@merqo/ui`'s `StatTile` with `card` (label/value plus optional + `caption` and a period-over-period `delta`/`deltaTooltip` pill). The recent-activity feed is + `recent-activity-table.tsx`, a `DataTable` in a Client Component whose vendor cell links to + `/admin/vendors?q=`; Kit and When hide on phones. - `vendors/` ## Connectivity diff --git a/src/app/admin/activity/activity-section.tsx b/src/app/admin/activity/activity-section.tsx index adc81b5..7da995c 100644 --- a/src/app/admin/activity/activity-section.tsx +++ b/src/app/admin/activity/activity-section.tsx @@ -40,7 +40,7 @@ const columns: DataTableColumn[] = [ e.target ? ( {e.target} diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx index 36fdd07..0d48fb0 100644 --- a/src/app/admin/page.tsx +++ b/src/app/admin/page.tsx @@ -1,24 +1,13 @@ import type { Metadata } from "next"; -import Link from "next/link"; import { requireAdmin } from "@/lib/admin"; import { platformTotals, recentActivity, securityStats, } from "@/lib/admin-data"; -import { Badge } from "@merqo/ui/primitives"; - -import { - EmptyState, - Money, - PageHeader, - StatCard, - Timestamp, - formatMoney, -} from "@merqo/ui"; -import type { TxStatus } from "@/lib/types"; -import { listHref } from "@/app/admin/list-params"; +import { PageHeader, Section, StatTile, formatMoney } from "@merqo/ui"; import { pctChange } from "@/lib/utils"; +import { RecentActivityTable } from "./recent-activity-table"; export const metadata: Metadata = { title: "Admin overview", @@ -26,13 +15,6 @@ export const metadata: Metadata = { export const revalidate = 0; -// API status values are unchanged; only the displayed wording differs. -const STATUS_LABELS: Record = { - pending: "Awaiting payment", - claimed: "Marked paid", - confirmed: "Received", -}; - export default async function AdminOverviewPage() { await requireAdmin(); @@ -47,35 +29,22 @@ export default async function AdminOverviewPage() {
- - - - + + + - - -
-
-

Security

+
- -
-
+
-
-

- Recent activity across all vendors -

- {activity.length > 0 ? ( -
    - {activity.map((tx) => ( -
  • - - - - {tx.email ?? "Not set"} - - - {tx.kit_slug} - - - {STATUS_LABELS[tx.status]} - - - - - - - -
  • - ))} -
- ) : ( - - )} -
+
+ +
); } diff --git a/src/app/admin/recent-activity-table.tsx b/src/app/admin/recent-activity-table.tsx new file mode 100644 index 0000000..cff5cac --- /dev/null +++ b/src/app/admin/recent-activity-table.tsx @@ -0,0 +1,91 @@ +"use client"; + +import Link from "next/link"; +import { + DataTable, + EmptyState, + Money, + Timestamp, + type DataTableColumn, +} from "@merqo/ui"; +import { Badge } from "@merqo/ui/primitives"; +import type { TxStatus } from "@/lib/types"; +import { listHref } from "@/app/admin/list-params"; + +export type RecentActivityRow = { + id: string; + vendor_id: string; + email: string | null; + kit_slug: string; + amount_cents: number; + status: TxStatus; + created_at: string; +}; + +// API status values are unchanged; only the displayed wording differs. +const STATUS_LABELS: Record = { + pending: "Awaiting payment", + claimed: "Marked paid", + confirmed: "Received", +}; + +// `columns` holds `cell` render callbacks, so `DataTable` has to be rendered +// from a Client Component rather than the server page. +const columns: DataTableColumn[] = [ + { + header: "Vendor", + cell: (tx) => ( + + {tx.email ?? "Not set"} + + ), + }, + { + header: "Kit", + className: "hidden sm:table-cell", + cell: (tx) => tx.kit_slug, + }, + { + header: "Status", + cell: (tx) => ( + + {STATUS_LABELS[tx.status]} + + ), + }, + { + header: "Amount", + align: "end", + cell: (tx) => , + }, + { + header: "When", + className: "hidden sm:table-cell", + cell: (tx) => ( + + ), + }, +]; + +export function RecentActivityTable({ rows }: { rows: RecentActivityRow[] }) { + return ( + tx.id} + emptyState={ + + } + /> + ); +} diff --git a/src/app/admin/vendors/vendors-table.tsx b/src/app/admin/vendors/vendors-table.tsx index 74b3c90..b04ea11 100644 --- a/src/app/admin/vendors/vendors-table.tsx +++ b/src/app/admin/vendors/vendors-table.tsx @@ -40,7 +40,8 @@ const columns: DataTableColumn[] = [ { header: "Transactions", cell: (v) => v.transaction_count, - className: "text-right tabular-nums", + align: "end", + className: "tabular-nums", }, { header: "Joined", diff --git a/src/app/dashboard/README.md b/src/app/dashboard/README.md index 6afacf4..24f126b 100644 --- a/src/app/dashboard/README.md +++ b/src/app/dashboard/README.md @@ -105,5 +105,4 @@ Gotchas: - `DataTable` has no row-level link, so make one cell's link a 44px target (`inline-flex min-h-11 items-center`) and hide low-value columns on phones with a column `className` of `hidden sm:table-cell`. - `SegmentedControl` link mode needs `LinkComponent={Link}` (from `next/link`) for client-side navigation, and `selected` on the active option sets `aria-current="page"`. - `ElevatedCard` has no padding of its own; add `p-6` (or similar) on the card. -- `src/app/admin/page.tsx` still uses the deprecated `StatCard`; move it to `StatTile card` in slice 4. - `@merqo/ui` has no bottom tab bar, More sheet or side rail export. Its `DashboardNav` only offers `mobileNav="menu" | "none"` (a burger menu), so the phone tab bar and desktop rail stay local in `src/components/nav`. diff --git a/src/app/dashboard/config/payment-config-form.tsx b/src/app/dashboard/config/payment-config-form.tsx index c4ed8dc..386c5ec 100644 --- a/src/app/dashboard/config/payment-config-form.tsx +++ b/src/app/dashboard/config/payment-config-form.tsx @@ -24,7 +24,7 @@ import { removeUnsavedImages, uploadPaykitImage, } from "@/lib/image-upload-adapter"; -import { FormError, resizeToWebp } from "@merqo/ui"; +import { ElevatedCard, FormError, resizeToWebp } from "@merqo/ui"; import { buildPayNowPayload } from "@/lib/payments/paynow"; import { isHttpUrl } from "@/lib/schemas"; import { saveConfigAction, type SaveConfigState } from "./actions"; @@ -186,12 +186,12 @@ function PayNowFields({ )} {previewPayload && ( -
+

Preview ($1.00 sample QR)

-
+ )} ); diff --git a/src/app/dashboard/plan/page.tsx b/src/app/dashboard/plan/page.tsx index cb5ceb0..feda6ee 100644 --- a/src/app/dashboard/plan/page.tsx +++ b/src/app/dashboard/plan/page.tsx @@ -6,8 +6,13 @@ import { freeListCutoff, FREE_LIST_DAYS, isPaidPlan } from "@/lib/free-limits"; import { resolvePlanView } from "@/lib/plan-view"; import { readVendorPlan } from "@/lib/vendor-entitlement"; import { merqoBaseUrl } from "@merqo/ui/kit-api"; -import { PricingLadder, fetchPlanCatalog } from "@merqo/ui"; -import { PageHeader } from "@merqo/ui"; +import { + ElevatedCard, + PageHeader, + PricingLadder, + Section, + fetchPlanCatalog, +} from "@merqo/ui"; export const metadata: Metadata = { title: "Plan", @@ -66,7 +71,7 @@ export default async function PlanPage() {
-
+

You are on {view.plan === "pro" ? "Pro" : "Free"}

@@ -79,11 +84,10 @@ export default async function PlanPage() { > Change plan in your Merqo account -
+ {paid ? null : ( -
-

What paid plans add

+
  • Full payment history with search. Free keeps the last{" "} @@ -101,7 +105,7 @@ export default async function PlanPage() { hidden on Free.

    ) : null} -
+
)} {catalog && paid && !currentListed ? ( diff --git a/src/app/dashboard/transactions/README.md b/src/app/dashboard/transactions/README.md index d3000f9..8c0e294 100644 --- a/src/app/dashboard/transactions/README.md +++ b/src/app/dashboard/transactions/README.md @@ -21,7 +21,7 @@ across every kit — plus, for Pro vendors, a per-payment refund action. renders `Kit`/`Reference`/`Amount`/`Status`/`Created` columns through `@merqo/ui` DataTable, plus a `Refund` column with `RefundDialog` when `isPro`. Amounts are shown with `Money` from `@merqo/ui` ("S$4.50"), in a right-aligned column. Empty state is the shared dashed `EmptyState` ("No payments yet"); the table sits in an - `hidden sm:block` wrapper; below 640px a `PhoneList` of expandable rows (amount + status, kit + date; tap for the reference and `RefundDialog`) replaces it, switched by CSS only. The Refund gate (Pro and confirmed) is the shared `canRefund` in `transaction-table.tsx`. + horizontally scrollable wrapper at every width; the Kit and Created columns are `hidden sm:table-cell`, so phones see Reference, Amount, Status and the action buttons. The Refund gate (Pro and confirmed) is the shared `canRefund` in `transaction-table.tsx`. - `transaction-notices.tsx` — `HiddenNote` (older payments Free hides) and `FreeRangeNote` ("Free shows the last 30 days."). A failed read renders the shared `ListError` ("Couldn't load payments"); the filter select uses `FILTER_SELECT_CLASS`. - `transaction-status-badge.tsx` — `TransactionStatusBadge({ status })` @@ -97,7 +97,7 @@ across every kit — plus, for Pro vendors, a per-payment refund action. Reachable from `dashboard-nav.tsx`'s "Payments" link. `page.tsx` reads transactions via `@/lib/vendor-session` and `@/lib/transactions`, and reads which rows have a screenshot (`transactionIdsWithProof`) and renders -`transaction-table.tsx` (a `Proof` column and phone-row button via +`transaction-table.tsx` (a `Proof` column via `proof-dialog.tsx`), which renders `refund-dialog.tsx` for Pro vendors — that dialog calls `issueRefundAction` in `actions.ts`. diff --git a/src/app/dashboard/transactions/transaction-table.dom.test.tsx b/src/app/dashboard/transactions/transaction-table.dom.test.tsx index 564ba1a..ce6f81f 100644 --- a/src/app/dashboard/transactions/transaction-table.dom.test.tsx +++ b/src/app/dashboard/transactions/transaction-table.dom.test.tsx @@ -1,6 +1,6 @@ // @vitest-environment jsdom import { describe, it, expect, vi } from "vitest"; -import { fireEvent, render, screen, within } from "@testing-library/react"; +import { render, screen, within } from "@testing-library/react"; import { TransactionTable } from "./transaction-table"; import type { Transaction } from "@/lib/types"; @@ -17,15 +17,13 @@ const TX: Transaction = { created_at: "2026-07-15T00:00:00Z", }; -// jsdom applies no Tailwind CSS, so both the phone list and the table are in -// the DOM; each assertion scopes to the one it means. vi.mock("./actions", () => ({ loadPaymentProofAction: vi.fn(), issueRefundAction: vi.fn(), })); describe("TransactionTable proof", () => { - it("offers View screenshot only on rows with a proof, in table and phone list", () => { + it("offers View screenshot only on rows with a proof", () => { const other = { ...TX, id: "tx2", order_ref: "A-002" }; render( { name: "View screenshot", }), ).toHaveLength(1); - const list = within(screen.getByRole("list", { name: "Payments" })); - fireEvent.click(list.getAllByRole("button", { name: /S\$4\.50/ })[0]); - expect( - list.getAllByRole("button", { name: "View screenshot" }), - ).toHaveLength(1); }); it("has no Proof column when no row has a screenshot", () => { @@ -64,6 +57,21 @@ describe("TransactionTable", () => { expect(table.getByText("Received")).toBeInTheDocument(); }); + it("hides the Kit and Created columns on phones only", () => { + render(); + expect(screen.getByRole("columnheader", { name: "Kit" })).toHaveClass( + "hidden", + "sm:table-cell", + ); + expect(screen.getByRole("columnheader", { name: "Created" })).toHaveClass( + "hidden", + "sm:table-cell", + ); + expect( + screen.getByRole("columnheader", { name: "Amount" }), + ).not.toHaveClass("hidden"); + }); + it("shows an empty state with no transactions", () => { render(); expect(screen.getByText(/no payments yet/i)).toBeInTheDocument(); @@ -90,61 +98,4 @@ describe("TransactionTable", () => { screen.getByRole("columnheader", { name: /refund/i }), ).toBeInTheDocument(); }); - - describe("phone list", () => { - it("shows amount, status, kit and date on the collapsed row", () => { - render(); - const list = within(screen.getByRole("list", { name: "Payments" })); - expect(list.getByText("S$4.50")).toBeInTheDocument(); - expect(list.getByText("Received")).toBeInTheDocument(); - expect(list.getByText("qkit")).toBeInTheDocument(); - expect(list.getByText(/2026/)).toBeInTheDocument(); - expect(list.queryByText("A-001")).not.toBeInTheDocument(); - expect( - list.queryByRole("button", { name: /refund/i }), - ).not.toBeInTheDocument(); - }); - - it("expands to reveal the reference and the Refund action", () => { - render(); - const list = within(screen.getByRole("list", { name: "Payments" })); - const toggle = list.getByRole("button", { name: /S\$4\.50/ }); - fireEvent.click(toggle); - expect(toggle).toHaveAttribute("aria-expanded", "true"); - expect(list.getByText("A-001")).toBeInTheDocument(); - expect(list.getByRole("button", { name: /refund/i })).toBeInTheDocument(); - fireEvent.click(toggle); - expect(toggle).toHaveAttribute("aria-expanded", "false"); - expect(list.queryByText("A-001")).not.toBeInTheDocument(); - }); - - it("keeps the Refund action outside the toggle so tapping it does not collapse the row", () => { - render(); - const list = within(screen.getByRole("list", { name: "Payments" })); - const toggle = list.getByRole("button", { name: /S\$4\.50/ }); - fireEvent.click(toggle); - const refund = list.getByRole("button", { name: /refund/i }); - expect(toggle).not.toContainElement(refund); - fireEvent.click(refund); - expect(toggle).toHaveAttribute("aria-expanded", "true"); - }); - - it("describes the toggle with the status and secondary line", () => { - render(); - const list = within(screen.getByRole("list", { name: "Payments" })); - expect( - list.getByRole("button", { name: /S\$4\.50/ }), - ).toHaveAccessibleDescription(/Received[\s\S]*qkit/); - }); - - it("offers no Refund on a Free vendor's expanded row", () => { - render(); - const list = within(screen.getByRole("list", { name: "Payments" })); - fireEvent.click(list.getByRole("button", { name: /S\$4\.50/ })); - expect(list.getByText("A-001")).toBeInTheDocument(); - expect( - list.queryByRole("button", { name: /refund/i }), - ).not.toBeInTheDocument(); - }); - }); }); diff --git a/src/app/dashboard/transactions/transaction-table.tsx b/src/app/dashboard/transactions/transaction-table.tsx index a00c821..d7a2447 100644 --- a/src/app/dashboard/transactions/transaction-table.tsx +++ b/src/app/dashboard/transactions/transaction-table.tsx @@ -8,7 +8,6 @@ import { Timestamp, type DataTableColumn, } from "@merqo/ui"; -import { PhoneList, PhoneRow } from "@/components/list/phone-row"; import { ProofDialog } from "./proof-dialog"; import { RefundDialog } from "./refund-dialog"; import { TransactionStatusBadge } from "./transaction-status-badge"; @@ -19,7 +18,11 @@ import type { Transaction } from "@/lib/types"; // Server → Client boundary into `@merqo/ui`'s `DataTable` directly from a // page. Same shape as `admin/vendors/vendors-table.tsx`. const BASE_COLUMNS: DataTableColumn[] = [ - { header: "Kit", cell: (tx) => tx.kit_slug }, + { + header: "Kit", + className: "hidden sm:table-cell", + cell: (tx) => tx.kit_slug, + }, { header: "Reference", cell: (tx) => tx.order_ref }, { header: "Amount", @@ -32,6 +35,7 @@ const BASE_COLUMNS: DataTableColumn[] = [ }, { header: "Created", + className: "hidden sm:table-cell", cell: (tx) => , }, ]; @@ -99,40 +103,12 @@ export function TransactionTable({ ...(isPro ? [REFUND_COLUMN] : []), ]; return ( - <> - - {transactions.map((tx) => ( - } - badge={} - secondary={ - <> - {tx.kit_slug} - - - } - > -

- Reference - {tx.order_ref} -

- {withProof.has(tx.id) ? ( - - ) : null} - {canRefund(tx, isPro) ? ( - - ) : null} -
- ))} -
-
- tx.id} - /> -
- +
+ tx.id} + /> +
); }