@remit/ui 0.0.191 → 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 +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.render.test.ts +152 -0
- package/src/components/account-service-choice.stories.tsx +122 -0
- package/src/components/account-service-choice.tsx +97 -0
- 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/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-types.ts +7 -0
- package/src/components/nav-sidebar.render.test.ts +40 -0
- package/src/components/nav-sidebar.tsx +13 -0
- package/src/index.ts +29 -0
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
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The onboarding service choice (#1178). Both services on is the caller's
|
|
3
|
+
* default, so what is asserted here is the choice's own contract: a provider
|
|
4
|
+
* that syncs one service renders no choice at all, the empty set is refused
|
|
5
|
+
* rather than submitted, and the re-consent line names the provider.
|
|
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 {
|
|
14
|
+
ACCOUNT_SERVICE_EMPTY_MESSAGE,
|
|
15
|
+
type AccountService,
|
|
16
|
+
AccountServiceChoice,
|
|
17
|
+
type AccountServiceChoiceProps,
|
|
18
|
+
} from "./account-service-choice.js";
|
|
19
|
+
|
|
20
|
+
const bothServices: AccountService[] = ["Mail", "Calendar"];
|
|
21
|
+
|
|
22
|
+
const render = (props: Partial<AccountServiceChoiceProps> = {}): string =>
|
|
23
|
+
renderToString(
|
|
24
|
+
createElement(AccountServiceChoice, {
|
|
25
|
+
providerName: "Microsoft",
|
|
26
|
+
offered: bothServices,
|
|
27
|
+
selected: bothServices,
|
|
28
|
+
onChange: () => {},
|
|
29
|
+
...props,
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
describe("AccountServiceChoice", () => {
|
|
34
|
+
it("offers mail and calendar, mail first", () => {
|
|
35
|
+
const html = render();
|
|
36
|
+
assert.match(html, /Mail/);
|
|
37
|
+
assert.match(html, /Calendar/);
|
|
38
|
+
assert.ok(html.indexOf("Mail") < html.indexOf("Calendar"));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("ticks the services it is given and leaves the rest clear", () => {
|
|
42
|
+
const html = render({ selected: ["Calendar"] });
|
|
43
|
+
assert.equal(html.match(/checked=""/g)?.length, 1);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("ticks both when both are selected", () => {
|
|
47
|
+
assert.equal(render().match(/checked=""/g)?.length, 2);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("names the provider adding a service sends you back to", () => {
|
|
51
|
+
assert.match(
|
|
52
|
+
render(),
|
|
53
|
+
/Adding a service later means signing in with Microsoft again\./,
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("renders nothing for a provider that only syncs mail", () => {
|
|
58
|
+
assert.equal(render({ offered: ["Mail"], selected: ["Mail"] }), "");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("still shows the refusal when there are no rows to show", () => {
|
|
62
|
+
assert.match(
|
|
63
|
+
render({
|
|
64
|
+
offered: ["Mail"],
|
|
65
|
+
selected: [],
|
|
66
|
+
error: ACCOUNT_SERVICE_EMPTY_MESSAGE,
|
|
67
|
+
}),
|
|
68
|
+
/Pick at least one/,
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("shows a refusal only when it is given one", () => {
|
|
73
|
+
assert.doesNotMatch(render({ selected: [] }), /Pick at least one/);
|
|
74
|
+
assert.match(
|
|
75
|
+
render({ selected: [], error: ACCOUNT_SERVICE_EMPTY_MESSAGE }),
|
|
76
|
+
/Pick at least one/,
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("announces the refusal", () => {
|
|
81
|
+
assert.match(
|
|
82
|
+
render({ selected: [], error: ACCOUNT_SERVICE_EMPTY_MESSAGE }),
|
|
83
|
+
/role="alert"/,
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("adds and removes one service at a time", () => {
|
|
88
|
+
const container = document.createElement("div");
|
|
89
|
+
document.body.appendChild(container);
|
|
90
|
+
const root = createRoot(container);
|
|
91
|
+
const changes: AccountService[][] = [];
|
|
92
|
+
|
|
93
|
+
act(() => {
|
|
94
|
+
root.render(
|
|
95
|
+
createElement(AccountServiceChoice, {
|
|
96
|
+
providerName: "Microsoft",
|
|
97
|
+
offered: bothServices,
|
|
98
|
+
selected: bothServices,
|
|
99
|
+
onChange: (next) => changes.push(next),
|
|
100
|
+
}),
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const boxes = container.querySelectorAll<HTMLInputElement>(
|
|
105
|
+
'input[type="checkbox"]',
|
|
106
|
+
);
|
|
107
|
+
act(() => {
|
|
108
|
+
boxes[1]?.click();
|
|
109
|
+
});
|
|
110
|
+
act(() => {
|
|
111
|
+
boxes[0]?.click();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
assert.deepEqual(changes, [["Mail"], ["Calendar"]]);
|
|
115
|
+
|
|
116
|
+
act(() => {
|
|
117
|
+
root.unmount();
|
|
118
|
+
});
|
|
119
|
+
container.remove();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("restores a service in the stored order", () => {
|
|
123
|
+
const container = document.createElement("div");
|
|
124
|
+
document.body.appendChild(container);
|
|
125
|
+
const root = createRoot(container);
|
|
126
|
+
const changes: AccountService[][] = [];
|
|
127
|
+
|
|
128
|
+
act(() => {
|
|
129
|
+
root.render(
|
|
130
|
+
createElement(AccountServiceChoice, {
|
|
131
|
+
providerName: "Microsoft",
|
|
132
|
+
offered: bothServices,
|
|
133
|
+
selected: ["Calendar"],
|
|
134
|
+
onChange: (next) => changes.push(next),
|
|
135
|
+
}),
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
act(() => {
|
|
140
|
+
container
|
|
141
|
+
.querySelector<HTMLInputElement>('input[type="checkbox"]')
|
|
142
|
+
?.click();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
assert.deepEqual(changes, [["Mail", "Calendar"]]);
|
|
146
|
+
|
|
147
|
+
act(() => {
|
|
148
|
+
root.unmount();
|
|
149
|
+
});
|
|
150
|
+
container.remove();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { expect, userEvent, within } from "storybook/test";
|
|
4
|
+
import {
|
|
5
|
+
ACCOUNT_SERVICE_EMPTY_MESSAGE,
|
|
6
|
+
type AccountService,
|
|
7
|
+
AccountServiceChoice,
|
|
8
|
+
} from "./account-service-choice.js";
|
|
9
|
+
import { Button } from "./button.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* What an account syncs, asked once before the provider redirect so the
|
|
13
|
+
* consent screen matches the pick (#1178).
|
|
14
|
+
*/
|
|
15
|
+
const meta: Meta<typeof AccountServiceChoice> = {
|
|
16
|
+
title: "Components/AccountServiceChoice",
|
|
17
|
+
component: AccountServiceChoice,
|
|
18
|
+
parameters: { layout: "padded" },
|
|
19
|
+
decorators: [
|
|
20
|
+
(Story) => (
|
|
21
|
+
<div className="mx-auto max-w-sm rounded-xl border border-line bg-surface p-4">
|
|
22
|
+
<Story />
|
|
23
|
+
</div>
|
|
24
|
+
),
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
export default meta;
|
|
28
|
+
|
|
29
|
+
type Story = StoryObj<typeof AccountServiceChoice>;
|
|
30
|
+
|
|
31
|
+
const bothServices: AccountService[] = ["Mail", "Calendar"];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Stands in for the host: the refusal appears on a refused Continue, the way
|
|
35
|
+
* the onboarding step raises it, not the moment the set goes empty.
|
|
36
|
+
*/
|
|
37
|
+
function LiveChoice({
|
|
38
|
+
initial,
|
|
39
|
+
offered = bothServices,
|
|
40
|
+
}: {
|
|
41
|
+
initial: AccountService[];
|
|
42
|
+
offered?: AccountService[];
|
|
43
|
+
}) {
|
|
44
|
+
const [selected, setSelected] = useState(initial);
|
|
45
|
+
const [refused, setRefused] = useState(false);
|
|
46
|
+
const empty = selected.length === 0;
|
|
47
|
+
return (
|
|
48
|
+
<div className="space-y-3">
|
|
49
|
+
<AccountServiceChoice
|
|
50
|
+
providerName="Microsoft"
|
|
51
|
+
offered={offered}
|
|
52
|
+
selected={selected}
|
|
53
|
+
onChange={setSelected}
|
|
54
|
+
error={refused && empty ? ACCOUNT_SERVICE_EMPTY_MESSAGE : undefined}
|
|
55
|
+
/>
|
|
56
|
+
<Button variant="primary" onClick={() => setRefused(empty)}>
|
|
57
|
+
Continue
|
|
58
|
+
</Button>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A provider that syncs both. Both on is the default a host arrives with. */
|
|
64
|
+
export const BothServices: Story = {
|
|
65
|
+
render: () => <LiveChoice initial={bothServices} />,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** Calendar only — the Outlook account kept for its calendar and nothing else. */
|
|
69
|
+
export const CalendarOnly: Story = {
|
|
70
|
+
render: () => <LiveChoice initial={["Calendar"]} />,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Neither ticked. Continue says what is wrong instead of going quiet, and its
|
|
75
|
+
* host refuses to submit the empty set.
|
|
76
|
+
*/
|
|
77
|
+
export const NeitherSelected: Story = {
|
|
78
|
+
render: () => <LiveChoice initial={[]} />,
|
|
79
|
+
play: async ({ canvasElement }) => {
|
|
80
|
+
const canvas = within(canvasElement);
|
|
81
|
+
await expect(canvas.queryByRole("alert")).toBeNull();
|
|
82
|
+
await userEvent.click(canvas.getByRole("button", { name: "Continue" }));
|
|
83
|
+
await expect(canvas.getByRole("alert")).toHaveTextContent(
|
|
84
|
+
"Pick at least one",
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A provider that only syncs mail. The rows are absent, not a disabled row —
|
|
91
|
+
* the border below is the whole render.
|
|
92
|
+
*/
|
|
93
|
+
export const MailOnlyProvider: Story = {
|
|
94
|
+
render: () => (
|
|
95
|
+
<>
|
|
96
|
+
<AccountServiceChoice
|
|
97
|
+
providerName="Microsoft"
|
|
98
|
+
offered={["Mail"]}
|
|
99
|
+
selected={["Mail"]}
|
|
100
|
+
onChange={() => {}}
|
|
101
|
+
/>
|
|
102
|
+
<p className="border-t border-line pt-2 text-2xs text-fg-subtle">
|
|
103
|
+
Nothing above this line: an IMAP account syncs mail and is not asked.
|
|
104
|
+
</p>
|
|
105
|
+
</>
|
|
106
|
+
),
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* One service on offer and none picked. There is nothing to tick, so the
|
|
111
|
+
* refusal is the whole render — the host's Continue must not go quiet.
|
|
112
|
+
*/
|
|
113
|
+
export const MailOnlyProviderRefused: Story = {
|
|
114
|
+
render: () => <LiveChoice initial={[]} offered={["Mail"]} />,
|
|
115
|
+
play: async ({ canvasElement }) => {
|
|
116
|
+
const canvas = within(canvasElement);
|
|
117
|
+
await userEvent.click(canvas.getByRole("button", { name: "Continue" }));
|
|
118
|
+
await expect(canvas.getByRole("alert")).toHaveTextContent(
|
|
119
|
+
"Pick at least one",
|
|
120
|
+
);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { useId } from "react";
|
|
2
|
+
import { Banner } from "./banner.js";
|
|
3
|
+
import { Checkbox } from "./checkbox.js";
|
|
4
|
+
|
|
5
|
+
/** One service an account syncs. Mirrors the set the account endpoints take. */
|
|
6
|
+
export type AccountService = "Mail" | "Calendar";
|
|
7
|
+
|
|
8
|
+
/** Refusal for the empty set: no stored account ever syncs nothing. */
|
|
9
|
+
export const ACCOUNT_SERVICE_EMPTY_MESSAGE =
|
|
10
|
+
"Pick at least one. An account has to sync something.";
|
|
11
|
+
|
|
12
|
+
/** One service as every surface names it: the same label and the same line. */
|
|
13
|
+
export interface AccountServiceRow {
|
|
14
|
+
id: AccountService;
|
|
15
|
+
label: string;
|
|
16
|
+
description: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const ACCOUNT_SERVICE_ROWS: AccountServiceRow[] = [
|
|
20
|
+
{
|
|
21
|
+
id: "Mail",
|
|
22
|
+
label: "Mail",
|
|
23
|
+
description: "Messages, folders and sending.",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "Calendar",
|
|
27
|
+
label: "Calendar",
|
|
28
|
+
description: "This account's provider calendar, read into Remit.",
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
export interface AccountServiceChoiceProps {
|
|
33
|
+
/** Provider named in the re-consent line, e.g. "Microsoft". */
|
|
34
|
+
providerName: string;
|
|
35
|
+
/** Services this provider syncs. Under two of them the rows are absent. */
|
|
36
|
+
offered: AccountService[];
|
|
37
|
+
selected: AccountService[];
|
|
38
|
+
onChange: (next: AccountService[]) => void;
|
|
39
|
+
/** Refusal shown under the rows, e.g. ACCOUNT_SERVICE_EMPTY_MESSAGE. */
|
|
40
|
+
error?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function AccountServiceChoice({
|
|
44
|
+
providerName,
|
|
45
|
+
offered,
|
|
46
|
+
selected,
|
|
47
|
+
onChange,
|
|
48
|
+
error,
|
|
49
|
+
}: AccountServiceChoiceProps) {
|
|
50
|
+
const noteId = useId();
|
|
51
|
+
const rows = ACCOUNT_SERVICE_ROWS.filter((row) => offered.includes(row.id));
|
|
52
|
+
|
|
53
|
+
const refusal = error ? (
|
|
54
|
+
<Banner tone="danger" variant="soft" className="mt-2 text-xs">
|
|
55
|
+
{error}
|
|
56
|
+
</Banner>
|
|
57
|
+
) : null;
|
|
58
|
+
|
|
59
|
+
// A single-service provider has nothing to choose, but its host can still
|
|
60
|
+
// refuse an empty set, and that refusal has to land somewhere.
|
|
61
|
+
if (rows.length < 2) return refusal;
|
|
62
|
+
|
|
63
|
+
const toggle = (id: AccountService, checked: boolean) => {
|
|
64
|
+
if (!checked) {
|
|
65
|
+
onChange(selected.filter((service) => service !== id));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
onChange(
|
|
69
|
+
rows
|
|
70
|
+
.filter((row) => row.id === id || selected.includes(row.id))
|
|
71
|
+
.map((row) => row.id),
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<fieldset aria-describedby={noteId}>
|
|
77
|
+
<legend className="text-sm font-semibold text-fg">
|
|
78
|
+
What should Remit sync?
|
|
79
|
+
</legend>
|
|
80
|
+
<div className="mt-1 divide-y divide-line">
|
|
81
|
+
{rows.map((row) => (
|
|
82
|
+
<Checkbox
|
|
83
|
+
key={row.id}
|
|
84
|
+
label={row.label}
|
|
85
|
+
description={row.description}
|
|
86
|
+
checked={selected.includes(row.id)}
|
|
87
|
+
onChange={(event) => toggle(row.id, event.target.checked)}
|
|
88
|
+
/>
|
|
89
|
+
))}
|
|
90
|
+
</div>
|
|
91
|
+
<p id={noteId} className="mt-1.5 text-2xs text-fg-subtle">
|
|
92
|
+
{`Adding a service later means signing in with ${providerName} again.`}
|
|
93
|
+
</p>
|
|
94
|
+
{refusal}
|
|
95
|
+
</fieldset>
|
|
96
|
+
);
|
|
97
|
+
}
|