@rapidmx/web-client 0.14.1 → 0.15.1
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/apps/admin/domains/[uid].tsx +3 -2
- package/apps/shared/appearance/AppearanceForm.tsx +9 -1
- package/apps/shared/calendar/bookingPlugin.ts +100 -0
- package/apps/shared/calendar/calendarLiveUpdates.ts +27 -0
- package/apps/shared/components/admin/layout/AdminShell.tsx +37 -5
- package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +3 -1
- package/apps/shared/components/admin/settings/PluginsManager.tsx +1545 -1491
- package/apps/shared/components/calendar/AppointmentQuickForm.tsx +327 -0
- package/apps/shared/components/calendar/DescriptionEditor.tsx +274 -0
- package/apps/shared/components/calendar/EventDescriptionView.tsx +70 -0
- package/apps/shared/components/calendar/EventDetails.tsx +401 -0
- package/apps/shared/components/calendar/EventEditor.tsx +640 -0
- package/apps/shared/components/calendar/EventExpandedForm.tsx +210 -0
- package/apps/shared/components/calendar/EventFormParts.tsx +622 -0
- package/apps/shared/components/calendar/EventModal.tsx +126 -866
- package/apps/shared/components/calendar/EventQuickForm.tsx +116 -0
- package/apps/shared/components/calendar/EventShell.tsx +202 -0
- package/apps/shared/components/calendar/FindATime.tsx +379 -0
- package/apps/shared/components/calendar/LazyDescriptionEditor.tsx +70 -0
- package/apps/shared/components/calendar/MonthView.tsx +15 -3
- package/apps/shared/components/calendar/QuickCreateFaces.tsx +87 -0
- package/apps/shared/components/calendar/QuickCreateTabs.tsx +81 -0
- package/apps/shared/components/calendar/QuickFaceFrame.tsx +81 -0
- package/apps/shared/components/calendar/RecurrenceEditor.tsx +10 -5
- package/apps/shared/components/calendar/RequestChangeForm.tsx +271 -0
- package/apps/shared/components/calendar/SplitDayView.tsx +6 -5
- package/apps/shared/components/calendar/TaskQuickForm.tsx +289 -0
- package/apps/shared/components/calendar/TimeGridView.tsx +8 -6
- package/apps/shared/components/calendar/eventDialogFields.ts +86 -0
- package/apps/shared/components/calendar/eventForm.ts +108 -0
- package/apps/shared/components/calendar/eventFormat.ts +183 -0
- package/apps/shared/components/calendar/findTimeGrid.ts +90 -0
- package/apps/shared/components/calendar/swipeNavigation.ts +14 -0
- package/apps/shared/components/layout/UserMenu.tsx +80 -28
- package/apps/shared/components/mail/ConversationList.tsx +100 -48
- package/apps/shared/components/mail/ConversationThreadPane.tsx +490 -486
- package/apps/shared/components/mail/InviteCard.tsx +387 -0
- package/apps/shared/components/mail/MessageDetailPane.tsx +24 -2
- package/apps/shared/components/mail/SwipeRow.tsx +120 -0
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +7 -3
- package/apps/shared/components/mail/invite/InviteRowChip.tsx +104 -0
- package/apps/shared/components/mail/invite/InviteRsvpPopover.tsx +271 -0
- package/apps/shared/components/mail/invite/InviteTimeline.tsx +200 -0
- package/apps/shared/components/mail/invite/ProposeTimeForm.tsx +109 -0
- package/apps/shared/components/mail/invite/inviteFormat.ts +110 -0
- package/apps/shared/components/mail/invite/inviteStore.ts +114 -0
- package/apps/shared/components/mail/layout/MailShell.tsx +522 -490
- package/apps/shared/components/settings/layout/SettingsShell.tsx +1 -0
- package/apps/shared/gestures/useEnterSlide.ts +54 -0
- package/apps/shared/gestures/useSwipe.ts +114 -0
- package/apps/shared/gestures/useSwipeSlide.ts +113 -0
- package/apps/shared/gestures/useWheelPaging.ts +107 -0
- package/apps/shared/mail/newMailNotifications.ts +171 -183
- package/apps/shared/mail/useNewMailNotifications.ts +178 -178
- package/apps/shared/notifications/preferences.ts +36 -0
- package/apps/shared/notifications/store.ts +560 -551
- package/apps/www/_routes.ts +1 -0
- package/apps/www/calendar/index.tsx +139 -37
- package/apps/www/index.tsx +273 -126
- package/apps/www/messages/[uid].tsx +31 -4
- package/apps/www/settings/profile/index.tsx +248 -0
- package/dist/apps/admin/domains/[uid].js +4 -2
- package/dist/apps/shared/appearance/AppearanceForm.js +9 -1
- package/dist/apps/shared/calendar/bookingPlugin.d.ts +50 -0
- package/dist/apps/shared/calendar/bookingPlugin.js +57 -0
- package/dist/apps/shared/calendar/calendarLiveUpdates.d.ts +11 -0
- package/dist/apps/shared/calendar/calendarLiveUpdates.js +23 -0
- package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +1 -1
- package/dist/apps/shared/components/admin/layout/AdminShell.js +7 -3
- package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +3 -1
- package/dist/apps/shared/components/admin/settings/PluginsManager.js +40 -6
- package/dist/apps/shared/components/calendar/AppointmentQuickForm.d.ts +47 -0
- package/dist/apps/shared/components/calendar/AppointmentQuickForm.js +135 -0
- package/dist/apps/shared/components/calendar/DescriptionEditor.d.ts +26 -0
- package/dist/apps/shared/components/calendar/DescriptionEditor.js +192 -0
- package/dist/apps/shared/components/calendar/EventDescriptionView.d.ts +14 -0
- package/dist/apps/shared/components/calendar/EventDescriptionView.js +39 -0
- package/dist/apps/shared/components/calendar/EventDetails.d.ts +33 -0
- package/dist/apps/shared/components/calendar/EventDetails.js +137 -0
- package/dist/apps/shared/components/calendar/EventEditor.d.ts +59 -0
- package/dist/apps/shared/components/calendar/EventEditor.js +549 -0
- package/dist/apps/shared/components/calendar/EventExpandedForm.d.ts +14 -0
- package/dist/apps/shared/components/calendar/EventExpandedForm.js +44 -0
- package/dist/apps/shared/components/calendar/EventFormParts.d.ts +69 -0
- package/dist/apps/shared/components/calendar/EventFormParts.js +202 -0
- package/dist/apps/shared/components/calendar/EventModal.d.ts +26 -13
- package/dist/apps/shared/components/calendar/EventModal.js +57 -459
- package/dist/apps/shared/components/calendar/EventQuickForm.d.ts +18 -0
- package/dist/apps/shared/components/calendar/EventQuickForm.js +25 -0
- package/dist/apps/shared/components/calendar/EventShell.d.ts +64 -0
- package/dist/apps/shared/components/calendar/EventShell.js +134 -0
- package/dist/apps/shared/components/calendar/FindATime.d.ts +18 -0
- package/dist/apps/shared/components/calendar/FindATime.js +190 -0
- package/dist/apps/shared/components/calendar/LazyDescriptionEditor.d.ts +8 -0
- package/dist/apps/shared/components/calendar/LazyDescriptionEditor.js +44 -0
- package/dist/apps/shared/components/calendar/MonthView.d.ts +5 -1
- package/dist/apps/shared/components/calendar/MonthView.js +11 -5
- package/dist/apps/shared/components/calendar/QuickCreateFaces.d.ts +30 -0
- package/dist/apps/shared/components/calendar/QuickCreateFaces.js +44 -0
- package/dist/apps/shared/components/calendar/QuickCreateTabs.d.ts +24 -0
- package/dist/apps/shared/components/calendar/QuickCreateTabs.js +46 -0
- package/dist/apps/shared/components/calendar/QuickFaceFrame.d.ts +25 -0
- package/dist/apps/shared/components/calendar/QuickFaceFrame.js +19 -0
- package/dist/apps/shared/components/calendar/RecurrenceEditor.d.ts +4 -1
- package/dist/apps/shared/components/calendar/RecurrenceEditor.js +2 -2
- package/dist/apps/shared/components/calendar/RequestChangeForm.d.ts +36 -0
- package/dist/apps/shared/components/calendar/RequestChangeForm.js +138 -0
- package/dist/apps/shared/components/calendar/SplitDayView.d.ts +3 -2
- package/dist/apps/shared/components/calendar/SplitDayView.js +3 -2
- package/dist/apps/shared/components/calendar/TaskQuickForm.d.ts +40 -0
- package/dist/apps/shared/components/calendar/TaskQuickForm.js +101 -0
- package/dist/apps/shared/components/calendar/TimeGridView.d.ts +4 -2
- package/dist/apps/shared/components/calendar/TimeGridView.js +3 -2
- package/dist/apps/shared/components/calendar/eventDialogFields.d.ts +28 -0
- package/dist/apps/shared/components/calendar/eventDialogFields.js +59 -0
- package/dist/apps/shared/components/calendar/eventForm.d.ts +98 -0
- package/dist/apps/shared/components/calendar/eventForm.js +1 -0
- package/dist/apps/shared/components/calendar/eventFormat.d.ts +67 -0
- package/dist/apps/shared/components/calendar/eventFormat.js +163 -0
- package/dist/apps/shared/components/calendar/findTimeGrid.d.ts +30 -0
- package/dist/apps/shared/components/calendar/findTimeGrid.js +83 -0
- package/dist/apps/shared/components/calendar/swipeNavigation.d.ts +9 -0
- package/dist/apps/shared/components/calendar/swipeNavigation.js +8 -0
- package/dist/apps/shared/components/layout/UserMenu.d.ts +10 -8
- package/dist/apps/shared/components/layout/UserMenu.js +70 -23
- package/dist/apps/shared/components/mail/ConversationList.d.ts +12 -1
- package/dist/apps/shared/components/mail/ConversationList.js +21 -4
- package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +4 -1
- package/dist/apps/shared/components/mail/InviteCard.d.ts +20 -0
- package/dist/apps/shared/components/mail/InviteCard.js +150 -0
- package/dist/apps/shared/components/mail/MessageDetailPane.js +13 -2
- package/dist/apps/shared/components/mail/SwipeRow.d.ts +22 -0
- package/dist/apps/shared/components/mail/SwipeRow.js +71 -0
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +8 -3
- package/dist/apps/shared/components/mail/invite/InviteRowChip.d.ts +23 -0
- package/dist/apps/shared/components/mail/invite/InviteRowChip.js +46 -0
- package/dist/apps/shared/components/mail/invite/InviteRsvpPopover.d.ts +20 -0
- package/dist/apps/shared/components/mail/invite/InviteRsvpPopover.js +141 -0
- package/dist/apps/shared/components/mail/invite/InviteTimeline.d.ts +27 -0
- package/dist/apps/shared/components/mail/invite/InviteTimeline.js +120 -0
- package/dist/apps/shared/components/mail/invite/ProposeTimeForm.d.ts +17 -0
- package/dist/apps/shared/components/mail/invite/ProposeTimeForm.js +45 -0
- package/dist/apps/shared/components/mail/invite/inviteFormat.d.ts +28 -0
- package/dist/apps/shared/components/mail/invite/inviteFormat.js +94 -0
- package/dist/apps/shared/components/mail/invite/inviteStore.d.ts +28 -0
- package/dist/apps/shared/components/mail/invite/inviteStore.js +95 -0
- package/dist/apps/shared/components/mail/layout/MailShell.d.ts +5 -0
- package/dist/apps/shared/components/mail/layout/MailShell.js +14 -3
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +1 -0
- package/dist/apps/shared/gestures/useEnterSlide.d.ts +14 -0
- package/dist/apps/shared/gestures/useEnterSlide.js +47 -0
- package/dist/apps/shared/gestures/useSwipe.d.ts +45 -0
- package/dist/apps/shared/gestures/useSwipe.js +90 -0
- package/dist/apps/shared/gestures/useSwipeSlide.d.ts +40 -0
- package/dist/apps/shared/gestures/useSwipeSlide.js +95 -0
- package/dist/apps/shared/gestures/useWheelPaging.d.ts +32 -0
- package/dist/apps/shared/gestures/useWheelPaging.js +85 -0
- package/dist/apps/shared/mail/newMailNotifications.d.ts +3 -8
- package/dist/apps/shared/mail/newMailNotifications.js +3 -12
- package/dist/apps/shared/mail/useNewMailNotifications.js +3 -2
- package/dist/apps/shared/notifications/preferences.d.ts +13 -0
- package/dist/apps/shared/notifications/preferences.js +36 -0
- package/dist/apps/shared/notifications/store.d.ts +1 -0
- package/dist/apps/shared/notifications/store.js +7 -23
- package/dist/apps/www/_routes.js +1 -0
- package/dist/apps/www/calendar/index.js +76 -6
- package/dist/apps/www/index.js +140 -39
- package/dist/apps/www/messages/[uid].js +13 -5
- package/dist/apps/www/settings/profile/index.d.ts +4 -0
- package/dist/apps/www/settings/profile/index.js +124 -0
- package/package.json +2 -2
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import { format } from "date-fns";
|
|
6
|
+
import { Attendee, AttendeeResponseStatus, BusyStatus, EventVisibility, GuestPermissions } from "@rapidmx/react-shared/calendar/calendarApi.js";
|
|
7
|
+
import { fromEventWallClock, toEventWallClock } from "@rapidmx/react-shared/calendar/recurrence.js";
|
|
8
|
+
import { toDatetimeLocal } from "@rapidmx/react-shared/util/dateInput.js";
|
|
9
|
+
import { addDaysToKey, allDayDateKey } from "./allDay.js";
|
|
10
|
+
|
|
11
|
+
/** What the event form and the read-only event view both need to say about a busy status / an answer. */
|
|
12
|
+
export const BUSY_STATUSES: BusyStatus[] = ["busy", "free", "tentative", "oof"];
|
|
13
|
+
export const BUSY_STATUS_LABEL: Record<BusyStatus, string> = { busy: "Busy", free: "Free", tentative: "Tentative", oof: "Out of office" };
|
|
14
|
+
/** Who may see an event's details, in the order the form lists them. */
|
|
15
|
+
export const VISIBILITIES: EventVisibility[] = ["default", "public", "private", "confidential"];
|
|
16
|
+
export const VISIBILITY_LABEL: Record<EventVisibility, string> = {
|
|
17
|
+
default: "Default visibility",
|
|
18
|
+
public: "Public",
|
|
19
|
+
private: "Private",
|
|
20
|
+
confidential: "Confidential",
|
|
21
|
+
};
|
|
22
|
+
/** What each visibility means here, where a reader of a shared calendar sees only a busy block for a private or confidential event. */
|
|
23
|
+
export const VISIBILITY_HELP: Record<EventVisibility, string> = {
|
|
24
|
+
default: "People who can see this calendar see the event's details, as the calendar's sharing allows.",
|
|
25
|
+
public: "Everyone who can see this calendar sees the event's details.",
|
|
26
|
+
private: "Only you and people who can edit this calendar see the details. Everyone else who can see the calendar sees a busy block.",
|
|
27
|
+
confidential:
|
|
28
|
+
"Shown like a private event on your calendar: only you and people who can edit it see the details. The invitation marks the event confidential for other calendar programs.",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** What guests may do, as a sentence: "Guests can modify the event, invite others and see the guest list." (or, when they can do none of it, what they cannot). */
|
|
32
|
+
export function describeGuestPermissions(permissions: GuestPermissions): string {
|
|
33
|
+
const can = [
|
|
34
|
+
permissions.guestsCanModify && "modify the event",
|
|
35
|
+
permissions.guestsCanInviteOthers && "invite others",
|
|
36
|
+
permissions.guestsCanSeeGuestList && "see the guest list",
|
|
37
|
+
].filter((text): text is string => !!text);
|
|
38
|
+
if (can.length === 0) {
|
|
39
|
+
return "Guests can't modify the event, invite others or see the guest list.";
|
|
40
|
+
}
|
|
41
|
+
return `Guests can ${can.length === 1 ? can[0] : `${can.slice(0, -1).join(", ")} and ${can[can.length - 1]}`}.`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const RESPONSE_STATUS_LABEL: Record<AttendeeResponseStatus, string> = {
|
|
45
|
+
needsAction: "Awaiting response",
|
|
46
|
+
accepted: "Accepted",
|
|
47
|
+
declined: "Declined",
|
|
48
|
+
tentative: "Tentative",
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** The units a reminder's lead time can be entered in - the event itself stores only minutes. */
|
|
52
|
+
export const REMINDER_UNITS = [
|
|
53
|
+
{ unit: "minutes", singular: "minute", factor: 1 },
|
|
54
|
+
{ unit: "hours", singular: "hour", factor: 60 },
|
|
55
|
+
{ unit: "days", singular: "day", factor: 1440 },
|
|
56
|
+
{ unit: "weeks", singular: "week", factor: 10080 },
|
|
57
|
+
] as const;
|
|
58
|
+
export type ReminderUnit = (typeof REMINDER_UNITS)[number]["unit"];
|
|
59
|
+
|
|
60
|
+
/** The unit a stored reminder reads best in: the largest that divides it evenly (`0` and odd values stay in minutes). */
|
|
61
|
+
export function bestReminderUnit(minutes: number): (typeof REMINDER_UNITS)[number] {
|
|
62
|
+
for (let i = REMINDER_UNITS.length - 1; i > 0; i--) {
|
|
63
|
+
if (minutes > 0 && minutes % REMINDER_UNITS[i].factor === 0) {
|
|
64
|
+
return REMINDER_UNITS[i];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return REMINDER_UNITS[0];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** "Notify 30 minutes before" / "Notify 1 hour before" / "Notify at the start" for a stored reminder, or "No notification". */
|
|
71
|
+
export function describeReminder(minutes: number | undefined): string {
|
|
72
|
+
if (minutes === undefined || !Number.isFinite(minutes) || minutes < 0) {
|
|
73
|
+
return "No notification";
|
|
74
|
+
}
|
|
75
|
+
if (minutes === 0) {
|
|
76
|
+
return "Notify at the start";
|
|
77
|
+
}
|
|
78
|
+
const unit = bestReminderUnit(minutes);
|
|
79
|
+
const amount = minutes / unit.factor;
|
|
80
|
+
return `Notify ${amount} ${amount === 1 ? unit.singular : unit.unit} before`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Splits what was typed into the guests field into its addresses: commas, semicolons and white space separate them. */
|
|
84
|
+
export function splitGuestInput(text: string): string[] {
|
|
85
|
+
return text.split(/[,;\s]+/).filter(Boolean);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The loosest address check that is still worth making before an invitation is sent: something, an @, something. */
|
|
89
|
+
export function isValidGuestAddress(address: string): boolean {
|
|
90
|
+
return /^[^\s@<>,;]+@[^\s@<>,;]+$/.test(address);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** An attendee as the guests field adds one. */
|
|
94
|
+
export function newGuest(address: string): Attendee {
|
|
95
|
+
return { address, role: "required", responseStatus: "needsAction", isOrganizer: false };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The wall-clock string a form input holds ("YYYY-MM-DDTHH:mm") read as `zone`'s clock, as an instant. `deviceZone` is the zone the browser
|
|
99
|
+
* itself parses such a string in, which needs no conversion. */
|
|
100
|
+
export function wallStringToMs(value: string, zone: string, deviceZone: string): number {
|
|
101
|
+
if (zone === deviceZone) {
|
|
102
|
+
return new Date(value).getTime();
|
|
103
|
+
}
|
|
104
|
+
const wall = Date.parse(`${value.slice(0, 16)}:00Z`);
|
|
105
|
+
return Number.isNaN(wall) ? Number.NaN : fromEventWallClock(wall, zone, false);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Inverse of `wallStringToMs()`. */
|
|
109
|
+
export function msToWallString(ms: number, zone: string, deviceZone: string): string {
|
|
110
|
+
if (zone === deviceZone) {
|
|
111
|
+
return toDatetimeLocal(new Date(ms).toISOString());
|
|
112
|
+
}
|
|
113
|
+
return new Date(toEventWallClock(ms, zone, false)).toISOString().slice(0, 16);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A local `Date` for a `YYYY-MM-DD` key (a plain `new Date(key)` would read it as UTC). */
|
|
117
|
+
export function localDateFromKey(key: string): Date {
|
|
118
|
+
const [year, month, day] = key.split("-").map(Number);
|
|
119
|
+
return new Date(year, month - 1, day);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function dayLabel(day: Date, now: Date): string {
|
|
123
|
+
return format(day, day.getFullYear() === now.getFullYear() ? "EEEE, MMMM d" : "EEEE, MMMM d, yyyy");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* "Thursday, September 24 2:00pm – 3:00pm" for a timed event ("Thursday, September 24 – Friday, September 25" style, with both
|
|
128
|
+
* days, when it crosses midnight), or "Thursday, September 24" (and the last day, when it spans several) for an all-day one. `start`
|
|
129
|
+
* and `end` are local wall-clock `Date`s - for an all-day event the first and the (inclusive) last day. The year is left out for
|
|
130
|
+
* the current one.
|
|
131
|
+
*/
|
|
132
|
+
export function formatWhen(start: Date, end: Date, allDay: boolean, now: Date = new Date()): string {
|
|
133
|
+
const first = dayLabel(start, now);
|
|
134
|
+
if (allDay) {
|
|
135
|
+
return end.getTime() > start.getTime() ? `${first} – ${dayLabel(end, now)}` : first;
|
|
136
|
+
}
|
|
137
|
+
const startTime = format(start, "h:mmaaa");
|
|
138
|
+
const endTime = format(end, "h:mmaaa");
|
|
139
|
+
if (format(start, "yyyy-MM-dd") === format(end, "yyyy-MM-dd")) {
|
|
140
|
+
return `${first} ${startTime} – ${endTime}`;
|
|
141
|
+
}
|
|
142
|
+
return `${first} ${startTime} – ${dayLabel(end, now)} ${endTime}`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** `formatWhen()` for a stored event: instants for a timed one, the date-only keys (with the exclusive end) for an all-day one. */
|
|
146
|
+
export function formatStoredWhen(startDate: string, endDate: string, allDay: boolean, now: Date = new Date()): string {
|
|
147
|
+
if (allDay) {
|
|
148
|
+
const startKey = allDayDateKey(startDate);
|
|
149
|
+
const lastKey = addDaysToKey(allDayDateKey(endDate), -1);
|
|
150
|
+
return formatWhen(localDateFromKey(startKey), localDateFromKey(lastKey < startKey ? startKey : lastKey), true, now);
|
|
151
|
+
}
|
|
152
|
+
return formatWhen(new Date(startDate), new Date(endDate), false, now);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Adds the addresses typed into the guests field to `current`: an address already on the list (in any case) is skipped, and what is not an
|
|
156
|
+
* address comes back as `invalid` for the field to keep. */
|
|
157
|
+
export function mergeGuests(current: Attendee[], text: string): { attendees: Attendee[]; invalid: string[] } {
|
|
158
|
+
const attendees = [...current];
|
|
159
|
+
const invalid: string[] = [];
|
|
160
|
+
for (const token of splitGuestInput(text)) {
|
|
161
|
+
if (!isValidGuestAddress(token)) {
|
|
162
|
+
invalid.push(token);
|
|
163
|
+
} else if (!attendees.some((a) => a.address.toLowerCase() === token.toLowerCase())) {
|
|
164
|
+
attendees.push(newGuest(token));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return { attendees, invalid };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** `formatWhen()` for the form's own wall-clock strings (an all-day event's `end` is its inclusive last day); a message while either is empty. */
|
|
171
|
+
export function formatFormWhen(start: string, end: string, allDay: boolean, now: Date = new Date()): string {
|
|
172
|
+
const first = allDay ? localDateFromKey(start.slice(0, 10)) : new Date(start);
|
|
173
|
+
const last = allDay ? localDateFromKey(end.slice(0, 10)) : new Date(end);
|
|
174
|
+
if (Number.isNaN(first.getTime()) || Number.isNaN(last.getTime())) {
|
|
175
|
+
return "Pick a date and time";
|
|
176
|
+
}
|
|
177
|
+
return formatWhen(first, last, allDay, now);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** A reminder as the form holds it (minutes, as typed; blank meaning none) as the number of minutes, or `undefined` for none. */
|
|
181
|
+
export function reminderOf(text: string): number | undefined {
|
|
182
|
+
return text.trim() === "" ? undefined : Number(text);
|
|
183
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import { format } from "date-fns";
|
|
6
|
+
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
7
|
+
import { AvailabilitySummary } from "@rapidmx/react-shared/calendar/freeBusyApi.js";
|
|
8
|
+
import { addDaysToKey } from "./allDay.js";
|
|
9
|
+
import { msToWallString, wallStringToMs } from "./eventFormat.js";
|
|
10
|
+
|
|
11
|
+
/** How many days, from the one on show, one look-up covers: the grid's own day and the days the suggested times are found in. */
|
|
12
|
+
export const SEARCH_DAYS = 7;
|
|
13
|
+
/** The working day suggestions are found in, in the hours of the zone the event is being set in. */
|
|
14
|
+
export const WORK_START_HOUR = 8;
|
|
15
|
+
export const WORK_END_HOUR = 18;
|
|
16
|
+
|
|
17
|
+
/** Whether `value` is a `YYYY-MM-DD` key. */
|
|
18
|
+
export function isDayKey(value: string): boolean {
|
|
19
|
+
return /^\d{4}-\d{2}-\d{2}$/.test(value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The instant a `YYYY-MM-DD` day starts in `zone` (`deviceZone` is the zone the browser itself parses a wall clock in). */
|
|
23
|
+
export function dayStartMs(dayKey: string, zone: string, deviceZone: string): number {
|
|
24
|
+
return wallStringToMs(`${dayKey}T00:00`, zone, deviceZone);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The stretches suggestions may fall in: each of the `SEARCH_DAYS` days from `dayKey`, 8:00 to 18:00 in `zone` - the first day always, the others only when
|
|
28
|
+
* they are a weekday. */
|
|
29
|
+
export function workingWindows(dayKey: string, zone: string, deviceZone: string): { startMs: number; endMs: number }[] {
|
|
30
|
+
const windows: { startMs: number; endMs: number }[] = [];
|
|
31
|
+
for (let offset = 0; offset < SEARCH_DAYS; offset++) {
|
|
32
|
+
const key = addDaysToKey(dayKey, offset);
|
|
33
|
+
const weekday = new Date(`${key}T12:00:00Z`).getUTCDay();
|
|
34
|
+
if (offset === 0 || (weekday >= 1 && weekday <= 5)) {
|
|
35
|
+
windows.push({
|
|
36
|
+
startMs: wallStringToMs(`${key}T${String(WORK_START_HOUR).padStart(2, "0")}:00`, zone, deviceZone),
|
|
37
|
+
endMs: wallStringToMs(`${key}T${String(WORK_END_HOUR).padStart(2, "0")}:00`, zone, deviceZone),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return windows;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Where an instant falls on the grid of `dayKey`, as minutes since that day's midnight on `zone`'s clock (so it lines up with the hour labels, whatever a
|
|
46
|
+
* daylight-saving change did to the day's length): 0 for anything before the day, 1440 for anything after it.
|
|
47
|
+
*/
|
|
48
|
+
export function minuteOfDay(ms: number, dayKey: string, zone: string, deviceZone: string): number {
|
|
49
|
+
const wall = msToWallString(ms, zone, deviceZone);
|
|
50
|
+
const date = wall.slice(0, 10);
|
|
51
|
+
if (date < dayKey) {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
if (date > dayKey) {
|
|
55
|
+
return 1440;
|
|
56
|
+
}
|
|
57
|
+
return Number(wall.slice(11, 13)) * 60 + Number(wall.slice(14, 16));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** "9:00am" for an instant on `zone`'s clock. */
|
|
61
|
+
export function clockLabel(ms: number, zone: string, deviceZone: string): string {
|
|
62
|
+
return format(new Date(msToWallString(ms, zone, deviceZone)), "h:mmaaa");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** What a failed look-up says: the wait for a rate limit, the server's own reason, or a plain failure. */
|
|
66
|
+
export function freeBusyErrorMessage(err: unknown): string {
|
|
67
|
+
if (err instanceof ApiRequestError) {
|
|
68
|
+
return err.status === 429 ? "Too many availability look-ups just now. Wait a moment and try again." : err.message;
|
|
69
|
+
}
|
|
70
|
+
return "Couldn't load availability. Check your connection and try again.";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The one line under the grid about the proposed time. "Everyone is free" is only ever said when every person could be checked and none is busy: someone
|
|
75
|
+
* whose availability is unknown (an external guest, or somebody who hides their calendar) is said so, never counted as free.
|
|
76
|
+
*/
|
|
77
|
+
export function summaryLine(summary: AvailabilitySummary): string {
|
|
78
|
+
const parts: string[] = [];
|
|
79
|
+
if (summary.conflicts > 0) {
|
|
80
|
+
parts.push(`${summary.conflicts} ${summary.conflicts === 1 ? "conflict" : "conflicts"}${summary.tentative > 0 ? ` (${summary.tentative} tentative)` : ""}`);
|
|
81
|
+
} else if (summary.unknown === 0) {
|
|
82
|
+
parts.push("Everyone is free");
|
|
83
|
+
} else {
|
|
84
|
+
parts.push("No conflicts found");
|
|
85
|
+
}
|
|
86
|
+
if (summary.unknown > 0) {
|
|
87
|
+
parts.push(`${summary.unknown} ${summary.unknown === 1 ? "person's availability is" : "people's availability is"} unknown`);
|
|
88
|
+
}
|
|
89
|
+
return parts.join(" · ");
|
|
90
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import type { SwipeDirection } from "../../gestures/useSwipe.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What a horizontal swipe on the phone layout's calendar does, as the direction the visible period moves: `-1` is the previous
|
|
9
|
+
* month/week/day, `1` the next. This is the one place that mapping lives, so it flips in a single line.
|
|
10
|
+
*
|
|
11
|
+
* Swiping left (finger right to left) shows the next period and swiping right shows the previous, as most calendar apps do: the page is
|
|
12
|
+
* dragged along with the finger, and what was to its right comes in.
|
|
13
|
+
*/
|
|
14
|
+
export const SWIPE_PERIOD_SHIFT: Readonly<Record<SwipeDirection, 1 | -1>> = { left: 1, right: -1 };
|
|
@@ -2,25 +2,28 @@
|
|
|
2
2
|
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
3
|
// SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
5
|
+
import React, { useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
6
6
|
import { createPortal } from "react-dom";
|
|
7
|
+
import useIsMobile from "@rapidmx/react-shared/util/useIsMobile.js";
|
|
7
8
|
import { HiOutlineShieldCheck } from "react-icons/hi2";
|
|
8
9
|
import { formatProfileName, getMyProfile, getMyUsername, Profile, profileInitials } from "@rapidmx/react-shared/auth/profileApi.js";
|
|
10
|
+
import { listMailboxes, Mailbox } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
9
11
|
import { accountUrlOf } from "../../auth/accountUrl.js";
|
|
10
12
|
import { DEFAULT_TRUSTED_ROLES, lookUpAdminAccess } from "../../auth/adminAccess.js";
|
|
11
13
|
import { ariaKeyShortcuts } from "../../keyboard/format.js";
|
|
12
14
|
import { SHORTCUTS } from "../../keyboard/keymap.js";
|
|
13
15
|
import { useKeyEnvironment } from "../../keyboard/ShortcutProvider.js";
|
|
14
16
|
import { SETTINGS_HREF } from "../../navigation/appHrefs.js";
|
|
17
|
+
import { MailConnectionContext } from "../../mail/useMailConnection.js";
|
|
15
18
|
import ThemeSwitch from "./ThemeSwitch.js";
|
|
16
19
|
import {
|
|
17
20
|
DesktopPermission,
|
|
18
21
|
desktopPermission,
|
|
19
|
-
getNewMailPopupsEnabled,
|
|
20
22
|
requestDesktopPermission,
|
|
21
23
|
setDesktopOfferDismissed,
|
|
22
|
-
setNewMailPopupsEnabled,
|
|
23
24
|
} from "../../mail/newMailNotifications.js";
|
|
25
|
+
import { getNotificationsEnabled, setNotificationsEnabled } from "../../notifications/preferences.js";
|
|
26
|
+
import { dismissAll } from "../../notifications/store.js";
|
|
24
27
|
|
|
25
28
|
export interface UserMenuProps {
|
|
26
29
|
userUid: string;
|
|
@@ -44,11 +47,11 @@ export interface UserMenuProps {
|
|
|
44
47
|
* `/settings/auto-reply`, the only settings section that exists today; repoint this at a real
|
|
45
48
|
* `/settings` landing page once a second section (Mail Filters, Signatures) makes one worth building. */
|
|
46
49
|
showSettingsLink?: boolean;
|
|
47
|
-
/** Shows the
|
|
48
|
-
* the browser hasn't been asked, "Turn on desktop notifications". Both are per browser (see `
|
|
49
|
-
* For the shells that
|
|
50
|
+
/** Shows the notification controls, above "Admin Console"/"Sign Out": a "Notifications" on/off switch for every pop-up and,
|
|
51
|
+
* while the browser hasn't been asked, "Turn on desktop notifications". Both are per browser (see `notifications/preferences.ts`
|
|
52
|
+
* and `newMailNotifications.ts`). For the shells that draw pop-ups (`AppShell`). */
|
|
50
53
|
showNotificationSettings?: boolean;
|
|
51
|
-
/** Shows a "Keyboard shortcuts" item that calls this - opening the help dialog (`?` and Ctrl+/ do too). For the shells that have the
|
|
54
|
+
/** Shows a "Keyboard shortcuts" item that calls this - opening the help dialog (`?` and Ctrl+/ do too); not on the phone layout. For the shells that have the
|
|
52
55
|
* keyboard layer (`AppChrome`); the consoles don't offer it. */
|
|
53
56
|
onShowShortcuts?: () => void;
|
|
54
57
|
/** Which way the menu opens from its button: `"down"` (the default; in a header) or `"up"` (in a footer, where there is no room below). */
|
|
@@ -84,10 +87,12 @@ function Avatar({ profile, initials, large }: { profile?: Profile; initials: str
|
|
|
84
87
|
* trigger that opens a dropdown showing the caller's avatar/name, an "Account" link to auth-server's account page,
|
|
85
88
|
* an optional "Settings" and "Admin Console" link, and "Sign Out". This service has no local user directory (see
|
|
86
89
|
* `.claude/NOTES.md`), so the name and avatar come from auth-server, and the displayed name (and the initials badge)
|
|
87
|
-
* falls back down a chain: the profile's name (`GET /api/profiles/me`), else the
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
90
|
+
* falls back down a chain: the profile's name (`GET /api/profiles/me`), else the display name of the mailbox the
|
|
91
|
+
* caller owns (`listMailboxes()`, or the list the app frame already holds; a shared or delegated mailbox does not count), else the caller's username - their first
|
|
92
|
+
* verified `name` alias (`GET /api/aliases?type=name`) - else the bare uid. The mailbox and the username are asked for
|
|
93
|
+
* only when the profile gave no name, and the username only when the mailbox gave none. Every lookup can fail
|
|
94
|
+
* (auth-server's CORS list not including this origin, or no profile document at all - a 404 for some accounts) and none
|
|
95
|
+
* ever surfaces as an error. The avatar image comes from the profile alone.
|
|
91
96
|
*/
|
|
92
97
|
export default function UserMenu({
|
|
93
98
|
userUid,
|
|
@@ -104,6 +109,8 @@ export default function UserMenu({
|
|
|
104
109
|
unseenErrors = 0,
|
|
105
110
|
}: UserMenuProps) {
|
|
106
111
|
const env = useKeyEnvironment();
|
|
112
|
+
// A phone has no keyboard to speak of, so the shortcuts list (and the dialog it opens) has nothing to offer there.
|
|
113
|
+
const isMobile = useIsMobile();
|
|
107
114
|
const [open, setOpen] = useState(false);
|
|
108
115
|
// Where the menu sits, in window coordinates: it is drawn through a portal into `<body>` with `position: fixed`, so no ancestor's
|
|
109
116
|
// `overflow`, `z-index` or stacking context - a custom branding header's, say - can clip it or put it behind the page.
|
|
@@ -113,7 +120,14 @@ export default function UserMenu({
|
|
|
113
120
|
const [popups, setPopups] = useState(true);
|
|
114
121
|
const [permission, setPermission] = useState<DesktopPermission>("unsupported");
|
|
115
122
|
const [profile, setProfile] = useState<Profile | undefined>(undefined);
|
|
123
|
+
// Whether the profile lookup has answered, with a profile or without: the fallback names are only worth asking for after that.
|
|
124
|
+
const [profileSettled, setProfileSettled] = useState(false);
|
|
116
125
|
const [username, setUsername] = useState<string | undefined>(undefined);
|
|
126
|
+
// The mailboxes this menu listed itself; `null` until it has, or when it has no need to.
|
|
127
|
+
const [ownListing, setOwnListing] = useState<Mailbox[] | null>(null);
|
|
128
|
+
// Inside the app frame the mailboxes are already listed for the whole session (see `useMailConnection()`), so they are reused, not listed again.
|
|
129
|
+
const connection = useContext(MailConnectionContext);
|
|
130
|
+
const framed = connection !== null;
|
|
117
131
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
118
132
|
|
|
119
133
|
useEffect(() => {
|
|
@@ -126,18 +140,11 @@ export default function UserMenu({
|
|
|
126
140
|
try {
|
|
127
141
|
loaded = await getMyProfile(authServerUrl);
|
|
128
142
|
} catch {
|
|
129
|
-
// Unreachable, blocked, or no profile document (404) - fall through to the
|
|
143
|
+
// Unreachable, blocked, or no profile document (404) - fall through to the fallback names.
|
|
130
144
|
}
|
|
131
|
-
if (cancelled) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
setProfile(loaded);
|
|
135
|
-
// The username is only the fallback for a missing name - no second request when the profile has one.
|
|
136
|
-
if (!formatProfileName(loaded)) {
|
|
137
|
-
const alias = await getMyUsername(authServerUrl);
|
|
138
|
-
if (!cancelled) {
|
|
139
|
-
setUsername(alias);
|
|
140
|
-
}
|
|
145
|
+
if (!cancelled) {
|
|
146
|
+
setProfile(loaded);
|
|
147
|
+
setProfileSettled(true);
|
|
141
148
|
}
|
|
142
149
|
})();
|
|
143
150
|
return () => {
|
|
@@ -145,6 +152,46 @@ export default function UserMenu({
|
|
|
145
152
|
};
|
|
146
153
|
}, [authServerUrl]);
|
|
147
154
|
|
|
155
|
+
// The mailbox's display name and then the username are only fallbacks for a missing name - nothing more is asked when the profile has
|
|
156
|
+
// one, and no username is asked for when the mailbox has a name. Without `authServerUrl` the profile never settles, so nothing is.
|
|
157
|
+
const needsFallbackName = profileSettled && !formatProfileName(profile);
|
|
158
|
+
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (!needsFallbackName || framed) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
let cancelled = false;
|
|
164
|
+
// A failure (no mail server, no access) is just "no mailbox name" - the username is asked for next.
|
|
165
|
+
listMailboxes({ limit: 50 }).then(
|
|
166
|
+
(list) => !cancelled && setOwnListing(Array.isArray(list) ? list : []),
|
|
167
|
+
() => !cancelled && setOwnListing([]),
|
|
168
|
+
);
|
|
169
|
+
return () => {
|
|
170
|
+
cancelled = true;
|
|
171
|
+
};
|
|
172
|
+
}, [needsFallbackName, framed]);
|
|
173
|
+
|
|
174
|
+
// `null` while the mailboxes are still on their way.
|
|
175
|
+
const listed = framed ? (connection.status === "checking" ? null : connection.mailboxes) : ownListing;
|
|
176
|
+
const mailboxesKnown = listed !== null;
|
|
177
|
+
// Only a mailbox the caller owns counts: a shared or delegated one carries somebody else's name.
|
|
178
|
+
const mailboxName = needsFallbackName ? listed?.find((mb) => mb.ownerUserUid === userUid)?.displayName?.trim() || undefined : undefined;
|
|
179
|
+
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
if (!authServerUrl || !needsFallbackName || !mailboxesKnown || mailboxName) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
let cancelled = false;
|
|
185
|
+
void getMyUsername(authServerUrl).then((alias) => {
|
|
186
|
+
if (!cancelled) {
|
|
187
|
+
setUsername(alias);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return () => {
|
|
191
|
+
cancelled = true;
|
|
192
|
+
};
|
|
193
|
+
}, [authServerUrl, needsFallbackName, mailboxesKnown, mailboxName]);
|
|
194
|
+
|
|
148
195
|
// Keyed on the joined names, not the array: a caller's fresh `["admin"]` each render must not re-ask.
|
|
149
196
|
const trustedRolesKey = JSON.stringify(trustedRoles);
|
|
150
197
|
useEffect(() => {
|
|
@@ -166,14 +213,18 @@ export default function UserMenu({
|
|
|
166
213
|
// Read fresh each time the menu opens - another tab may have changed either since - and only on the client.
|
|
167
214
|
useEffect(() => {
|
|
168
215
|
if (open && showNotificationSettings) {
|
|
169
|
-
setPopups(
|
|
216
|
+
setPopups(getNotificationsEnabled());
|
|
170
217
|
setPermission(desktopPermission());
|
|
171
218
|
}
|
|
172
219
|
}, [open, showNotificationSettings]);
|
|
173
220
|
|
|
174
221
|
function togglePopups() {
|
|
175
|
-
|
|
222
|
+
setNotificationsEnabled(!popups);
|
|
176
223
|
setPopups(!popups);
|
|
224
|
+
if (popups) {
|
|
225
|
+
// Turned off: what is on screen goes too (it stays in "Recent notifications").
|
|
226
|
+
dismissAll();
|
|
227
|
+
}
|
|
177
228
|
}
|
|
178
229
|
|
|
179
230
|
async function enableDesktopNotifications() {
|
|
@@ -230,8 +281,9 @@ export default function UserMenu({
|
|
|
230
281
|
};
|
|
231
282
|
}, [open, placement]);
|
|
232
283
|
|
|
233
|
-
const name = formatProfileName(profile) ?? username ?? userUid;
|
|
234
|
-
|
|
284
|
+
const name = formatProfileName(profile) ?? mailboxName ?? username ?? userUid;
|
|
285
|
+
// The badge takes its letter from whichever fallback name is shown, so it never disagrees with the name beside it.
|
|
286
|
+
const initials = profileInitials(profile, userUid, mailboxName ?? username);
|
|
235
287
|
const accountUrl = accountUrlOf(authServerUrl);
|
|
236
288
|
|
|
237
289
|
return (
|
|
@@ -299,7 +351,7 @@ export default function UserMenu({
|
|
|
299
351
|
onClick={togglePopups}
|
|
300
352
|
className="flex w-full items-center justify-between gap-2 px-3.5 py-2 text-left text-sm text-text hover:bg-surface-alt"
|
|
301
353
|
>
|
|
302
|
-
<span>
|
|
354
|
+
<span>Notifications</span>
|
|
303
355
|
<span className="text-xs font-semibold text-text-muted">{popups ? "On" : "Off"}</span>
|
|
304
356
|
</button>
|
|
305
357
|
)}
|
|
@@ -332,7 +384,7 @@ export default function UserMenu({
|
|
|
332
384
|
)}
|
|
333
385
|
</button>
|
|
334
386
|
)}
|
|
335
|
-
{onShowShortcuts && (
|
|
387
|
+
{onShowShortcuts && !isMobile && (
|
|
336
388
|
<button
|
|
337
389
|
role="menuitem"
|
|
338
390
|
type="button"
|