@remit/ui 0.0.192 → 0.0.194
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 +1 -1
- package/src/components/account-service-change-dialog.render.test.ts +73 -0
- package/src/components/account-service-change-dialog.stories.tsx +66 -0
- package/src/components/account-service-change-dialog.tsx +117 -0
- package/src/components/account-service-choice.tsx +4 -3
- package/src/components/account-service-status.render.test.ts +82 -0
- package/src/components/account-service-status.stories.tsx +61 -0
- package/src/components/account-service-status.tsx +89 -0
- package/src/components/account-service-toggles.render.test.ts +123 -0
- package/src/components/account-service-toggles.stories.tsx +121 -0
- package/src/components/account-service-toggles.tsx +125 -0
- package/src/components/agenda-composer.render.test.ts +1 -0
- package/src/components/agenda-composer.stories.tsx +1 -0
- package/src/components/agenda-flow.tsx +3 -0
- package/src/components/app-shell-types.ts +7 -0
- package/src/components/calendar-list.render.test.ts +34 -0
- package/src/components/calendar-list.stories.tsx +32 -0
- package/src/components/calendar-list.tsx +43 -30
- package/src/components/calendar-slot-offers.render.test.ts +7 -1
- package/src/components/calendar-slot-offers.stories.tsx +7 -1
- package/src/components/calendar-types.ts +9 -0
- package/src/components/event-editor.render.test.ts +23 -0
- package/src/components/event-editor.stories.tsx +31 -4
- package/src/components/event-editor.tsx +78 -50
- package/src/components/intelligence-calendar-fixtures.ts +7 -1
- package/src/components/nav-sidebar.render.test.ts +40 -0
- package/src/components/nav-sidebar.tsx +13 -0
- package/src/index.ts +27 -0
- package/src/lib/agenda-time.ts +15 -0
- package/src/lib/calendar-slot-pick.test.ts +25 -5
- package/src/lib/calendar-slot-pick.ts +13 -3
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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 =
|
|
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
|
+
});
|