@remit/web-client 0.0.304 → 0.0.306

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.
@@ -2,7 +2,7 @@
2
2
  * OnboardingWizard — full 7-step onboarding flow.
3
3
  *
4
4
  * Steps: Welcome → Connector → Address → Servers → Credentials → Test → Sync
5
- * Microsoft path: Connector → MicrosoftEmail → redirect
5
+ * Microsoft path: Connector → MicrosoftEmail → redirect → MicrosoftGranted
6
6
  *
7
7
  * Entry points:
8
8
  * - First-run (zero accounts): full-screen wizard via /onboarding route
@@ -24,7 +24,12 @@ import {
24
24
  microsoftOAuthOperationsMicrosoftOAuthStartMutation,
25
25
  syncOperationsGetSyncStatusOptions,
26
26
  } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
27
+ import type { RemitImapAccountResponse } from "@remit/api-http-client/types.gen.ts";
27
28
  import {
29
+ ACCOUNT_SERVICE_EMPTY_MESSAGE,
30
+ ACCOUNT_SERVICE_ROWS,
31
+ type AccountService,
32
+ AccountServiceChoice,
28
33
  Banner,
29
34
  Button,
30
35
  CheckRow,
@@ -71,6 +76,7 @@ type WizardStep =
71
76
  | "welcome"
72
77
  | "connector"
73
78
  | "microsoft-email"
79
+ | "microsoft-granted"
74
80
  | "address"
75
81
  | "servers"
76
82
  | "credentials"
@@ -91,6 +97,7 @@ const STEP_INDEX: Record<WizardStep, number> = {
91
97
  welcome: 0,
92
98
  connector: 0,
93
99
  "microsoft-email": 0,
100
+ "microsoft-granted": 5,
94
101
  address: 1,
95
102
  servers: 2,
96
103
  credentials: 3,
@@ -277,15 +284,25 @@ function StepConnector({
277
284
  );
278
285
  }
279
286
 
280
- function StepMicrosoftEmail({
281
- onBack,
282
- onConnected,
283
- }: {
287
+ const MICROSOFT_SERVICES: AccountService[] = ["Mail", "Calendar"];
288
+
289
+ export interface StepMicrosoftEmailProps {
290
+ refusal?: MicrosoftRefusal;
284
291
  onBack: () => void;
285
292
  onConnected: (accountId: string) => void;
286
- }) {
287
- const [email, setEmail] = useState("");
288
- const [error, setError] = useState<string | null>(null);
293
+ }
294
+
295
+ export function StepMicrosoftEmail({
296
+ refusal,
297
+ onBack,
298
+ onConnected,
299
+ }: StepMicrosoftEmailProps) {
300
+ const [email, setEmail] = useState(refusal?.email ?? "");
301
+ const [services, setServices] = useState<AccountService[]>(
302
+ refusal?.services ?? MICROSOFT_SERVICES,
303
+ );
304
+ const [servicesRefused, setServicesRefused] = useState(false);
305
+ const [error, setError] = useState<string | null>(refusal?.message ?? null);
289
306
  const [awaitingReturn, setAwaitingReturn] = useState(false);
290
307
  const [preparing, setPreparing] = useState(false);
291
308
  // The account read is in flight across a step the user can leave — Escape and
@@ -368,6 +385,10 @@ function StepMicrosoftEmail({
368
385
 
369
386
  const handleSubmit = () => {
370
387
  if (redirecting) return;
388
+ if (services.length === 0) {
389
+ setServicesRefused(true);
390
+ return;
391
+ }
371
392
  setError(null);
372
393
  setPreparing(true);
373
394
  void refetchConfig().then(({ data, isError }) => {
@@ -383,7 +404,7 @@ function StepMicrosoftEmail({
383
404
  data.accounts.map((account) => account.accountId),
384
405
  );
385
406
  startMutation.mutate({
386
- body: { email: email.trim() || undefined },
407
+ body: { email: email.trim() || undefined, services },
387
408
  });
388
409
  });
389
410
  };
@@ -406,8 +427,12 @@ function StepMicrosoftEmail({
406
427
  <WizardShell
407
428
  steps={STEP_LABELS}
408
429
  activeStep={STEP_INDEX.connector}
409
- title="Sign in with Microsoft"
410
- subtitle="You'll be redirected to Microsoft to sign in securely."
430
+ title={
431
+ refusal?.reconnect && refusal.email
432
+ ? `Reconnect ${refusal.email}`
433
+ : "Sign in with Microsoft"
434
+ }
435
+ subtitle="Microsoft is asked for the mail and calendar access you pick here."
411
436
  footer={
412
437
  <>
413
438
  <Button variant="ghost" onClick={onBack}>
@@ -433,6 +458,16 @@ function StepMicrosoftEmail({
433
458
  }
434
459
  >
435
460
  <div className="space-y-3">
461
+ <AccountServiceChoice
462
+ providerName="Microsoft"
463
+ offered={MICROSOFT_SERVICES}
464
+ selected={services}
465
+ onChange={(next) => {
466
+ setServices(next);
467
+ if (next.length > 0) setServicesRefused(false);
468
+ }}
469
+ error={servicesRefused ? ACCOUNT_SERVICE_EMPTY_MESSAGE : undefined}
470
+ />
436
471
  <div>
437
472
  <FieldLabel htmlFor="microsoft-email">
438
473
  Email address (optional)
@@ -463,6 +498,170 @@ function StepMicrosoftEmail({
463
498
  );
464
499
  }
465
500
 
501
+ export interface StepMicrosoftGrantedProps {
502
+ accountId: string;
503
+ onSignInAgain: () => void;
504
+ onContinue: (accountId: string) => void;
505
+ }
506
+
507
+ export function StepMicrosoftGranted({
508
+ accountId,
509
+ onSignInAgain,
510
+ onContinue,
511
+ }: StepMicrosoftGrantedProps) {
512
+ const {
513
+ data: config,
514
+ isError,
515
+ isFetching,
516
+ refetch,
517
+ } = useQuery(configOperationsGetConfigOptions());
518
+ const account = config?.accounts.find(
519
+ (candidate) => candidate.accountId === accountId,
520
+ );
521
+
522
+ if (isError) {
523
+ return (
524
+ <WizardShell
525
+ steps={STEP_LABELS}
526
+ activeStep={STEP_INDEX["microsoft-granted"]}
527
+ title="Couldn't read the new account"
528
+ subtitle="Microsoft finished, but this instance did not answer."
529
+ footer={
530
+ <>
531
+ <span />
532
+ <Button
533
+ variant="primary"
534
+ onClick={() => void refetch()}
535
+ disabled={isFetching}
536
+ >
537
+ Retry
538
+ </Button>
539
+ </>
540
+ }
541
+ >
542
+ <Banner tone="danger">
543
+ Couldn't load the account Microsoft just connected. Check your
544
+ connection and retry, or open Settings › Accounts to see it.
545
+ </Banner>
546
+ </WizardShell>
547
+ );
548
+ }
549
+
550
+ if (!config || (!account && isFetching)) {
551
+ return (
552
+ <WizardShell
553
+ steps={STEP_LABELS}
554
+ activeStep={STEP_INDEX["microsoft-granted"]}
555
+ title="Reading the new account"
556
+ subtitle="Checking what Microsoft granted."
557
+ footer={
558
+ <>
559
+ <span className="text-2xs text-fg-subtle">Loading…</span>
560
+ <span />
561
+ </>
562
+ }
563
+ >
564
+ <div className="flex items-center gap-2 py-4 text-sm text-fg-muted">
565
+ <Loader2 className="size-4 animate-spin text-accent" />
566
+ Loading the account…
567
+ </div>
568
+ </WizardShell>
569
+ );
570
+ }
571
+
572
+ if (!account) {
573
+ return (
574
+ <WizardShell
575
+ steps={STEP_LABELS}
576
+ activeStep={STEP_INDEX["microsoft-granted"]}
577
+ title="The account is not here"
578
+ subtitle="Microsoft sent the sign-in back, but no account was kept."
579
+ footer={
580
+ <>
581
+ <span />
582
+ <Button variant="primary" onClick={onSignInAgain}>
583
+ Sign in again
584
+ </Button>
585
+ </>
586
+ }
587
+ >
588
+ <Banner tone="danger">
589
+ This instance holds no account from that sign-in. Sign in with
590
+ Microsoft again to connect it.
591
+ </Banner>
592
+ </WizardShell>
593
+ );
594
+ }
595
+
596
+ return <AccountGranted account={account} onContinue={onContinue} />;
597
+ }
598
+
599
+ export interface AccountGrantedProps {
600
+ account: Pick<
601
+ RemitImapAccountResponse,
602
+ "accountId" | "email" | "syncedServices" | "grantedScopes"
603
+ >;
604
+ onContinue: (accountId: string) => void;
605
+ }
606
+
607
+ export function AccountGranted({ account, onContinue }: AccountGrantedProps) {
608
+ const syncsMail = account.syncedServices.includes("Mail");
609
+ return (
610
+ <WizardShell
611
+ steps={STEP_LABELS}
612
+ activeStep={STEP_INDEX["microsoft-granted"]}
613
+ title={`Connected ${account.email}`}
614
+ subtitle="Microsoft granted access to what you picked."
615
+ footer={
616
+ <>
617
+ <span className="text-2xs text-fg-subtle">
618
+ Change this later in Settings › Accounts
619
+ </span>
620
+ <Button
621
+ variant="primary"
622
+ onClick={() => onContinue(account.accountId)}
623
+ >
624
+ {syncsMail ? "Go to inbox" : "Continue"}
625
+ </Button>
626
+ </>
627
+ }
628
+ >
629
+ <div className="space-y-3">
630
+ <div className="divide-y divide-line">
631
+ {ACCOUNT_SERVICE_ROWS.map((row) =>
632
+ account.syncedServices.includes(row.id) ? (
633
+ <CheckRow
634
+ key={row.id}
635
+ label={row.label}
636
+ detail="Access granted — syncing"
637
+ state="ok"
638
+ />
639
+ ) : (
640
+ <CheckRow
641
+ key={row.id}
642
+ label={row.label}
643
+ detail="Not synced. Turn it on in Settings › Accounts; Microsoft asks for access then."
644
+ state="pending"
645
+ />
646
+ ),
647
+ )}
648
+ </div>
649
+ <div>
650
+ <p className="text-2xs text-fg-subtle">
651
+ Permissions Microsoft granted
652
+ </p>
653
+ <code
654
+ className="mt-1 block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted"
655
+ data-testid="granted-scopes"
656
+ >
657
+ {account.grantedScopes.join(" ")}
658
+ </code>
659
+ </div>
660
+ </div>
661
+ </WizardShell>
662
+ );
663
+ }
664
+
466
665
  function StepAddress({
467
666
  initialEmail,
468
667
  initialDisplayName,
@@ -1150,16 +1349,45 @@ export interface OnboardingWizardProps {
1150
1349
  * has one — importing a configuration is a first-run move, not an add.
1151
1350
  */
1152
1351
  onImportConfig?: () => void;
1352
+ microsoftReturn?: MicrosoftReturn;
1353
+ }
1354
+
1355
+ export interface MicrosoftRefusal {
1356
+ kind: "refused";
1357
+ message: string;
1358
+ email?: string;
1359
+ services?: AccountService[];
1360
+ reconnect: boolean;
1153
1361
  }
1154
1362
 
1363
+ export type MicrosoftReturn =
1364
+ | { kind: "connected"; accountId: string }
1365
+ | MicrosoftRefusal;
1366
+
1367
+ const initialStep = (
1368
+ skipWelcome: boolean,
1369
+ microsoftReturn: MicrosoftReturn | undefined,
1370
+ ): WizardStep => {
1371
+ if (microsoftReturn?.kind === "connected") return "microsoft-granted";
1372
+ if (microsoftReturn?.kind === "refused") return "microsoft-email";
1373
+ return skipWelcome ? "connector" : "welcome";
1374
+ };
1375
+
1155
1376
  export function OnboardingWizard({
1156
1377
  skipWelcome = false,
1157
1378
  onComplete,
1158
1379
  onCancel,
1159
1380
  onImportConfig,
1381
+ microsoftReturn,
1160
1382
  }: OnboardingWizardProps) {
1161
1383
  const [step, setStep] = useState<WizardStep>(
1162
- skipWelcome ? "connector" : "welcome",
1384
+ initialStep(skipWelcome, microsoftReturn),
1385
+ );
1386
+ const [microsoftRefusal, setMicrosoftRefusal] = useState<
1387
+ MicrosoftRefusal | undefined
1388
+ >(microsoftReturn?.kind === "refused" ? microsoftReturn : undefined);
1389
+ const [microsoftAccountId, setMicrosoftAccountId] = useState<string | null>(
1390
+ microsoftReturn?.kind === "connected" ? microsoftReturn.accountId : null,
1163
1391
  );
1164
1392
  const [state, setState] = useState<WizardState>({
1165
1393
  email: "",
@@ -1254,6 +1482,20 @@ export function OnboardingWizard({
1254
1482
  [onComplete],
1255
1483
  );
1256
1484
 
1485
+ const microsoftSignIn = (
1486
+ <StepMicrosoftEmail
1487
+ refusal={microsoftRefusal}
1488
+ onBack={() => {
1489
+ setMicrosoftRefusal(undefined);
1490
+ setStep("connector");
1491
+ }}
1492
+ onConnected={(accountId) => {
1493
+ setMicrosoftAccountId(accountId);
1494
+ setStep("microsoft-granted");
1495
+ }}
1496
+ />
1497
+ );
1498
+
1257
1499
  switch (step) {
1258
1500
  case "welcome":
1259
1501
  return (
@@ -1274,10 +1516,15 @@ export function OnboardingWizard({
1274
1516
  );
1275
1517
 
1276
1518
  case "microsoft-email":
1519
+ return microsoftSignIn;
1520
+
1521
+ case "microsoft-granted":
1522
+ if (microsoftAccountId === null) return microsoftSignIn;
1277
1523
  return (
1278
- <StepMicrosoftEmail
1279
- onBack={() => setStep("connector")}
1280
- onConnected={handleGoToInbox}
1524
+ <StepMicrosoftGranted
1525
+ accountId={microsoftAccountId}
1526
+ onSignInAgain={() => setStep("microsoft-email")}
1527
+ onContinue={handleGoToInbox}
1281
1528
  />
1282
1529
  );
1283
1530
 
@@ -458,3 +458,93 @@ export const SyncStalled: Story = {
458
458
  );
459
459
  },
460
460
  };
461
+
462
+ const OUTLOOK = makeAccount({
463
+ accountId: "acc-outlook",
464
+ email: "alice@outlook.com",
465
+ authType: "oauthMicrosoft",
466
+ syncedServices: ["Calendar"],
467
+ grantedScopes: ["https://graph.microsoft.com/Calendars.Read"],
468
+ });
469
+
470
+ const withOutlook = mailWorld({
471
+ accounts: [...mailWorld().accounts, OUTLOOK],
472
+ });
473
+
474
+ export const MicrosoftServiceChoice: Story = {
475
+ play: async ({ canvasElement }) => {
476
+ const canvas = within(canvasElement);
477
+ await toMicrosoft(canvas);
478
+ await expect(canvas.getByRole("checkbox", { name: /^Mail/ })).toBeChecked();
479
+ await expect(
480
+ canvas.getByRole("checkbox", { name: /^Calendar/ }),
481
+ ).toBeChecked();
482
+ },
483
+ };
484
+
485
+ export const MicrosoftNothingPicked: Story = {
486
+ play: async ({ canvasElement }) => {
487
+ const canvas = within(canvasElement);
488
+ const signIn = await toMicrosoft(canvas);
489
+ await userEvent.click(canvas.getByRole("checkbox", { name: /^Mail/ }));
490
+ await userEvent.click(canvas.getByRole("checkbox", { name: /^Calendar/ }));
491
+ await userEvent.click(signIn);
492
+ await expect(await canvas.findByRole("alert")).toHaveTextContent(
493
+ "Pick at least one",
494
+ );
495
+ await expect(signIn).toBeEnabled();
496
+ },
497
+ };
498
+
499
+ export const MicrosoftGranted: Story = {
500
+ args: { url: `/settings/accounts?connected=${OUTLOOK.accountId}` },
501
+ parameters: handlers({}, withOutlook),
502
+ play: async ({ canvasElement }) => {
503
+ const canvas = within(canvasElement);
504
+ await expect(
505
+ await canvas.findByText(`Connected ${OUTLOOK.email}`),
506
+ ).toBeVisible();
507
+ await expect(canvas.getByText("Access granted — syncing")).toBeVisible();
508
+ await expect(
509
+ canvas.getByRole("button", { name: "Continue" }),
510
+ ).toBeEnabled();
511
+ },
512
+ };
513
+
514
+ export const MicrosoftScopeNotGranted: Story = {
515
+ args: {
516
+ url: "/settings/accounts?oauthError=scope_not_granted&oauthEmail=bob%40outlook.com&missingServices=Calendar",
517
+ },
518
+ parameters: handlers({}, mailWorld()),
519
+ play: async ({ canvasElement }) => {
520
+ const canvas = within(canvasElement);
521
+ await expect(
522
+ await canvas.findByText(/did not grant access to Calendar/),
523
+ ).toBeVisible();
524
+ await expect(canvas.getByLabelText("Email address (optional)")).toHaveValue(
525
+ "bob@outlook.com",
526
+ );
527
+ await expect(
528
+ canvas.getByRole("button", { name: "Sign in with Microsoft" }),
529
+ ).toBeEnabled();
530
+ },
531
+ };
532
+
533
+ export const MicrosoftReconnectScopeNotGranted: Story = {
534
+ args: {
535
+ url: `/settings/accounts?oauthError=scope_not_granted&oauthEmail=${encodeURIComponent(OUTLOOK.email)}&missingServices=Calendar`,
536
+ },
537
+ parameters: handlers({}, withOutlook),
538
+ play: async ({ canvasElement }) => {
539
+ const canvas = within(canvasElement);
540
+ await expect(
541
+ await canvas.findByText(`Reconnect ${OUTLOOK.email}`),
542
+ ).toBeVisible();
543
+ await expect(
544
+ canvas.getByText(/did not grant access to Calendar/),
545
+ ).toBeVisible();
546
+ await expect(canvas.getByLabelText("Email address (optional)")).toHaveValue(
547
+ OUTLOOK.email,
548
+ );
549
+ },
550
+ };
@@ -130,7 +130,10 @@ describe("AccountServices", () => {
130
130
  const mounted = await mount(outlook());
131
131
 
132
132
  mounted.click(switchFor(mounted, "calendar"));
133
- await mounted.waitFor(() => patches().length > 0, "the save to start");
133
+ await mounted.waitFor(
134
+ () => patches().length > 0 && switchFor(mounted, "calendar").disabled,
135
+ "the save to start",
136
+ );
134
137
 
135
138
  assert.equal(checked(mounted, "calendar"), "true");
136
139
  assert.equal(switchFor(mounted, "mail").disabled, true);
@@ -2,7 +2,7 @@
2
2
  * One calendar on the settings page: its name and zone, deleting it, and its
3
3
  * subscription address, wired to the server.
4
4
  */
5
- import { useState } from "react";
5
+ import { type ReactNode, useState } from "react";
6
6
  import { CalendarDetailsForm } from "@/components/settings/CalendarDetailsForm";
7
7
  import { CalendarFeedPanel } from "@/components/settings/CalendarFeedPanel";
8
8
  import {
@@ -14,12 +14,15 @@ export interface CalendarSettingsPanelProps {
14
14
  calendarId: string;
15
15
  calendarName: string;
16
16
  timezone: string;
17
+ /** Where a subscribed calendar comes from, drawn above its details. */
18
+ subscription?: ReactNode;
17
19
  }
18
20
 
19
21
  export function CalendarSettingsPanel({
20
22
  calendarId,
21
23
  calendarName,
22
24
  timezone,
25
+ subscription,
23
26
  }: CalendarSettingsPanelProps) {
24
27
  const { updateCalendar, deleteCalendar, isWriting } =
25
28
  useCalendarCollectionWrites();
@@ -33,21 +36,24 @@ export function CalendarSettingsPanel({
33
36
  calendarId={calendarId}
34
37
  calendarName={calendarName}
35
38
  details={
36
- <CalendarDetailsForm
37
- key={`${calendarName}\u0000${timezone}`}
38
- calendarName={calendarName}
39
- timezone={timezone}
40
- isBusy={isWriting}
41
- problem={problem}
42
- onSave={(details) => {
43
- setProblem("");
44
- void updateCalendar(calendarId, details).then(settle);
45
- }}
46
- onDelete={() => {
47
- setProblem("");
48
- void deleteCalendar(calendarId).then(settle);
49
- }}
50
- />
39
+ <>
40
+ {subscription}
41
+ <CalendarDetailsForm
42
+ key={`${calendarName}\u0000${timezone}`}
43
+ calendarName={calendarName}
44
+ timezone={timezone}
45
+ isBusy={isWriting}
46
+ problem={problem}
47
+ onSave={(details) => {
48
+ setProblem("");
49
+ void updateCalendar(calendarId, details).then(settle);
50
+ }}
51
+ onDelete={() => {
52
+ setProblem("");
53
+ void deleteCalendar(calendarId).then(settle);
54
+ }}
55
+ />
56
+ </>
51
57
  }
52
58
  />
53
59
  );
@@ -0,0 +1,89 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite";
2
+ import { expect, fn, userEvent, within } from "storybook/test";
3
+ import { CalendarSubscribeCard } from "./CalendarSubscribeCard";
4
+
5
+ /**
6
+ * Settings › Calendars: subscribing to another calendar's read-only iCal
7
+ * address (#1261). The server reads the feed before creating anything, so a
8
+ * refusal means nothing was added.
9
+ */
10
+ const meta: Meta<typeof CalendarSubscribeCard> = {
11
+ title: "Playground/Shipped/Settings/Calendars/Subscribe to a calendar",
12
+ component: CalendarSubscribeCard,
13
+ parameters: { layout: "padded" },
14
+ args: {
15
+ isBusy: false,
16
+ error: undefined,
17
+ onSubscribe: fn(),
18
+ },
19
+ };
20
+ export default meta;
21
+
22
+ type Story = StoryObj<typeof CalendarSubscribeCard>;
23
+
24
+ /** Empty: the button waits for a name and an address. */
25
+ export const Empty: Story = {
26
+ play: async ({ canvasElement }) => {
27
+ const canvas = within(canvasElement);
28
+ await expect(
29
+ canvas.getByRole("button", { name: "Subscribe" }),
30
+ ).toBeDisabled();
31
+ },
32
+ };
33
+
34
+ /** Filled in and sent. */
35
+ export const Filled: Story = {
36
+ play: async ({ canvasElement, args }) => {
37
+ const canvas = within(canvasElement);
38
+ await userEvent.type(
39
+ canvas.getByLabelText("Calendar name"),
40
+ "Harbour rota",
41
+ );
42
+ await userEvent.type(
43
+ canvas.getByLabelText("Calendar address"),
44
+ "webcal://calendar.example/harbour/basic.ics",
45
+ );
46
+ await userEvent.click(canvas.getByRole("button", { name: "Subscribe" }));
47
+ await expect(args.onSubscribe).toHaveBeenCalledWith(
48
+ {
49
+ displayName: "Harbour rota",
50
+ url: "webcal://calendar.example/harbour/basic.ics",
51
+ },
52
+ expect.any(Function),
53
+ );
54
+ },
55
+ };
56
+
57
+ /** The feed is being read. */
58
+ export const Subscribing: Story = {
59
+ args: { isBusy: true },
60
+ };
61
+
62
+ /** The feed could not be read, so no calendar was made. */
63
+ export const Refused: Story = {
64
+ args: {
65
+ error: {
66
+ code: "subscription_unreachable",
67
+ message: "the calendar was not created: the feed answered HTTP 404",
68
+ },
69
+ },
70
+ play: async ({ canvasElement }) => {
71
+ const canvas = within(canvasElement);
72
+ await expect(canvas.getByRole("alert")).toHaveTextContent(
73
+ "The calendar was not added.",
74
+ );
75
+ },
76
+ };
77
+
78
+ /** Refused, on the dark theme. */
79
+ export const RefusedDark: Story = {
80
+ name: "Refused (dark)",
81
+ parameters: { theme: "dark" },
82
+ args: {
83
+ error: {
84
+ code: "subscription_unreachable",
85
+ message:
86
+ "the calendar was not created: the feed could not be reached (ENOTFOUND)",
87
+ },
88
+ },
89
+ };