@remit/ui 0.0.200 → 0.0.202

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.200",
3
+ "version": "0.0.202",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -324,6 +324,47 @@ export const Searching: Story = {
324
324
  ),
325
325
  };
326
326
 
327
+ export const SearchingSenderFirst: Story = {
328
+ args: {
329
+ sections: [
330
+ {
331
+ id: "matches",
332
+ threads: [
333
+ {
334
+ id: "s1",
335
+ accountId: "a1",
336
+ fromName: "Penny Lane",
337
+ fromEmail: "penny@example.com",
338
+ subject: "Dinner on Friday?",
339
+ snippet: "I booked the place on the corner.",
340
+ timeLabel: "Mar 2",
341
+ isRead: true,
342
+ category: "personal",
343
+ },
344
+ {
345
+ id: "s2",
346
+ accountId: "a1",
347
+ fromName: "Sam Ortiz",
348
+ fromEmail: "sam@example.com",
349
+ subject: "Weekend plans",
350
+ snippet: "Penny said she can bring the tent.",
351
+ timeLabel: "9:14",
352
+ isRead: false,
353
+ category: "personal",
354
+ },
355
+ ],
356
+ },
357
+ ],
358
+ briefCategory: "all",
359
+ flat: true,
360
+ },
361
+ render: (args) => (
362
+ <div className="flex h-screen w-96 flex-col border-r border-line">
363
+ <BriefHost {...args} />
364
+ </div>
365
+ ),
366
+ };
367
+
327
368
  const accountSources: FilterSheetSource[] = [
328
369
  { id: "all", label: "All", active: true },
329
370
  { id: "a1", label: "work", count: 3 },
@@ -0,0 +1,48 @@
1
+ import { TriangleAlert } from "lucide-react";
2
+ import { cn } from "../lib/cn.js";
3
+
4
+ export interface CalendarFailureNoteProps {
5
+ /** What did not happen, and what to do about it. */
6
+ text: string;
7
+ /** A prefilled issue to file when retrying does not help. */
8
+ reportHref?: string;
9
+ className?: string;
10
+ }
11
+
12
+ /**
13
+ * An answer or a read that did not land, stated where it was asked for, with
14
+ * the way to report it when trying again does not help.
15
+ */
16
+ export function CalendarFailureNote({
17
+ text,
18
+ reportHref,
19
+ className,
20
+ }: CalendarFailureNoteProps) {
21
+ return (
22
+ <div
23
+ role="alert"
24
+ className={cn(
25
+ "flex items-start gap-1.5 rounded-md border border-danger/40 bg-danger-soft p-2 text-xs text-danger",
26
+ className,
27
+ )}
28
+ >
29
+ <TriangleAlert className="mt-0.5 size-3.5 shrink-0" aria-hidden />
30
+ <p className="min-w-0 flex-1">
31
+ {text}
32
+ {reportHref && (
33
+ <>
34
+ {" "}
35
+ <a
36
+ href={reportHref}
37
+ target="_blank"
38
+ rel="noreferrer"
39
+ className="font-medium text-accent hover:underline"
40
+ >
41
+ Report an issue
42
+ </a>
43
+ </>
44
+ )}
45
+ </p>
46
+ </div>
47
+ );
48
+ }
@@ -107,4 +107,72 @@ describe("CalendarInviteCard", () => {
107
107
  assert.match(render({ touch: true }), /min-h-11/);
108
108
  assert.doesNotMatch(render(), /min-h-11/);
109
109
  });
110
+
111
+ it("leaves off the answers the host cannot store", () => {
112
+ const html = render({ onTentative: undefined, onReopen: undefined });
113
+ assert.doesNotMatch(html, />Maybe</);
114
+ assert.doesNotMatch(
115
+ render({ rsvp: "accepted", onReopen: undefined }),
116
+ />Change</,
117
+ );
118
+ });
119
+
120
+ it("names the sender the mute rule matches, not the organiser", () => {
121
+ assert.doesNotMatch(render(), /Stop offering invitations/);
122
+ const html = render({
123
+ mute: { sender: "Alex Forwarder", onMute: () => undefined },
124
+ });
125
+ assert.match(html, /Stop offering invitations from Alex Forwarder/);
126
+ assert.doesNotMatch(html, /Stop offering invitations from Priya/);
127
+ });
128
+
129
+ it("states an answer that did not land, with the way to report it", () => {
130
+ const html = render({
131
+ failure: "The calendar refused it.",
132
+ reportHref: "https://example.invalid/issues/new",
133
+ });
134
+ assert.match(html, /role="alert"/);
135
+ assert.match(html, /The calendar refused it\./);
136
+ assert.match(html, /href="https:\/\/example\.invalid\/issues\/new"/);
137
+ assert.match(html, /Report an issue/);
138
+ });
139
+
140
+ it("holds only the answers that write, when there is no calendar to write to", () => {
141
+ const html = render({
142
+ addBlocked: "You have no calendar yet.",
143
+ mute: { sender: "Alex", onMute: () => undefined },
144
+ });
145
+ assert.match(html, /You have no calendar yet\./);
146
+ const before = (label: string) => {
147
+ const upTo = html.slice(0, html.indexOf(label));
148
+ return upTo.slice(upTo.lastIndexOf("<button"));
149
+ };
150
+ assert.match(before("Add to calendar"), /disabled=""/);
151
+ assert.doesNotMatch(before("Decline"), /disabled=""/);
152
+ assert.doesNotMatch(before("Stop offering"), /disabled=""/);
153
+ });
154
+
155
+ it("points at no control that is not there for a superseded one", () => {
156
+ const html = render({
157
+ invite: { ...kickoffInvite, state: "superseded", sequence: 1 },
158
+ });
159
+ assert.doesNotMatch(html, /Open the newer invitation/);
160
+ assert.doesNotMatch(html, /Answer the newer one/);
161
+ });
162
+
163
+ it("holds the answers while one is on its way", () => {
164
+ const html = render({ busy: true });
165
+ const accept = html.slice(0, html.indexOf("Add to calendar"));
166
+ assert.match(accept.slice(accept.lastIndexOf("<button")), /disabled=""/);
167
+ });
168
+
169
+ it("draws no guest tally when the invitation named nobody", () => {
170
+ const html = render({
171
+ invite: {
172
+ ...kickoffInvite,
173
+ proposed: { ...kickoffInvite.proposed, attendees: [] },
174
+ },
175
+ });
176
+ assert.doesNotMatch(html, /guests/);
177
+ });
110
178
  });
@@ -1,4 +1,5 @@
1
1
  import {
2
+ BellOff,
2
3
  Calendar,
3
4
  Check,
4
5
  Clock,
@@ -13,6 +14,7 @@ import { cn } from "../lib/cn.js";
13
14
  import { RsvpBadge } from "./attendee-row.js";
14
15
  import { Button } from "./button.js";
15
16
  import { CalendarClashStrip } from "./calendar-clash-strip.js";
17
+ import { CalendarFailureNote } from "./calendar-failure-note.js";
16
18
  import { CalendarParseBadge } from "./calendar-parse-badge.js";
17
19
  import type {
18
20
  CalendarClash,
@@ -43,10 +45,22 @@ export interface CalendarInviteCardProps {
43
45
  clashes: CalendarClash[];
44
46
  rsvp: RsvpState;
45
47
  onAdd: () => void;
46
- onTentative: () => void;
48
+ /** Wired only where a tentative answer can be stored. */
49
+ onTentative?: () => void;
47
50
  onDecline: () => void;
48
- onReopen: () => void;
51
+ /**
52
+ * Takes an answer back, or keeps a cancelled event. Wired only where the
53
+ * store can undo the answer; an answer it cannot take back offers no Change.
54
+ */
55
+ onReopen?: () => void;
49
56
  onOfferOtherTimes: () => void;
57
+ /**
58
+ * Stops invitations arriving from the mail's sender being offered at all.
59
+ * The rule is written against the message's From, which is not always the
60
+ * organiser — a forwarded invitation names someone else — so the button
61
+ * names whoever the rule will match.
62
+ */
63
+ mute?: { sender: string; onMute: () => void };
50
64
  /** Wired only for a cancellation the reader has not acted on. */
51
65
  onRemove?: () => void;
52
66
  /** Wired only when a later message carries a higher SEQUENCE. */
@@ -56,6 +70,17 @@ export interface CalendarInviteCardProps {
56
70
  * passes it here rather than the card growing a second one.
57
71
  */
58
72
  guests?: ReactNode;
73
+ /** An answer is on its way to the server; the buttons wait for it. */
74
+ busy?: boolean;
75
+ /** Why the last answer did not land, in words the reader can act on. */
76
+ failure?: string;
77
+ /** A prefilled issue report for the failure above. */
78
+ reportHref?: string;
79
+ /**
80
+ * Why nothing can be written to a calendar yet, and the way to fix it. Set,
81
+ * it holds Add and Remove; the answers that write nothing stay live.
82
+ */
83
+ addBlocked?: ReactNode;
59
84
  touch?: boolean;
60
85
  className?: string;
61
86
  }
@@ -86,9 +111,14 @@ export function CalendarInviteCard({
86
111
  onDecline,
87
112
  onReopen,
88
113
  onOfferOtherTimes,
114
+ mute,
89
115
  onRemove,
90
116
  onOpenNewer,
91
117
  guests,
118
+ busy = false,
119
+ failure = "",
120
+ reportHref,
121
+ addBlocked,
92
122
  touch,
93
123
  className,
94
124
  }: CalendarInviteCardProps) {
@@ -146,8 +176,8 @@ export function CalendarInviteCard({
146
176
  {invite.organizerName} has sent a newer version of this.
147
177
  </p>
148
178
  <p className="mt-1 text-xs text-fg">
149
- This one is revision {invite.sequence} and is out of date. Answer
150
- the newer one instead.
179
+ This one is revision {invite.sequence} and is out of date. The
180
+ newer message carries the one to answer.
151
181
  </p>
152
182
  {onOpenNewer && (
153
183
  <Button
@@ -181,18 +211,22 @@ export function CalendarInviteCard({
181
211
  size={touch ? "md" : "sm"}
182
212
  icon={<Trash2 className="size-3.5" />}
183
213
  onClick={onRemove}
214
+ disabled={busy || addBlocked !== undefined}
184
215
  className={cn(touch && "min-h-11 flex-1")}
185
216
  >
186
217
  Remove from calendar
187
218
  </Button>
188
- <Button
189
- variant="secondary"
190
- size={touch ? "md" : "sm"}
191
- onClick={onReopen}
192
- className={cn(touch && "min-h-11 flex-1")}
193
- >
194
- Keep it
195
- </Button>
219
+ {onReopen && (
220
+ <Button
221
+ variant="secondary"
222
+ size={touch ? "md" : "sm"}
223
+ onClick={onReopen}
224
+ disabled={busy}
225
+ className={cn(touch && "min-h-11 flex-1")}
226
+ >
227
+ Keep it
228
+ </Button>
229
+ )}
196
230
  </div>
197
231
  )}
198
232
  </div>
@@ -201,10 +235,21 @@ export function CalendarInviteCard({
201
235
 
202
236
  {!stale && <CalendarClashStrip clashes={clashes} />}
203
237
 
204
- {guests ?? (
205
- <p className="text-2xs uppercase tracking-wider text-fg-subtle">
206
- {attendees.length} guests{tally === "" ? "" : ` · ${tally}`}
207
- </p>
238
+ {guests ??
239
+ (attendees.length > 0 && (
240
+ <p className="text-2xs uppercase tracking-wider text-fg-subtle">
241
+ {attendees.length} guests{tally === "" ? "" : ` · ${tally}`}
242
+ </p>
243
+ ))}
244
+
245
+ {failure !== "" && (
246
+ <CalendarFailureNote text={failure} reportHref={reportHref} />
247
+ )}
248
+
249
+ {addBlocked !== undefined && (
250
+ <div className="rounded-md border border-warning/40 bg-warning-soft p-2 text-xs text-fg">
251
+ {addBlocked}
252
+ </div>
208
253
  )}
209
254
 
210
255
  {!stale &&
@@ -216,23 +261,28 @@ export function CalendarInviteCard({
216
261
  size={touch ? "md" : "sm"}
217
262
  icon={<Calendar className="size-3.5" />}
218
263
  onClick={onAdd}
264
+ disabled={busy || addBlocked !== undefined}
219
265
  className={cn(touch && "min-h-11 flex-1")}
220
266
  >
221
267
  Add to calendar
222
268
  </Button>
223
- <Button
224
- variant="secondary"
225
- size={touch ? "md" : "sm"}
226
- onClick={onTentative}
227
- className={cn(touch && "min-h-11 flex-1")}
228
- >
229
- Maybe
230
- </Button>
269
+ {onTentative && (
270
+ <Button
271
+ variant="secondary"
272
+ size={touch ? "md" : "sm"}
273
+ onClick={onTentative}
274
+ disabled={busy}
275
+ className={cn(touch && "min-h-11 flex-1")}
276
+ >
277
+ Maybe
278
+ </Button>
279
+ )}
231
280
  <Button
232
281
  variant="secondary"
233
282
  size={touch ? "md" : "sm"}
234
283
  icon={<X className="size-3.5" />}
235
284
  onClick={onDecline}
285
+ disabled={busy}
236
286
  className={cn(touch && "min-h-11 flex-1")}
237
287
  >
238
288
  Decline
@@ -246,6 +296,18 @@ export function CalendarInviteCard({
246
296
  >
247
297
  Offer other times
248
298
  </Button>
299
+ {mute && (
300
+ <Button
301
+ variant="ghost"
302
+ size={touch ? "md" : "sm"}
303
+ icon={<BellOff className="size-3.5" />}
304
+ onClick={mute.onMute}
305
+ disabled={busy}
306
+ className={cn("self-start", touch && "min-h-11 w-full")}
307
+ >
308
+ {`Stop offering invitations from ${mute.sender}`}
309
+ </Button>
310
+ )}
249
311
  <p className="text-2xs text-fg-subtle">
250
312
  {invite.organizerName} is not notified. Reader writes this to your
251
313
  calendar and sends no reply — tell them in the thread.
@@ -258,14 +320,17 @@ export function CalendarInviteCard({
258
320
  {rsvp === "declined" ? "You declined" : "On your calendar"}
259
321
  <RsvpBadge rsvp={rsvp} />
260
322
  </span>
261
- <Button
262
- variant="ghost"
263
- size={touch ? "md" : "sm"}
264
- onClick={onReopen}
265
- className={touch ? "min-h-11" : ""}
266
- >
267
- Change
268
- </Button>
323
+ {onReopen && (
324
+ <Button
325
+ variant="ghost"
326
+ size={touch ? "md" : "sm"}
327
+ onClick={onReopen}
328
+ disabled={busy}
329
+ className={touch ? "min-h-11" : ""}
330
+ >
331
+ Change
332
+ </Button>
333
+ )}
269
334
  {rsvp === "declined" && (
270
335
  <Button
271
336
  variant="secondary"
@@ -54,11 +54,17 @@ export interface EventSuggestionCardProps {
54
54
  * Correcting the reading first. It is handed the same settled zone Add is,
55
55
  * and is refused on the same terms — an editor opened on an hour nobody has
56
56
  * placed on a clock seeds the draft with the wrong time, which is the
57
- * mistake Add is dimmed to prevent.
57
+ * mistake Add is dimmed to prevent. Wired only where an editor can take the
58
+ * reading; without it the card offers Add and Dismiss alone.
58
59
  */
59
- onReview: (timeZone: string) => void;
60
+ onReview?: (timeZone: string) => void;
60
61
  onDismiss: () => void;
61
- onOpenThread: () => void;
62
+ /** Wired only where the mail is somewhere else; beside it, it is plain text. */
63
+ onOpenThread?: () => void;
64
+ /** An answer is on its way to the server; the buttons wait for it. */
65
+ busy?: boolean;
66
+ /** Nothing can be added yet; the host says why beside the card. */
67
+ addBlocked?: boolean;
62
68
  /** The clock picked so far. Omit to let the card hold the choice itself. */
63
69
  zoneChoice?: string;
64
70
  onZoneChoice?: (timeZone: string) => void;
@@ -72,6 +78,12 @@ export interface EventSuggestionCardProps {
72
78
  className?: string;
73
79
  }
74
80
 
81
+ function mailLine(suggestion: EventSuggestion): string {
82
+ return suggestion.threadSubject === ""
83
+ ? suggestion.sender
84
+ : `${suggestion.sender} — ${suggestion.threadSubject}`;
85
+ }
86
+
75
87
  /** Words for a number, so the card never shows a false 87%. */
76
88
  function confidenceText(confidence: number): string {
77
89
  if (confidence >= 0.85) return "Read cleanly";
@@ -97,6 +109,8 @@ export function EventSuggestionCard({
97
109
  onReview,
98
110
  onDismiss,
99
111
  onOpenThread,
112
+ busy = false,
113
+ addBlocked = false,
100
114
  zoneChoice,
101
115
  onZoneChoice,
102
116
  addLabel = "Add",
@@ -148,6 +162,7 @@ export function EventSuggestionCard({
148
162
  type="button"
149
163
  aria-label="Dismiss suggestion"
150
164
  onClick={onDismiss}
165
+ disabled={busy}
151
166
  className={cn(
152
167
  "flex shrink-0 items-center justify-center rounded-md text-fg-subtle outline-none hover:bg-surface hover:text-fg focus-visible:ring-2 focus-visible:ring-ring",
153
168
  touch ? "size-11" : "size-7",
@@ -164,16 +179,21 @@ export function EventSuggestionCard({
164
179
  </p>
165
180
  )}
166
181
 
167
- <button
168
- type="button"
169
- onClick={onOpenThread}
170
- className="flex w-full min-w-0 items-center gap-1.5 rounded-sm text-left text-2xs text-accent-2 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring"
171
- >
172
- <Mail className="size-3 shrink-0" />
173
- <span className="truncate">
174
- {suggestion.sender} — {suggestion.threadSubject}
175
- </span>
176
- </button>
182
+ {onOpenThread ? (
183
+ <button
184
+ type="button"
185
+ onClick={onOpenThread}
186
+ className="flex w-full min-w-0 items-center gap-1.5 rounded-sm text-left text-2xs text-accent-2 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring"
187
+ >
188
+ <Mail className="size-3 shrink-0" />
189
+ <span className="truncate">{mailLine(suggestion)}</span>
190
+ </button>
191
+ ) : (
192
+ <p className="flex w-full min-w-0 items-center gap-1.5 text-2xs text-fg-subtle">
193
+ <Mail className="size-3 shrink-0" />
194
+ <span className="truncate">{mailLine(suggestion)}</span>
195
+ </p>
196
+ )}
177
197
 
178
198
  {suggestion.zoneOptions && (
179
199
  <div className="flex flex-col gap-1.5 rounded-md border border-warning/40 p-2">
@@ -221,6 +241,7 @@ export function EventSuggestionCard({
221
241
  size={touch ? "md" : "sm"}
222
242
  icon={<Plus className="size-3.5" />}
223
243
  onClick={carryingTheZone(onAdd)}
244
+ disabled={busy || addBlocked}
224
245
  aria-describedby={settlement.settled ? undefined : reasonId}
225
246
  className={cn(
226
247
  touch && "min-h-11 flex-1",
@@ -229,19 +250,22 @@ export function EventSuggestionCard({
229
250
  >
230
251
  {addLabel}
231
252
  </Button>
232
- <Button
233
- variant="secondary"
234
- size={touch ? "md" : "sm"}
235
- icon={<SlidersHorizontal className="size-3.5" />}
236
- onClick={carryingTheZone(onReview)}
237
- aria-describedby={settlement.settled ? undefined : reasonId}
238
- className={cn(
239
- touch && "min-h-11",
240
- !settlement.settled && "opacity-55",
241
- )}
242
- >
243
- Change first
244
- </Button>
253
+ {onReview && (
254
+ <Button
255
+ variant="secondary"
256
+ size={touch ? "md" : "sm"}
257
+ icon={<SlidersHorizontal className="size-3.5" />}
258
+ onClick={carryingTheZone(onReview)}
259
+ disabled={busy}
260
+ aria-describedby={settlement.settled ? undefined : reasonId}
261
+ className={cn(
262
+ touch && "min-h-11",
263
+ !settlement.settled && "opacity-55",
264
+ )}
265
+ >
266
+ Change first
267
+ </Button>
268
+ )}
245
269
  </div>
246
270
  </article>
247
271
  );