diff --git a/CHANGELOG.md b/CHANGELOG.md index 97174c09..6ea284b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to loopkit are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## [0.6.3] - 2026-12-01 + +### Changed + +- The loopkit stamp now shows on every qkit order by default. Migration `0071` adds `qkit_earn_resolve_program`: a Pro vendor with no `qkit_earn_config` row offers its oldest active stamp program (free vendors still have to opt in, as before), an explicit `enabled = false` stays off, and `qkit_earn_offer` also returns `reward_label`, `stamps_goal` and `stamps_per_order`. The `/earn` claim uses the same resolution. The dashboard qkit setting shows as on by default for Pro vendors and says a stamp card shows on every qkit order. Saving the setting stays Pro-only. + ## [0.6.2] - 2026-12-01 ### Security diff --git a/README.md b/README.md index db425416..0f815d06 100644 --- a/README.md +++ b/README.md @@ -390,9 +390,11 @@ flips it from a switch there (`src/app/dashboard/customer-notify-settings.tsx`, under RLS (`for all` own-row policy, not service-role-only). See `docs/superpowers/specs/2026-08-16-customer-notify-vendor-toggle-design.md`. -Separately, a Pro vendor can let customers earn a stamp from a completed +Separately, every Pro vendor with a stamp program shows it on qkit orders by default and can switch it off +(migration `0071`; a vendor with no `qkit_earn_config` row offers its oldest active stamp program) +so customers can earn a stamp from a completed qkit order (`src/app/dashboard/qkit-earn-settings.tsx`) — this is a pull-model -claim link, not push automation: qkit shows an "Earn a stamp" link on the +claim link, not push automation: qkit shows a stamp card on the customer's order page, which sends them to loopkit's own `/earn?order=...` page to enter their phone number and claim it (`src/app/earn/`). Existing customers must also supply their saved card token, directly or through the HttpOnly proof cookie; the shop assists with lost-card recovery. This is a claim flow rather than the stamp being awarded automatically the moment the qkit order completes. diff --git a/package.json b/package.json index d45e5efa..c0085f4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopkit", - "version": "0.6.2", + "version": "0.6.3", "private": true, "packageManager": "pnpm@11.10.0", "engines": { diff --git a/src/app/dashboard/README.md b/src/app/dashboard/README.md index b694b65b..13da88f1 100644 --- a/src/app/dashboard/README.md +++ b/src/app/dashboard/README.md @@ -44,8 +44,8 @@ Shared controls and `cn` used by this folder's modules are imported from `@merqo - `referrals/` - `points-offset-form.dom.test.tsx` — jsdom tests for `PointsOffsetForm`: input defaults to the card's full balance and Apply calls through, Apply disables once the entered amount exceeds the card's balance - `points-offset-form.tsx` — client `PointsOffsetForm`: a small inline apply-points form (not an AlertDialog like `redeem-button.tsx`/`redeem-voucher/`'s confirm screen, since there's a number to pick here) — calls `applyPointsOffsetAction` and reports the updated card plus the dollar figure back to the caller for the vendor to apply manually at their own register -- `qkit-earn-settings.dom.test.tsx` — jsdom tests for `QkitEarnSettings`: shows upgrade prompt when not Pro (and that its copy never claims the stamp is awarded automatically), lets a Pro vendor pick a program and toggle the switch -- `qkit-earn-settings.tsx` — client `QkitEarnSettings` form: Pro-gated switch + program picker that calls `saveQkitEarnConfigAction`; the non-Pro upsell copy describes the real claim-link flow (customer taps a link on their qkit order, enters their phone number on `/earn`) rather than overselling it as automatic. Wrapped in `@merqo/ui`'s `ElevatedCard` +- `qkit-earn-settings.dom.test.tsx` — jsdom tests for `QkitEarnSettings`: the not-Pro note, the on-by-default switch and its every-qkit-order copy (never claiming the stamp is awarded automatically), the no-stamp-program note, and picking a program and toggling the switch +- `qkit-earn-settings.tsx` — client `QkitEarnSettings` form: switch + program picker that calls `saveQkitEarnConfigAction`, with a not-available note for non-Pro vendors. The stamp card shows on every qkit order by default (migration `0071`), and turning the switch off saves `enabled = false`. With no stamp program it shows a note to create one. Wrapped in `@merqo/ui`'s `ElevatedCard` - `redeem-button.dom.test.tsx` — jsdom test asserting `RedeemButton`'s confirm dialog shows the exact stamp count and carryover wording - `redeem-button.tsx` — client `RedeemButton`: ConfirmDialog-confirmed redeem control that calls `redeemAction` and reports the reset card back to the caller - `redeem-voucher/` @@ -86,7 +86,7 @@ Each page exports its own `metadata.title`, shown through the root `loopkit | %s card-link test pins the clipboard-failure copy. -`qkit-earn-settings.tsx` shows the plain line "Qkit stamp earning is not available yet." with no link to non-Pro vendors. +`qkit-earn-settings.tsx` stays Pro-gated: the qkit stamp card is on for every Pro vendor with a stamp program until they switch it off. Dates and times on these pages render through `@merqo/ui`'s `formatDate`/`formatDateTime` (Singapore time). diff --git a/src/app/dashboard/profile/README.md b/src/app/dashboard/profile/README.md index 6be2f91c..4f8b38ae 100644 --- a/src/app/dashboard/profile/README.md +++ b/src/app/dashboard/profile/README.md @@ -10,7 +10,7 @@ Shared controls and `cn` used by this folder's modules are imported from `@merqo - `actions.test.ts` — unit tests for `updateSocialLinksAction`: saves valid links while preserving the existing `stall_name`, rejects an invalid URL without calling `patchVendorProfile`, errors when not signed in, and errors (without revalidating) when the field-specific patch fails. - `actions.ts` — server actions `updateStallNameAction()` (thin wrapper around `saveStallName`, `src/lib/vendor.ts`, revalidates the dashboard layout), `updatePasswordAction()` (Zod-validates an 8-72 char password, updates it via the Supabase auth client), and `updateSocialLinksAction()` (Zod-validates each link as an optional URL, uses a field-specific shared-profile patch for `social_links`, preserving concurrent stall-name changes). -- `page.tsx` — `ProfilePage` server component (also hosts the former Settings page: an `#integrations` block with `QkitEarnSettings` and `CustomerNotifySettings`, loaded from `qkit_earn_config` / `vendor_notify_settings`); requires a vendor, loads the vendor profile (`getVendorProfile()`, `src/lib/vendor.ts`) and auth `user_metadata` display name, reads the shared `merqo.vendor_profile` row's `social_links` (degrading to `{}` on failure, same pattern as `/setup`'s page), and renders `@merqo/ui`'s `BackButton` ("Back to dashboard") above `ProfileForm`. Its root element is `
` — deliberately narrower than the `../layout.tsx` `
`'s shared `max-w-7xl` (this form genuinely reads better constrained), so it nests its own `mx-auto`/`max-w-*` wrapper inside that container rather than stretching full-width; the page no longer sets its own padding, which the layout's `
` now owns. +- `page.tsx` — `ProfilePage` server component (also hosts the former Settings page: an `#integrations` block with `QkitEarnSettings` and `CustomerNotifySettings`, loaded from `qkit_earn_config` / `vendor_notify_settings`; with no `qkit_earn_config` row the oldest active stamp program is passed as already on, mirroring `qkit_earn_resolve_program`); requires a vendor, loads the vendor profile (`getVendorProfile()`, `src/lib/vendor.ts`) and auth `user_metadata` display name, reads the shared `merqo.vendor_profile` row's `social_links` (degrading to `{}` on failure, same pattern as `/setup`'s page), and renders `@merqo/ui`'s `BackButton` ("Back to dashboard") above `ProfileForm`. Its root element is `
` — deliberately narrower than the `../layout.tsx` `
`'s shared `max-w-7xl` (this form genuinely reads better constrained), so it nests its own `mx-auto`/`max-w-*` wrapper inside that container rather than stretching full-width; the page no longer sets its own padding, which the layout's `
` now owns. - `profile-form.dom.test.tsx` — jsdom tests for `ProfileForm`: renders all 5 sections, prefills the social-links fields from `socialLinks` and saves them via `updateSocialLinksAction`, saves the stall name via `updateStallNameAction`. - `profile-form.tsx` — `ProfileForm` client component; `@merqo/ui`'s `TwoColumnSections` (column 1: stall name, profile icon, change password; column 2: display name, social links — the locked cross-kit order) of five independently-saving `Section` cards (stall name via server action, social/website links via `@merqo/ui`'s `SocialLinksFields` + server action, avatar via `@merqo/ui`'s `ImageUploader` + browser auth client, display name via browser auth client, password change with client-side confirm match). diff --git a/src/app/dashboard/profile/page.tsx b/src/app/dashboard/profile/page.tsx index dbb93af3..cca522c8 100644 --- a/src/app/dashboard/profile/page.tsx +++ b/src/app/dashboard/profile/page.tsx @@ -34,6 +34,21 @@ export default async function ProfilePage() { .maybeSingle(), ]); const qkitEarnConfig = qkitEarnConfigResult.data; + const qkitPrograms = programs.filter( + (prog) => prog.type === "stamp" && prog.active, + ); + // Mirrors qkit_earn_resolve_program: with no saved row a Pro vendor's oldest + // active stamp program is already on. + const defaultProgram = pro ? qkitPrograms[0] : undefined; + let qkitCurrent: { programId: string; enabled: boolean } | null = null; + if (qkitEarnConfig) { + qkitCurrent = { + programId: qkitEarnConfig.program_id, + enabled: qkitEarnConfig.enabled, + }; + } else if (defaultProgram) { + qkitCurrent = { programId: defaultProgram.id, enabled: true }; + } const notifySettings = notifySettingsResult.data; // Same cross-schema, degrade-to-empty-on-failure pattern as /setup's page // (src/app/setup/page.tsx) — social links are a nice-to-have, not worth @@ -79,17 +94,11 @@ export default async function ProfilePage() { qkit integration prog.type === "stamp") - .map((prog) => ({ id: prog.id, name: prog.name }))} - current={ - qkitEarnConfig - ? { - programId: qkitEarnConfig.program_id, - enabled: qkitEarnConfig.enabled, - } - : null - } + programs={qkitPrograms.map((prog) => ({ + id: prog.id, + name: prog.name, + }))} + current={qkitCurrent} isPro={pro} />
diff --git a/src/app/dashboard/profile/profile-page.dom.test.tsx b/src/app/dashboard/profile/profile-page.dom.test.tsx index 336a881d..f90d9f83 100644 --- a/src/app/dashboard/profile/profile-page.dom.test.tsx +++ b/src/app/dashboard/profile/profile-page.dom.test.tsx @@ -16,10 +16,10 @@ vi.mock("@/lib/vendor", () => ({ })); vi.mock("@/lib/program", () => ({ listPrograms: vi.fn(async () => [ - { id: "p1", name: "Coffee Stamps", type: "stamp" }, + { id: "p1", name: "Coffee Stamps", type: "stamp", active: true }, { id: "p2", name: "Lucky Wheel", type: "wheel" }, ]), - isPro: vi.fn(async () => false), + isPro: vi.fn(async () => true), })); const qkitMaybeSingle = vi.fn( async (): Promise<{ @@ -53,8 +53,10 @@ vi.mock("@/app/dashboard/qkit-earn-settings", () => ({ }) => (
{props.programs.map((p) => p.name).join(",")} / current: - {props.current ? props.current.programId : "none"} / pro: - {String(props.isPro)} + {props.current + ? `${props.current.programId}:${String(props.current.enabled)}` + : "none"}{" "} + / pro:{String(props.isPro)}
), })); @@ -106,32 +108,53 @@ describe("ProfilePage", () => { const qkit = screen.getByTestId("qkit-earn-settings"); expect(qkit).toHaveTextContent("Coffee Stamps"); expect(qkit).not.toHaveTextContent("Lucky Wheel"); - expect(qkit).toHaveTextContent("current:none"); + expect(qkit).toHaveTextContent("current:p1:true"); expect(screen.getByTestId("customer-notify-settings")).toHaveTextContent( "current:none", ); }); - it("passes saved qkit earn config, Pro state and an explicit notify opt-out through", async () => { + it("passes saved qkit earn config and an explicit notify opt-out through", async () => { qkitMaybeSingle.mockResolvedValueOnce({ data: { program_id: "p1", enabled: true }, }); notifySettingsMaybeSingle.mockResolvedValueOnce({ data: { customer_telegram_notify_enabled: false }, }); - const { isPro } = await import("@/lib/program"); - vi.mocked(isPro).mockResolvedValueOnce(true); render(await ProfilePage()); expect(screen.getByTestId("qkit-earn-settings")).toHaveTextContent( - "current:p1 / pro:true", + "current:p1:true", ); expect(screen.getByTestId("customer-notify-settings")).toHaveTextContent( "current:false", ); }); + it("does not default the qkit stamp on for a non-Pro vendor", async () => { + const { isPro } = await import("@/lib/program"); + vi.mocked(isPro).mockResolvedValueOnce(false); + + render(await ProfilePage()); + + expect(screen.getByTestId("qkit-earn-settings")).toHaveTextContent( + "current:none / pro:false", + ); + }); + + it("keeps the qkit stamp card off when the saved row says so", async () => { + qkitMaybeSingle.mockResolvedValueOnce({ + data: { program_id: "p1", enabled: false }, + }); + + render(await ProfilePage()); + + expect(screen.getByTestId("qkit-earn-settings")).toHaveTextContent( + "current:p1:false", + ); + }); + it("degrades to empty social links when the shared merqo profile read fails", async () => { const { getOrCreateVendorProfile } = await import("@/lib/merqo-vendor-profile"); diff --git a/src/app/dashboard/qkit-earn-settings.dom.test.tsx b/src/app/dashboard/qkit-earn-settings.dom.test.tsx index 7f7cb928..531599d5 100644 --- a/src/app/dashboard/qkit-earn-settings.dom.test.tsx +++ b/src/app/dashboard/qkit-earn-settings.dom.test.tsx @@ -21,33 +21,39 @@ describe("QkitEarnSettings", () => { expect(screen.queryByRole("combobox")).not.toBeInTheDocument(); }); - it("does not oversell the qkit stamp as fully automatic", () => { + it("says a stamp card shows on every qkit order and is not automatic", () => { render( , ); - // The real flow needs the customer to visit /earn and enter their phone - // number (see earn-form.tsx) — it's a claim link, not push automation. + expect(screen.getByText(/shows on every qkit order/i)).toBeInTheDocument(); + expect(screen.getByRole("switch")).toBeChecked(); expect(screen.queryByText(/automatically/i)).not.toBeInTheDocument(); }); + it("asks a Pro vendor for a stamp program when there is none", () => { + render(); + expect(screen.getByText(/create a stamp program/i)).toBeInTheDocument(); + expect(screen.queryByRole("switch")).not.toBeInTheDocument(); + }); + it("lets a Pro vendor pick a program and enable it", () => { render( , ); expect(screen.getByRole("combobox")).toBeInTheDocument(); fireEvent.click( - screen.getByRole("switch", { name: /earn from qkit orders/i }), + screen.getByRole("switch", { name: /show stamp card on qkit orders/i }), ); expect( - screen.getByRole("switch", { name: /earn from qkit orders/i }), + screen.getByRole("switch", { name: /show stamp card on qkit orders/i }), ).toBeChecked(); }); }); diff --git a/src/app/dashboard/qkit-earn-settings.tsx b/src/app/dashboard/qkit-earn-settings.tsx index 0cb78f8e..5ce238b3 100644 --- a/src/app/dashboard/qkit-earn-settings.tsx +++ b/src/app/dashboard/qkit-earn-settings.tsx @@ -40,6 +40,14 @@ export function QkitEarnSettings({ ); } + if (programs.length === 0) { + return ( + + Create a stamp program and its stamp card will show on every qkit order. + + ); + } + return (
@@ -47,12 +55,16 @@ export function QkitEarnSettings({ id="qkit-earn-enabled" name="enabled" defaultChecked={current?.enabled ?? false} - aria-label="Earn from qkit orders" + aria-label="Show stamp card on qkit orders" />
+

+ A stamp card shows on every qkit order, and customers enter their phone + number to collect the stamp. Turn this off to hide it. +