@remit/ui 0.0.192 → 0.0.193

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/ui",
3
- "version": "0.0.192",
3
+ "version": "0.0.193",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The confirmation between a switch and the change it asks for (#1179). The
3
+ * promise disabling makes — nothing is deleted, the stored rows stay — is a
4
+ * sentence a person reads before they commit, so it is asserted here rather
5
+ * than left to the copy of the day.
6
+ */
7
+ import "@remit/test-dom";
8
+ import assert from "node:assert/strict";
9
+ import { describe, it } from "node:test";
10
+ import { createElement } from "react";
11
+ import { renderToString } from "react-dom/server";
12
+ import {
13
+ type AccountServiceChange,
14
+ AccountServiceChangeDialog,
15
+ accountServiceChangeCopy,
16
+ } from "./account-service-change-dialog.js";
17
+
18
+ const render = (change: AccountServiceChange | null): string =>
19
+ renderToString(
20
+ createElement(AccountServiceChangeDialog, {
21
+ change,
22
+ providerName: "Microsoft",
23
+ onConfirm: () => {},
24
+ onCancel: () => {},
25
+ }),
26
+ );
27
+
28
+ describe("AccountServiceChangeDialog", () => {
29
+ it("renders nothing while no change is pending", () => {
30
+ assert.equal(render(null), "");
31
+ });
32
+
33
+ it("promises stored mail stays and says sync stops", () => {
34
+ const html = render({ kind: "disable", service: "Mail" });
35
+ assert.match(html, /Mail already in Remit stays/);
36
+ assert.match(html, /New mail stops arriving until you turn it back on\./);
37
+ assert.match(html, /Nothing is deleted\./);
38
+ });
39
+
40
+ it("promises stored events stay when calendar goes off", () => {
41
+ const html = render({ kind: "disable", service: "Calendar" });
42
+ assert.match(html, /Events already in Remit stay on your calendar\./);
43
+ assert.match(html, /Nothing is deleted\./);
44
+ });
45
+
46
+ it("names the sign-in round trip before a service is added", () => {
47
+ const html = render({ kind: "enable", service: "Calendar" });
48
+ assert.match(html, /Remit sends you to Microsoft to ask for it/);
49
+ assert.match(html, /Nothing changes until you get back\./);
50
+ assert.match(html, /Continue to Microsoft/);
51
+ });
52
+
53
+ it("sends the last service off to removing the account", () => {
54
+ const copy = accountServiceChangeCopy(
55
+ { kind: "last", service: "Mail" },
56
+ "Microsoft",
57
+ );
58
+ assert.match(copy.title, /only thing this account syncs/);
59
+ assert.match(copy.description, /An account has to sync something\./);
60
+ assert.equal(copy.confirmLabel, "Remove account");
61
+ assert.equal(copy.cancelLabel, "Keep syncing mail");
62
+ assert.equal(copy.destructive, true);
63
+ });
64
+
65
+ it("keeps switching a service off away from the destructive style", () => {
66
+ const copy = accountServiceChangeCopy(
67
+ { kind: "disable", service: "Mail" },
68
+ "Microsoft",
69
+ );
70
+ assert.equal(copy.destructive, false);
71
+ assert.equal(copy.confirmLabel, "Stop syncing mail");
72
+ });
73
+ });
@@ -0,0 +1,66 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite";
2
+ import { expect, within } from "storybook/test";
3
+ import { AccountServiceChangeDialog } from "./account-service-change-dialog.js";
4
+
5
+ /**
6
+ * The question between a service switch and the change it asks for (#1179).
7
+ * Every state of it is copy, so every state is a story.
8
+ */
9
+ const meta: Meta<typeof AccountServiceChangeDialog> = {
10
+ title: "Components/AccountServiceChangeDialog",
11
+ component: AccountServiceChangeDialog,
12
+ parameters: { layout: "fullscreen" },
13
+ args: {
14
+ providerName: "Microsoft",
15
+ onConfirm: () => undefined,
16
+ onCancel: () => undefined,
17
+ },
18
+ };
19
+ export default meta;
20
+
21
+ type Story = StoryObj<typeof AccountServiceChangeDialog>;
22
+
23
+ /**
24
+ * Mail off. The confirmation is the only place the promise is made, so it makes
25
+ * it in full: what stays, what stops, and that nothing is deleted.
26
+ */
27
+ export const DisableMail: Story = {
28
+ args: { change: { kind: "disable", service: "Mail" } },
29
+ play: async ({ canvasElement }) => {
30
+ const canvas = within(canvasElement);
31
+ await expect(canvas.getByText(/Nothing is deleted/)).toBeVisible();
32
+ },
33
+ };
34
+
35
+ /** Calendar off. The events already read in stay on the calendar. */
36
+ export const DisableCalendar: Story = {
37
+ args: { change: { kind: "disable", service: "Calendar" } },
38
+ };
39
+
40
+ /**
41
+ * Calendar on, for an account whose consent never covered it. The round trip is
42
+ * named before the person commits, and nothing changes until they are back.
43
+ */
44
+ export const EnableCalendar: Story = {
45
+ args: { change: { kind: "enable", service: "Calendar" } },
46
+ play: async ({ canvasElement }) => {
47
+ const canvas = within(canvasElement);
48
+ await expect(
49
+ canvas.getByRole("button", { name: "Continue to Microsoft" }),
50
+ ).toBeVisible();
51
+ },
52
+ };
53
+
54
+ /**
55
+ * The switch that would leave the account syncing nothing. No stored account
56
+ * holds the empty set, so this points at removing the account and says what
57
+ * that costs — which is what switching a service off never does.
58
+ */
59
+ export const LastService: Story = {
60
+ args: { change: { kind: "last", service: "Mail" } },
61
+ };
62
+
63
+ /** Nothing pending: the dialog is absent, not an empty overlay. */
64
+ export const NothingPending: Story = {
65
+ args: { change: null },
66
+ };
@@ -0,0 +1,117 @@
1
+ import type { AccountService } from "./account-service-choice.js";
2
+ import { ConfirmDialog } from "./confirm-dialog.js";
3
+
4
+ /**
5
+ * A pending change to what an account syncs. `last` is the switch that would
6
+ * leave the account syncing nothing: no stored account holds the empty set, so
7
+ * the way to sync nothing is to remove the account.
8
+ */
9
+ export type AccountServiceChange =
10
+ | { kind: "enable"; service: AccountService }
11
+ | { kind: "disable"; service: AccountService }
12
+ | { kind: "last"; service: AccountService };
13
+
14
+ export interface AccountServiceChangeCopy {
15
+ title: string;
16
+ description: string;
17
+ confirmLabel: string;
18
+ cancelLabel: string;
19
+ destructive: boolean;
20
+ }
21
+
22
+ const STORED: Record<AccountService, string> = {
23
+ Mail: "Mail already in Remit stays, and you can keep reading it.",
24
+ Calendar: "Events already in Remit stay on your calendar.",
25
+ };
26
+
27
+ const STOPS: Record<AccountService, string> = {
28
+ Mail: "New mail stops arriving until you turn it back on.",
29
+ Calendar: "Changes stop arriving until you turn it back on.",
30
+ };
31
+
32
+ const NOUN: Record<AccountService, string> = {
33
+ Mail: "mail",
34
+ Calendar: "calendar",
35
+ };
36
+
37
+ /**
38
+ * The words each change gets, in one place, so the dialog and the tests that
39
+ * pin the promise read the same sentence.
40
+ */
41
+ export function accountServiceChangeCopy(
42
+ change: AccountServiceChange,
43
+ providerName: string,
44
+ ): AccountServiceChangeCopy {
45
+ const noun = NOUN[change.service];
46
+
47
+ if (change.kind === "enable") {
48
+ return {
49
+ title: `Sign in with ${providerName} to add ${noun}?`,
50
+ description: `This account was never asked for ${noun} access. Remit sends you to ${providerName} to ask for it, and brings you back here when you are done. Nothing changes until you get back.`,
51
+ confirmLabel: `Continue to ${providerName}`,
52
+ cancelLabel: "Cancel",
53
+ destructive: false,
54
+ };
55
+ }
56
+
57
+ if (change.kind === "last") {
58
+ return {
59
+ title: `${change.service} is the only thing this account syncs`,
60
+ description: `An account has to sync something. To stop this one entirely, remove the account — that deletes what Remit stored for it, which switching ${noun} off never does.`,
61
+ confirmLabel: "Remove account",
62
+ cancelLabel: `Keep syncing ${noun}`,
63
+ destructive: true,
64
+ };
65
+ }
66
+
67
+ return {
68
+ title: `Stop syncing ${noun} for this account?`,
69
+ description: `${STORED[change.service]} ${STOPS[change.service]} Nothing is deleted.`,
70
+ confirmLabel: `Stop syncing ${noun}`,
71
+ cancelLabel: "Cancel",
72
+ destructive: false,
73
+ };
74
+ }
75
+
76
+ export interface AccountServiceChangeDialogProps {
77
+ /** The change waiting for an answer; `null` while nothing is pending. */
78
+ change: AccountServiceChange | null;
79
+ providerName: string;
80
+ /** Commits the change, or leaves for the provider, or opens account removal. */
81
+ onConfirm: () => void;
82
+ onCancel: () => void;
83
+ /** Disables the confirm button while the host's mutation is in flight. */
84
+ isBusy?: boolean;
85
+ }
86
+
87
+ /**
88
+ * The confirmation between a service switch and the change it asks for (#1179).
89
+ *
90
+ * Switching a service off says what stays and what stops, because a person only
91
+ * believes disabling deletes nothing if the screen says so. Switching one on
92
+ * names the sign-in round trip before they commit, because the scopes come from
93
+ * the authorization request and no saved setting can grant them.
94
+ */
95
+ export function AccountServiceChangeDialog({
96
+ change,
97
+ providerName,
98
+ onConfirm,
99
+ onCancel,
100
+ isBusy,
101
+ }: AccountServiceChangeDialogProps) {
102
+ if (change === null) return null;
103
+ const copy = accountServiceChangeCopy(change, providerName);
104
+ return (
105
+ <ConfirmDialog
106
+ isOpen
107
+ title={copy.title}
108
+ description={copy.description}
109
+ confirmLabel={copy.confirmLabel}
110
+ cancelLabel={copy.cancelLabel}
111
+ destructive={copy.destructive}
112
+ isBusy={isBusy ?? false}
113
+ onConfirm={onConfirm}
114
+ onCancel={onCancel}
115
+ />
116
+ );
117
+ }
@@ -9,13 +9,14 @@ export type AccountService = "Mail" | "Calendar";
9
9
  export const ACCOUNT_SERVICE_EMPTY_MESSAGE =
10
10
  "Pick at least one. An account has to sync something.";
11
11
 
12
- interface ServiceRow {
12
+ /** One service as every surface names it: the same label and the same line. */
13
+ export interface AccountServiceRow {
13
14
  id: AccountService;
14
15
  label: string;
15
16
  description: string;
16
17
  }
17
18
 
18
- const SERVICE_ROWS: ServiceRow[] = [
19
+ export const ACCOUNT_SERVICE_ROWS: AccountServiceRow[] = [
19
20
  {
20
21
  id: "Mail",
21
22
  label: "Mail",
@@ -47,7 +48,7 @@ export function AccountServiceChoice({
47
48
  error,
48
49
  }: AccountServiceChoiceProps) {
49
50
  const noteId = useId();
50
- const rows = SERVICE_ROWS.filter((row) => offered.includes(row.id));
51
+ const rows = ACCOUNT_SERVICE_ROWS.filter((row) => offered.includes(row.id));
51
52
 
52
53
  const refusal = error ? (
53
54
  <Banner tone="danger" variant="soft" className="mt-2 text-xs">
@@ -0,0 +1,82 @@
1
+ /**
2
+ * How a switched-off service reads wherever its account or its stored rows are
3
+ * (#1179). Every surface says the same thing, and the notice over stored rows
4
+ * says what stayed before it says what stopped.
5
+ */
6
+ import "@remit/test-dom";
7
+ import assert from "node:assert/strict";
8
+ import { describe, it } from "node:test";
9
+ import { createElement } from "react";
10
+ import { renderToString } from "react-dom/server";
11
+ import {
12
+ AccountServiceOffBadge,
13
+ AccountServiceOffNotice,
14
+ } from "./account-service-status.js";
15
+
16
+ describe("AccountServiceOffBadge", () => {
17
+ it("labels a mail-disabled account", () => {
18
+ assert.match(
19
+ renderToString(
20
+ createElement(AccountServiceOffBadge, { service: "Mail" }),
21
+ ),
22
+ /mail sync off/,
23
+ );
24
+ });
25
+
26
+ it("labels a calendar-disabled account", () => {
27
+ assert.match(
28
+ renderToString(
29
+ createElement(AccountServiceOffBadge, { service: "Calendar" }),
30
+ ),
31
+ /calendar sync off/,
32
+ );
33
+ });
34
+ });
35
+
36
+ describe("AccountServiceOffNotice", () => {
37
+ it("says the stored mail is there before it says sync stopped", () => {
38
+ const html = renderToString(
39
+ createElement(AccountServiceOffNotice, { service: "Mail" }),
40
+ );
41
+ assert.match(html, /Everything already synced is here to read/);
42
+ assert.ok(
43
+ html.indexOf("here to read") < html.indexOf("nothing new arrives"),
44
+ );
45
+ });
46
+
47
+ it("keeps a paused calendar's events on the calendar", () => {
48
+ assert.match(
49
+ renderToString(
50
+ createElement(AccountServiceOffNotice, { service: "Calendar" }),
51
+ ),
52
+ /Its events stay on your calendar/,
53
+ );
54
+ });
55
+
56
+ it("states the account rather than raising an alarm", () => {
57
+ assert.match(
58
+ renderToString(
59
+ createElement(AccountServiceOffNotice, { service: "Mail" }),
60
+ ),
61
+ /role="status"/,
62
+ );
63
+ });
64
+
65
+ it("offers the way back on only when it is given one", () => {
66
+ assert.doesNotMatch(
67
+ renderToString(
68
+ createElement(AccountServiceOffNotice, { service: "Mail" }),
69
+ ),
70
+ /Turn mail back on/,
71
+ );
72
+ assert.match(
73
+ renderToString(
74
+ createElement(AccountServiceOffNotice, {
75
+ service: "Mail",
76
+ onEnable: () => {},
77
+ }),
78
+ ),
79
+ /Turn mail back on/,
80
+ );
81
+ });
82
+ });
@@ -0,0 +1,61 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite";
2
+ import { expect, within } from "storybook/test";
3
+ import {
4
+ AccountServiceOffBadge,
5
+ AccountServiceOffNotice,
6
+ } from "./account-service-status.js";
7
+
8
+ /**
9
+ * How a switched-off service reads on the surfaces that hold what it left
10
+ * behind (#1179): a label wherever the account is listed, and a notice over the
11
+ * stored rows themselves.
12
+ */
13
+ const meta: Meta = {
14
+ title: "Components/AccountServiceStatus",
15
+ parameters: { layout: "padded" },
16
+ };
17
+ export default meta;
18
+
19
+ type Story = StoryObj;
20
+
21
+ /** The label an account carries in a list, a picker or the sidebar. */
22
+ export const Badges: Story = {
23
+ render: () => (
24
+ <div className="flex flex-col items-start gap-2">
25
+ <AccountServiceOffBadge service="Mail" />
26
+ <AccountServiceOffBadge service="Calendar" />
27
+ </div>
28
+ ),
29
+ };
30
+
31
+ /**
32
+ * Over a mail-disabled account's stored mailboxes. It says what is there before
33
+ * it says what stopped — an empty-looking mailbox is the failure this exists to
34
+ * prevent.
35
+ */
36
+ export const MailNotice: Story = {
37
+ render: () => (
38
+ <AccountServiceOffNotice service="Mail" onEnable={() => undefined} />
39
+ ),
40
+ play: async ({ canvasElement }) => {
41
+ const canvas = within(canvasElement);
42
+ await expect(
43
+ canvas.getByText(/Everything already synced is here to read/),
44
+ ).toBeVisible();
45
+ await expect(
46
+ canvas.getByRole("button", { name: "Turn mail back on" }),
47
+ ).toBeVisible();
48
+ },
49
+ };
50
+
51
+ /** Over a paused provider calendar. Its events stay drawn on the grid. */
52
+ export const CalendarNotice: Story = {
53
+ render: () => (
54
+ <AccountServiceOffNotice service="Calendar" onEnable={() => undefined} />
55
+ ),
56
+ };
57
+
58
+ /** No way back on from here — the notice is a statement, never a dead button. */
59
+ export const NoticeWithoutAction: Story = {
60
+ render: () => <AccountServiceOffNotice service="Mail" />,
61
+ };
@@ -0,0 +1,89 @@
1
+ import { PauseCircle } from "lucide-react";
2
+ import { cn } from "../lib/cn.js";
3
+ import type { AccountService } from "./account-service-choice.js";
4
+ import { Badge } from "./badge.js";
5
+ import { Banner } from "./banner.js";
6
+
7
+ /**
8
+ * How every surface names a service an account has switched off. One wording,
9
+ * so an account list, a picker and the sidebar say the same thing about the
10
+ * same account.
11
+ */
12
+ export const ACCOUNT_SERVICE_OFF_LABEL: Record<AccountService, string> = {
13
+ Mail: "mail sync off",
14
+ Calendar: "calendar sync off",
15
+ };
16
+
17
+ /**
18
+ * What the stored rows are, said where they are read. Disabling deletes
19
+ * nothing, so the surface holding the rows says what it is holding rather than
20
+ * reading as a broken account or an empty mailbox.
21
+ */
22
+ export const ACCOUNT_SERVICE_OFF_MESSAGE: Record<AccountService, string> = {
23
+ Mail: "Mail sync is off for this account. Everything already synced is here to read; nothing new arrives until you turn mail back on.",
24
+ Calendar:
25
+ "Calendar sync is off for this account. Its events stay on your calendar; nothing new arrives until you turn calendar back on.",
26
+ };
27
+
28
+ /**
29
+ * Why an account is offered no switches at all. An IMAP connector carries mail
30
+ * alone, so the screen says that rather than showing a control that can never
31
+ * move.
32
+ */
33
+ export const ACCOUNT_NO_SERVICE_TOGGLES_MESSAGE =
34
+ "This account connects over IMAP, which carries mail and nothing else. There is nothing to switch.";
35
+
36
+ export interface AccountServiceOffBadgeProps {
37
+ service: AccountService;
38
+ className?: string;
39
+ }
40
+
41
+ /**
42
+ * The label an account carries wherever it is listed while a service is off. It
43
+ * is a label and never a removal: the account keeps its place in the list, the
44
+ * picker and the sidebar (#1179).
45
+ */
46
+ export function AccountServiceOffBadge({
47
+ service,
48
+ className,
49
+ }: AccountServiceOffBadgeProps) {
50
+ return (
51
+ <Badge tone="neutral" className={className}>
52
+ <PauseCircle className="size-3 shrink-0" aria-hidden />
53
+ {ACCOUNT_SERVICE_OFF_LABEL[service]}
54
+ </Badge>
55
+ );
56
+ }
57
+
58
+ export interface AccountServiceOffNoticeProps {
59
+ service: AccountService;
60
+ /** The way back on. Absent leaves the notice a statement. */
61
+ onEnable?: () => void;
62
+ className?: string;
63
+ }
64
+
65
+ /**
66
+ * The notice above stored rows a switched-off service left behind — a mailbox
67
+ * opened directly, or a provider calendar still drawn on the grid. It states
68
+ * what stayed and what stopped, and offers the switch that resumes it.
69
+ */
70
+ export function AccountServiceOffNotice({
71
+ service,
72
+ onEnable,
73
+ className,
74
+ }: AccountServiceOffNoticeProps) {
75
+ return (
76
+ <Banner tone="info" variant="soft" className={cn("text-xs", className)}>
77
+ <span>{ACCOUNT_SERVICE_OFF_MESSAGE[service]}</span>
78
+ {onEnable && (
79
+ <button
80
+ type="button"
81
+ onClick={onEnable}
82
+ className="ml-1 font-medium text-accent underline"
83
+ >
84
+ {service === "Mail" ? "Turn mail back on" : "Turn calendar back on"}
85
+ </button>
86
+ )}
87
+ </Banner>
88
+ );
89
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * The service switches on account settings (#1179). What is pinned here is the
3
+ * contract the ADR binds: an IMAP account gets no switches at all, a service the
4
+ * grant never covered names the sign-in round trip before it is pressed, and a
5
+ * press asks the host rather than flipping anything itself.
6
+ */
7
+ import "@remit/test-dom";
8
+ import assert from "node:assert/strict";
9
+ import { describe, it } from "node:test";
10
+ import { act, createElement } from "react";
11
+ import { createRoot } from "react-dom/client";
12
+ import { renderToString } from "react-dom/server";
13
+ import type { AccountService } from "./account-service-choice.js";
14
+ import {
15
+ type AccountServiceIntent,
16
+ AccountServiceToggles,
17
+ type AccountServiceTogglesProps,
18
+ } from "./account-service-toggles.js";
19
+
20
+ const bothServices: AccountService[] = ["Mail", "Calendar"];
21
+
22
+ const props = (
23
+ overrides: Partial<AccountServiceTogglesProps> = {},
24
+ ): AccountServiceTogglesProps => ({
25
+ providerName: "Microsoft",
26
+ offered: bothServices,
27
+ enabled: bothServices,
28
+ consented: bothServices,
29
+ onRequestChange: () => {},
30
+ ...overrides,
31
+ });
32
+
33
+ const render = (overrides: Partial<AccountServiceTogglesProps> = {}): string =>
34
+ renderToString(createElement(AccountServiceToggles, props(overrides)));
35
+
36
+ interface Press {
37
+ service: AccountService;
38
+ intent: AccountServiceIntent;
39
+ }
40
+
41
+ function pressSwitch(
42
+ index: number,
43
+ overrides: Partial<AccountServiceTogglesProps> = {},
44
+ ): Press[] {
45
+ const container = document.createElement("div");
46
+ document.body.appendChild(container);
47
+ const root = createRoot(container);
48
+ const presses: Press[] = [];
49
+
50
+ act(() => {
51
+ root.render(
52
+ createElement(
53
+ AccountServiceToggles,
54
+ props({
55
+ ...overrides,
56
+ onRequestChange: (service, intent) =>
57
+ presses.push({ service, intent }),
58
+ }),
59
+ ),
60
+ );
61
+ });
62
+
63
+ const switches =
64
+ container.querySelectorAll<HTMLButtonElement>('[role="switch"]');
65
+ act(() => {
66
+ switches[index]?.click();
67
+ });
68
+
69
+ act(() => {
70
+ root.unmount();
71
+ });
72
+ container.remove();
73
+ return presses;
74
+ }
75
+
76
+ describe("AccountServiceToggles", () => {
77
+ it("offers a switch per service, mail first", () => {
78
+ const html = render();
79
+ assert.equal(html.match(/role="switch"/g)?.length, 2);
80
+ assert.ok(html.indexOf("Mail") < html.indexOf("Calendar"));
81
+ });
82
+
83
+ it("shows each switch in the state the account is in", () => {
84
+ const html = render({ enabled: ["Calendar"] });
85
+ assert.equal(html.match(/aria-checked="true"/g)?.length, 1);
86
+ assert.equal(html.match(/aria-checked="false"/g)?.length, 1);
87
+ });
88
+
89
+ it("renders nothing for an IMAP account, which syncs mail alone", () => {
90
+ assert.equal(render({ offered: ["Mail"], enabled: ["Mail"] }), "");
91
+ });
92
+
93
+ it("names the sign-in round trip on a service the grant never covered", () => {
94
+ assert.match(
95
+ render({ enabled: ["Mail"], consented: ["Mail"] }),
96
+ /Turning this on means signing in with Microsoft again\./,
97
+ );
98
+ });
99
+
100
+ it("says nothing about signing in for a service the grant covers", () => {
101
+ assert.doesNotMatch(
102
+ render({ enabled: ["Mail"] }),
103
+ /signing in with Microsoft again/,
104
+ );
105
+ });
106
+
107
+ it("says nothing about signing in for a service already on", () => {
108
+ assert.doesNotMatch(
109
+ render({ consented: ["Mail"] }),
110
+ /signing in with Microsoft again/,
111
+ );
112
+ });
113
+
114
+ it("asks the host to switch a running service off", () => {
115
+ assert.deepEqual(pressSwitch(0), [{ service: "Mail", intent: "off" }]);
116
+ });
117
+
118
+ it("asks the host to switch a stopped service on", () => {
119
+ assert.deepEqual(pressSwitch(1, { enabled: ["Mail"] }), [
120
+ { service: "Calendar", intent: "on" },
121
+ ]);
122
+ });
123
+ });
@@ -0,0 +1,121 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite";
2
+ import { expect, userEvent, within } from "storybook/test";
3
+ import type { AccountService } from "./account-service-choice.js";
4
+ import { ACCOUNT_NO_SERVICE_TOGGLES_MESSAGE } from "./account-service-status.js";
5
+ import {
6
+ type AccountServiceIntent,
7
+ AccountServiceToggles,
8
+ } from "./account-service-toggles.js";
9
+
10
+ /**
11
+ * What an account syncs, on its settings screen (#1179). The switch asks; the
12
+ * host confirms and commits.
13
+ */
14
+ const meta: Meta<typeof AccountServiceToggles> = {
15
+ title: "Components/AccountServiceToggles",
16
+ component: AccountServiceToggles,
17
+ parameters: { layout: "padded" },
18
+ decorators: [
19
+ (Story) => (
20
+ <div className="mx-auto max-w-sm rounded-xl border border-line bg-surface p-4">
21
+ <Story />
22
+ </div>
23
+ ),
24
+ ],
25
+ };
26
+ export default meta;
27
+
28
+ type Story = StoryObj<typeof AccountServiceToggles>;
29
+
30
+ const bothServices: AccountService[] = ["Mail", "Calendar"];
31
+
32
+ /**
33
+ * Stands in for the host that owns the change: the switch reports the ask and
34
+ * nothing moves until the host answers it, which is what these stories show.
35
+ */
36
+ function Toggles({
37
+ enabled,
38
+ consented = bothServices,
39
+ offered = bothServices,
40
+ onRequestChange = () => {},
41
+ }: {
42
+ enabled: AccountService[];
43
+ consented?: AccountService[];
44
+ offered?: AccountService[];
45
+ onRequestChange?: (
46
+ service: AccountService,
47
+ intent: AccountServiceIntent,
48
+ ) => void;
49
+ }) {
50
+ return (
51
+ <AccountServiceToggles
52
+ providerName="Microsoft"
53
+ offered={offered}
54
+ enabled={enabled}
55
+ consented={consented}
56
+ onRequestChange={onRequestChange}
57
+ />
58
+ );
59
+ }
60
+
61
+ /** Both services on: the state an Outlook account arrives in from onboarding. */
62
+ export const BothOn: Story = {
63
+ render: () => <Toggles enabled={bothServices} />,
64
+ };
65
+
66
+ /**
67
+ * Mail off. The switch is the only thing that changed — the account keeps its
68
+ * place and its stored mail, which the other surfaces say for themselves.
69
+ */
70
+ export const MailOff: Story = {
71
+ render: () => <Toggles enabled={["Calendar"]} />,
72
+ };
73
+
74
+ /**
75
+ * Calendar was never consented to. The row says what turning it on costs before
76
+ * it is pressed, because no saved setting can grant a scope.
77
+ */
78
+ export const CalendarNeedsConsent: Story = {
79
+ render: () => <Toggles enabled={["Mail"]} consented={["Mail"]} />,
80
+ play: async ({ canvasElement }) => {
81
+ const canvas = within(canvasElement);
82
+ await expect(
83
+ canvas.getByText(/signing in with Microsoft again/),
84
+ ).toBeVisible();
85
+ },
86
+ };
87
+
88
+ /**
89
+ * Pressing a running service asks to switch it off. Nothing moves on screen:
90
+ * the host raises the confirmation and owns the change.
91
+ */
92
+ export const AsksBeforeItMoves: Story = {
93
+ render: () => <Toggles enabled={bothServices} />,
94
+ play: async ({ canvasElement }) => {
95
+ const canvas = within(canvasElement);
96
+ const mail = canvas.getByRole("switch", { name: "Sync mail" });
97
+ await userEvent.click(mail);
98
+ await expect(mail).toBeChecked();
99
+ },
100
+ };
101
+
102
+ /**
103
+ * An IMAP account. It syncs mail and nothing else, so there is nothing to
104
+ * switch — the border below is the whole render.
105
+ */
106
+ export const ImapAccount: Story = {
107
+ render: () => (
108
+ <>
109
+ <AccountServiceToggles
110
+ providerName="Fastmail"
111
+ offered={["Mail"]}
112
+ enabled={["Mail"]}
113
+ consented={["Mail"]}
114
+ onRequestChange={() => {}}
115
+ />
116
+ <p className="border-t border-line pt-2 text-2xs text-fg-subtle">
117
+ {ACCOUNT_NO_SERVICE_TOGGLES_MESSAGE}
118
+ </p>
119
+ </>
120
+ ),
121
+ };
@@ -0,0 +1,125 @@
1
+ import { useId } from "react";
2
+ import { cn } from "../lib/cn.js";
3
+ import {
4
+ ACCOUNT_SERVICE_ROWS,
5
+ type AccountService,
6
+ } from "./account-service-choice.js";
7
+
8
+ /**
9
+ * A service switch on the account settings screen. Switching off always asks,
10
+ * because it stops a sync. Switching on asks only when the grant does not cover
11
+ * the service yet, because granting it leaves for the provider; a service the
12
+ * consent already covers comes back on without a question.
13
+ */
14
+ export type AccountServiceIntent = "on" | "off";
15
+
16
+ export interface AccountServiceTogglesProps {
17
+ /** Provider named in the consent note, e.g. "Microsoft". */
18
+ providerName: string;
19
+ /** Services this account's connector carries. Under two, nothing renders. */
20
+ offered: AccountService[];
21
+ /** Services the account syncs today. */
22
+ enabled: AccountService[];
23
+ /** Services the account's grant already covers. The rest cost a sign-in. */
24
+ consented: AccountService[];
25
+ /** Asks the host for a change. The host owns the question and the commit. */
26
+ onRequestChange: (
27
+ service: AccountService,
28
+ intent: AccountServiceIntent,
29
+ ) => void;
30
+ }
31
+
32
+ function ServiceSwitch({
33
+ checked,
34
+ label,
35
+ describedBy,
36
+ onToggle,
37
+ }: {
38
+ checked: boolean;
39
+ label: string;
40
+ describedBy: string;
41
+ onToggle: () => void;
42
+ }) {
43
+ return (
44
+ <button
45
+ type="button"
46
+ role="switch"
47
+ aria-checked={checked}
48
+ aria-label={label}
49
+ aria-describedby={describedBy}
50
+ onClick={onToggle}
51
+ className={cn(
52
+ "relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors",
53
+ "outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface",
54
+ checked
55
+ ? "border-positive bg-positive"
56
+ : "border-line-strong bg-surface-sunken",
57
+ )}
58
+ >
59
+ <span
60
+ aria-hidden
61
+ className={cn(
62
+ "size-4 rounded-full bg-canvas transition-transform",
63
+ checked ? "translate-x-6" : "translate-x-1",
64
+ )}
65
+ />
66
+ </button>
67
+ );
68
+ }
69
+
70
+ /**
71
+ * What an account syncs, on the account settings screen (#1179). One switch per
72
+ * service the connector carries, mail first.
73
+ *
74
+ * An IMAP account carries mail and nothing else, so it gets no switches at all
75
+ * rather than one it can never move — the same rule the onboarding choice
76
+ * follows for a single-service provider.
77
+ */
78
+ export function AccountServiceToggles({
79
+ providerName,
80
+ offered,
81
+ enabled,
82
+ consented,
83
+ onRequestChange,
84
+ }: AccountServiceTogglesProps) {
85
+ const groupId = useId();
86
+ const rows = ACCOUNT_SERVICE_ROWS.filter((row) => offered.includes(row.id));
87
+
88
+ if (rows.length < 2) return null;
89
+
90
+ return (
91
+ <fieldset>
92
+ <legend className="text-sm font-semibold text-fg">
93
+ What this account syncs
94
+ </legend>
95
+ <div className="mt-1 divide-y divide-line">
96
+ {rows.map((row) => {
97
+ const on = enabled.includes(row.id);
98
+ const noteId = `${groupId}-${row.id}`;
99
+ const needsConsent = !on && !consented.includes(row.id);
100
+ return (
101
+ <div
102
+ key={row.id}
103
+ className="flex min-h-11 items-center gap-3 py-2 text-left"
104
+ >
105
+ <span className="flex min-w-0 flex-1 flex-col">
106
+ <span className="text-sm text-fg">{row.label}</span>
107
+ <span id={noteId} className="text-xs text-fg-subtle">
108
+ {needsConsent
109
+ ? `${row.description} Turning this on means signing in with ${providerName} again.`
110
+ : row.description}
111
+ </span>
112
+ </span>
113
+ <ServiceSwitch
114
+ checked={on}
115
+ label={`Sync ${row.label.toLowerCase()}`}
116
+ describedBy={noteId}
117
+ onToggle={() => onRequestChange(row.id, on ? "off" : "on")}
118
+ />
119
+ </div>
120
+ );
121
+ })}
122
+ </div>
123
+ </fieldset>
124
+ );
125
+ }
@@ -12,6 +12,7 @@ import type {
12
12
  } from "../category-presentation.js";
13
13
  import type { TriageHandlers } from "../lib/keymap.js";
14
14
  import type { SelectionModifiers } from "../lib/use-selection.js";
15
+ import type { AccountService } from "./account-service-choice.js";
15
16
  import type {
16
17
  IntelligenceData,
17
18
  SenderTrustLevel,
@@ -198,6 +199,12 @@ export interface NavAccount {
198
199
  email: string;
199
200
  /** Muted: excluded from unified views, still syncing. Rendered dimmed. */
200
201
  muted?: boolean;
202
+ /**
203
+ * Services this account syncs. Absent is the account that syncs mail, which
204
+ * is every IMAP account. An account without `Mail` keeps its place in the
205
+ * nav with every mailbox it already synced, labelled rather than dropped.
206
+ */
207
+ syncedServices?: AccountService[];
201
208
  mailboxes: NavMailbox[];
202
209
  /**
203
210
  * Number of outbox messages pending send. When provided, an Outbox entry
@@ -75,3 +75,37 @@ describe("CalendarList", () => {
75
75
  assert.match(html, /Family/);
76
76
  });
77
77
  });
78
+
79
+ /**
80
+ * A provider calendar whose account has calendar sync off. Nothing was deleted,
81
+ * so the row stays, its tick keeps drawing the stored events, and the pause is
82
+ * a label on the row (#1179).
83
+ */
84
+ describe("CalendarList with a paused calendar", () => {
85
+ const paused: CalendarDescriptor[] = calendars.map((calendar) =>
86
+ calendar.id === "c1" ? { ...calendar, sync: "paused" } : calendar,
87
+ );
88
+
89
+ const renderPaused = (visible: string[]) =>
90
+ renderToString(
91
+ createElement(CalendarList, {
92
+ calendars: paused,
93
+ visible: new Set(visible),
94
+ onToggle: () => undefined,
95
+ }),
96
+ );
97
+
98
+ it("keeps the row and labels the pause", () => {
99
+ const html = renderPaused(["c1"]);
100
+ assert.match(html, /Northwind/);
101
+ assert.match(html, /calendar sync off/);
102
+ });
103
+
104
+ it("leaves a live calendar unlabelled", () => {
105
+ assert.doesNotMatch(render(["c1"]), /calendar sync off/);
106
+ });
107
+
108
+ it("keeps a paused calendar tickable, so its events stay drawable", () => {
109
+ assert.match(renderPaused(["c1"]), /checked=""/);
110
+ });
111
+ });
@@ -169,6 +169,38 @@ export const SingleCalendar: Story = {
169
169
  },
170
170
  };
171
171
 
172
+ /**
173
+ * A paused provider calendar. Sync stopped; the calendar is still listed, still
174
+ * coloured and still tickable, so the pause icon is decoration and the words
175
+ * that carry it sit beside the row rather than inside the tick's name.
176
+ */
177
+ export const Paused: Story = {
178
+ render: () => {
179
+ const paused = calendars.map((calendar) =>
180
+ calendar.id === "c1"
181
+ ? { ...calendar, sync: "paused" as const }
182
+ : calendar,
183
+ );
184
+ return (
185
+ <CalendarList
186
+ calendars={paused}
187
+ visible={new Set(calendars.map((c) => c.id))}
188
+ onToggle={() => {}}
189
+ onToggleAccount={() => {}}
190
+ />
191
+ );
192
+ },
193
+ play: async ({ canvasElement }) => {
194
+ const canvas = within(canvasElement);
195
+ await expect(
196
+ canvas.getByRole("checkbox", { name: "Northwind" }),
197
+ ).toBeChecked();
198
+ await expect(
199
+ canvas.getByText("Northwind: calendar sync off"),
200
+ ).toBeInTheDocument();
201
+ },
202
+ };
203
+
172
204
  /**
173
205
  * The same control on a surface with no room for a rail: a scrolling row of
174
206
  * chips at thumb size. It is laid out differently and it is not a popover —
@@ -1,7 +1,8 @@
1
- import { Check, ChevronDown, ChevronRight } from "lucide-react";
1
+ import { Check, ChevronDown, ChevronRight, PauseCircle } from "lucide-react";
2
2
  import { useState } from "react";
3
3
  import { calendarColorClasses } from "../lib/calendar-color.js";
4
4
  import { cn } from "../lib/cn.js";
5
+ import { ACCOUNT_SERVICE_OFF_LABEL } from "./account-service-status.js";
5
6
  import type { CalendarDescriptor } from "./calendar-types.js";
6
7
 
7
8
  export interface CalendarListProps {
@@ -187,39 +188,51 @@ function CalendarListRow({
187
188
  onToggle: () => void;
188
189
  }) {
189
190
  const hue = calendarColorClasses(calendar.color);
191
+ const paused = calendar.sync === "paused";
190
192
  return (
191
- <label
192
- className={cn(
193
- "flex cursor-pointer items-center gap-2.5 rounded-sm px-row-inset hover:bg-surface-sunken",
194
- touch ? "min-h-11" : "min-h-9",
195
- )}
196
- >
197
- <input
198
- type="checkbox"
199
- checked={checked}
200
- onChange={onToggle}
201
- className="peer sr-only"
202
- />
203
- <span
204
- aria-hidden
193
+ <div className="flex flex-col">
194
+ <label
205
195
  className={cn(
206
- "flex size-4 shrink-0 items-center justify-center rounded-xs border transition-colors",
207
- "peer-focus-visible:ring-2 peer-focus-visible:ring-ring peer-focus-visible:ring-offset-1 peer-focus-visible:ring-offset-surface",
208
- checked
209
- ? cn(hue.solid, hue.border)
210
- : cn("bg-transparent", hue.border),
196
+ "flex cursor-pointer items-center gap-2.5 rounded-sm px-row-inset hover:bg-surface-sunken",
197
+ touch ? "min-h-11" : "min-h-9",
211
198
  )}
212
199
  >
213
- {checked && <Check className="size-3 text-canvas" strokeWidth={3} />}
214
- </span>
215
- <span
216
- className={cn(
217
- "min-w-0 flex-1 truncate text-sm",
218
- checked ? "text-fg" : "text-fg-subtle",
200
+ <input
201
+ type="checkbox"
202
+ checked={checked}
203
+ onChange={onToggle}
204
+ className="peer sr-only"
205
+ />
206
+ <span
207
+ aria-hidden
208
+ className={cn(
209
+ "flex size-4 shrink-0 items-center justify-center rounded-xs border transition-colors",
210
+ "peer-focus-visible:ring-2 peer-focus-visible:ring-ring peer-focus-visible:ring-offset-1 peer-focus-visible:ring-offset-surface",
211
+ checked
212
+ ? cn(hue.solid, hue.border)
213
+ : cn("bg-transparent", hue.border),
214
+ )}
215
+ >
216
+ {checked && <Check className="size-3 text-canvas" strokeWidth={3} />}
217
+ </span>
218
+ <span
219
+ className={cn(
220
+ "min-w-0 flex-1 truncate text-sm",
221
+ checked ? "text-fg" : "text-fg-subtle",
222
+ )}
223
+ >
224
+ {calendar.name}
225
+ </span>
226
+ {paused && (
227
+ <PauseCircle
228
+ className="size-3.5 shrink-0 text-fg-subtle"
229
+ aria-hidden
230
+ />
219
231
  )}
220
- >
221
- {calendar.name}
222
- </span>
223
- </label>
232
+ </label>
233
+ {paused && (
234
+ <span className="sr-only">{`${calendar.name}: ${ACCOUNT_SERVICE_OFF_LABEL.Calendar}`}</span>
235
+ )}
236
+ </div>
224
237
  );
225
238
  }
@@ -39,6 +39,13 @@ export interface CalendarDescriptor {
39
39
  accountLabel: string;
40
40
  name: string;
41
41
  color: CalendarColorId;
42
+ /**
43
+ * Whether the provider still fills this calendar. `paused` is a provider
44
+ * calendar whose account has calendar sync off: its stored events stay on the
45
+ * grid and its tick keeps working, and only new changes have stopped.
46
+ * Defaults to `live`.
47
+ */
48
+ sync?: "live" | "paused";
42
49
  }
43
50
 
44
51
  /**
@@ -308,6 +308,46 @@ describe("NavSidebar", () => {
308
308
  });
309
309
  });
310
310
 
311
+ /**
312
+ * An account that stopped syncing mail (#1179). It kept every mailbox it had,
313
+ * so the nav keeps it too — labelled, never dropped, and never an empty tree.
314
+ */
315
+ describe("NavSidebar with mail sync off", () => {
316
+ const mailOff: NavAccount[] = accounts.map((account) => ({
317
+ ...account,
318
+ syncedServices: ["Calendar"],
319
+ }));
320
+ const mailOn: NavAccount[] = accounts.map((account) => ({
321
+ ...account,
322
+ syncedServices: ["Mail"],
323
+ }));
324
+
325
+ const render = (list: NavAccount[]) =>
326
+ renderToString(
327
+ createElement(NavSidebar, {
328
+ accounts: list,
329
+ selectedNavId: "personal-inbox",
330
+ onSelectNav: () => undefined,
331
+ }),
332
+ );
333
+
334
+ it("keeps the account and every mailbox it already synced", () => {
335
+ const html = render(mailOff);
336
+ assert.match(html, /Personal/);
337
+ assert.match(html, /Inbox/);
338
+ assert.match(html, /Travel/);
339
+ });
340
+
341
+ it("labels the account rather than leaving it to be guessed at", () => {
342
+ assert.match(render(mailOff), /mail sync off/);
343
+ });
344
+
345
+ it("leaves an account that syncs mail unlabelled", () => {
346
+ assert.doesNotMatch(render(accounts), /mail sync off/);
347
+ assert.doesNotMatch(render(mailOn), /mail sync off/);
348
+ });
349
+ });
350
+
311
351
  describe("NavSidebar collapse persistence", () => {
312
352
  afterEach(() => {
313
353
  Reflect.deleteProperty(globalThis, "localStorage");
@@ -10,6 +10,7 @@ import {
10
10
  Folder,
11
11
  Inbox,
12
12
  Mails,
13
+ PauseCircle,
13
14
  Send,
14
15
  Sparkles,
15
16
  Star,
@@ -19,6 +20,7 @@ import type { ReactNode } from "react";
19
20
  import { useRef, useState } from "react";
20
21
  import { cn } from "../lib/cn.js";
21
22
  import { useRovingFocus } from "../lib/roving-focus.js";
23
+ import { ACCOUNT_SERVICE_OFF_LABEL } from "./account-service-status.js";
22
24
  import type {
23
25
  AppShellProps,
24
26
  NavAccount,
@@ -274,6 +276,9 @@ function AccountNav({
274
276
  const hiddenCount = folders.length - visibleFolders.length;
275
277
 
276
278
  const status = account.status ?? "ready";
279
+ const mailOff =
280
+ account.syncedServices !== undefined &&
281
+ !account.syncedServices.includes("Mail");
277
282
  const isEmpty =
278
283
  status === "ready" && system.length === 0 && folders.length === 0;
279
284
 
@@ -303,6 +308,14 @@ function AccountNav({
303
308
  <span className="text-2xs text-fg-subtle">muted</span>
304
309
  </>
305
310
  )}
311
+ {mailOff && (
312
+ <>
313
+ <PauseCircle className="size-3 shrink-0 text-fg-subtle" />
314
+ <span className="text-2xs text-fg-subtle">
315
+ {ACCOUNT_SERVICE_OFF_LABEL.Mail}
316
+ </span>
317
+ </>
318
+ )}
306
319
  </button>
307
320
 
308
321
  {accountOpen && (
package/src/index.ts CHANGED
@@ -16,12 +16,35 @@ export {
16
16
  isThreadCategory,
17
17
  type ThreadCategory,
18
18
  } from "./category-presentation.js";
19
+ export {
20
+ type AccountServiceChange,
21
+ type AccountServiceChangeCopy,
22
+ AccountServiceChangeDialog,
23
+ type AccountServiceChangeDialogProps,
24
+ accountServiceChangeCopy,
25
+ } from "./components/account-service-change-dialog.js";
19
26
  export {
20
27
  ACCOUNT_SERVICE_EMPTY_MESSAGE,
28
+ ACCOUNT_SERVICE_ROWS,
21
29
  type AccountService,
22
30
  AccountServiceChoice,
23
31
  type AccountServiceChoiceProps,
32
+ type AccountServiceRow,
24
33
  } from "./components/account-service-choice.js";
34
+ export {
35
+ ACCOUNT_NO_SERVICE_TOGGLES_MESSAGE,
36
+ ACCOUNT_SERVICE_OFF_LABEL,
37
+ ACCOUNT_SERVICE_OFF_MESSAGE,
38
+ AccountServiceOffBadge,
39
+ type AccountServiceOffBadgeProps,
40
+ AccountServiceOffNotice,
41
+ type AccountServiceOffNoticeProps,
42
+ } from "./components/account-service-status.js";
43
+ export {
44
+ type AccountServiceIntent,
45
+ AccountServiceToggles,
46
+ type AccountServiceTogglesProps,
47
+ } from "./components/account-service-toggles.js";
25
48
  export {
26
49
  AddressDisplay,
27
50
  type AddressDisplayProps,