@remit/web-client 0.0.237 → 0.0.239
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/mail/IntelligencePane.test.ts +34 -0
- package/src/components/mail/IntelligencePane.tsx +15 -1
- package/src/components/mail/SelectionWizardHost.tsx +8 -1
- package/src/components/mail/intelligence-semantic-off.render.test.ts +128 -0
- package/src/components/settings/CalendarFeedCard.render.test.ts +154 -0
- package/src/components/settings/CalendarFeedCard.stories.tsx +134 -0
- package/src/components/settings/CalendarFeedCard.tsx +282 -0
- package/src/components/settings/CalendarFeedPanel.tsx +34 -0
- package/src/components/settings/calendar-feed-flow.render.test.ts +449 -0
- package/src/hooks/calendar/useCalendarFeed.ts +163 -0
- package/src/hooks/useIntelligenceData.ts +16 -1
- package/src/hooks/useSemanticSearchEnabled.ts +23 -0
- package/src/lib/calendar-feed-copy.ts +29 -0
- package/src/lib/calendar-feed-url.ts +14 -0
- package/src/routeTree.gen.ts +21 -0
- package/src/routes/settings/calendars.tsx +73 -0
- package/src/routes/settings.tsx +15 -1
- package/src/test-support/fixtures.ts +3 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings › Calendars: one calendar's secret subscription address (#1067).
|
|
3
|
+
*
|
|
4
|
+
* Presentational. Every state the server can put this control in is drawn —
|
|
5
|
+
* the read still out, the read refused, not shared, shared, and the one moment
|
|
6
|
+
* the address is legible — because a control that renders nothing for one of
|
|
7
|
+
* them is indistinguishable from a calendar that cannot be shared at all.
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
Badge,
|
|
11
|
+
Banner,
|
|
12
|
+
Button,
|
|
13
|
+
Card,
|
|
14
|
+
CardBody,
|
|
15
|
+
CardHeader,
|
|
16
|
+
CardTitle,
|
|
17
|
+
ConfirmDialog,
|
|
18
|
+
} from "@remit/ui";
|
|
19
|
+
import { Check, Copy, Link2, RefreshCw, Trash2 } from "lucide-react";
|
|
20
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
21
|
+
import { ErrorState, formatErrorMessage } from "@/components/ui/ErrorState";
|
|
22
|
+
import type { CalendarFeedState } from "@/hooks/calendar/useCalendarFeed";
|
|
23
|
+
import {
|
|
24
|
+
revokeFeedConfirmCopy,
|
|
25
|
+
rotateFeedConfirmCopy,
|
|
26
|
+
} from "@/lib/calendar-feed-copy";
|
|
27
|
+
import { formatDatePreset } from "@/lib/format";
|
|
28
|
+
|
|
29
|
+
export interface CalendarFeedCardProps {
|
|
30
|
+
calendarName: string;
|
|
31
|
+
state: CalendarFeedState;
|
|
32
|
+
/** The address just minted, shown once. Empty at every other moment. */
|
|
33
|
+
mintedUrl: string;
|
|
34
|
+
isBusy: boolean;
|
|
35
|
+
/** A create, rotate or revoke the server turned down. */
|
|
36
|
+
actionError: unknown;
|
|
37
|
+
onMint: () => void;
|
|
38
|
+
onRevoke: () => void;
|
|
39
|
+
onDismissMinted: () => void;
|
|
40
|
+
onRetry: () => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type Pending = "none" | "rotate" | "revoke";
|
|
44
|
+
|
|
45
|
+
function MintedAddress({
|
|
46
|
+
calendarName,
|
|
47
|
+
url,
|
|
48
|
+
onDismiss,
|
|
49
|
+
}: {
|
|
50
|
+
calendarName: string;
|
|
51
|
+
url: string;
|
|
52
|
+
onDismiss: () => void;
|
|
53
|
+
}) {
|
|
54
|
+
const [copied, setCopied] = useState(false);
|
|
55
|
+
const [copyFailed, setCopyFailed] = useState(false);
|
|
56
|
+
const revert = useRef(0);
|
|
57
|
+
|
|
58
|
+
useEffect(() => () => window.clearTimeout(revert.current), []);
|
|
59
|
+
|
|
60
|
+
const copy = () => {
|
|
61
|
+
navigator.clipboard
|
|
62
|
+
.writeText(url)
|
|
63
|
+
.then(() => {
|
|
64
|
+
setCopyFailed(false);
|
|
65
|
+
setCopied(true);
|
|
66
|
+
revert.current = window.setTimeout(() => setCopied(false), 2000);
|
|
67
|
+
})
|
|
68
|
+
.catch(() => setCopyFailed(true));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div className="mt-3 space-y-2 rounded-sm border border-accent-2/40 bg-accent-2/10 px-3 py-2.5">
|
|
73
|
+
<p className="text-sm font-medium text-fg">
|
|
74
|
+
Subscribe with this address. It is shown once and cannot be read back.
|
|
75
|
+
</p>
|
|
76
|
+
<div className="flex flex-col gap-2 sm:flex-row sm:items-center">
|
|
77
|
+
<input
|
|
78
|
+
readOnly
|
|
79
|
+
value={url}
|
|
80
|
+
aria-label={`Subscription address for ${calendarName}`}
|
|
81
|
+
onFocus={(event) => event.currentTarget.select()}
|
|
82
|
+
className="min-w-0 flex-1 rounded-sm border border-line bg-surface px-2 py-1.5 font-mono text-xs text-fg"
|
|
83
|
+
/>
|
|
84
|
+
<Button
|
|
85
|
+
variant="primary"
|
|
86
|
+
size="sm"
|
|
87
|
+
icon={
|
|
88
|
+
copied ? (
|
|
89
|
+
<Check className="size-3.5" />
|
|
90
|
+
) : (
|
|
91
|
+
<Copy className="size-3.5" />
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
onClick={copy}
|
|
95
|
+
>
|
|
96
|
+
{copied ? "Copied" : "Copy address"}
|
|
97
|
+
</Button>
|
|
98
|
+
</div>
|
|
99
|
+
{copyFailed && (
|
|
100
|
+
<Banner tone="warning" variant="soft">
|
|
101
|
+
The address could not be copied to the clipboard. Select it above and
|
|
102
|
+
copy it by hand before leaving this page.
|
|
103
|
+
</Banner>
|
|
104
|
+
)}
|
|
105
|
+
<p className="text-xs text-fg-muted">
|
|
106
|
+
Anyone holding this address can read every event in this calendar,
|
|
107
|
+
without signing in. Rotate it if it reaches the wrong person.
|
|
108
|
+
</p>
|
|
109
|
+
<Button variant="ghost" size="sm" onClick={onDismiss}>
|
|
110
|
+
I've saved it
|
|
111
|
+
</Button>
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function ActiveFeed({
|
|
117
|
+
createdAt,
|
|
118
|
+
rotatedAt,
|
|
119
|
+
isBusy,
|
|
120
|
+
onRotate,
|
|
121
|
+
onRevoke,
|
|
122
|
+
}: {
|
|
123
|
+
createdAt: number;
|
|
124
|
+
rotatedAt: number;
|
|
125
|
+
isBusy: boolean;
|
|
126
|
+
onRotate: () => void;
|
|
127
|
+
onRevoke: () => void;
|
|
128
|
+
}) {
|
|
129
|
+
return (
|
|
130
|
+
<div className="space-y-2">
|
|
131
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
132
|
+
<Badge tone="positive">shared</Badge>
|
|
133
|
+
<span className="text-xs text-fg-muted">
|
|
134
|
+
Address created {formatDatePreset(createdAt, "medium")}
|
|
135
|
+
{rotatedAt > 0
|
|
136
|
+
? `, last replaced ${formatDatePreset(rotatedAt, "medium")}`
|
|
137
|
+
: ""}
|
|
138
|
+
</span>
|
|
139
|
+
</div>
|
|
140
|
+
<p className="text-sm text-fg-muted">
|
|
141
|
+
The address itself is not stored in readable form, so it cannot be shown
|
|
142
|
+
again. Replace it if you no longer know where it went.
|
|
143
|
+
</p>
|
|
144
|
+
<div className="flex flex-wrap gap-2">
|
|
145
|
+
<Button
|
|
146
|
+
variant="secondary"
|
|
147
|
+
size="sm"
|
|
148
|
+
disabled={isBusy}
|
|
149
|
+
icon={<RefreshCw className="size-3.5" />}
|
|
150
|
+
onClick={onRotate}
|
|
151
|
+
>
|
|
152
|
+
Replace address
|
|
153
|
+
</Button>
|
|
154
|
+
<Button
|
|
155
|
+
variant="danger"
|
|
156
|
+
size="sm"
|
|
157
|
+
disabled={isBusy}
|
|
158
|
+
icon={<Trash2 className="size-3.5" />}
|
|
159
|
+
onClick={onRevoke}
|
|
160
|
+
>
|
|
161
|
+
Stop sharing
|
|
162
|
+
</Button>
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function CalendarFeedCard({
|
|
169
|
+
calendarName,
|
|
170
|
+
state,
|
|
171
|
+
mintedUrl,
|
|
172
|
+
isBusy,
|
|
173
|
+
actionError,
|
|
174
|
+
onMint,
|
|
175
|
+
onRevoke,
|
|
176
|
+
onDismissMinted,
|
|
177
|
+
onRetry,
|
|
178
|
+
}: CalendarFeedCardProps) {
|
|
179
|
+
const [pending, setPending] = useState<Pending>("none");
|
|
180
|
+
const titleId = useId();
|
|
181
|
+
|
|
182
|
+
const confirm = () => {
|
|
183
|
+
const action = pending;
|
|
184
|
+
setPending("none");
|
|
185
|
+
if (action === "rotate") onMint();
|
|
186
|
+
if (action === "revoke") onRevoke();
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const copy =
|
|
190
|
+
pending === "revoke"
|
|
191
|
+
? revokeFeedConfirmCopy(calendarName)
|
|
192
|
+
: rotateFeedConfirmCopy(calendarName);
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
// Named region: the settings page draws one of these per calendar, and every
|
|
196
|
+
// control in them is worded identically, so the calendar's name is the only
|
|
197
|
+
// thing telling two cards apart.
|
|
198
|
+
<Card className="max-w-xl" role="region" aria-labelledby={titleId}>
|
|
199
|
+
<CardHeader>
|
|
200
|
+
<CardTitle id={titleId}>{calendarName}</CardTitle>
|
|
201
|
+
</CardHeader>
|
|
202
|
+
<CardBody>
|
|
203
|
+
{state.status === "loading" && mintedUrl === "" && (
|
|
204
|
+
// biome-ignore lint/a11y/useAriaPropsSupportedByRole: aria-label on a loading skeleton is what assistive tech has to go on
|
|
205
|
+
<div
|
|
206
|
+
className="h-12 animate-pulse rounded-sm bg-surface-sunken"
|
|
207
|
+
aria-busy="true"
|
|
208
|
+
aria-label={`Loading the subscription address for ${calendarName}`}
|
|
209
|
+
/>
|
|
210
|
+
)}
|
|
211
|
+
|
|
212
|
+
{state.status === "unreadable" && mintedUrl === "" && (
|
|
213
|
+
<ErrorState
|
|
214
|
+
variant="inline"
|
|
215
|
+
title={`Couldn't read whether ${calendarName} is shared`}
|
|
216
|
+
error={state.error}
|
|
217
|
+
onRetry={onRetry}
|
|
218
|
+
/>
|
|
219
|
+
)}
|
|
220
|
+
|
|
221
|
+
{state.status === "absent" && mintedUrl === "" && (
|
|
222
|
+
<div className="space-y-2">
|
|
223
|
+
<p className="text-sm text-fg-muted">
|
|
224
|
+
Give this calendar a secret address and Apple Calendar, Google
|
|
225
|
+
Calendar, Outlook and Thunderbird can subscribe to it read-only.
|
|
226
|
+
Nobody signs in — the address is the credential, so treat it like
|
|
227
|
+
a password.
|
|
228
|
+
</p>
|
|
229
|
+
<Button
|
|
230
|
+
variant="primary"
|
|
231
|
+
size="sm"
|
|
232
|
+
disabled={isBusy}
|
|
233
|
+
icon={<Link2 className="size-3.5" />}
|
|
234
|
+
onClick={onMint}
|
|
235
|
+
>
|
|
236
|
+
{isBusy ? "Creating…" : "Create subscription address"}
|
|
237
|
+
</Button>
|
|
238
|
+
</div>
|
|
239
|
+
)}
|
|
240
|
+
|
|
241
|
+
{state.status === "active" && (
|
|
242
|
+
<ActiveFeed
|
|
243
|
+
createdAt={state.createdAt}
|
|
244
|
+
rotatedAt={state.rotatedAt}
|
|
245
|
+
isBusy={isBusy}
|
|
246
|
+
onRotate={() => setPending("rotate")}
|
|
247
|
+
onRevoke={() => setPending("revoke")}
|
|
248
|
+
/>
|
|
249
|
+
)}
|
|
250
|
+
|
|
251
|
+
{actionError !== undefined && actionError !== null && (
|
|
252
|
+
<Banner tone="danger" variant="soft" className="mt-3">
|
|
253
|
+
<p className="font-medium">
|
|
254
|
+
The subscription address for {calendarName} was not changed.
|
|
255
|
+
</p>
|
|
256
|
+
<p className="mt-0.5 break-words">
|
|
257
|
+
{formatErrorMessage(actionError)}
|
|
258
|
+
</p>
|
|
259
|
+
</Banner>
|
|
260
|
+
)}
|
|
261
|
+
|
|
262
|
+
{mintedUrl !== "" && (
|
|
263
|
+
<MintedAddress
|
|
264
|
+
calendarName={calendarName}
|
|
265
|
+
url={mintedUrl}
|
|
266
|
+
onDismiss={onDismissMinted}
|
|
267
|
+
/>
|
|
268
|
+
)}
|
|
269
|
+
</CardBody>
|
|
270
|
+
|
|
271
|
+
<ConfirmDialog
|
|
272
|
+
isOpen={pending !== "none"}
|
|
273
|
+
title={copy.title}
|
|
274
|
+
description={copy.description}
|
|
275
|
+
confirmLabel={pending === "revoke" ? "Stop sharing" : "Replace address"}
|
|
276
|
+
destructive
|
|
277
|
+
onConfirm={confirm}
|
|
278
|
+
onCancel={() => setPending("none")}
|
|
279
|
+
/>
|
|
280
|
+
</Card>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One calendar's subscription address, wired to the server (#1067).
|
|
3
|
+
*
|
|
4
|
+
* A component rather than a loop body in the settings route: each calendar
|
|
5
|
+
* reads and writes its own feed, and a hook cannot be called per iteration.
|
|
6
|
+
*/
|
|
7
|
+
import { CalendarFeedCard } from "@/components/settings/CalendarFeedCard";
|
|
8
|
+
import { useCalendarFeed } from "@/hooks/calendar/useCalendarFeed";
|
|
9
|
+
|
|
10
|
+
export interface CalendarFeedPanelProps {
|
|
11
|
+
calendarId: string;
|
|
12
|
+
calendarName: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function CalendarFeedPanel({
|
|
16
|
+
calendarId,
|
|
17
|
+
calendarName,
|
|
18
|
+
}: CalendarFeedPanelProps) {
|
|
19
|
+
const feed = useCalendarFeed(calendarId);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<CalendarFeedCard
|
|
23
|
+
calendarName={calendarName}
|
|
24
|
+
state={feed.state}
|
|
25
|
+
mintedUrl={feed.mintedUrl}
|
|
26
|
+
isBusy={feed.isBusy}
|
|
27
|
+
actionError={feed.actionError}
|
|
28
|
+
onMint={feed.mint}
|
|
29
|
+
onRevoke={feed.revoke}
|
|
30
|
+
onDismissMinted={feed.dismissMinted}
|
|
31
|
+
onRetry={feed.retry}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|