@rapidmx/web-client 0.3.0 → 0.4.0
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/branding/index.tsx +39 -404
- package/apps/admin/domains/[uid].tsx +92 -259
- package/apps/admin/encryption-policy/index.tsx +19 -0
- package/apps/admin/index.tsx +100 -82
- package/apps/admin/mailbox-policy/index.tsx +19 -0
- package/apps/admin/mailboxes/new/index.tsx +28 -291
- package/apps/admin/plugins/index.tsx +15 -0
- package/apps/admin/retention-policy/index.tsx +39 -132
- package/apps/admin/setup/index.tsx +15 -0
- package/apps/shared/components/admin/layout/AdminShell.tsx +249 -210
- package/apps/shared/components/admin/settings/BrandingForm.tsx +374 -0
- package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +176 -0
- package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +104 -0
- package/apps/shared/components/admin/settings/LoadedSettingsForm.tsx +34 -0
- package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +302 -0
- package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +119 -0
- package/apps/shared/components/admin/settings/PluginsManager.tsx +595 -0
- package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +98 -0
- package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +254 -0
- package/apps/shared/components/admin/setup/SetupWizard.tsx +300 -0
- package/apps/shared/components/calendar/CalendarListSidebar.tsx +120 -76
- package/apps/shared/components/calendar/EventModal.tsx +40 -4
- package/apps/shared/components/calendar/layout/CalendarShell.tsx +80 -99
- package/apps/shared/components/contacts/ContactForm.tsx +38 -4
- package/apps/shared/components/layout/AppShell.tsx +198 -169
- package/apps/shared/components/layout/KeyEnrollmentGate.tsx +298 -265
- package/apps/shared/components/layout/UnlockPromptProvider.tsx +128 -0
- package/apps/shared/components/mail/MessageDetailPane.tsx +630 -595
- package/apps/shared/components/mail/compose/ComposeContext.tsx +8 -3
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +930 -765
- package/apps/shared/components/mail/layout/MailShell.tsx +408 -302
- package/apps/shared/components/settings/layout/SettingsShell.tsx +1 -0
- package/apps/shared/mail/findWellKnownFolderUid.ts +13 -0
- package/apps/shared/search/LocalIndexLifecycle.tsx +89 -0
- package/apps/shared/search/localIndexBlockCipher.ts +83 -0
- package/apps/shared/search/localIndexBuilder.ts +179 -0
- package/apps/shared/search/localIndexKey.ts +27 -0
- package/apps/shared/search/localIndexRpcClient.ts +116 -0
- package/apps/shared/search/localIndexSchema.ts +227 -0
- package/apps/shared/search/localIndexSizePreference.ts +88 -0
- package/apps/shared/search/localIndexVFS.ts +235 -0
- package/apps/shared/search/localIndexWorker.ts +464 -0
- package/apps/shared/search/searchTier2.ts +79 -0
- package/apps/shared/search/wa-sqlite-shims.d.ts +44 -0
- package/apps/www/calendar/index.tsx +31 -21
- package/apps/www/contacts/index.tsx +33 -6
- package/apps/www/index.tsx +661 -106
- package/apps/www/messages/[uid].tsx +5 -1
- package/apps/www/settings/encryption/index.tsx +63 -1
- package/apps/www/settings/sharing/index.tsx +271 -0
- package/apps/www/tasks/index.tsx +53 -4
- package/dist/apps/admin/branding/index.js +4 -98
- package/dist/apps/admin/domains/[uid].js +5 -68
- package/dist/apps/admin/encryption-policy/index.js +8 -0
- package/dist/apps/admin/index.js +14 -1
- package/dist/apps/admin/mailbox-policy/index.js +8 -0
- package/dist/apps/admin/mailboxes/new/index.js +4 -89
- package/dist/apps/admin/plugins/index.js +6 -0
- package/dist/apps/admin/retention-policy/index.js +3 -36
- package/dist/apps/admin/setup/index.js +6 -0
- package/dist/apps/shared/components/admin/layout/AdminShell.js +34 -3
- package/dist/apps/shared/components/admin/settings/BrandingForm.js +105 -0
- package/dist/apps/shared/components/admin/settings/DomainDnsSetup.js +77 -0
- package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.js +57 -0
- package/dist/apps/shared/components/admin/settings/LoadedSettingsForm.js +25 -0
- package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +106 -0
- package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.js +52 -0
- package/dist/apps/shared/components/admin/settings/PluginsManager.js +260 -0
- package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.js +44 -0
- package/dist/apps/shared/components/admin/setup/EscrowSetupStep.js +131 -0
- package/dist/apps/shared/components/admin/setup/SetupWizard.js +142 -0
- package/dist/apps/shared/components/calendar/CalendarListSidebar.js +24 -13
- package/dist/apps/shared/components/calendar/EventModal.js +16 -4
- package/dist/apps/shared/components/calendar/layout/CalendarShell.js +47 -39
- package/dist/apps/shared/components/contacts/ContactForm.js +16 -5
- package/dist/apps/shared/components/layout/AppShell.js +30 -7
- package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +15 -3
- package/dist/apps/shared/components/layout/UnlockPromptProvider.js +77 -0
- package/dist/apps/shared/components/mail/MessageDetailPane.js +27 -2
- package/dist/apps/shared/components/mail/compose/ComposeContext.js +2 -2
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +134 -14
- package/dist/apps/shared/components/mail/layout/MailShell.js +106 -40
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +1 -0
- package/dist/apps/shared/mail/findWellKnownFolderUid.js +12 -0
- package/dist/apps/shared/search/LocalIndexLifecycle.js +76 -0
- package/dist/apps/shared/search/localIndexBlockCipher.js +63 -0
- package/dist/apps/shared/search/localIndexBuilder.js +153 -0
- package/dist/apps/shared/search/localIndexKey.js +25 -0
- package/dist/apps/shared/search/localIndexRpcClient.js +78 -0
- package/dist/apps/shared/search/localIndexSchema.js +179 -0
- package/dist/apps/shared/search/localIndexSizePreference.js +78 -0
- package/dist/apps/shared/search/localIndexVFS.js +230 -0
- package/dist/apps/shared/search/localIndexWorker.js +341 -0
- package/dist/apps/shared/search/searchTier2.js +38 -0
- package/dist/apps/www/calendar/index.js +14 -12
- package/dist/apps/www/contacts/index.js +15 -6
- package/dist/apps/www/index.js +496 -94
- package/dist/apps/www/messages/[uid].js +5 -1
- package/dist/apps/www/settings/encryption/index.js +30 -2
- package/dist/apps/www/settings/sharing/index.js +128 -0
- package/dist/apps/www/tasks/index.js +27 -5
- package/package.json +3 -2
|
@@ -3,45 +3,67 @@
|
|
|
3
3
|
// SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
///////////////////////////////////////////////////////////////////////////////
|
|
5
5
|
import React, { FormEvent, useState } from "react";
|
|
6
|
-
import { CALENDAR_COLOR_PALETTE, colorForFolder } from "@rapidmx/react-shared/calendar/calendarColors.js";
|
|
7
|
-
import { Folder } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
6
|
+
import { CALENDAR_COLOR_PALETTE, accentColorForMailbox, colorForFolder } from "@rapidmx/react-shared/calendar/calendarColors.js";
|
|
7
|
+
import { Folder, Mailbox } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
8
8
|
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
9
9
|
|
|
10
|
+
export interface CalendarListSidebarMailbox {
|
|
11
|
+
mailbox: Mailbox;
|
|
12
|
+
calendarFolders: Folder[];
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
export interface CalendarListSidebarProps {
|
|
11
|
-
/** Every `type
|
|
12
|
-
|
|
17
|
+
/** Every accessible mailbox's `calendar`-type folders, grouped per mailbox (see `CalendarShell`). */
|
|
18
|
+
mailboxCalendars: CalendarListSidebarMailbox[];
|
|
13
19
|
checkedFolderUids: Set<string>;
|
|
14
20
|
onToggle: (folderUid: string) => void;
|
|
15
|
-
onAddCalendar: (name: string, color: string) => Promise<void>;
|
|
21
|
+
onAddCalendar: (mailboxUid: string, name: string, color: string) => Promise<void>;
|
|
22
|
+
/** A calendar's display color - defaults to its own `color` (see `CalendarShell`'s `colorFor`). */
|
|
23
|
+
colorFor?: (folder: Folder) => string;
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
/**
|
|
19
|
-
* Calendar's left-sidebar checklist of
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
27
|
+
* Calendar's left-sidebar checklist of calendars — one row per `calendar`-type folder, a color swatch,
|
|
28
|
+
* and a checkbox controlling whether that calendar's events are currently shown (the checked set is owned
|
|
29
|
+
* by `apps/www/calendar/index.tsx`, since it drives which folders get fanned out to on every reload).
|
|
30
|
+
* With one mailbox this is a single "My calendars" list, as before; with several, each mailbox gets its
|
|
31
|
+
* own section (a shared mailbox labeled as such, with a color-dot accent) and its own "+ Add calendar",
|
|
32
|
+
* which creates the calendar in that mailbox. "+ Add calendar" is a real `createFolder({type: "calendar",
|
|
33
|
+
* ...})` call — folder creation has no type restriction server-side, so this needed no new backend route.
|
|
25
34
|
*/
|
|
26
|
-
export default function CalendarListSidebar({
|
|
27
|
-
|
|
35
|
+
export default function CalendarListSidebar({
|
|
36
|
+
mailboxCalendars,
|
|
37
|
+
checkedFolderUids,
|
|
38
|
+
onToggle,
|
|
39
|
+
onAddCalendar,
|
|
40
|
+
colorFor = (folder) => colorForFolder(folder),
|
|
41
|
+
}: CalendarListSidebarProps) {
|
|
42
|
+
const [addingFor, setAddingFor] = useState<string | null>(null);
|
|
28
43
|
const [name, setName] = useState("");
|
|
29
44
|
const [color, setColor] = useState(CALENDAR_COLOR_PALETTE[0]);
|
|
30
45
|
const [error, setError] = useState<string | null>(null);
|
|
31
46
|
const [saving, setSaving] = useState(false);
|
|
47
|
+
const multiple = mailboxCalendars.length > 1;
|
|
48
|
+
|
|
49
|
+
function startAdding(mailboxUid: string) {
|
|
50
|
+
setAddingFor(mailboxUid);
|
|
51
|
+
setName("");
|
|
52
|
+
setColor(CALENDAR_COLOR_PALETTE[0]);
|
|
53
|
+
}
|
|
32
54
|
|
|
33
55
|
async function handleAdd(e: FormEvent) {
|
|
34
56
|
e.preventDefault();
|
|
35
|
-
if (!name.trim()) {
|
|
57
|
+
if (!name.trim() || !addingFor) {
|
|
36
58
|
return;
|
|
37
59
|
}
|
|
38
60
|
setError(null);
|
|
39
61
|
setSaving(true);
|
|
40
62
|
try {
|
|
41
|
-
await onAddCalendar(name.trim(), color);
|
|
63
|
+
await onAddCalendar(addingFor, name.trim(), color);
|
|
42
64
|
setName("");
|
|
43
65
|
setColor(CALENDAR_COLOR_PALETTE[0]);
|
|
44
|
-
|
|
66
|
+
setAddingFor(null);
|
|
45
67
|
} catch {
|
|
46
68
|
setError("Could not create this calendar.");
|
|
47
69
|
} finally {
|
|
@@ -49,71 +71,93 @@ export default function CalendarListSidebar({ calendars, checkedFolderUids, onTo
|
|
|
49
71
|
}
|
|
50
72
|
}
|
|
51
73
|
|
|
52
|
-
|
|
53
|
-
<
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
<input
|
|
74
|
-
type="checkbox"
|
|
75
|
-
checked={checkedFolderUids.has(folder.uid)}
|
|
76
|
-
onChange={() => onToggle(folder.uid)}
|
|
77
|
-
style={{ accentColor: colorForFolder(folder) }}
|
|
78
|
-
/>
|
|
79
|
-
<span aria-hidden="true" className="w-2.5 h-2.5 rounded-full shrink-0" style={{ backgroundColor: colorForFolder(folder) }} />
|
|
80
|
-
<span className="truncate">{folder.name}</span>
|
|
81
|
-
</label>
|
|
74
|
+
const addForm = (
|
|
75
|
+
<form onSubmit={handleAdd} className="flex flex-col gap-1.5 mt-2">
|
|
76
|
+
<input
|
|
77
|
+
type="text"
|
|
78
|
+
autoFocus
|
|
79
|
+
aria-label="New calendar name"
|
|
80
|
+
value={name}
|
|
81
|
+
onChange={(e) => setName(e.target.value)}
|
|
82
|
+
className="text-xs py-1 px-1.5 border border-border rounded-sm bg-surface"
|
|
83
|
+
/>
|
|
84
|
+
<div className="flex items-center gap-1" role="radiogroup" aria-label="Calendar color">
|
|
85
|
+
{CALENDAR_COLOR_PALETTE.map((swatch) => (
|
|
86
|
+
<button
|
|
87
|
+
key={swatch}
|
|
88
|
+
type="button"
|
|
89
|
+
aria-label={`Color ${swatch}`}
|
|
90
|
+
aria-pressed={color === swatch}
|
|
91
|
+
onClick={() => setColor(swatch)}
|
|
92
|
+
className={["w-4 h-4 rounded-full shrink-0", color === swatch ? "ring-2 ring-offset-1 ring-text" : ""].join(" ")}
|
|
93
|
+
style={{ backgroundColor: swatch }}
|
|
94
|
+
/>
|
|
82
95
|
))}
|
|
83
96
|
</div>
|
|
84
|
-
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
<div className="flex items-center gap-2">
|
|
98
|
+
<button type="submit" disabled={saving} className="text-xs font-semibold text-primary-dark">
|
|
99
|
+
Add
|
|
100
|
+
</button>
|
|
101
|
+
<button type="button" onClick={() => setAddingFor(null)} className="text-xs text-text-muted">
|
|
102
|
+
Cancel
|
|
103
|
+
</button>
|
|
104
|
+
</div>
|
|
105
|
+
</form>
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<nav aria-label="My calendars" className="p-3 border-t border-border flex flex-col gap-3">
|
|
110
|
+
{error && <Alert>{error}</Alert>}
|
|
111
|
+
{mailboxCalendars.map(({ mailbox, calendarFolders, error: mailboxError }) => {
|
|
112
|
+
const title = multiple ? `${mailbox.displayName}${mailbox.ownerUserUid ? "" : " (shared)"}` : "My calendars";
|
|
113
|
+
return (
|
|
114
|
+
<div key={mailbox.uid}>
|
|
115
|
+
<div className="flex items-center justify-between mb-1 gap-2">
|
|
116
|
+
<h2 className="flex items-center gap-1.5 text-xs font-bold uppercase tracking-wide text-text-muted min-w-0">
|
|
117
|
+
{multiple && (
|
|
118
|
+
<span
|
|
119
|
+
aria-hidden="true"
|
|
120
|
+
className="w-2 h-2 rounded-full shrink-0"
|
|
121
|
+
style={{ backgroundColor: accentColorForMailbox(mailbox.uid) }}
|
|
122
|
+
/>
|
|
123
|
+
)}
|
|
124
|
+
<span className="truncate">{title}</span>
|
|
125
|
+
</h2>
|
|
96
126
|
<button
|
|
97
|
-
key={swatch}
|
|
98
127
|
type="button"
|
|
99
|
-
|
|
100
|
-
aria-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
<
|
|
112
|
-
|
|
113
|
-
|
|
128
|
+
onClick={() => startAdding(mailbox.uid)}
|
|
129
|
+
aria-label={multiple ? `Add calendar to ${mailbox.displayName}` : "Add calendar"}
|
|
130
|
+
className="text-xs font-bold text-primary-dark hover:underline shrink-0"
|
|
131
|
+
>
|
|
132
|
+
+
|
|
133
|
+
</button>
|
|
134
|
+
</div>
|
|
135
|
+
{mailboxError && (
|
|
136
|
+
<div className="mb-1">
|
|
137
|
+
<Alert>{mailboxError}</Alert>
|
|
138
|
+
</div>
|
|
139
|
+
)}
|
|
140
|
+
<div className="flex flex-col gap-0.5">
|
|
141
|
+
{calendarFolders.map((folder) => (
|
|
142
|
+
<label
|
|
143
|
+
key={folder.uid}
|
|
144
|
+
className="flex items-center gap-2 text-sm px-1 py-1 rounded-sm hover:bg-surface-alt cursor-pointer"
|
|
145
|
+
>
|
|
146
|
+
<input
|
|
147
|
+
type="checkbox"
|
|
148
|
+
checked={checkedFolderUids.has(folder.uid)}
|
|
149
|
+
onChange={() => onToggle(folder.uid)}
|
|
150
|
+
style={{ accentColor: colorFor(folder) }}
|
|
151
|
+
/>
|
|
152
|
+
<span aria-hidden="true" className="w-2.5 h-2.5 rounded-full shrink-0" style={{ backgroundColor: colorFor(folder) }} />
|
|
153
|
+
<span className="truncate">{folder.name}</span>
|
|
154
|
+
</label>
|
|
155
|
+
))}
|
|
156
|
+
</div>
|
|
157
|
+
{addingFor === mailbox.uid && addForm}
|
|
114
158
|
</div>
|
|
115
|
-
|
|
116
|
-
)}
|
|
159
|
+
);
|
|
160
|
+
})}
|
|
117
161
|
</nav>
|
|
118
162
|
);
|
|
119
163
|
}
|
|
@@ -54,6 +54,10 @@ export interface EventModalProps {
|
|
|
54
54
|
* one calendar exists" — no selector is shown and `folderUid` is used as-is, matching this
|
|
55
55
|
* component's original single-calendar behavior exactly. */
|
|
56
56
|
calendars?: { uid: string; name: string }[];
|
|
57
|
+
/** Every mailbox a new event could be created in, each with its own calendars. With more than one, a
|
|
58
|
+
* "Mailbox" selector (create mode only) chooses the mailbox, which in turn drives the Calendar selector
|
|
59
|
+
* and the organizer address; `mailboxUid`/`folderUid` are the initial selection. */
|
|
60
|
+
mailboxOptions?: { mailbox: Mailbox; calendars: { uid: string; name: string }[] }[];
|
|
57
61
|
organizerAddress: string;
|
|
58
62
|
/** `null` when creating a new event. */
|
|
59
63
|
occurrence: CalendarOccurrence | null;
|
|
@@ -77,6 +81,7 @@ export default function EventModal({
|
|
|
77
81
|
mailboxUid,
|
|
78
82
|
folderUid,
|
|
79
83
|
calendars,
|
|
84
|
+
mailboxOptions,
|
|
80
85
|
organizerAddress,
|
|
81
86
|
occurrence,
|
|
82
87
|
initialStart,
|
|
@@ -85,6 +90,19 @@ export default function EventModal({
|
|
|
85
90
|
onDeleted,
|
|
86
91
|
}: EventModalProps) {
|
|
87
92
|
const [targetFolderUid, setTargetFolderUid] = useState(folderUid);
|
|
93
|
+
const [targetMailboxUid, setTargetMailboxUid] = useState(mailboxUid);
|
|
94
|
+
const targetMailboxOption = mailboxOptions?.find((option) => option.mailbox.uid === targetMailboxUid);
|
|
95
|
+
// Create mode follows the chosen mailbox; editing an existing event always keeps the passed-in values.
|
|
96
|
+
const calendarChoices = !occurrence && targetMailboxOption ? targetMailboxOption.calendars : calendars;
|
|
97
|
+
const effectiveOrganizerAddress = !occurrence && targetMailboxOption ? targetMailboxOption.mailbox.primarySmtpAddress : organizerAddress;
|
|
98
|
+
|
|
99
|
+
function handleMailboxChange(nextMailboxUid: string) {
|
|
100
|
+
setTargetMailboxUid(nextMailboxUid);
|
|
101
|
+
const firstCalendar = mailboxOptions?.find((option) => option.mailbox.uid === nextMailboxUid)?.calendars[0];
|
|
102
|
+
if (firstCalendar) {
|
|
103
|
+
setTargetFolderUid(firstCalendar.uid);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
88
106
|
const [title, setTitle] = useState(occurrence?.title ?? "");
|
|
89
107
|
const [location, setLocation] = useState(occurrence?.location ?? "");
|
|
90
108
|
const [start, setStart] = useState(toDatetimeLocal(occurrence?.startDate ?? initialStart?.toISOString() ?? new Date().toISOString()));
|
|
@@ -150,7 +168,7 @@ export default function EventModal({
|
|
|
150
168
|
endDate: new Date(end).toISOString(),
|
|
151
169
|
allDay,
|
|
152
170
|
timezone,
|
|
153
|
-
organizer: { address:
|
|
171
|
+
organizer: { address: effectiveOrganizerAddress, type: "to" },
|
|
154
172
|
attendees,
|
|
155
173
|
recurrenceRule: recurrenceRule ?? undefined,
|
|
156
174
|
reminderMinutesBeforeStart: reminderMinutes.trim() ? Number(reminderMinutes) : undefined,
|
|
@@ -162,7 +180,7 @@ export default function EventModal({
|
|
|
162
180
|
setSaving(true);
|
|
163
181
|
try {
|
|
164
182
|
if (!occurrence) {
|
|
165
|
-
await createCalendarEvent({ mailboxUid, folderUid: targetFolderUid, ...fields } as CalendarEventInput);
|
|
183
|
+
await createCalendarEvent({ mailboxUid: targetMailboxUid, folderUid: targetFolderUid, ...fields } as CalendarEventInput);
|
|
166
184
|
} else if (occurrence.isRecurringOccurrence && editScope === "occurrence") {
|
|
167
185
|
await detachOccurrence(occurrence, fields);
|
|
168
186
|
} else if (occurrence.isRecurringOccurrence) {
|
|
@@ -222,7 +240,25 @@ export default function EventModal({
|
|
|
222
240
|
<form onSubmit={handleSubmit} className="flex flex-col gap-1">
|
|
223
241
|
{error && <Alert>{error}</Alert>}
|
|
224
242
|
|
|
225
|
-
{!occurrence &&
|
|
243
|
+
{!occurrence && mailboxOptions && mailboxOptions.length > 1 && (
|
|
244
|
+
<FormField label="Mailbox" htmlFor="event-mailbox">
|
|
245
|
+
<select
|
|
246
|
+
id="event-mailbox"
|
|
247
|
+
className={INPUT_CLASS}
|
|
248
|
+
value={targetMailboxUid}
|
|
249
|
+
onChange={(e) => handleMailboxChange(e.target.value)}
|
|
250
|
+
>
|
|
251
|
+
{mailboxOptions.map(({ mailbox }) => (
|
|
252
|
+
<option key={mailbox.uid} value={mailbox.uid}>
|
|
253
|
+
{mailbox.displayName}
|
|
254
|
+
{mailbox.ownerUserUid ? "" : " (shared)"}
|
|
255
|
+
</option>
|
|
256
|
+
))}
|
|
257
|
+
</select>
|
|
258
|
+
</FormField>
|
|
259
|
+
)}
|
|
260
|
+
|
|
261
|
+
{!occurrence && calendarChoices && calendarChoices.length > 1 && (
|
|
226
262
|
<FormField label="Calendar" htmlFor="event-calendar">
|
|
227
263
|
<select
|
|
228
264
|
id="event-calendar"
|
|
@@ -230,7 +266,7 @@ export default function EventModal({
|
|
|
230
266
|
value={targetFolderUid}
|
|
231
267
|
onChange={(e) => setTargetFolderUid(e.target.value)}
|
|
232
268
|
>
|
|
233
|
-
{
|
|
269
|
+
{calendarChoices.map((cal) => (
|
|
234
270
|
<option key={cal.uid} value={cal.uid}>
|
|
235
271
|
{cal.name}
|
|
236
272
|
</option>
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
3
|
// SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
import React, { createContext, PropsWithChildren, ReactNode, useContext, useEffect, useMemo, useState } from "react";
|
|
6
|
-
import { HiOutlineBars3 } from "react-icons/hi2";
|
|
5
|
+
import React, { createContext, PropsWithChildren, ReactNode, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
7
6
|
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
8
|
-
import
|
|
7
|
+
import { accentColorForMailbox, colorForFolder } from "@rapidmx/react-shared/calendar/calendarColors.js";
|
|
9
8
|
import { Folder, Mailbox, listFolders, listMailboxes } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
10
9
|
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
11
10
|
import Skeleton, { SkeletonList } from "@rapidmx/react-shared/components/feedback/Skeleton.js";
|
|
@@ -14,23 +13,43 @@ import MailboxProvisioning from "../../layout/MailboxProvisioning.js";
|
|
|
14
13
|
|
|
15
14
|
export type CalendarShellProps = Omit<AppShellProps, "active">;
|
|
16
15
|
|
|
16
|
+
/** One mailbox's own `calendar`-type folders. `error` is set (and `calendarFolders` left empty) when that
|
|
17
|
+
* mailbox's own `listFolders()` failed - one mailbox's failure never hides every other mailbox's calendars. */
|
|
18
|
+
export interface MailboxCalendars {
|
|
19
|
+
mailbox: Mailbox;
|
|
20
|
+
calendarFolders: Folder[];
|
|
21
|
+
error?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
17
24
|
export interface CalendarShellContextValue {
|
|
18
|
-
/** The mailbox
|
|
25
|
+
/** The default mailbox for "+ New event" (`?mailboxUid=` if accessible, else the caller's own mailbox,
|
|
26
|
+
* else the first accessible one) - every accessible mailbox's calendars are shown regardless. */
|
|
19
27
|
mailboxUid?: string;
|
|
20
|
-
/**
|
|
21
|
-
* single calendar (e.g. as the default target for "+ New event"). */
|
|
28
|
+
/** `mailboxUid`'s first `calendar`-type folder - the default target for "+ New event". */
|
|
22
29
|
folderUid?: string;
|
|
23
|
-
/** Every `calendar`-type
|
|
24
|
-
*
|
|
30
|
+
/** Every accessible mailbox's `calendar`-type folders, flattened - the set of calendars that can be
|
|
31
|
+
* checked/shown (see `CalendarListSidebar`). Each folder's own `mailboxUid` says which mailbox it's in. */
|
|
25
32
|
calendarFolders: Folder[];
|
|
33
|
+
/** The same folders, grouped per mailbox, for the sidebar's per-mailbox sections. */
|
|
34
|
+
mailboxCalendars: MailboxCalendars[];
|
|
26
35
|
mailboxes: Mailbox[];
|
|
27
|
-
/** Re-fetches
|
|
36
|
+
/** Re-fetches every mailbox's folders (e.g. after creating a new calendar) without a full reload. */
|
|
28
37
|
reloadFolders: () => void;
|
|
38
|
+
/** The display color for a calendar folder: its own `color`, else the default for the caller's own
|
|
39
|
+
* mailbox, else its mailbox's `accentColorForMailbox()` - so a shared mailbox's calendar is visually
|
|
40
|
+
* distinct from the caller's own even when neither has a color set. */
|
|
41
|
+
colorFor: (folder: Folder) => string;
|
|
29
42
|
}
|
|
30
43
|
|
|
31
|
-
const CalendarShellContext = createContext<CalendarShellContextValue>({
|
|
44
|
+
const CalendarShellContext = createContext<CalendarShellContextValue>({
|
|
45
|
+
calendarFolders: [],
|
|
46
|
+
mailboxCalendars: [],
|
|
47
|
+
mailboxes: [],
|
|
48
|
+
reloadFolders: () => undefined,
|
|
49
|
+
colorFor: (folder) => colorForFolder(folder),
|
|
50
|
+
});
|
|
32
51
|
|
|
33
|
-
/** Reads the
|
|
52
|
+
/** Reads the calendars the Calendar is currently showing, as resolved by the enclosing `CalendarShell`. */
|
|
34
53
|
export function useCalendarShell(): CalendarShellContextValue {
|
|
35
54
|
return useContext(CalendarShellContext);
|
|
36
55
|
}
|
|
@@ -38,13 +57,11 @@ export function useCalendarShell(): CalendarShellContextValue {
|
|
|
38
57
|
type Status = "checking" | "error" | "ready";
|
|
39
58
|
|
|
40
59
|
/**
|
|
41
|
-
* The Calendar app's shell
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* be instant (no full page reload) and this framework has no client-side router to make a URL-driven
|
|
47
|
-
* approach for that free.
|
|
60
|
+
* The Calendar app's shell. Fetches every accessible mailbox's calendar folders in parallel so shared
|
|
61
|
+
* mailboxes' calendars show alongside the caller's own, each mailbox color-coded (see `colorFor`) - there
|
|
62
|
+
* is no mailbox switcher. The actual view being looked at (month/week/day, and which one) is *not* shell
|
|
63
|
+
* state — it lives in `apps/www/calendar/index.tsx`'s own local state, since navigating between
|
|
64
|
+
* views/dates must be instant (no full page reload) and this framework has no client-side router.
|
|
48
65
|
*/
|
|
49
66
|
export default function CalendarShell({
|
|
50
67
|
userUid,
|
|
@@ -57,10 +74,9 @@ export default function CalendarShell({
|
|
|
57
74
|
const [status, setStatus] = useState<Status>("checking");
|
|
58
75
|
const [error, setError] = useState<string | null>(null);
|
|
59
76
|
const [mailboxes, setMailboxes] = useState<Mailbox[]>([]);
|
|
60
|
-
const [
|
|
61
|
-
const [folderError, setFolderError] = useState<string | null>(null);
|
|
77
|
+
const [mailboxCalendars, setMailboxCalendars] = useState<MailboxCalendars[]>([]);
|
|
62
78
|
const [requestedMailboxUid, setRequestedMailboxUid] = useState<string | null>(null);
|
|
63
|
-
const [
|
|
79
|
+
const [folderRefreshToken, setFolderRefreshToken] = useState(0);
|
|
64
80
|
|
|
65
81
|
useEffect(() => {
|
|
66
82
|
setRequestedMailboxUid(new URLSearchParams(window.location.search).get("mailboxUid"));
|
|
@@ -81,43 +97,64 @@ export default function CalendarShell({
|
|
|
81
97
|
});
|
|
82
98
|
}, [userUid]);
|
|
83
99
|
|
|
100
|
+
const ownMailboxUid = mailboxes.find((mb) => mb.ownerUserUid === userUid)?.uid ?? mailboxes[0]?.uid;
|
|
84
101
|
const mailboxUid: string | undefined =
|
|
85
102
|
(requestedMailboxUid && mailboxes.some((mb) => mb.uid === requestedMailboxUid) ? requestedMailboxUid : undefined) ??
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const [folderRefreshToken, setFolderRefreshToken] = useState(0);
|
|
103
|
+
ownMailboxUid;
|
|
89
104
|
|
|
90
105
|
useEffect(() => {
|
|
91
|
-
if (
|
|
92
|
-
|
|
106
|
+
if (mailboxes.length === 0) {
|
|
107
|
+
setMailboxCalendars([]);
|
|
93
108
|
return;
|
|
94
109
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
let cancelled = false;
|
|
111
|
+
Promise.all(
|
|
112
|
+
mailboxes.map((mailbox) =>
|
|
113
|
+
listFolders(mailbox.uid)
|
|
114
|
+
.then((folders): MailboxCalendars => ({ mailbox, calendarFolders: folders.filter((f) => f.type === "calendar") }))
|
|
115
|
+
.catch(
|
|
116
|
+
(err): MailboxCalendars => ({
|
|
117
|
+
mailbox,
|
|
118
|
+
calendarFolders: [],
|
|
119
|
+
error: err instanceof ApiRequestError ? err.message : "Could not load this mailbox's calendar folder.",
|
|
120
|
+
}),
|
|
121
|
+
),
|
|
122
|
+
),
|
|
123
|
+
).then((result) => {
|
|
124
|
+
if (!cancelled) {
|
|
125
|
+
setMailboxCalendars(result);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return () => {
|
|
129
|
+
cancelled = true;
|
|
130
|
+
};
|
|
131
|
+
}, [mailboxes, folderRefreshToken]);
|
|
132
|
+
|
|
133
|
+
const calendarFolders = useMemo(() => mailboxCalendars.flatMap((mc) => mc.calendarFolders), [mailboxCalendars]);
|
|
134
|
+
const folderUid: string | undefined = calendarFolders.find((f) => f.mailboxUid === mailboxUid)?.uid;
|
|
135
|
+
|
|
136
|
+
const colorFor = useCallback(
|
|
137
|
+
(folder: Folder) => colorForFolder(folder, folder.mailboxUid === ownMailboxUid ? undefined : accentColorForMailbox(folder.mailboxUid)),
|
|
138
|
+
[ownMailboxUid],
|
|
139
|
+
);
|
|
140
|
+
const reloadFolders = useCallback(() => setFolderRefreshToken((t) => t + 1), []);
|
|
103
141
|
|
|
104
142
|
const contextValue = useMemo<CalendarShellContextValue>(
|
|
105
|
-
() => ({ mailboxUid, folderUid, calendarFolders, mailboxes, reloadFolders
|
|
106
|
-
[mailboxUid, folderUid, calendarFolders, mailboxes],
|
|
143
|
+
() => ({ mailboxUid, folderUid, calendarFolders, mailboxCalendars, mailboxes, reloadFolders, colorFor }),
|
|
144
|
+
[mailboxUid, folderUid, calendarFolders, mailboxCalendars, mailboxes, reloadFolders, colorFor],
|
|
107
145
|
);
|
|
108
146
|
|
|
109
147
|
// A full-screen takeover, not nested inside the rest of the app's chrome — there's nothing else
|
|
110
148
|
// for a mailbox-less caller to do here yet, so the icon rail/header don't render at all.
|
|
111
|
-
if (userUid && status === "ready" &&
|
|
149
|
+
if (userUid && status === "ready" && mailboxes.length === 0) {
|
|
112
150
|
return <MailboxProvisioning />;
|
|
113
151
|
}
|
|
114
152
|
|
|
115
153
|
let inner: ReactNode = null;
|
|
116
154
|
if (userUid && status === "checking") {
|
|
117
155
|
// Renders immediately (no network round trip needed) so switching into Calendar never shows a
|
|
118
|
-
// blank pane while `listMailboxes()` is in flight — the
|
|
119
|
-
// calendar list)
|
|
120
|
-
// shape rather than the (minimal, mailbox-switcher-only) shape of this shell's own sidebar.
|
|
156
|
+
// blank pane while `listMailboxes()` is in flight — mimics the rough shape of the real sidebar
|
|
157
|
+
// (mini date-picker + calendar list) that `apps/www/calendar/index.tsx` renders.
|
|
121
158
|
inner = (
|
|
122
159
|
<div className="w-56 shrink-0 bg-surface border-r border-border p-3 flex flex-col gap-4">
|
|
123
160
|
<Skeleton height="h-40" className="rounded-md" />
|
|
@@ -133,66 +170,10 @@ export default function CalendarShell({
|
|
|
133
170
|
</div>
|
|
134
171
|
);
|
|
135
172
|
} else if (userUid && status === "ready") {
|
|
136
|
-
// A function, not a plain JSX constant — see MailShell/ContactsShell's identical comment: it's
|
|
137
|
-
// rendered twice (desktop `<aside>` + mobile `Drawer`), possibly simultaneously mounted, so the
|
|
138
|
-
// `<select>`'s `id`/its `<label>`'s `htmlFor` need a distinct value per instance.
|
|
139
|
-
const mailboxSwitcher = (idPrefix: string) =>
|
|
140
|
-
mailboxes.length > 1 && (
|
|
141
|
-
<div>
|
|
142
|
-
<label
|
|
143
|
-
className="block text-xs font-bold uppercase tracking-wide text-text-muted mb-1"
|
|
144
|
-
htmlFor={`${idPrefix}-calendar-mailbox-switcher`}
|
|
145
|
-
>
|
|
146
|
-
Mailbox
|
|
147
|
-
</label>
|
|
148
|
-
<select
|
|
149
|
-
id={`${idPrefix}-calendar-mailbox-switcher`}
|
|
150
|
-
className="w-full text-sm border border-border rounded-sm py-1.5 px-2 bg-surface"
|
|
151
|
-
value={mailboxUid}
|
|
152
|
-
onChange={(e) => {
|
|
153
|
-
window.location.href = `/calendar?mailboxUid=${encodeURIComponent(e.target.value)}`;
|
|
154
|
-
}}
|
|
155
|
-
>
|
|
156
|
-
{mailboxes.map((mb) => (
|
|
157
|
-
<option key={mb.uid} value={mb.uid}>
|
|
158
|
-
{mb.displayName}
|
|
159
|
-
{mb.ownerUserUid ? "" : " (shared)"}
|
|
160
|
-
</option>
|
|
161
|
-
))}
|
|
162
|
-
</select>
|
|
163
|
-
</div>
|
|
164
|
-
);
|
|
165
|
-
|
|
166
173
|
inner = (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
)}
|
|
171
|
-
<Drawer open={drawerOpen} onClose={() => setDrawerOpen(false)} title="Mailbox">
|
|
172
|
-
<div className="flex flex-col gap-3">
|
|
173
|
-
{mailboxSwitcher("mobile")}
|
|
174
|
-
{folderError && <Alert>{folderError}</Alert>}
|
|
175
|
-
</div>
|
|
176
|
-
</Drawer>
|
|
177
|
-
<div className="flex-1 min-w-0 flex flex-col">
|
|
178
|
-
{(mailboxes.length > 1 || folderError) && (
|
|
179
|
-
<button
|
|
180
|
-
type="button"
|
|
181
|
-
className="md:hidden m-3 w-9 h-9 flex items-center justify-center rounded-sm text-text-muted hover:bg-surface-alt hover:text-text"
|
|
182
|
-
aria-label="Open mailbox switcher"
|
|
183
|
-
onClick={() => setDrawerOpen(true)}
|
|
184
|
-
>
|
|
185
|
-
<HiOutlineBars3 size={20} aria-hidden="true" />
|
|
186
|
-
</button>
|
|
187
|
-
)}
|
|
188
|
-
{folderError && (
|
|
189
|
-
<div className="hidden md:block p-3">
|
|
190
|
-
<Alert>{folderError}</Alert>
|
|
191
|
-
</div>
|
|
192
|
-
)}
|
|
193
|
-
<CalendarShellContext.Provider value={contextValue}>{children}</CalendarShellContext.Provider>
|
|
194
|
-
</div>
|
|
195
|
-
</>
|
|
174
|
+
<div className="flex-1 min-w-0 flex flex-col">
|
|
175
|
+
<CalendarShellContext.Provider value={contextValue}>{children}</CalendarShellContext.Provider>
|
|
176
|
+
</div>
|
|
196
177
|
);
|
|
197
178
|
}
|
|
198
179
|
|