@burdenoff/microfe-calendar 2026.1124.3 → 2026.1124.4
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/dist/generated/wspace-operations.d.ts +342 -69
- package/dist/generated/wspace-operations.js +73 -31
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/generated/wspace-types.d.ts +405 -6
- package/dist/translations/en.d.ts +22 -4
- package/dist/v2/CalendarPageV2.js +45 -41
- package/dist/v2/CalendarPageV2.js.map +1 -1
- package/dist/v2/CalendarRoutesV2.js +64 -64
- package/dist/v2/CalendarRoutesV2.js.map +1 -1
- package/dist/v2/data/errors.d.ts +5 -0
- package/dist/v2/data/errors.js +6 -2
- package/dist/v2/data/errors.js.map +1 -1
- package/dist/v2/data/normalize.d.ts +31 -3
- package/dist/v2/data/normalize.js +57 -13
- package/dist/v2/data/normalize.js.map +1 -1
- package/dist/v2/data/seriesDateLookup.d.ts +9 -0
- package/dist/v2/data/seriesDateLookup.js +12 -0
- package/dist/v2/data/seriesDateLookup.js.map +1 -0
- package/dist/v2/data/useEventActions.d.ts +9 -3
- package/dist/v2/data/useEventActions.js +239 -186
- package/dist/v2/data/useEventActions.js.map +1 -1
- package/dist/v2/data/useEventForPeek.js +63 -21
- package/dist/v2/data/useEventForPeek.js.map +1 -1
- package/dist/v2/data/useEventsInRangeV2.d.ts +40 -2
- package/dist/v2/data/useEventsInRangeV2.js +76 -47
- package/dist/v2/data/useEventsInRangeV2.js.map +1 -1
- package/dist/v2/day/DayPanel.js +1 -1
- package/dist/v2/day/DayPanel.js.map +1 -1
- package/dist/v2/event/EventDialog.d.ts +13 -3
- package/dist/v2/event/EventDialog.js +189 -166
- package/dist/v2/event/EventDialog.js.map +1 -1
- package/dist/v2/event/EventDialogs.js +57 -50
- package/dist/v2/event/EventDialogs.js.map +1 -1
- package/dist/v2/event/EventMoreTab.js +8 -7
- package/dist/v2/event/EventMoreTab.js.map +1 -1
- package/dist/v2/event/EventPlaceTab.js +2 -2
- package/dist/v2/event/EventPlaceTab.js.map +1 -1
- package/dist/v2/event/FindTimeDialog.js +1 -1
- package/dist/v2/event/FindTimeDialog.js.map +1 -1
- package/dist/v2/event/RepeatField.js +10 -7
- package/dist/v2/event/RepeatField.js.map +1 -1
- package/dist/v2/event/dialogLogic.d.ts +10 -0
- package/dist/v2/event/dialogLogic.js +25 -22
- package/dist/v2/event/dialogLogic.js.map +1 -1
- package/dist/v2/event/dialogModel.d.ts +3 -0
- package/dist/v2/event/dialogModel.js.map +1 -1
- package/dist/v2/event/eventForm.d.ts +26 -0
- package/dist/v2/event/eventForm.js +145 -92
- package/dist/v2/event/eventForm.js.map +1 -1
- package/dist/v2/event/findTimeSource.js +44 -44
- package/dist/v2/event/findTimeSource.js.map +1 -1
- package/dist/v2/event/rrule.js.map +1 -1
- package/dist/v2/event/savePlan.d.ts +125 -15
- package/dist/v2/event/savePlan.js +162 -68
- package/dist/v2/event/savePlan.js.map +1 -1
- package/dist/v2/event/useEventData.d.ts +7 -2
- package/dist/v2/event/useEventData.js +107 -80
- package/dist/v2/event/useEventData.js.map +1 -1
- package/dist/v2/event/useEventDialogModel.d.ts +16 -3
- package/dist/v2/event/useEventDialogModel.js +82 -67
- package/dist/v2/event/useEventDialogModel.js.map +1 -1
- package/dist/v2/event/useEventSave.d.ts +20 -4
- package/dist/v2/event/useEventSave.js +181 -90
- package/dist/v2/event/useEventSave.js.map +1 -1
- package/dist/v2/events/eventLook.js +16 -16
- package/dist/v2/events/eventLook.js.map +1 -1
- package/dist/v2/events/eventModel.d.ts +17 -4
- package/dist/v2/events/eventModel.js +46 -34
- package/dist/v2/events/eventModel.js.map +1 -1
- package/dist/v2/events/localChanges.d.ts +4 -1
- package/dist/v2/events/localChanges.js +4 -2
- package/dist/v2/events/localChanges.js.map +1 -1
- package/dist/v2/page/CalendarPageContext.d.ts +2 -2
- package/dist/v2/page/CalendarPageContext.js.map +1 -1
- package/dist/v2/page/useCalendarPageModel.js +141 -139
- package/dist/v2/page/useCalendarPageModel.js.map +1 -1
- package/dist/v2/page/viewState.d.ts +9 -1
- package/dist/v2/page/viewState.js +5 -3
- package/dist/v2/page/viewState.js.map +1 -1
- package/dist/v2/peek/PeekEvent.js +210 -204
- package/dist/v2/peek/PeekEvent.js.map +1 -1
- package/dist/v2/rail/useMonthEventDates.js +1 -1
- package/dist/v2/rail/useMonthEventDates.js.map +1 -1
- package/dist/v2/states/CalendarStates.d.ts +15 -0
- package/dist/v2/states/CalendarStates.js +42 -11
- package/dist/v2/states/CalendarStates.js.map +1 -1
- package/dist/v2/types.d.ts +30 -2
- package/package.json +1 -1
|
@@ -1,60 +1,93 @@
|
|
|
1
|
-
import { CalendarV2AddGuestDocument as e, CalendarV2BookRoomDocument as t,
|
|
2
|
-
import { REMINDER_CHANNEL as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
1
|
+
import { CalendarV2AddGuestDocument as e, CalendarV2BookRoomDocument as t, CalendarV2CancelOccurrenceDocument as n, CalendarV2CancelRoomBookingDocument as r, CalendarV2CreateEventDocument as i, CalendarV2CreateReminderDocument as a, CalendarV2DeleteReminderDocument as o, CalendarV2ModifyOccurrenceDocument as s, CalendarV2RemoveGuestDocument as c, CalendarV2SplitSeriesDocument as l, CalendarV2UpdateEventDocument as u } from "../../generated/wspace-operations.js";
|
|
2
|
+
import { REMINDER_CHANNEL as d } from "../data/enums.js";
|
|
3
|
+
import { graphQLErrorKey as f } from "../data/errors.js";
|
|
4
|
+
import { invalidateCalendarEvents as p } from "../data/invalidation.js";
|
|
5
|
+
import { toCalendarEventV2 as m } from "../data/normalize.js";
|
|
6
|
+
import { isSeriesDate as h } from "../events/eventModel.js";
|
|
7
|
+
import { formatDay as g, formatDuration as _, formatInstantRange as v } from "../format.js";
|
|
8
|
+
import { instantToZoned as y } from "../time/calendarTime.js";
|
|
9
|
+
import { endInstant as b, rruleOf as x, startInstant as S } from "./eventForm.js";
|
|
10
|
+
import { carriesWork as C, planOnNewEvent as w, saveRouteFor as T } from "./savePlan.js";
|
|
11
|
+
import { useCallback as E, useEffect as D, useRef as O } from "react";
|
|
12
|
+
import { useNotify as k } from "@burdenoff/fe-libs/ui";
|
|
13
|
+
import { CombinedGraphQLErrors as A } from "@apollo/client";
|
|
14
|
+
import { useApolloClient as j } from "@apollo/client/react";
|
|
12
15
|
// src/v2/event/useEventSave.ts
|
|
13
|
-
var
|
|
14
|
-
function
|
|
15
|
-
return
|
|
16
|
+
var M = 4;
|
|
17
|
+
function N(e) {
|
|
18
|
+
return A.is(e) ? e.errors.map((e) => e.message.trim()).find(Boolean) ?? null : null;
|
|
16
19
|
}
|
|
17
|
-
async function
|
|
20
|
+
async function P(e, t) {
|
|
18
21
|
let n = 0, r = async () => {
|
|
19
22
|
let t = e[n];
|
|
20
23
|
n += 1, t && (await t(), await r());
|
|
21
24
|
};
|
|
22
25
|
await Promise.all(Array.from({ length: Math.min(t, e.length) }, r));
|
|
23
26
|
}
|
|
24
|
-
async function
|
|
27
|
+
async function F(e, t, n = 0) {
|
|
25
28
|
let r = e[n];
|
|
26
29
|
if (r === void 0) return null;
|
|
27
30
|
let i = await t(r, n);
|
|
28
|
-
return i === null ?
|
|
31
|
+
return i === null ? F(e, t, n + 1) : i;
|
|
29
32
|
}
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
var I = /* @__PURE__ */ new Set([
|
|
34
|
+
"resource.errors.bookingNotFound",
|
|
35
|
+
"resource.errors.cannotCancelBooking",
|
|
36
|
+
"recurrence.errors.instanceAlreadyCancelled",
|
|
37
|
+
"recurrence.errors.notRecurringSeries",
|
|
38
|
+
"recurrence.errors.seriesNotFound"
|
|
39
|
+
]);
|
|
40
|
+
function L(e) {
|
|
41
|
+
let t = f(e);
|
|
42
|
+
return t !== null && I.has(t);
|
|
43
|
+
}
|
|
44
|
+
function R(e, t) {
|
|
45
|
+
return N(e) ?? t("calendar.v2.eventSaveOffline", "The calendar service didn’t answer. Check your connection.");
|
|
32
46
|
}
|
|
33
|
-
function
|
|
34
|
-
return e.minutesBefore === 0 ? t.tr("calendar.v2.reminderAtStart", "When it starts") : t.tr("calendar.v2.reminderBefore", "{{time}} before", { time:
|
|
47
|
+
function z(e, t) {
|
|
48
|
+
return e.minutesBefore === 0 ? t.tr("calendar.v2.reminderAtStart", "When it starts") : t.tr("calendar.v2.reminderBefore", "{{time}} before", { time: _(e.minutesBefore, t.durationWords) });
|
|
35
49
|
}
|
|
36
|
-
function
|
|
50
|
+
function B(e, t, n, r, i = () => !1) {
|
|
37
51
|
return async () => {
|
|
38
52
|
try {
|
|
39
53
|
return await n(), e.wrote = !0, !0;
|
|
40
54
|
} catch (n) {
|
|
41
|
-
return e.problems.push(r(
|
|
55
|
+
return i(n) ? !0 : (e.problems.push(r(R(n, t.tr))), !1);
|
|
42
56
|
}
|
|
43
57
|
};
|
|
44
58
|
}
|
|
45
|
-
async function
|
|
59
|
+
async function V(e, t, n) {
|
|
60
|
+
let r = (await e.mutate({
|
|
61
|
+
mutation: s,
|
|
62
|
+
variables: { input: t }
|
|
63
|
+
})).data?.modifyRecurringInstance, i = r ? m(r, n) : null;
|
|
64
|
+
if (!i) throw Error("No event came back");
|
|
65
|
+
return i;
|
|
66
|
+
}
|
|
67
|
+
async function H(e, t, n, r) {
|
|
68
|
+
let i = (await e.mutate({
|
|
69
|
+
mutation: l,
|
|
70
|
+
variables: {
|
|
71
|
+
id: t,
|
|
72
|
+
input: n
|
|
73
|
+
}
|
|
74
|
+
})).data?.updateEvent, a = i ? m(i, r) : null;
|
|
75
|
+
if (!a) throw Error("No event came back");
|
|
76
|
+
return a;
|
|
77
|
+
}
|
|
78
|
+
async function U(e, t) {
|
|
46
79
|
let n = (await e.mutate({
|
|
47
|
-
mutation:
|
|
80
|
+
mutation: i,
|
|
48
81
|
variables: { input: t }
|
|
49
82
|
})).data?.createEvent.id;
|
|
50
83
|
if (!n) throw Error("No event came back");
|
|
51
84
|
return n;
|
|
52
85
|
}
|
|
53
|
-
async function
|
|
54
|
-
return
|
|
86
|
+
async function W(e, t, n, r, i, a) {
|
|
87
|
+
return F(n.updates, async (n, o) => {
|
|
55
88
|
try {
|
|
56
89
|
return await e.mutate({
|
|
57
|
-
mutation:
|
|
90
|
+
mutation: u,
|
|
58
91
|
variables: {
|
|
59
92
|
id: t,
|
|
60
93
|
input: n.input,
|
|
@@ -62,19 +95,19 @@ async function M(e, t, n, r, i) {
|
|
|
62
95
|
}
|
|
63
96
|
}), r.wrote = !0, null;
|
|
64
97
|
} catch (e) {
|
|
65
|
-
return
|
|
98
|
+
return o === 0 && !a ? { error: e } : (r.problems.push(o === 0 ? i.tr("calendar.v2.eventRestFailed", "Its other changes didn’t save: {{reason}}", { reason: R(e, i.tr) }) : i.tr("calendar.v2.eventRuleFailed", "The new repeat didn’t save: {{reason}}", { reason: R(e, i.tr) })), null);
|
|
66
99
|
}
|
|
67
100
|
});
|
|
68
101
|
}
|
|
69
|
-
function
|
|
70
|
-
let { tr:
|
|
71
|
-
return [...r.removeGuests.map((e) =>
|
|
72
|
-
mutation:
|
|
102
|
+
function G(t, n, r, i, a) {
|
|
103
|
+
let { tr: o } = a;
|
|
104
|
+
return [...r.removeGuests.map((e) => B(i, a, () => t.mutate({
|
|
105
|
+
mutation: c,
|
|
73
106
|
variables: { attendeeId: e.attendeeId ?? "" }
|
|
74
|
-
}), (t) =>
|
|
107
|
+
}), (t) => o("calendar.v2.guestRemoveFailed", "Couldn’t remove {{name}}: {{reason}}", {
|
|
75
108
|
name: a.guestName(e),
|
|
76
109
|
reason: t
|
|
77
|
-
}))), ...r.addGuests.map((r) =>
|
|
110
|
+
}))), ...r.addGuests.map((r) => B(i, a, () => t.mutate({
|
|
78
111
|
mutation: e,
|
|
79
112
|
variables: {
|
|
80
113
|
eventId: n,
|
|
@@ -82,104 +115,162 @@ function N(t, n, r, i, a) {
|
|
|
82
115
|
email: r.email,
|
|
83
116
|
name: r.name
|
|
84
117
|
}
|
|
85
|
-
}), (e) =>
|
|
118
|
+
}), (e) => o("calendar.v2.guestAddFailed", "Couldn’t invite {{name}}: {{reason}}", {
|
|
86
119
|
name: a.guestName(r),
|
|
87
120
|
reason: e
|
|
88
121
|
})))];
|
|
89
122
|
}
|
|
90
|
-
function
|
|
91
|
-
let { tr: s } =
|
|
92
|
-
return [...n.removeReminders.map((t) =>
|
|
93
|
-
mutation:
|
|
123
|
+
function K(e, t, n, r, i) {
|
|
124
|
+
let { tr: s } = i;
|
|
125
|
+
return [...n.removeReminders.map((t) => B(r, i, () => e.mutate({
|
|
126
|
+
mutation: o,
|
|
94
127
|
variables: { id: t.reminderId ?? "" }
|
|
95
128
|
}), (e) => s("calendar.v2.reminderRemoveFailed", "Couldn’t remove the reminder {{when}}: {{reason}}", {
|
|
96
|
-
when:
|
|
129
|
+
when: z(t, i),
|
|
97
130
|
reason: e
|
|
98
|
-
}))), ...n.addReminders.map((n) =>
|
|
99
|
-
mutation:
|
|
131
|
+
}))), ...n.addReminders.map((n) => B(r, i, () => e.mutate({
|
|
132
|
+
mutation: a,
|
|
100
133
|
variables: { input: {
|
|
101
134
|
eventId: t,
|
|
102
135
|
minutesBefore: n.minutesBefore,
|
|
103
|
-
channel:
|
|
136
|
+
channel: d[n.channel]
|
|
104
137
|
} }
|
|
105
138
|
}), (e) => s("calendar.v2.reminderAddFailed", "Couldn’t add the reminder {{when}}: {{reason}}", {
|
|
106
|
-
when:
|
|
139
|
+
when: z(n, i),
|
|
107
140
|
reason: e
|
|
108
141
|
})))];
|
|
109
142
|
}
|
|
110
|
-
function
|
|
111
|
-
let
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
143
|
+
function q(e, t, n, r) {
|
|
144
|
+
let i = t.tags;
|
|
145
|
+
if (!i) return [];
|
|
146
|
+
let a = B(n, r, () => e.mutate({
|
|
147
|
+
mutation: u,
|
|
148
|
+
variables: {
|
|
149
|
+
id: i.eventId,
|
|
150
|
+
input: i.input,
|
|
151
|
+
scope: i.scope
|
|
152
|
+
}
|
|
153
|
+
}), (e) => r.tr("calendar.v2.eventTagsFailed", "Its tags didn’t save: {{reason}}", { reason: e }));
|
|
154
|
+
return [async () => {
|
|
155
|
+
await a() || (n.left.tags = i);
|
|
156
|
+
}];
|
|
157
|
+
}
|
|
158
|
+
function J(e, t, n) {
|
|
159
|
+
let r = e.cancels.find((e) => e.seriesId === t);
|
|
160
|
+
r ? r.dates.push(n) : e.cancels.push({
|
|
161
|
+
seriesId: t,
|
|
162
|
+
dates: [n]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
function Y(e, t, r, i) {
|
|
166
|
+
return t.cancels.map(({ seriesId: t, dates: a }) => async () => {
|
|
167
|
+
await F(a, async (a) => (await B(r, i, () => e.mutate({
|
|
168
|
+
mutation: n,
|
|
169
|
+
variables: {
|
|
170
|
+
seriesId: t,
|
|
171
|
+
instanceDate: a.toISOString()
|
|
172
|
+
}
|
|
173
|
+
}), (e) => i.tr("calendar.v2.eventKeepCancelledFailed", "Couldn’t keep {{day}} cancelled: {{reason}}", {
|
|
174
|
+
day: g(y(a, i.timeZone).date, i.format, "short"),
|
|
175
|
+
reason: e
|
|
176
|
+
}), L)() || J(r.left, t, a), null));
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function X(e, n, i, a, o) {
|
|
180
|
+
let { tr: s } = o, c = i.bookRoom, l = (t) => B(a, o, () => e.mutate({
|
|
181
|
+
mutation: r,
|
|
182
|
+
variables: { bookingId: t }
|
|
183
|
+
}), (e) => c ? s("calendar.v2.roomMoveFailed", "Couldn’t move the room booking, so it stays as it was: {{reason}}", { reason: e }) : s("calendar.v2.roomReleaseFailed", "Couldn’t let go of the room booked before: {{reason}}", { reason: e }), L), u = i.cancelBookingId, d = u ? l(u) : null, f = c ? B(a, o, () => e.mutate({
|
|
115
184
|
mutation: t,
|
|
116
185
|
variables: { input: {
|
|
117
|
-
eventId:
|
|
118
|
-
resourceId:
|
|
119
|
-
startTime:
|
|
120
|
-
endTime:
|
|
186
|
+
eventId: n,
|
|
187
|
+
resourceId: c.resourceId,
|
|
188
|
+
startTime: c.start.toISOString(),
|
|
189
|
+
endTime: c.end.toISOString()
|
|
121
190
|
} }
|
|
122
191
|
}), (e) => s("calendar.v2.roomBookFailed", "Couldn’t book {{room}}: {{reason}}", {
|
|
123
|
-
room: o.roomName(
|
|
192
|
+
room: o.roomName(c.resourceId) ?? s("calendar.v2.theRoom", "The room"),
|
|
124
193
|
reason: e
|
|
125
|
-
})) : null;
|
|
126
|
-
return
|
|
127
|
-
|
|
194
|
+
})) : null, p = i.releaseBookingIds;
|
|
195
|
+
return p.length === 0 && !d && !f ? [] : [async () => {
|
|
196
|
+
let e = [];
|
|
197
|
+
await F(p, async (t) => (await l(t)() || e.push(t), null)), e.length > 0 ? a.left.releaseBookingIds.push(...e) : (!d || await d()) && f && await f();
|
|
128
198
|
}];
|
|
129
199
|
}
|
|
130
|
-
function
|
|
131
|
-
let { tr: i } = r, a = e.title.trim();
|
|
132
|
-
if (
|
|
133
|
-
|
|
200
|
+
function Z(e, t, n, r) {
|
|
201
|
+
let { tr: i } = r, a = e.title.trim(), o = S(e), s = e.allDay ? e.firstDay : y(o, r.timeZone).date;
|
|
202
|
+
if (t.kind === "thisDate") return i("calendar.v2.eventSavedDate", "Saved “{{title}}” on {{day}}.", {
|
|
203
|
+
title: a,
|
|
204
|
+
day: g(s, r.format, "short")
|
|
205
|
+
});
|
|
206
|
+
if (t.kind === "split") return i("calendar.v2.eventSavedLater", "Saved “{{title}}” from {{day}} on.", {
|
|
207
|
+
title: a,
|
|
208
|
+
day: g(s, r.format, "short")
|
|
209
|
+
});
|
|
210
|
+
if (t.kind === "edit") return n?.isRecurring && t.eventId === n.eventId ? i("calendar.v2.eventSavedSeries", "Saved every event in “{{title}}”.", { title: a }) : i("calendar.v2.eventSaved", "Saved “{{title}}”.", { title: a });
|
|
211
|
+
let c = e.allDay ? i("calendar.v2.allDayLower", "all day") : v(o, b(e), r.timeZone, r.format);
|
|
134
212
|
return i("calendar.v2.eventAdded", "Added “{{title}}” to {{calendar}}, {{day}} {{time}}.", {
|
|
135
213
|
title: a,
|
|
136
214
|
calendar: r.calendarName(e.calendarId ?? "") ?? i("calendar.v2.aCalendar", "a calendar"),
|
|
137
|
-
day:
|
|
215
|
+
day: g(s, r.format, "short"),
|
|
138
216
|
time: c
|
|
139
217
|
});
|
|
140
218
|
}
|
|
141
|
-
function
|
|
142
|
-
let
|
|
143
|
-
return
|
|
219
|
+
function Q(e, t, n) {
|
|
220
|
+
let { form: r, initial: i, event: a } = e;
|
|
221
|
+
return t.kind !== "edit" || !a || a.eventId !== n || !h(a) ? null : x(r) === x(i) ? S(r) : null;
|
|
222
|
+
}
|
|
223
|
+
function $(e) {
|
|
224
|
+
let t = j(), n = k(), r = O(e);
|
|
225
|
+
return D(() => {
|
|
144
226
|
r.current = e;
|
|
145
|
-
}),
|
|
146
|
-
let o = r.current, { tr:
|
|
147
|
-
title:
|
|
148
|
-
description:
|
|
227
|
+
}), E(async (e) => {
|
|
228
|
+
let { form: i, initial: a, event: o, row: s, carry: c } = e, l = r.current, { tr: u } = l, d = i.title.trim(), f = T(e, l.timeZone), m = f.kind === "create", h = (e) => (n({
|
|
229
|
+
title: m ? u("calendar.v2.eventAddFailed", "Couldn’t add “{{title}}”", { title: d }) : u("calendar.v2.eventSaveFailed", "Couldn’t save “{{title}}”", { title: d }),
|
|
230
|
+
description: R(e, u),
|
|
149
231
|
tone: "error",
|
|
150
232
|
urgent: !0
|
|
151
|
-
}), { kind: "failed" }),
|
|
152
|
-
|
|
153
|
-
f = await
|
|
233
|
+
}), { kind: "failed" }), g, _, v = null;
|
|
234
|
+
try {
|
|
235
|
+
f.kind === "create" ? (g = await U(t, f.plan.create), _ = f.plan) : f.kind === "edit" ? (g = f.eventId, _ = f.plan) : (v = f.kind === "thisDate" ? await V(t, f.input, l.me) : await H(t, f.seriesId, f.input, l.me), g = v.eventId, _ = w(f.form, a, v, o ?? v, s ?? v, l.timeZone, c));
|
|
154
236
|
} catch (e) {
|
|
155
|
-
return
|
|
237
|
+
return h(e);
|
|
156
238
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
239
|
+
let y = v !== null, b = {
|
|
240
|
+
wrote: m || y,
|
|
241
|
+
problems: [],
|
|
242
|
+
left: {
|
|
243
|
+
releaseBookingIds: [],
|
|
244
|
+
tags: null,
|
|
245
|
+
cancels: []
|
|
246
|
+
}
|
|
247
|
+
}, x = await W(t, g, _, b, l, y);
|
|
248
|
+
return x ? h(x.error) : (await P([
|
|
249
|
+
...G(t, g, _, b, l),
|
|
250
|
+
...K(t, g, _, b, l),
|
|
251
|
+
...X(t, g, _, b, l),
|
|
252
|
+
...q(t, _, b, l),
|
|
253
|
+
...Y(t, _, b, l)
|
|
254
|
+
], M), b.wrote && p(), b.problems.length > 0 ? (n({
|
|
255
|
+
title: m ? u("calendar.v2.eventAddedPartly", "Added “{{title}}”, but not all of it", { title: d }) : u("calendar.v2.eventSavedPartly", "Saved “{{title}}”, but not all of it", { title: d }),
|
|
256
|
+
description: `${b.problems.join(" ")} ${u("calendar.v2.eventSaveAgain", "Save again to try the rest.")}`,
|
|
169
257
|
tone: "warning",
|
|
170
258
|
urgent: !0
|
|
171
259
|
}), {
|
|
172
260
|
kind: "partial",
|
|
173
|
-
eventId:
|
|
261
|
+
eventId: g,
|
|
262
|
+
instanceDate: Q(e, f, g),
|
|
263
|
+
madeNew: y,
|
|
264
|
+
carry: C(b.left) ? b.left : null
|
|
174
265
|
}) : (n({
|
|
175
|
-
title:
|
|
266
|
+
title: Z(i, f, s, l),
|
|
176
267
|
tone: "success"
|
|
177
268
|
}), {
|
|
178
269
|
kind: "saved",
|
|
179
|
-
eventId:
|
|
270
|
+
eventId: g
|
|
180
271
|
}));
|
|
181
272
|
}, [t, n]);
|
|
182
273
|
}
|
|
183
|
-
export {
|
|
274
|
+
export { N as serviceMessage, $ as useEventSave };
|
|
184
275
|
|
|
185
276
|
//# sourceMappingURL=useEventSave.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEventSave.js","names":["PARALLEL_WRITES","serviceMessage","CombinedGraphQLErrors","error","item","inTurns","next","worker","task","tasks","size","inOrder","items","index","stop","step","reasonFor","tr","reminderWords","reminder","ctx","formatDuration","attempt","work","run","failed","createEvent","id","client","CalendarV2CreateEventDocument","applyUpdates","plan","CalendarV2UpdateEventDocument","update","guestTasks","CalendarV2RemoveGuestDocument","guest","why","CalendarV2AddGuestDocument","reminderTasks","CalendarV2DeleteReminderDocument","CalendarV2CreateReminderDocument","REMINDER_CHANNEL","roomTask","cancelId","book","release","CalendarV2CancelRoomBookingDocument","reserve","CalendarV2BookRoomDocument","savedWords","title","form","created","event","start","startInstant","day","instantToZoned","when","formatInstantRange","endInstant","formatDay","useEventSave","useApolloClient","notify","useNotify","contextRef","useRef","context","useEffect","useCallback","planEdit","scope","planNewEvent","firstUpdate","invalidateCalendarEvents"],"sources":["../../../src/v2/event/useEventSave.ts"],"sourcesContent":["/**\n * Saving the event dialog (BOFF-15698 A2): runs the plan (`savePlan.ts`) against the service\n * and says how it went in a themed toast.\n *\n * - The event itself first: `createEvent`, or the `updateEvent` calls. If that fails nothing\n * else is sent, the service's words are shown, and the dialog keeps everything typed.\n * - Then its guests, reminders and room, a few at a time. Whatever of those fails is named with\n * the service's words, and the dialog stays open on the saved event (an edit from then on),\n * so saving again sends only what is still missing.\n * - After any write the views, free/busy and the dialog's own copy of the event reload\n * (`invalidateCalendarEvents`).\n */\nimport { useCallback, useEffect, useRef } from 'react';\nimport { CombinedGraphQLErrors } from '@apollo/client';\nimport { useApolloClient } from '@apollo/client/react';\nimport { useNotify } from '@burdenoff/fe-libs/ui';\nimport {\n CalendarV2AddGuestDocument,\n CalendarV2BookRoomDocument,\n CalendarV2CancelRoomBookingDocument,\n CalendarV2CreateEventDocument,\n CalendarV2CreateReminderDocument,\n CalendarV2DeleteReminderDocument,\n CalendarV2RemoveGuestDocument,\n CalendarV2UpdateEventDocument,\n type CalendarV2AddGuestMutation,\n type CalendarV2AddGuestMutationVariables,\n type CalendarV2BookRoomMutation,\n type CalendarV2BookRoomMutationVariables,\n type CalendarV2CancelRoomBookingMutation,\n type CalendarV2CancelRoomBookingMutationVariables,\n type CalendarV2CreateEventMutation,\n type CalendarV2CreateEventMutationVariables,\n type CalendarV2CreateReminderMutation,\n type CalendarV2CreateReminderMutationVariables,\n type CalendarV2DeleteReminderMutation,\n type CalendarV2DeleteReminderMutationVariables,\n type CalendarV2RemoveGuestMutation,\n type CalendarV2RemoveGuestMutationVariables,\n type CalendarV2UpdateEventMutation,\n type CalendarV2UpdateEventMutationVariables,\n} from '../../generated/wspace-operations';\nimport type { CreateEventInput } from '../../generated/wspace-types';\nimport { REMINDER_CHANNEL } from '../data/enums';\nimport { invalidateCalendarEvents } from '../data/invalidation';\nimport type { Tr } from '../data/useEventActions';\nimport {\n formatDay,\n formatDuration,\n formatInstantRange,\n type CalendarFormat,\n type DurationWords,\n} from '../format';\nimport { instantToZoned } from '../time/calendarTime';\nimport type { CalendarEventV2 } from '../types';\nimport {\n startInstant,\n endInstant,\n type EventForm,\n type GuestDraft,\n type ReminderDraft,\n} from './eventForm';\nimport { planEdit, planNewEvent, type SavePlan, type ScopeChoice } from './savePlan';\n\nexport interface EventSaveContext {\n tr: Tr;\n format: CalendarFormat;\n durationWords: DurationWords;\n /** The calendar's zone: where the toast says the event is. */\n timeZone: string;\n /** A calendar's name, for \"Added … to Customer calls\". */\n calendarName: (calendarId: string) => string | null;\n /** A room's name, for \"Couldn't book Atlas\". */\n roomName: (roomId: string) => string | null;\n /** A guest's name, for \"Couldn't add Priya Raman\". */\n guestName: (guest: GuestDraft) => string;\n}\n\nexport interface SaveRequest {\n form: EventForm;\n /** The event as the service last returned it; null for a new event. */\n event: CalendarEventV2 | null;\n /** A repeating event's answer to \"Change …\". */\n scope: ScopeChoice;\n}\n\nexport type SaveOutcome =\n | { kind: 'saved'; eventId: string }\n /** The event saved but some of its guests, reminders or room didn't. */\n | { kind: 'partial'; eventId: string }\n /** Nothing changed on the service. */\n | { kind: 'failed' };\n\n/** How many guest, reminder and room writes run at once. */\nconst PARALLEL_WRITES = 4;\n\ntype Client = ReturnType<typeof useApolloClient>;\n\n/** The service's own words for a failed write; null when it never answered. */\nexport function serviceMessage(error: unknown): string | null {\n if (CombinedGraphQLErrors.is(error)) {\n const message = error.errors.map((item) => item.message.trim()).find(Boolean);\n return message ?? null;\n }\n return null;\n}\n\n/** Runs `tasks`, at most `size` at a time, each as soon as one before it is done. */\nasync function inTurns(tasks: readonly (() => Promise<unknown>)[], size: number): Promise<void> {\n let next = 0;\n const worker = async (): Promise<void> => {\n const task = tasks[next];\n next += 1;\n if (!task) return;\n await task();\n await worker();\n };\n await Promise.all(Array.from({ length: Math.min(size, tasks.length) }, worker));\n}\n\n/**\n * Runs `step` on each item in order, the next only once the one before is done. A step that\n * returns something stops there, and that is returned; null when every step ran.\n */\nasync function inOrder<T, R>(\n items: readonly T[],\n step: (item: T, index: number) => Promise<R | null>,\n index = 0\n): Promise<R | null> {\n const item = items[index];\n if (item === undefined) return null;\n const stop = await step(item, index);\n return stop === null ? inOrder(items, step, index + 1) : stop;\n}\n\n/** What a save has done so far: whether anything was written, and what failed. */\ninterface SaveRun {\n wrote: boolean;\n problems: string[];\n}\n\n/** Why a write failed: the service's words, or that it never answered. */\nfunction reasonFor(error: unknown, tr: Tr): string {\n return (\n serviceMessage(error) ??\n tr('calendar.v2.eventSaveOffline', 'The calendar service didn’t answer. Check your connection.')\n );\n}\n\n/** \"10 min before\", \"When it starts\". */\nfunction reminderWords(reminder: ReminderDraft, ctx: EventSaveContext): string {\n return reminder.minutesBefore === 0\n ? ctx.tr('calendar.v2.reminderAtStart', 'When it starts')\n : ctx.tr('calendar.v2.reminderBefore', '{{time}} before', {\n time: formatDuration(reminder.minutesBefore, ctx.durationWords),\n });\n}\n\n/**\n * A write whose failure is noted (in the service's words) rather than thrown; it says whether\n * it went through.\n */\nfunction attempt(\n run: SaveRun,\n ctx: EventSaveContext,\n work: () => Promise<unknown>,\n failed: (why: string) => string\n): () => Promise<boolean> {\n return async () => {\n try {\n await work();\n run.wrote = true;\n return true;\n } catch (error) {\n run.problems.push(failed(reasonFor(error, ctx.tr)));\n return false;\n }\n };\n}\n\n/** Creates the event; its id. */\nasync function createEvent(client: Client, input: CreateEventInput): Promise<string> {\n const created = await client.mutate<\n CalendarV2CreateEventMutation,\n CalendarV2CreateEventMutationVariables\n >({\n mutation: CalendarV2CreateEventDocument,\n variables: { input },\n });\n const id = created.data?.createEvent.id;\n if (!id) throw new Error('No event came back');\n return id;\n}\n\n/**\n * The event's updates, one after the other (a new rule first, then the series' new start). If\n * the first fails nothing has changed: its error is returned. A later one that fails is noted.\n */\nasync function applyUpdates(\n client: Client,\n id: string,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): Promise<{ error: unknown } | null> {\n return inOrder(plan.updates, async (update, index) => {\n try {\n await client.mutate<CalendarV2UpdateEventMutation, CalendarV2UpdateEventMutationVariables>({\n mutation: CalendarV2UpdateEventDocument,\n variables: { id, input: update.input, scope: update.scope },\n });\n run.wrote = true;\n return null;\n } catch (error) {\n if (index === 0) return { error };\n run.problems.push(\n ctx.tr('calendar.v2.eventRuleFailed', 'The new repeat didn’t save: {{reason}}', {\n reason: reasonFor(error, ctx.tr),\n })\n );\n return null;\n }\n });\n}\n\n/** Guests out and in. */\nfunction guestTasks(\n client: Client,\n id: string,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<boolean>)[] {\n const { tr } = ctx;\n return [\n ...plan.removeGuests.map((guest) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<CalendarV2RemoveGuestMutation, CalendarV2RemoveGuestMutationVariables>({\n mutation: CalendarV2RemoveGuestDocument,\n variables: { attendeeId: guest.attendeeId ?? '' },\n }),\n (why) =>\n tr('calendar.v2.guestRemoveFailed', 'Couldn’t remove {{name}}: {{reason}}', {\n name: ctx.guestName(guest),\n reason: why,\n })\n )\n ),\n ...plan.addGuests.map((guest: GuestDraft) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<CalendarV2AddGuestMutation, CalendarV2AddGuestMutationVariables>({\n mutation: CalendarV2AddGuestDocument,\n variables: { eventId: id, userId: guest.userId, email: guest.email, name: guest.name },\n }),\n (why) =>\n tr('calendar.v2.guestAddFailed', 'Couldn’t invite {{name}}: {{reason}}', {\n name: ctx.guestName(guest),\n reason: why,\n })\n )\n ),\n ];\n}\n\n/** Reminders out and in. */\nfunction reminderTasks(\n client: Client,\n id: string,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<boolean>)[] {\n const { tr } = ctx;\n return [\n ...plan.removeReminders.map((reminder) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<\n CalendarV2DeleteReminderMutation,\n CalendarV2DeleteReminderMutationVariables\n >({\n mutation: CalendarV2DeleteReminderDocument,\n variables: { id: reminder.reminderId ?? '' },\n }),\n (why) =>\n tr(\n 'calendar.v2.reminderRemoveFailed',\n 'Couldn’t remove the reminder {{when}}: {{reason}}',\n {\n when: reminderWords(reminder, ctx),\n reason: why,\n }\n )\n )\n ),\n ...plan.addReminders.map((reminder) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<\n CalendarV2CreateReminderMutation,\n CalendarV2CreateReminderMutationVariables\n >({\n mutation: CalendarV2CreateReminderDocument,\n variables: {\n input: {\n eventId: id,\n minutesBefore: reminder.minutesBefore,\n channel: REMINDER_CHANNEL[reminder.channel],\n },\n },\n }),\n (why) =>\n tr('calendar.v2.reminderAddFailed', 'Couldn’t add the reminder {{when}}: {{reason}}', {\n when: reminderWords(reminder, ctx),\n reason: why,\n })\n )\n ),\n ];\n}\n\n/**\n * The room, as one task: a room moving to a new time (or another room) is let go before it is\n * booked again, and booked only once it is let go; else the event would hold two bookings. The\n * old one then stands, and saving again tries both again.\n */\nfunction roomTask(\n client: Client,\n id: string,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<void>)[] {\n const { tr } = ctx;\n const cancelId = plan.cancelBookingId;\n const book = plan.bookRoom;\n const release = cancelId\n ? attempt(\n run,\n ctx,\n () =>\n client.mutate<\n CalendarV2CancelRoomBookingMutation,\n CalendarV2CancelRoomBookingMutationVariables\n >({\n mutation: CalendarV2CancelRoomBookingDocument,\n variables: { bookingId: cancelId },\n }),\n (why) =>\n book\n ? tr(\n 'calendar.v2.roomMoveFailed',\n 'Couldn’t move the room booking, so it stays as it was: {{reason}}',\n { reason: why }\n )\n : tr(\n 'calendar.v2.roomReleaseFailed',\n 'Couldn’t let go of the room booked before: {{reason}}',\n { reason: why }\n )\n )\n : null;\n const reserve = book\n ? attempt(\n run,\n ctx,\n () =>\n client.mutate<CalendarV2BookRoomMutation, CalendarV2BookRoomMutationVariables>({\n mutation: CalendarV2BookRoomDocument,\n variables: {\n input: {\n eventId: id,\n resourceId: book.resourceId,\n startTime: book.start.toISOString(),\n endTime: book.end.toISOString(),\n },\n },\n }),\n (why) =>\n tr('calendar.v2.roomBookFailed', 'Couldn’t book {{room}}: {{reason}}', {\n room: ctx.roomName(book.resourceId) ?? tr('calendar.v2.theRoom', 'The room'),\n reason: why,\n })\n )\n : null;\n if (!release && !reserve) return [];\n return [\n async () => {\n if (release && !(await release())) return;\n if (reserve) await reserve();\n },\n ];\n}\n\n/** The success toast's title: \"Added “Sync” to Customer calls, Fri 20 Nov 13:00 – 14:00.\" */\nfunction savedWords(\n form: EventForm,\n event: CalendarEventV2 | null,\n created: boolean,\n ctx: EventSaveContext\n): string {\n const { tr } = ctx;\n const title = form.title.trim();\n if (!created) {\n return event?.isRecurring\n ? tr('calendar.v2.eventSavedSeries', 'Saved every event in “{{title}}”.', { title })\n : tr('calendar.v2.eventSaved', 'Saved “{{title}}”.', { title });\n }\n const start = startInstant(form);\n const day = form.allDay ? form.firstDay : instantToZoned(start, ctx.timeZone).date;\n const when = form.allDay\n ? tr('calendar.v2.allDayLower', 'all day')\n : formatInstantRange(start, endInstant(form), ctx.timeZone, ctx.format);\n return tr('calendar.v2.eventAdded', 'Added “{{title}}” to {{calendar}}, {{day}} {{time}}.', {\n title,\n calendar: ctx.calendarName(form.calendarId ?? '') ?? tr('calendar.v2.aCalendar', 'a calendar'),\n day: formatDay(day, ctx.format, 'short'),\n time: when,\n });\n}\n\nexport function useEventSave(\n context: EventSaveContext\n): (request: SaveRequest) => Promise<SaveOutcome> {\n const client = useApolloClient();\n const notify = useNotify();\n const contextRef = useRef(context);\n useEffect(() => {\n contextRef.current = context;\n });\n\n return useCallback(\n async ({ form, event, scope }: SaveRequest): Promise<SaveOutcome> => {\n const ctx = contextRef.current;\n const { tr } = ctx;\n const title = form.title.trim();\n const plan: SavePlan = event\n ? planEdit(form, event, ctx.timeZone, scope)\n : planNewEvent(form);\n const failed = (error: unknown): SaveOutcome => {\n notify({\n title: plan.create\n ? tr('calendar.v2.eventAddFailed', 'Couldn’t add “{{title}}”', { title })\n : tr('calendar.v2.eventSaveFailed', 'Couldn’t save “{{title}}”', { title }),\n description: reasonFor(error, tr),\n tone: 'error',\n urgent: true,\n });\n return { kind: 'failed' };\n };\n\n // ── The event itself ──\n let id = event?.id ?? null;\n if (plan.create) {\n try {\n id = await createEvent(client, plan.create);\n } catch (error) {\n return failed(error);\n }\n }\n if (!id) return { kind: 'failed' };\n const run: SaveRun = { wrote: plan.create !== null, problems: [] };\n const firstUpdate = await applyUpdates(client, id, plan, run, ctx);\n if (firstUpdate) return failed(firstUpdate.error);\n\n // ── Its guests, reminders and room ──\n await inTurns(\n [\n ...guestTasks(client, id, plan, run, ctx),\n ...reminderTasks(client, id, plan, run, ctx),\n ...roomTask(client, id, plan, run, ctx),\n ],\n PARALLEL_WRITES\n );\n if (run.wrote) invalidateCalendarEvents();\n\n if (run.problems.length > 0) {\n notify({\n title: plan.create\n ? tr('calendar.v2.eventAddedPartly', 'Added “{{title}}”, but not all of it', { title })\n : tr('calendar.v2.eventSavedPartly', 'Saved “{{title}}”, but not all of it', { title }),\n description: `${run.problems.join(' ')} ${tr(\n 'calendar.v2.eventSaveAgain',\n 'Save again to try the rest.'\n )}`,\n tone: 'warning',\n urgent: true,\n });\n return { kind: 'partial', eventId: id };\n }\n notify({ title: savedWords(form, event, plan.create !== null, ctx), tone: 'success' });\n return { kind: 'saved', eventId: id };\n },\n [client, notify]\n );\n}\n"],"mappings":";;;;;;;;;;;;AA8FA,IAAMA,IAAkB;AAKxB,SAAgBC,EAAe,GAA+B;CAK5D,OAJIC,EAAsB,GAAGC,CAAK,IAChBA,EAAM,OAAO,KAAK,MAASC,EAAK,QAAQ,KAAK,CAAC,CAAC,CAAC,KAAK,OAC9D,KAAW,OAEb;AACT;AAGA,eAAeC,EAAQ,GAA4C,GAA6B;CAC9F,IAAIC,IAAO,GACLC,IAAS,YAA2B;EACxC,IAAMC,IAAOC,EAAMH;EAEnB,AADA,KAAQ,GACHE,MACL,MAAMA,EAAK,GACX,MAAMD,EAAO;CACf;CACA,MAAM,QAAQ,IAAI,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAIG,GAAMD,EAAM,MAAM,EAAE,GAAGF,CAAM,CAAC;AAChF;AAMA,eAAeI,EACb,GACA,GACA,IAAQ,GACW;CACnB,IAAMP,IAAOQ,EAAMC;CACnB,IAAIT,MAAS,KAAA,GAAW,OAAO;CAC/B,IAAMU,IAAO,MAAMC,EAAKX,GAAMS,CAAK;CACnC,OAAOC,MAAS,OAAOH,EAAQC,GAAOG,GAAMF,IAAQ,CAAC,IAAIC;AAC3D;AASA,SAASE,EAAU,GAAgB,GAAgB;CACjD,OACEf,EAAeE,CAAK,KACpBc,EAAG,gCAAgC,4DAA4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,GAAKJ,CAAG;GAC3C,GAAGuB,EAASf,GAAQD,GAAII,GAAMP,GAAKJ,CAAG;EACxC,GACApB,CACF,GACIwB,EAAI,SAAOoD,EAAyB,GAEpCpD,EAAI,SAAS,SAAS,KACxByC,EAAO;GACL,OAAOlC,EAAK,SACRd,EAAG,gCAAgC,wCAAwC,EAAE,SAAM,CAAC,IACpFA,EAAG,gCAAgC,wCAAwC,EAAE,SAAM,CAAC;GACxF,aAAa,GAAGO,EAAI,SAAS,KAAK,GAAG,EAAE,GAAGP,EACxC,8BACA,6BACF;GACA,MAAM;GACN,QAAQ;EACV,CAAC,GACM;GAAE,MAAM;GAAW,SAASU;EAAG,MAExCsC,EAAO;GAAE,OAAOf,EAAWE,GAAME,GAAOvB,EAAK,WAAW,MAAMX,CAAG;GAAG,MAAM;EAAU,CAAC,GAC9E;GAAE,MAAM;GAAS,SAASO;EAAG;CACtC,GACA,CAACC,GAAQqC,CAAM,CACjB;AACF"}
|
|
1
|
+
{"version":3,"file":"useEventSave.js","names":["PARALLEL_WRITES","serviceMessage","CombinedGraphQLErrors","error","item","inTurns","next","worker","task","tasks","size","inOrder","items","index","stop","step","ALREADY_SO","alreadySo","key","graphQLErrorKey","reasonFor","tr","reminderWords","reminder","ctx","formatDuration","attempt","work","done","run","failed","modifyOccurrence","raw","client","CalendarV2ModifyOccurrenceDocument","made","toCalendarEventV2","me","splitSeries","CalendarV2SplitSeriesDocument","seriesId","createEvent","id","CalendarV2CreateEventDocument","applyUpdates","plan","CalendarV2UpdateEventDocument","update","madeNew","guestTasks","CalendarV2RemoveGuestDocument","guest","why","CalendarV2AddGuestDocument","reminderTasks","CalendarV2DeleteReminderDocument","CalendarV2CreateReminderDocument","REMINDER_CHANNEL","tagsTask","tags","write","leaveCancel","left","entry","date","cancelledDateTasks","dates","CalendarV2CancelOccurrenceDocument","formatDay","instantToZoned","roomTask","book","letGo","CalendarV2CancelRoomBookingDocument","cancelId","release","reserve","CalendarV2BookRoomDocument","seriesHeld","stillHeld","bookingId","savedWords","title","form","start","startInstant","day","route","row","when","formatInstantRange","endInstant","dateAfterSave","request","event","savedId","isSeriesDate","rruleOf","initial","useEventSave","useApolloClient","notify","useNotify","contextRef","useRef","context","useEffect","useCallback","saveRouteFor","creating","planOnNewEvent","carry","firstUpdate","invalidateCalendarEvents","carriesWork"],"sources":["../../../src/v2/event/useEventSave.ts"],"sourcesContent":["/**\n * Saving the event dialog (BOFF-15698 A2, A4): runs the plan (`savePlan.ts`) against the service\n * and says how it went in a themed toast.\n *\n * - The event itself first: `createEvent`, or the `updateEvent` calls. If that fails nothing\n * else is sent, the service's words are shown, and the dialog keeps everything typed.\n * - A date of a series changed on its own (\"This event\") is made an event of its own first\n * (`modifyRecurringInstance`, by the date's original start), and \"This and later\" splits the\n * series at the date (`updateEvent` with THIS_AND_FUTURE); the rest is then planned on what\n * the service made, which carries no guests, reminders or room of the series yet, nor (a\n * split) its cancelled dates. If that first step fails nothing changed; anything after it that\n * fails is a partial save.\n * - A series' cancelled dates are cancelled again where its new times put them\n * (`cancelRecurringInstance`), as the service keeps them by the instants they were at. The\n * service adds each to the series' list on its own, so a series' dates go one after another.\n * - Then its guests, reminders and room, a few at a time. Whatever of those fails is named with\n * the service's words, and the dialog stays open on the saved event (an edit from then on),\n * so saving again sends only what is still missing. What failed that the event read back\n * can't show (a series' booking still holding the room, tags, dates still to cancel) comes\n * back as the outcome's `carry`, for the next save to send.\n * - Letting go of a booking already let go, or cancelling a date already cancelled, is done:\n * saving again after a write whose answer was lost doesn't fail on it.\n * - After any write the views, free/busy and the dialog's own copy of the event reload\n * (`invalidateCalendarEvents`).\n */\nimport { useCallback, useEffect, useRef } from 'react';\nimport { CombinedGraphQLErrors } from '@apollo/client';\nimport { useApolloClient } from '@apollo/client/react';\nimport { useNotify } from '@burdenoff/fe-libs/ui';\nimport {\n CalendarV2AddGuestDocument,\n CalendarV2BookRoomDocument,\n CalendarV2CancelOccurrenceDocument,\n CalendarV2CancelRoomBookingDocument,\n CalendarV2CreateEventDocument,\n CalendarV2CreateReminderDocument,\n CalendarV2DeleteReminderDocument,\n CalendarV2ModifyOccurrenceDocument,\n CalendarV2RemoveGuestDocument,\n CalendarV2SplitSeriesDocument,\n CalendarV2UpdateEventDocument,\n type CalendarV2AddGuestMutation,\n type CalendarV2AddGuestMutationVariables,\n type CalendarV2BookRoomMutation,\n type CalendarV2BookRoomMutationVariables,\n type CalendarV2CancelOccurrenceMutation,\n type CalendarV2CancelOccurrenceMutationVariables,\n type CalendarV2CancelRoomBookingMutation,\n type CalendarV2CancelRoomBookingMutationVariables,\n type CalendarV2CreateEventMutation,\n type CalendarV2CreateEventMutationVariables,\n type CalendarV2CreateReminderMutation,\n type CalendarV2CreateReminderMutationVariables,\n type CalendarV2DeleteReminderMutation,\n type CalendarV2DeleteReminderMutationVariables,\n type CalendarV2ModifyOccurrenceMutation,\n type CalendarV2ModifyOccurrenceMutationVariables,\n type CalendarV2RemoveGuestMutation,\n type CalendarV2RemoveGuestMutationVariables,\n type CalendarV2SplitSeriesMutation,\n type CalendarV2SplitSeriesMutationVariables,\n type CalendarV2UpdateEventMutation,\n type CalendarV2UpdateEventMutationVariables,\n} from '../../generated/wspace-operations';\nimport type {\n CreateEventInput,\n ModifyRecurringInstanceInput,\n UpdateEventInput,\n} from '../../generated/wspace-types';\nimport { REMINDER_CHANNEL } from '../data/enums';\nimport { graphQLErrorKey } from '../data/errors';\nimport { invalidateCalendarEvents } from '../data/invalidation';\nimport { toCalendarEventV2 } from '../data/normalize';\nimport { isSeriesDate } from '../events/eventModel';\nimport type { Tr } from '../data/useEventActions';\nimport {\n formatDay,\n formatDuration,\n formatInstantRange,\n type CalendarFormat,\n type DurationWords,\n} from '../format';\nimport { instantToZoned } from '../time/calendarTime';\nimport type { CalendarEventV2 } from '../types';\nimport {\n startInstant,\n endInstant,\n rruleOf,\n type EventForm,\n type GuestDraft,\n type ReminderDraft,\n} from './eventForm';\nimport {\n carriesWork,\n planOnNewEvent,\n saveRouteFor,\n type SaveCarry,\n type SavePlan,\n type SaveRoute,\n type ScopeChoice,\n} from './savePlan';\n\nexport interface EventSaveContext {\n tr: Tr;\n format: CalendarFormat;\n durationWords: DurationWords;\n /** The calendar's zone: where the toast says the event is. */\n timeZone: string;\n /** A calendar's name, for \"Added … to Customer calls\". */\n calendarName: (calendarId: string) => string | null;\n /** A room's name, for \"Couldn't book Atlas\". */\n roomName: (roomId: string) => string | null;\n /** A guest's name, for \"Couldn't add Priya Raman\". */\n guestName: (guest: GuestDraft) => string;\n /** The signed-in person: whose answer an event read back carries. */\n me: string | null;\n}\n\nexport interface SaveRequest {\n form: EventForm;\n /** The form as the dialog opened (for a series' date, at that date). */\n initial: EventForm;\n /** The event as the service last returned it (a series' date at that date); null when new. */\n event: CalendarEventV2 | null;\n /** The stored event behind it: for a series' date, the series at its first date. */\n row: CalendarEventV2 | null;\n /** A series' date: the answer to \"Change …\". */\n scope: ScopeChoice;\n /** What a save before left undone and the event read back can't show; null when nothing. */\n carry: SaveCarry | null;\n}\n\nexport type SaveOutcome =\n | { kind: 'saved'; eventId: string }\n /**\n * The event saved but not all of it did. The dialog goes on with `eventId` (at\n * `instanceDate`, a series' date); `madeNew`: the service made that event from a series (a\n * date on its own, or the later part of a split), so the guests and reminders the form holds\n * are new to it. `carry`: what failed that the event read back won't show, for the next save.\n */\n | {\n kind: 'partial';\n eventId: string;\n instanceDate: Date | null;\n madeNew: boolean;\n carry: SaveCarry | null;\n }\n /** Nothing changed on the service. */\n | { kind: 'failed' };\n\n/** How many guest, reminder and room writes run at once. */\nconst PARALLEL_WRITES = 4;\n\ntype Client = ReturnType<typeof useApolloClient>;\n\n/** The service's own words for a failed write; null when it never answered. */\nexport function serviceMessage(error: unknown): string | null {\n if (CombinedGraphQLErrors.is(error)) {\n const message = error.errors.map((item) => item.message.trim()).find(Boolean);\n return message ?? null;\n }\n return null;\n}\n\n/** Runs `tasks`, at most `size` at a time, each as soon as one before it is done. */\nasync function inTurns(tasks: readonly (() => Promise<unknown>)[], size: number): Promise<void> {\n let next = 0;\n const worker = async (): Promise<void> => {\n const task = tasks[next];\n next += 1;\n if (!task) return;\n await task();\n await worker();\n };\n await Promise.all(Array.from({ length: Math.min(size, tasks.length) }, worker));\n}\n\n/**\n * Runs `step` on each item in order, the next only once the one before is done. A step that\n * returns something stops there, and that is returned; null when every step ran.\n */\nasync function inOrder<T, R>(\n items: readonly T[],\n step: (item: T, index: number) => Promise<R | null>,\n index = 0\n): Promise<R | null> {\n const item = items[index];\n if (item === undefined) return null;\n const stop = await step(item, index);\n return stop === null ? inOrder(items, step, index + 1) : stop;\n}\n\n/**\n * What a save has done so far: whether anything was written, what failed, and of that what the\n * next plan couldn't send again on its own (`left`).\n */\ninterface SaveRun {\n wrote: boolean;\n problems: string[];\n left: SaveCarry;\n}\n\n/**\n * The service's words for a booking already let go (gone, cancelled or over), and for a date\n * already cancelled (or its series gone, or no longer repeating): what the write was for is so.\n */\nconst ALREADY_SO = new Set([\n 'resource.errors.bookingNotFound',\n 'resource.errors.cannotCancelBooking',\n 'recurrence.errors.instanceAlreadyCancelled',\n 'recurrence.errors.notRecurringSeries',\n 'recurrence.errors.seriesNotFound',\n]);\n\nfunction alreadySo(error: unknown): boolean {\n const key = graphQLErrorKey(error);\n return key !== null && ALREADY_SO.has(key);\n}\n\n/** Why a write failed: the service's words, or that it never answered. */\nfunction reasonFor(error: unknown, tr: Tr): string {\n return (\n serviceMessage(error) ??\n tr('calendar.v2.eventSaveOffline', 'The calendar service didn’t answer. Check your connection.')\n );\n}\n\n/** \"10 min before\", \"When it starts\". */\nfunction reminderWords(reminder: ReminderDraft, ctx: EventSaveContext): string {\n return reminder.minutesBefore === 0\n ? ctx.tr('calendar.v2.reminderAtStart', 'When it starts')\n : ctx.tr('calendar.v2.reminderBefore', '{{time}} before', {\n time: formatDuration(reminder.minutesBefore, ctx.durationWords),\n });\n}\n\n/**\n * A write whose failure is noted (in the service's words) rather than thrown; it says whether\n * it went through. An error `done` accepts means what it was for is so already.\n */\nfunction attempt(\n run: SaveRun,\n ctx: EventSaveContext,\n work: () => Promise<unknown>,\n failed: (why: string) => string,\n done: (error: unknown) => boolean = () => false\n): () => Promise<boolean> {\n return async () => {\n try {\n await work();\n run.wrote = true;\n return true;\n } catch (error) {\n if (done(error)) return true;\n run.problems.push(failed(reasonFor(error, ctx.tr)));\n return false;\n }\n };\n}\n\n/** Makes a series' date an event of its own; that event, as the service has it. */\nasync function modifyOccurrence(\n client: Client,\n input: ModifyRecurringInstanceInput,\n me: string | null\n): Promise<CalendarEventV2> {\n const result = await client.mutate<\n CalendarV2ModifyOccurrenceMutation,\n CalendarV2ModifyOccurrenceMutationVariables\n >({ mutation: CalendarV2ModifyOccurrenceDocument, variables: { input } });\n const raw = result.data?.modifyRecurringInstance;\n const made = raw ? toCalendarEventV2(raw, me) : null;\n if (!made) throw new Error('No event came back');\n return made;\n}\n\n/** Splits a series at a date; the new series from that date, as the service has it. */\nasync function splitSeries(\n client: Client,\n seriesId: string,\n input: UpdateEventInput,\n me: string | null\n): Promise<CalendarEventV2> {\n const result = await client.mutate<\n CalendarV2SplitSeriesMutation,\n CalendarV2SplitSeriesMutationVariables\n >({ mutation: CalendarV2SplitSeriesDocument, variables: { id: seriesId, input } });\n const raw = result.data?.updateEvent;\n const made = raw ? toCalendarEventV2(raw, me) : null;\n if (!made) throw new Error('No event came back');\n return made;\n}\n\n/** Creates the event; its id. */\nasync function createEvent(client: Client, input: CreateEventInput): Promise<string> {\n const created = await client.mutate<\n CalendarV2CreateEventMutation,\n CalendarV2CreateEventMutationVariables\n >({\n mutation: CalendarV2CreateEventDocument,\n variables: { input },\n });\n const id = created.data?.createEvent.id;\n if (!id) throw new Error('No event came back');\n return id;\n}\n\n/**\n * The event's updates, one after the other (a new rule first, then the series' new start). If\n * the first fails, its error is returned: nothing has changed, unless the service already made\n * the event from a series (`madeNew`), when it is noted with the rest. A later one that fails is\n * noted.\n */\nasync function applyUpdates(\n client: Client,\n id: string,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext,\n madeNew: boolean\n): Promise<{ error: unknown } | null> {\n return inOrder(plan.updates, async (update, index) => {\n try {\n await client.mutate<CalendarV2UpdateEventMutation, CalendarV2UpdateEventMutationVariables>({\n mutation: CalendarV2UpdateEventDocument,\n variables: { id, input: update.input, scope: update.scope },\n });\n run.wrote = true;\n return null;\n } catch (error) {\n if (index === 0 && !madeNew) return { error };\n run.problems.push(\n index === 0\n ? ctx.tr('calendar.v2.eventRestFailed', 'Its other changes didn’t save: {{reason}}', {\n reason: reasonFor(error, ctx.tr),\n })\n : ctx.tr('calendar.v2.eventRuleFailed', 'The new repeat didn’t save: {{reason}}', {\n reason: reasonFor(error, ctx.tr),\n })\n );\n return null;\n }\n });\n}\n\n/** Guests out and in. */\nfunction guestTasks(\n client: Client,\n id: string,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<boolean>)[] {\n const { tr } = ctx;\n return [\n ...plan.removeGuests.map((guest) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<CalendarV2RemoveGuestMutation, CalendarV2RemoveGuestMutationVariables>({\n mutation: CalendarV2RemoveGuestDocument,\n variables: { attendeeId: guest.attendeeId ?? '' },\n }),\n (why) =>\n tr('calendar.v2.guestRemoveFailed', 'Couldn’t remove {{name}}: {{reason}}', {\n name: ctx.guestName(guest),\n reason: why,\n })\n )\n ),\n ...plan.addGuests.map((guest: GuestDraft) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<CalendarV2AddGuestMutation, CalendarV2AddGuestMutationVariables>({\n mutation: CalendarV2AddGuestDocument,\n variables: { eventId: id, userId: guest.userId, email: guest.email, name: guest.name },\n }),\n (why) =>\n tr('calendar.v2.guestAddFailed', 'Couldn’t invite {{name}}: {{reason}}', {\n name: ctx.guestName(guest),\n reason: why,\n })\n )\n ),\n ];\n}\n\n/** Reminders out and in. */\nfunction reminderTasks(\n client: Client,\n id: string,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<boolean>)[] {\n const { tr } = ctx;\n return [\n ...plan.removeReminders.map((reminder) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<\n CalendarV2DeleteReminderMutation,\n CalendarV2DeleteReminderMutationVariables\n >({\n mutation: CalendarV2DeleteReminderDocument,\n variables: { id: reminder.reminderId ?? '' },\n }),\n (why) =>\n tr(\n 'calendar.v2.reminderRemoveFailed',\n 'Couldn’t remove the reminder {{when}}: {{reason}}',\n {\n when: reminderWords(reminder, ctx),\n reason: why,\n }\n )\n )\n ),\n ...plan.addReminders.map((reminder) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<\n CalendarV2CreateReminderMutation,\n CalendarV2CreateReminderMutationVariables\n >({\n mutation: CalendarV2CreateReminderDocument,\n variables: {\n input: {\n eventId: id,\n minutesBefore: reminder.minutesBefore,\n channel: REMINDER_CHANNEL[reminder.channel],\n },\n },\n }),\n (why) =>\n tr('calendar.v2.reminderAddFailed', 'Couldn’t add the reminder {{when}}: {{reason}}', {\n when: reminderWords(reminder, ctx),\n reason: why,\n })\n )\n ),\n ];\n}\n\n/** The series' tags on the event made from it (A4); kept for the next save when it fails. */\nfunction tagsTask(\n client: Client,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<void>)[] {\n const tags = plan.tags;\n if (!tags) return [];\n const write = attempt(\n run,\n ctx,\n () =>\n client.mutate<CalendarV2UpdateEventMutation, CalendarV2UpdateEventMutationVariables>({\n mutation: CalendarV2UpdateEventDocument,\n variables: { id: tags.eventId, input: tags.input, scope: tags.scope },\n }),\n (why) =>\n ctx.tr('calendar.v2.eventTagsFailed', 'Its tags didn’t save: {{reason}}', { reason: why })\n );\n return [\n async () => {\n if (!(await write())) run.left.tags = tags;\n },\n ];\n}\n\n/** Notes a series' date still to cancel, for the next save. */\nfunction leaveCancel(left: SaveCarry, seriesId: string, date: Date): void {\n const item = left.cancels.find((entry) => entry.seriesId === seriesId);\n if (item) item.dates.push(date);\n else left.cancels.push({ seriesId, dates: [date] });\n}\n\n/**\n * Series' cancelled dates, cancelled again where their new times put them (A4): one task a\n * series, its dates one after another (the service adds each to the series' list on its own,\n * so two at once could leave one out). One that fails is kept for the next save.\n */\nfunction cancelledDateTasks(\n client: Client,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<void>)[] {\n return plan.cancels.map(({ seriesId, dates }) => async () => {\n await inOrder(dates, async (date) => {\n const cancelled = await attempt(\n run,\n ctx,\n () =>\n client.mutate<\n CalendarV2CancelOccurrenceMutation,\n CalendarV2CancelOccurrenceMutationVariables\n >({\n mutation: CalendarV2CancelOccurrenceDocument,\n variables: { seriesId, instanceDate: date.toISOString() },\n }),\n (why) =>\n ctx.tr(\n 'calendar.v2.eventKeepCancelledFailed',\n 'Couldn’t keep {{day}} cancelled: {{reason}}',\n {\n day: formatDay(instantToZoned(date, ctx.timeZone).date, ctx.format, 'short'),\n reason: why,\n }\n ),\n alreadySo\n )();\n if (!cancelled) leaveCancel(run.left, seriesId, date);\n return null;\n });\n });\n}\n\n/**\n * The room, as one task: a room moving to a new time (or another room) is let go before it is\n * booked again, and booked only once it is let go; else the event would hold two bookings. The\n * old one then stands, and saving again tries both again. A booking a series held for the date\n * made an event of its own goes first; one that can't be let go is kept for the next save (the\n * event read back doesn't show it).\n */\nfunction roomTask(\n client: Client,\n id: string,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<void>)[] {\n const { tr } = ctx;\n const book = plan.bookRoom;\n const letGo = (bookingId: string) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<\n CalendarV2CancelRoomBookingMutation,\n CalendarV2CancelRoomBookingMutationVariables\n >({\n mutation: CalendarV2CancelRoomBookingDocument,\n variables: { bookingId },\n }),\n (why) =>\n book\n ? tr(\n 'calendar.v2.roomMoveFailed',\n 'Couldn’t move the room booking, so it stays as it was: {{reason}}',\n { reason: why }\n )\n : tr(\n 'calendar.v2.roomReleaseFailed',\n 'Couldn’t let go of the room booked before: {{reason}}',\n { reason: why }\n ),\n alreadySo\n );\n const cancelId = plan.cancelBookingId;\n const release = cancelId ? letGo(cancelId) : null;\n const reserve = book\n ? attempt(\n run,\n ctx,\n () =>\n client.mutate<CalendarV2BookRoomMutation, CalendarV2BookRoomMutationVariables>({\n mutation: CalendarV2BookRoomDocument,\n variables: {\n input: {\n eventId: id,\n resourceId: book.resourceId,\n startTime: book.start.toISOString(),\n endTime: book.end.toISOString(),\n },\n },\n }),\n (why) =>\n tr('calendar.v2.roomBookFailed', 'Couldn’t book {{room}}: {{reason}}', {\n room: ctx.roomName(book.resourceId) ?? tr('calendar.v2.theRoom', 'The room'),\n reason: why,\n })\n )\n : null;\n const seriesHeld = plan.releaseBookingIds;\n if (seriesHeld.length === 0 && !release && !reserve) return [];\n return [\n async () => {\n const stillHeld: string[] = [];\n await inOrder(seriesHeld, async (bookingId) => {\n if (!(await letGo(bookingId)())) stillHeld.push(bookingId);\n return null;\n });\n if (stillHeld.length > 0) {\n run.left.releaseBookingIds.push(...stillHeld);\n return;\n }\n if (release && !(await release())) return;\n if (reserve) await reserve();\n },\n ];\n}\n\n/** The success toast's title: \"Added “Sync” to Customer calls, Fri 20 Nov 13:00 – 14:00.\" */\nfunction savedWords(\n form: EventForm,\n route: SaveRoute,\n row: CalendarEventV2 | null,\n ctx: EventSaveContext\n): string {\n const { tr } = ctx;\n const title = form.title.trim();\n const start = startInstant(form);\n const day = form.allDay ? form.firstDay : instantToZoned(start, ctx.timeZone).date;\n if (route.kind === 'thisDate') {\n return tr('calendar.v2.eventSavedDate', 'Saved “{{title}}” on {{day}}.', {\n title,\n day: formatDay(day, ctx.format, 'short'),\n });\n }\n if (route.kind === 'split') {\n return tr('calendar.v2.eventSavedLater', 'Saved “{{title}}” from {{day}} on.', {\n title,\n day: formatDay(day, ctx.format, 'short'),\n });\n }\n if (route.kind === 'edit') {\n return row?.isRecurring && route.eventId === row.eventId\n ? tr('calendar.v2.eventSavedSeries', 'Saved every event in “{{title}}”.', { title })\n : tr('calendar.v2.eventSaved', 'Saved “{{title}}”.', { title });\n }\n const when = form.allDay\n ? tr('calendar.v2.allDayLower', 'all day')\n : formatInstantRange(start, endInstant(form), ctx.timeZone, ctx.format);\n return tr('calendar.v2.eventAdded', 'Added “{{title}}” to {{calendar}}, {{day}} {{time}}.', {\n title,\n calendar: ctx.calendarName(form.calendarId ?? '') ?? tr('calendar.v2.aCalendar', 'a calendar'),\n day: formatDay(day, ctx.format, 'short'),\n time: when,\n });\n}\n\n/**\n * The date of a series the dialog goes on with after a partial save: the date edited, where the\n * save put it (every event moved as the form moved it). With no date when that may not be a\n * date of the series any more (its repeat changed: a new end, other days), and for a split's new\n * series and a date made its own event: the series read back is its first date (for a split, the\n * edited one, at whatever time its update left it), and the event made is one of its own.\n */\nfunction dateAfterSave(request: SaveRequest, route: SaveRoute, savedId: string): Date | null {\n const { form, initial, event } = request;\n if (route.kind !== 'edit' || !event || event.eventId !== savedId || !isSeriesDate(event)) {\n return null;\n }\n return rruleOf(form) === rruleOf(initial) ? startInstant(form) : null;\n}\n\nexport function useEventSave(\n context: EventSaveContext\n): (request: SaveRequest) => Promise<SaveOutcome> {\n const client = useApolloClient();\n const notify = useNotify();\n const contextRef = useRef(context);\n useEffect(() => {\n contextRef.current = context;\n });\n\n return useCallback(\n async (request: SaveRequest): Promise<SaveOutcome> => {\n const { form, initial, event, row, carry } = request;\n const ctx = contextRef.current;\n const { tr } = ctx;\n const title = form.title.trim();\n const route = saveRouteFor(request, ctx.timeZone);\n const creating = route.kind === 'create';\n const failed = (error: unknown): SaveOutcome => {\n notify({\n title: creating\n ? tr('calendar.v2.eventAddFailed', 'Couldn’t add “{{title}}”', { title })\n : tr('calendar.v2.eventSaveFailed', 'Couldn’t save “{{title}}”', { title }),\n description: reasonFor(error, tr),\n tone: 'error',\n urgent: true,\n });\n return { kind: 'failed' };\n };\n\n // ── The event itself ──\n let id: string;\n let plan: SavePlan;\n // The service made an event from the series (a date on its own, or a split's new series).\n let made: CalendarEventV2 | null = null;\n try {\n if (route.kind === 'create') {\n id = await createEvent(client, route.plan.create);\n plan = route.plan;\n } else if (route.kind === 'edit') {\n id = route.eventId;\n plan = route.plan;\n } else {\n made =\n route.kind === 'thisDate'\n ? await modifyOccurrence(client, route.input, ctx.me)\n : await splitSeries(client, route.seriesId, route.input, ctx.me);\n id = made.eventId;\n plan = planOnNewEvent(\n route.form,\n initial,\n made,\n event ?? made,\n row ?? made,\n ctx.timeZone,\n carry\n );\n }\n } catch (error) {\n return failed(error);\n }\n const madeNew = made !== null;\n const run: SaveRun = {\n wrote: creating || madeNew,\n problems: [],\n left: { releaseBookingIds: [], tags: null, cancels: [] },\n };\n const firstUpdate = await applyUpdates(client, id, plan, run, ctx, madeNew);\n if (firstUpdate) return failed(firstUpdate.error);\n\n // ── Its guests, reminders and room ──\n await inTurns(\n [\n ...guestTasks(client, id, plan, run, ctx),\n ...reminderTasks(client, id, plan, run, ctx),\n ...roomTask(client, id, plan, run, ctx),\n ...tagsTask(client, plan, run, ctx),\n ...cancelledDateTasks(client, plan, run, ctx),\n ],\n PARALLEL_WRITES\n );\n if (run.wrote) invalidateCalendarEvents();\n\n if (run.problems.length > 0) {\n notify({\n title: creating\n ? tr('calendar.v2.eventAddedPartly', 'Added “{{title}}”, but not all of it', { title })\n : tr('calendar.v2.eventSavedPartly', 'Saved “{{title}}”, but not all of it', { title }),\n description: `${run.problems.join(' ')} ${tr(\n 'calendar.v2.eventSaveAgain',\n 'Save again to try the rest.'\n )}`,\n tone: 'warning',\n urgent: true,\n });\n return {\n kind: 'partial',\n eventId: id,\n instanceDate: dateAfterSave(request, route, id),\n madeNew,\n carry: carriesWork(run.left) ? run.left : null,\n };\n }\n notify({ title: savedWords(form, route, row, ctx), tone: 'success' });\n return { kind: 'saved', eventId: id };\n },\n [client, notify]\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuJA,IAAMA,IAAkB;AAKxB,SAAgBC,EAAe,GAA+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,CAAC;GACX,MAAM;IAAE,mBAAmB,CAAC;IAAG,MAAM;IAAM,SAAS,CAAC;GAAE;EACzD,GACMgE,IAAc,MAAMpE,EAAaX,GAAQS,GAAIG,GAAMhB,GAAKL,GAAKwB,CAAO;EAqC1E,OApCIgE,IAAoBlF,EAAOkF,EAAY,KAAK,KAGhD,MAAM3G,EACJ;GACE,GAAG4C,EAAWhB,GAAQS,GAAIG,GAAMhB,GAAKL,CAAG;GACxC,GAAG8B,EAAcrB,GAAQS,GAAIG,GAAMhB,GAAKL,CAAG;GAC3C,GAAG8C,EAASrC,GAAQS,GAAIG,GAAMhB,GAAKL,CAAG;GACtC,GAAGkC,EAASzB,GAAQY,GAAMhB,GAAKL,CAAG;GAClC,GAAGyC,EAAmBhC,GAAQY,GAAMhB,GAAKL,CAAG;EAC9C,GACAxB,CACF,GACI6B,EAAI,SAAOoF,EAAyB,GAEpCpF,EAAI,SAAS,SAAS,KACxBwE,EAAO;GACL,OAAOQ,IACHxF,EAAG,gCAAgC,wCAAwC,EAAE,SAAM,CAAC,IACpFA,EAAG,gCAAgC,wCAAwC,EAAE,SAAM,CAAC;GACxF,aAAa,GAAGQ,EAAI,SAAS,KAAK,GAAG,EAAE,GAAGR,EACxC,8BACA,6BACF;GACA,MAAM;GACN,QAAQ;EACV,CAAC,GACM;GACL,MAAM;GACN,SAASqB;GACT,cAAckD,EAAcC,GAASN,GAAO7C,CAAE;GAC9C;GACA,OAAOwE,EAAYrF,EAAI,IAAI,IAAIA,EAAI,OAAO;EAC5C,MAEFwE,EAAO;GAAE,OAAOpB,EAAWE,GAAMI,GAAOC,GAAKhE,CAAG;GAAG,MAAM;EAAU,CAAC,GAC7D;GAAE,MAAM;GAAS,SAASkB;EAAG;CACtC,GACA,CAACT,GAAQoE,CAAM,CACjB;AACF"}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import { formatDayTimeSpan as e, formatInstantRange as t } from "../format.js";
|
|
2
2
|
import { eventDays as n } from "../time/calendarTime.js";
|
|
3
|
-
import { canEditEvent as r, canMoveOnGrid as i, eventRoom as a,
|
|
3
|
+
import { canEditEvent as r, canMoveOnGrid as i, eventRoom as a, inSeries as o, isBusyOnly as s, isHappeningNow as c, isPastEvent as l, joinUrl as u, myPart as d } from "./eventModel.js";
|
|
4
4
|
// src/v2/events/eventLook.ts
|
|
5
|
-
function
|
|
6
|
-
let n =
|
|
5
|
+
function f(e, t) {
|
|
6
|
+
let n = s(e, t.calendar, t.me), f = d({
|
|
7
7
|
...e,
|
|
8
8
|
myResponse: t.answer ?? e.myResponse
|
|
9
|
-
}, t.me),
|
|
9
|
+
}, t.me), p = n ? null : a(e), m = !n && u(e) !== null, h = (e.location ?? e.locationAddress ?? "").split(",")[0]?.trim() ?? "";
|
|
10
10
|
return {
|
|
11
11
|
busyOnly: n,
|
|
12
|
-
invitation: !n &&
|
|
13
|
-
maybe: !n &&
|
|
14
|
-
declined: !n &&
|
|
15
|
-
faded: t.dimPast &&
|
|
16
|
-
happeningNow:
|
|
12
|
+
invitation: !n && f === "invited",
|
|
13
|
+
maybe: !n && f === "maybe",
|
|
14
|
+
declined: !n && f === "declined",
|
|
15
|
+
faded: t.dimPast && l(e, t.now, t.timeZone),
|
|
16
|
+
happeningNow: c(e, t.now),
|
|
17
17
|
editable: !n && r(e, t.calendar, t.me),
|
|
18
18
|
movable: !n && i(e, t.calendar, t.me, t.timeZone),
|
|
19
|
-
roomPending:
|
|
20
|
-
roomRefused:
|
|
21
|
-
repeating: !n && e
|
|
22
|
-
online:
|
|
19
|
+
roomPending: p?.status === "PENDING",
|
|
20
|
+
roomRefused: p?.status === "REJECTED",
|
|
21
|
+
repeating: !n && o(e),
|
|
22
|
+
online: m,
|
|
23
23
|
title: n ? t.tr("calendar.v2.busy", "Busy") : e.title || t.tr("calendar.v2.untitled", "(No title)"),
|
|
24
|
-
place: n ? null :
|
|
24
|
+
place: n ? null : p?.name ?? (m ? t.tr("calendar.v2.videoCall", "Video call") : h || null)
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function p(r, i, a) {
|
|
28
28
|
let { tr: o } = a, s = n(r, a.timeZone), c;
|
|
29
29
|
c = r.allDay ? o("calendar.v2.allDayLower", "all day") : s.start === s.end ? t(r.start, r.end, a.timeZone, a.format) : e(r.start, r.end, a.timeZone, a.format);
|
|
30
30
|
let l = [i.title, c];
|
|
31
31
|
return a.calendarName && l.push(a.calendarName), i.invitation && l.push(o("calendar.v2.markerInvitation", "waiting for your answer")), i.maybe && l.push(o("calendar.v2.markerMaybe", "you said maybe")), i.declined && l.push(o("calendar.v2.markerDeclined", "you declined")), i.roomPending && l.push(o("calendar.v2.markerRoomPending", "room waiting for approval")), i.roomRefused && l.push(o("calendar.v2.markerRoomRefused", "room not available")), i.repeating && l.push(o("calendar.v2.markerRepeats", "repeats")), i.happeningNow && l.push(o("calendar.v2.markerNow", "happening now")), l.join(", ");
|
|
32
32
|
}
|
|
33
|
-
export {
|
|
33
|
+
export { p as eventAriaLabel, f as eventLook };
|
|
34
34
|
|
|
35
35
|
//# sourceMappingURL=eventLook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventLook.js","names":["eventLook","busyOnly","isBusyOnly","event","context","part","myPart","room","eventRoom","online","joinUrl","address","isPastEvent","isHappeningNow","canEditEvent","canMoveOnGrid","eventAriaLabel","days","eventDays","when","tr","formatInstantRange","formatDayTimeSpan","parts","look"],"sources":["../../../src/v2/events/eventLook.ts"],"sourcesContent":["/**\n * How an event looks in every view (BOFF-15698 A1): the markers (invitation, maybe, private\n * \"Busy\", ended, on now, room waiting or refused, repeating) and the words a screen reader\n * hears for it. Pure apart from the translations it is given.\n */\nimport type { Tr } from '../data/useEventActions';\nimport type { CalendarFormat } from '../format';\nimport { formatDayTimeSpan, formatInstantRange } from '../format';\nimport { eventDays } from '../time/calendarTime';\nimport type { CalendarEventV2, CalendarV2, EventResponseV2 } from '../types';\nimport {\n canEditEvent,\n canMoveOnGrid,\n eventRoom,\n isBusyOnly,\n isHappeningNow,\n isPastEvent,\n joinUrl,\n myPart,\n} from './eventModel';\n\nexport interface EventLook {\n /** Someone else's private time: only \"Busy\" shows. */\n busyOnly: boolean;\n /** Waiting for the person's answer. */\n invitation: boolean;\n maybe: boolean;\n declined: boolean;\n /** Ended, and \"Fade past events\" is on. */\n faded: boolean;\n happeningNow: boolean;\n editable: boolean;\n /** Can be dragged and moved with the keyboard on the grid. */\n movable: boolean;\n /** The room is waiting for approval. */\n roomPending: boolean;\n /** The room booking was turned down. */\n roomRefused: boolean;\n repeating: boolean;\n /** A video call to join. */\n online: boolean;\n /** \"Busy\" or the title. */\n title: string;\n /** Where: the room, \"Video call\", or the first part of the address. */\n place: string | null;\n}\n\nexport interface LookContext {\n tr: Tr;\n me: string | null;\n now: Date;\n timeZone: string;\n dimPast: boolean;\n calendar: CalendarV2 | undefined;\n /** The person's answer, with one given on this page first. */\n answer: EventResponseV2 | null;\n}\n\nexport function eventLook(event: CalendarEventV2, context: LookContext): EventLook {\n const busyOnly = isBusyOnly(event, context.calendar, context.me);\n const part = myPart({ ...event, myResponse: context.answer ?? event.myResponse }, context.me);\n // Someone else's private time shows nothing but \"Busy\": no room, call or repeat markers.\n const room = busyOnly ? null : eventRoom(event);\n const online = !busyOnly && joinUrl(event) !== null;\n const address = (event.location ?? event.locationAddress ?? '').split(',')[0]?.trim() ?? '';\n return {\n busyOnly,\n invitation: !busyOnly && part === 'invited',\n maybe: !busyOnly && part === 'maybe',\n declined: !busyOnly && part === 'declined',\n faded: context.dimPast && isPastEvent(event, context.now, context.timeZone),\n happeningNow: isHappeningNow(event, context.now),\n editable: !busyOnly && canEditEvent(event, context.calendar, context.me),\n movable: !busyOnly && canMoveOnGrid(event, context.calendar, context.me, context.timeZone),\n roomPending: room?.status === 'PENDING',\n roomRefused: room?.status === 'REJECTED',\n repeating: !busyOnly && event
|
|
1
|
+
{"version":3,"file":"eventLook.js","names":["eventLook","busyOnly","isBusyOnly","event","context","part","myPart","room","eventRoom","online","joinUrl","address","isPastEvent","isHappeningNow","canEditEvent","canMoveOnGrid","inSeries","eventAriaLabel","days","eventDays","when","tr","formatInstantRange","formatDayTimeSpan","parts","look"],"sources":["../../../src/v2/events/eventLook.ts"],"sourcesContent":["/**\n * How an event looks in every view (BOFF-15698 A1): the markers (invitation, maybe, private\n * \"Busy\", ended, on now, room waiting or refused, repeating) and the words a screen reader\n * hears for it. Pure apart from the translations it is given.\n */\nimport type { Tr } from '../data/useEventActions';\nimport type { CalendarFormat } from '../format';\nimport { formatDayTimeSpan, formatInstantRange } from '../format';\nimport { eventDays } from '../time/calendarTime';\nimport type { CalendarEventV2, CalendarV2, EventResponseV2 } from '../types';\nimport {\n canEditEvent,\n canMoveOnGrid,\n eventRoom,\n inSeries,\n isBusyOnly,\n isHappeningNow,\n isPastEvent,\n joinUrl,\n myPart,\n} from './eventModel';\n\nexport interface EventLook {\n /** Someone else's private time: only \"Busy\" shows. */\n busyOnly: boolean;\n /** Waiting for the person's answer. */\n invitation: boolean;\n maybe: boolean;\n declined: boolean;\n /** Ended, and \"Fade past events\" is on. */\n faded: boolean;\n happeningNow: boolean;\n editable: boolean;\n /** Can be dragged and moved with the keyboard on the grid. */\n movable: boolean;\n /** The room is waiting for approval. */\n roomPending: boolean;\n /** The room booking was turned down. */\n roomRefused: boolean;\n repeating: boolean;\n /** A video call to join. */\n online: boolean;\n /** \"Busy\" or the title. */\n title: string;\n /** Where: the room, \"Video call\", or the first part of the address. */\n place: string | null;\n}\n\nexport interface LookContext {\n tr: Tr;\n me: string | null;\n now: Date;\n timeZone: string;\n dimPast: boolean;\n calendar: CalendarV2 | undefined;\n /** The person's answer, with one given on this page first. */\n answer: EventResponseV2 | null;\n}\n\nexport function eventLook(event: CalendarEventV2, context: LookContext): EventLook {\n const busyOnly = isBusyOnly(event, context.calendar, context.me);\n const part = myPart({ ...event, myResponse: context.answer ?? event.myResponse }, context.me);\n // Someone else's private time shows nothing but \"Busy\": no room, call or repeat markers.\n const room = busyOnly ? null : eventRoom(event);\n const online = !busyOnly && joinUrl(event) !== null;\n const address = (event.location ?? event.locationAddress ?? '').split(',')[0]?.trim() ?? '';\n return {\n busyOnly,\n invitation: !busyOnly && part === 'invited',\n maybe: !busyOnly && part === 'maybe',\n declined: !busyOnly && part === 'declined',\n faded: context.dimPast && isPastEvent(event, context.now, context.timeZone),\n happeningNow: isHappeningNow(event, context.now),\n editable: !busyOnly && canEditEvent(event, context.calendar, context.me),\n movable: !busyOnly && canMoveOnGrid(event, context.calendar, context.me, context.timeZone),\n roomPending: room?.status === 'PENDING',\n roomRefused: room?.status === 'REJECTED',\n repeating: !busyOnly && inSeries(event),\n online,\n title: busyOnly\n ? context.tr('calendar.v2.busy', 'Busy')\n : event.title || context.tr('calendar.v2.untitled', '(No title)'),\n place: busyOnly\n ? null\n : (room?.name ??\n (online ? context.tr('calendar.v2.videoCall', 'Video call') : address || null)),\n };\n}\n\n/** What a screen reader hears for an event: title, when, calendar, and its markers. */\nexport function eventAriaLabel(\n event: CalendarEventV2,\n look: EventLook,\n context: { tr: Tr; format: CalendarFormat; timeZone: string; calendarName: string | null }\n): string {\n const { tr } = context;\n const days = eventDays(event, context.timeZone);\n let when: string;\n if (event.allDay) when = tr('calendar.v2.allDayLower', 'all day');\n else if (days.start === days.end) {\n when = formatInstantRange(event.start, event.end, context.timeZone, context.format);\n } else {\n // Over midnight, or a day or more: both ends with their days.\n when = formatDayTimeSpan(event.start, event.end, context.timeZone, context.format);\n }\n const parts = [look.title, when];\n if (context.calendarName) parts.push(context.calendarName);\n if (look.invitation) parts.push(tr('calendar.v2.markerInvitation', 'waiting for your answer'));\n if (look.maybe) parts.push(tr('calendar.v2.markerMaybe', 'you said maybe'));\n if (look.declined) parts.push(tr('calendar.v2.markerDeclined', 'you declined'));\n if (look.roomPending)\n parts.push(tr('calendar.v2.markerRoomPending', 'room waiting for approval'));\n if (look.roomRefused) parts.push(tr('calendar.v2.markerRoomRefused', 'room not available'));\n if (look.repeating) parts.push(tr('calendar.v2.markerRepeats', 'repeats'));\n if (look.happeningNow) parts.push(tr('calendar.v2.markerNow', 'happening now'));\n return parts.join(', ');\n}\n"],"mappings":";;;;AA2DA,SAAgBA,EAAU,GAAwB,GAAiC;CACjF,IAAMC,IAAWC,EAAWC,GAAOC,EAAQ,UAAUA,EAAQ,EAAE,GACzDC,IAAOC,EAAO;EAAE,GAAGH;EAAO,YAAYC,EAAQ,UAAUD,EAAM;CAAW,GAAGC,EAAQ,EAAE,GAEtFG,IAAON,IAAW,OAAOO,EAAUL,CAAK,GACxCM,IAAS,CAACR,KAAYS,EAAQP,CAAK,MAAM,MACzCQ,KAAWR,EAAM,YAAYA,EAAM,mBAAmB,GAAA,CAAI,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK;CACzF,OAAO;EACL;EACA,YAAY,CAACF,KAAYI,MAAS;EAClC,OAAO,CAACJ,KAAYI,MAAS;EAC7B,UAAU,CAACJ,KAAYI,MAAS;EAChC,OAAOD,EAAQ,WAAWQ,EAAYT,GAAOC,EAAQ,KAAKA,EAAQ,QAAQ;EAC1E,cAAcS,EAAeV,GAAOC,EAAQ,GAAG;EAC/C,UAAU,CAACH,KAAYa,EAAaX,GAAOC,EAAQ,UAAUA,EAAQ,EAAE;EACvE,SAAS,CAACH,KAAYc,EAAcZ,GAAOC,EAAQ,UAAUA,EAAQ,IAAIA,EAAQ,QAAQ;EACzF,aAAaG,GAAM,WAAW;EAC9B,aAAaA,GAAM,WAAW;EAC9B,WAAW,CAACN,KAAYe,EAASb,CAAK;EACtC;EACA,OAAOF,IACHG,EAAQ,GAAG,oBAAoB,MAAM,IACrCD,EAAM,SAASC,EAAQ,GAAG,wBAAwB,YAAY;EAClE,OAAOH,IACH,OACCM,GAAM,SACNE,IAASL,EAAQ,GAAG,yBAAyB,YAAY,IAAIO,KAAW;CAC/E;AACF;AAGA,SAAgBM,EACd,GACA,GACA,GACQ;CACR,IAAM,EAAE,UAAOb,GACTc,IA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