Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "loopkit",
"version": "0.6.2",
"version": "0.6.3",
"private": true,
"packageManager": "pnpm@11.10.0",
"engines": {
Expand Down
6 changes: 3 additions & 3 deletions src/app/dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/`
Expand Down Expand Up @@ -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).

Expand Down
2 changes: 1 addition & 1 deletion src/app/dashboard/profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<div className="mx-auto max-w-lg space-y-8 md:max-w-4xl">` — deliberately narrower than the `../layout.tsx` `<main>`'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 `<main>` 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 `<div className="mx-auto max-w-lg space-y-8 md:max-w-4xl">` — deliberately narrower than the `../layout.tsx` `<main>`'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 `<main>` 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).

Expand Down
31 changes: 20 additions & 11 deletions src/app/dashboard/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,17 +94,11 @@ export default async function ProfilePage() {
qkit integration
</h2>
<QkitEarnSettings
programs={programs
.filter((prog) => 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}
/>
</div>
Expand Down
41 changes: 32 additions & 9 deletions src/app/dashboard/profile/profile-page.dom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand Down Expand Up @@ -53,8 +53,10 @@ vi.mock("@/app/dashboard/qkit-earn-settings", () => ({
}) => (
<div data-testid="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)}
</div>
),
}));
Expand Down Expand Up @@ -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");
Expand Down
22 changes: 14 additions & 8 deletions src/app/dashboard/qkit-earn-settings.dom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<QkitEarnSettings
programs={[{ id: "p1", name: "Coffee Stamps" }]}
current={null}
isPro={false}
current={{ programId: "p1", enabled: true }}
isPro
/>,
);
// 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(<QkitEarnSettings programs={[]} current={null} isPro />);
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(
<QkitEarnSettings
programs={[{ id: "p1", name: "Coffee Stamps" }]}
current={null}
isPro={true}
isPro
/>,
);
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();
});
});
16 changes: 14 additions & 2 deletions src/app/dashboard/qkit-earn-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,31 @@ export function QkitEarnSettings({
);
}

if (programs.length === 0) {
return (
<ElevatedCard className="p-4 text-sm text-muted-foreground">
Create a stamp program and its stamp card will show on every qkit order.
</ElevatedCard>
);
}

return (
<FormCard className="space-y-3 p-4" action={save}>
<div className="flex items-center gap-2">
<Switch
id="qkit-earn-enabled"
name="enabled"
defaultChecked={current?.enabled ?? false}
aria-label="Earn from qkit orders"
aria-label="Show stamp card on qkit orders"
/>
<Label htmlFor="qkit-earn-enabled" className="text-sm">
Earn from qkit orders
Show stamp card on qkit orders
</Label>
</div>
<p className="text-sm text-muted-foreground">
A stamp card shows on every qkit order, and customers enter their phone
number to collect the stamp. Turn this off to hide it.
</p>
<Select name="program_id" defaultValue={current?.programId || undefined}>
<SelectTrigger className="w-full">
<SelectValue placeholder="Choose a program" />
Expand Down
Loading
Loading