@burdenoff/microfe-calendar 2026.1124.2 → 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.
Files changed (130) hide show
  1. package/dist/generated/wspace-operations.d.ts +811 -69
  2. package/dist/generated/wspace-operations.js +173 -19
  3. package/dist/generated/wspace-operations.js.map +1 -1
  4. package/dist/generated/wspace-types.d.ts +405 -6
  5. package/dist/pages/ResourcesPage.js.map +1 -1
  6. package/dist/translations/en.d.ts +250 -1
  7. package/dist/v2/CalendarPageV2.js +45 -41
  8. package/dist/v2/CalendarPageV2.js.map +1 -1
  9. package/dist/v2/CalendarRoutesV2.js +64 -64
  10. package/dist/v2/CalendarRoutesV2.js.map +1 -1
  11. package/dist/v2/data/enums.d.ts +1 -0
  12. package/dist/v2/data/enums.js +6 -2
  13. package/dist/v2/data/enums.js.map +1 -1
  14. package/dist/v2/data/errors.d.ts +5 -0
  15. package/dist/v2/data/errors.js +6 -2
  16. package/dist/v2/data/errors.js.map +1 -1
  17. package/dist/v2/data/normalize.d.ts +31 -3
  18. package/dist/v2/data/normalize.js +57 -13
  19. package/dist/v2/data/normalize.js.map +1 -1
  20. package/dist/v2/data/seriesDateLookup.d.ts +9 -0
  21. package/dist/v2/data/seriesDateLookup.js +12 -0
  22. package/dist/v2/data/seriesDateLookup.js.map +1 -0
  23. package/dist/v2/data/useEventActions.d.ts +9 -3
  24. package/dist/v2/data/useEventActions.js +239 -186
  25. package/dist/v2/data/useEventActions.js.map +1 -1
  26. package/dist/v2/data/useEventForPeek.js +63 -21
  27. package/dist/v2/data/useEventForPeek.js.map +1 -1
  28. package/dist/v2/data/useEventsInRangeV2.d.ts +40 -2
  29. package/dist/v2/data/useEventsInRangeV2.js +76 -47
  30. package/dist/v2/data/useEventsInRangeV2.js.map +1 -1
  31. package/dist/v2/day/DayPanel.js +1 -1
  32. package/dist/v2/day/DayPanel.js.map +1 -1
  33. package/dist/v2/dialogs/CalendarDialogsV2.js +12 -9
  34. package/dist/v2/dialogs/CalendarDialogsV2.js.map +1 -1
  35. package/dist/v2/event/CustomRepeat.d.ts +5 -0
  36. package/dist/v2/event/CustomRepeat.js +246 -0
  37. package/dist/v2/event/CustomRepeat.js.map +1 -0
  38. package/dist/v2/event/EventDetailsTab.d.ts +6 -0
  39. package/dist/v2/event/EventDetailsTab.js +291 -0
  40. package/dist/v2/event/EventDetailsTab.js.map +1 -0
  41. package/dist/v2/event/EventDialog.d.ts +35 -0
  42. package/dist/v2/event/EventDialog.js +388 -0
  43. package/dist/v2/event/EventDialog.js.map +1 -0
  44. package/dist/v2/event/EventDialogs.d.ts +3 -0
  45. package/dist/v2/event/EventDialogs.js +118 -0
  46. package/dist/v2/event/EventDialogs.js.map +1 -0
  47. package/dist/v2/event/EventMoreTab.d.ts +4 -0
  48. package/dist/v2/event/EventMoreTab.js +215 -0
  49. package/dist/v2/event/EventMoreTab.js.map +1 -0
  50. package/dist/v2/event/EventPeopleTab.d.ts +8 -0
  51. package/dist/v2/event/EventPeopleTab.js +422 -0
  52. package/dist/v2/event/EventPeopleTab.js.map +1 -0
  53. package/dist/v2/event/EventPlaceTab.d.ts +6 -0
  54. package/dist/v2/event/EventPlaceTab.js +264 -0
  55. package/dist/v2/event/EventPlaceTab.js.map +1 -0
  56. package/dist/v2/event/FindTimeDialog.d.ts +26 -0
  57. package/dist/v2/event/FindTimeDialog.js +667 -0
  58. package/dist/v2/event/FindTimeDialog.js.map +1 -0
  59. package/dist/v2/event/RepeatField.d.ts +5 -0
  60. package/dist/v2/event/RepeatField.js +91 -0
  61. package/dist/v2/event/RepeatField.js.map +1 -0
  62. package/dist/v2/event/dialogLogic.d.ts +97 -0
  63. package/dist/v2/event/dialogLogic.js +120 -0
  64. package/dist/v2/event/dialogLogic.js.map +1 -0
  65. package/dist/v2/event/dialogModel.d.ts +51 -0
  66. package/dist/v2/event/dialogModel.js +13 -0
  67. package/dist/v2/event/dialogModel.js.map +1 -0
  68. package/dist/v2/event/eventForm.d.ts +235 -0
  69. package/dist/v2/event/eventForm.js +450 -0
  70. package/dist/v2/event/eventForm.js.map +1 -0
  71. package/dist/v2/event/findTime.d.ts +120 -0
  72. package/dist/v2/event/findTime.js +149 -0
  73. package/dist/v2/event/findTime.js.map +1 -0
  74. package/dist/v2/event/findTimeSource.d.ts +102 -0
  75. package/dist/v2/event/findTimeSource.js +107 -0
  76. package/dist/v2/event/findTimeSource.js.map +1 -0
  77. package/dist/v2/event/parts.d.ts +46 -0
  78. package/dist/v2/event/parts.js +124 -0
  79. package/dist/v2/event/parts.js.map +1 -0
  80. package/dist/v2/event/place.d.ts +64 -0
  81. package/dist/v2/event/place.js +48 -0
  82. package/dist/v2/event/place.js.map +1 -0
  83. package/dist/v2/event/repeatWords.d.ts +19 -0
  84. package/dist/v2/event/repeatWords.js +130 -0
  85. package/dist/v2/event/repeatWords.js.map +1 -0
  86. package/dist/v2/event/rrule.d.ts +90 -0
  87. package/dist/v2/event/rrule.js +368 -0
  88. package/dist/v2/event/rrule.js.map +1 -0
  89. package/dist/v2/event/savePlan.d.ts +160 -0
  90. package/dist/v2/event/savePlan.js +219 -0
  91. package/dist/v2/event/savePlan.js.map +1 -0
  92. package/dist/v2/event/useEventData.d.ts +96 -0
  93. package/dist/v2/event/useEventData.js +229 -0
  94. package/dist/v2/event/useEventData.js.map +1 -0
  95. package/dist/v2/event/useEventDialogModel.d.ts +50 -0
  96. package/dist/v2/event/useEventDialogModel.js +144 -0
  97. package/dist/v2/event/useEventDialogModel.js.map +1 -0
  98. package/dist/v2/event/useEventSave.d.ts +57 -0
  99. package/dist/v2/event/useEventSave.js +276 -0
  100. package/dist/v2/event/useEventSave.js.map +1 -0
  101. package/dist/v2/events/eventLook.js +16 -16
  102. package/dist/v2/events/eventLook.js.map +1 -1
  103. package/dist/v2/events/eventModel.d.ts +17 -4
  104. package/dist/v2/events/eventModel.js +46 -34
  105. package/dist/v2/events/eventModel.js.map +1 -1
  106. package/dist/v2/events/localChanges.d.ts +4 -1
  107. package/dist/v2/events/localChanges.js +4 -2
  108. package/dist/v2/events/localChanges.js.map +1 -1
  109. package/dist/v2/format.d.ts +2 -0
  110. package/dist/v2/format.js +4 -0
  111. package/dist/v2/format.js.map +1 -1
  112. package/dist/v2/page/CalendarPageContext.d.ts +2 -2
  113. package/dist/v2/page/CalendarPageContext.js.map +1 -1
  114. package/dist/v2/page/useCalendarPageModel.js +141 -139
  115. package/dist/v2/page/useCalendarPageModel.js.map +1 -1
  116. package/dist/v2/page/viewState.d.ts +9 -1
  117. package/dist/v2/page/viewState.js +5 -3
  118. package/dist/v2/page/viewState.js.map +1 -1
  119. package/dist/v2/peek/EventPeek.js.map +1 -1
  120. package/dist/v2/peek/PeekEvent.js +210 -204
  121. package/dist/v2/peek/PeekEvent.js.map +1 -1
  122. package/dist/v2/rail/CalendarRail.js.map +1 -1
  123. package/dist/v2/rail/useMonthEventDates.js +1 -1
  124. package/dist/v2/rail/useMonthEventDates.js.map +1 -1
  125. package/dist/v2/runs/RunPeek.js.map +1 -1
  126. package/dist/v2/states/CalendarStates.d.ts +15 -0
  127. package/dist/v2/states/CalendarStates.js +42 -11
  128. package/dist/v2/states/CalendarStates.js.map +1 -1
  129. package/dist/v2/types.d.ts +32 -2
  130. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEventData.js","names":["EventMissingError","readSeriesDate","question","seriesDateQuestion","series","instanceMs","answer","client","CalendarV2EventOccurrencesDocument","id","occurrenceId","raw","occurrence","toOccurrenceV2","me","readEdited","result","CalendarV2EventDocument","eventId","row","toCalendarEventV2","event","editedState","key","error","load","graphQLErrorCode","read","refresh","useEditedEvent","useApolloClient","useCalendar","currentUser","revision","useCalendarEventsRevision","instanceDate","useKeyedLoad","toBooking","start","parseInstant","end","toBookings","parsed","booking","a","b","featuresOf","value","item","on","name","toRoomForEvent","place","part","listed","bookings","knownUntilOf","loadRooms","CalendarV2EventRoomsDocument","rooms","room","until","roomKnownFor","CalendarV2RoomBookingsDocument","DAY_MS","useRoomsForEvent","dayEnd","options","NO_ROOMS","IDENTITY_BATCH","loadIdentities","batches","index","userIds","CalendarV2MemberIdentitiesDocument","batch","identity","useIdentities","ids","useMemo","MEMBER_PAGE","MAX_MEMBER_PAGES","loadMembers","page","list","CalendarV2MembersDocument","useMemberDirectory","enabled","workspaceId","NO_MEMBERS","useTeamSearch","text","query","CalendarV2SearchTeamsDocument","team","loadTeamMemberIds","members","CalendarV2TeamMembersDocument","edge","node"],"sources":["../../../src/v2/event/useEventData.ts"],"sourcesContent":["/**\n * What the event dialog and Find a time read (BOFF-15698 A2): the event being edited, the rooms\n * with their bookings, the names of the people on an event, and the workspace's members and\n * teams for the guest picker. Each reloads after a write (`invalidateCalendarEvents`), and each\n * says when it failed: a failed load is never an empty list.\n */\nimport { useMemo } from 'react';\nimport { useApolloClient } from '@apollo/client/react';\nimport {\n CalendarV2EventDocument,\n CalendarV2EventOccurrencesDocument,\n CalendarV2EventRoomsDocument,\n CalendarV2MemberIdentitiesDocument,\n CalendarV2MembersDocument,\n CalendarV2RoomBookingsDocument,\n CalendarV2SearchTeamsDocument,\n CalendarV2TeamMembersDocument,\n type CalendarV2EventOccurrencesQuery,\n type CalendarV2EventOccurrencesQueryVariables,\n type CalendarV2EventQuery,\n type CalendarV2EventQueryVariables,\n type CalendarV2EventRoomsQuery,\n type CalendarV2EventRoomsQueryVariables,\n type CalendarV2MemberIdentitiesQuery,\n type CalendarV2MemberIdentitiesQueryVariables,\n type CalendarV2MembersQuery,\n type CalendarV2MembersQueryVariables,\n type CalendarV2RoomBookingsQuery,\n type CalendarV2RoomBookingsQueryVariables,\n type CalendarV2SearchTeamsQuery,\n type CalendarV2SearchTeamsQueryVariables,\n type CalendarV2TeamMembersQuery,\n type CalendarV2TeamMembersQueryVariables,\n} from '../../generated/wspace-operations';\nimport { useCalendar } from '../../providers/CalendarProvider';\nimport { graphQLErrorCode } from '../data/errors';\nimport { useCalendarEventsRevision } from '../data/invalidation';\nimport { occurrenceId, parseInstant, toCalendarEventV2, toOccurrenceV2 } from '../data/normalize';\nimport { seriesDateQuestion } from '../data/seriesDateLookup';\nimport { useKeyedLoad, type KeyedLoadState } from '../data/useKeyedLoad';\nimport type { CalendarEventV2 } from '../types';\nimport { knownUntilOf, roomKnownFor, type RoomBookingForEvent, type RoomForEvent } from './place';\n\ntype Client = ReturnType<typeof useApolloClient>;\ntype LoadStatus = 'idle' | 'loading' | 'ready' | 'error';\n\n// ── The event being edited ───────────────────────────────────────────────────\n\nexport type EditedEvent =\n | { status: 'none' }\n | { status: 'loading' }\n | { status: 'missing' }\n | { status: 'error'; error: Error; retry: () => void }\n | {\n status: 'ready';\n /** The event as the dialog edits it: a series' date at that date (A4). */\n event: CalendarEventV2;\n /** The stored event behind it: for a series' date, the series at its first date. */\n row: CalendarEventV2;\n retry: () => void;\n /**\n * After a write the event is read again: until then (or when that fails) `event` is the\n * one read before, fine to show but not to plan a save on.\n */\n refresh: 'current' | 'loading' | 'failed';\n };\n\nclass EventMissingError extends Error {}\n\n/** The edited event and the stored event behind it, as read. */\ninterface EditedRead {\n event: CalendarEventV2;\n row: CalendarEventV2;\n}\n\n/**\n * One date of a series as the calendar has it now, looked up with the views' range query (a\n * date cancelled or moved since isn't found); null when it isn't there.\n */\nasync function readSeriesDate(\n client: Client,\n series: CalendarEventV2,\n instanceMs: number,\n me: string | null\n): Promise<CalendarEventV2 | null> {\n const question = seriesDateQuestion(series, instanceMs);\n if (!question) return null;\n const result = await client.query<\n CalendarV2EventOccurrencesQuery,\n CalendarV2EventOccurrencesQueryVariables\n >({\n query: CalendarV2EventOccurrencesDocument,\n variables: question,\n fetchPolicy: 'network-only',\n });\n const answer = result.data?.eventsInRangeForCalendars;\n if (!answer) throw new Error('The series’ dates could not be read');\n const id = occurrenceId(series.eventId, new Date(instanceMs));\n const raw = answer.occurrences.find((occurrence) => occurrence.id === id);\n return raw ? toOccurrenceV2(raw, me) : null;\n}\n\n/** Reads the event (and with `instanceMs`, that date of its series, as the calendar has it). */\nasync function readEdited(\n client: Client,\n eventId: string,\n instanceMs: number | null,\n me: string | null\n): Promise<EditedRead> {\n const result = await client.query<CalendarV2EventQuery, CalendarV2EventQueryVariables>({\n query: CalendarV2EventDocument,\n variables: { id: eventId },\n fetchPolicy: 'network-only',\n });\n const row = result.data?.event ? toCalendarEventV2(result.data.event, me) : null;\n if (!row) throw new EventMissingError('The event could not be found');\n if (instanceMs === null) return { event: row, row };\n const event = await readSeriesDate(client, row, instanceMs, me);\n if (!event) throw new EventMissingError('That date of the series is not on the calendar');\n return { event, row };\n}\n\n/** What the dialog is told about the read, from the load for its key. */\nfunction editedState(key: string | null, load: KeyedLoadState<EditedRead>): EditedEvent {\n if (!key) return { status: 'none' };\n const error = load.error;\n if (error instanceof EventMissingError || (error && graphQLErrorCode(error) === 'NOT_FOUND')) {\n return { status: 'missing' };\n }\n const read = load.dataKey === key ? load.data : undefined;\n // After a write the last answer stands while the next one loads (or if it fails).\n if (read) {\n const refresh = error ? 'failed' : load.loading ? 'loading' : 'current';\n return { status: 'ready', event: read.event, row: read.row, retry: load.reload, refresh };\n }\n return error ? { status: 'error', error, retry: load.reload } : { status: 'loading' };\n}\n\n/**\n * The event as the service has it now (never the view's copy, which may carry a move the\n * service hasn't confirmed), read again after every write. With `instanceDate`, a series is\n * edited at that date of it (A4), as the calendar has the date now: a date cancelled or moved\n * since the dialog opened is `missing`, never edited as if it were still there.\n */\nexport function useEditedEvent(\n eventId: string | null,\n instanceDate: Date | null = null\n): EditedEvent {\n const client = useApolloClient();\n const { currentUser } = useCalendar();\n const me = currentUser?.id ?? null;\n const revision = useCalendarEventsRevision();\n const instanceMs = instanceDate?.getTime() ?? null;\n const key = eventId === null ? null : `${eventId}|${instanceMs ?? ''}`;\n const load = useKeyedLoad<EditedRead>(\n key,\n () => readEdited(client, eventId ?? '', instanceMs, me),\n revision\n );\n return editedState(key, load);\n}\n\n// ── Rooms ────────────────────────────────────────────────────────────────────\n\n/** The bookings the service's room list holds per room. */\nexport const ROOM_LIST_BOOKINGS = 5;\n\ntype RawRoom = CalendarV2EventRoomsQuery['getCalendarResources'][number];\ntype RawBooking = RawRoom['bookings'][number];\n\nfunction toBooking(raw: RawBooking): RoomBookingForEvent | null {\n if (raw.status !== 'APPROVED' && raw.status !== 'PENDING') return null;\n const start = parseInstant(raw.startTime);\n const end = parseInstant(raw.endTime);\n if (!start || !end) return null;\n return { id: raw.id, eventId: raw.eventId, start, end, pending: raw.status === 'PENDING' };\n}\n\nfunction toBookings(raw: readonly RawBooking[]): RoomBookingForEvent[] {\n return raw\n .flatMap((booking) => {\n const parsed = toBooking(booking);\n return parsed ? [parsed] : [];\n })\n .sort((a, b) => a.start.getTime() - b.start.getTime());\n}\n\n/** What a room has, from its stored features: a list of words, or the names set to true. */\nexport function featuresOf(value: unknown): string[] {\n if (Array.isArray(value)) {\n return value.filter((item): item is string => typeof item === 'string' && item.trim() !== '');\n }\n if (value && typeof value === 'object') {\n return Object.entries(value)\n .filter(([, on]) => on === true)\n .map(([name]) => name);\n }\n return [];\n}\n\nexport function toRoomForEvent(raw: RawRoom): RoomForEvent {\n const place = [raw.location, raw.building, raw.floor]\n .map((part) => part?.trim())\n .filter((part): part is string => Boolean(part));\n const listed = raw.bookings.filter(\n (booking) => booking.status === 'APPROVED' || booking.status === 'PENDING'\n );\n const bookings = toBookings(listed);\n return {\n id: raw.id,\n name: raw.name,\n place: place.length > 0 ? [...new Set(place)].join(' · ') : null,\n capacity: raw.capacity ?? null,\n bookable: raw.isBookable,\n needsApproval: raw.requireApproval,\n features: featuresOf(raw.features),\n bufferBefore: Math.max(0, raw.bufferBefore),\n bufferAfter: Math.max(0, raw.bufferAfter),\n bookings,\n // The list's limit counts the bookings it returned, parsed or not.\n knownUntil:\n listed.length < ROOM_LIST_BOOKINGS ? null : knownUntilOf(bookings, ROOM_LIST_BOOKINGS),\n };\n}\n\nasync function loadRooms(client: Client, until: Date | null): Promise<RoomForEvent[]> {\n const result = await client.query<CalendarV2EventRoomsQuery, CalendarV2EventRoomsQueryVariables>({\n query: CalendarV2EventRoomsDocument,\n fetchPolicy: 'network-only',\n });\n if (!result.data) throw new Error('The rooms could not be loaded');\n const rooms = result.data.getCalendarResources\n .filter((room) => room.isActive)\n .map(toRoomForEvent)\n .sort((a, b) => a.name.localeCompare(b.name));\n if (!until) return rooms;\n // Rooms booked beyond their five listed bookings before `until`: read their whole list.\n return Promise.all(\n rooms.map(async (room) => {\n if (roomKnownFor(room, until)) return room;\n const full = await client.query<\n CalendarV2RoomBookingsQuery,\n CalendarV2RoomBookingsQueryVariables\n >({\n query: CalendarV2RoomBookingsDocument,\n variables: { id: room.id },\n fetchPolicy: 'network-only',\n });\n const bookings = full.data?.getCalendarResource?.bookings;\n if (!bookings) throw new Error('The room’s bookings could not be loaded');\n return { ...room, bookings: toBookings(bookings), knownUntil: null };\n })\n );\n}\n\nexport interface RoomsForEvent {\n rooms: RoomForEvent[];\n status: LoadStatus;\n error: Error | null;\n retry: () => void;\n}\n\nconst DAY_MS = 86_400_000;\n\n/**\n * The workspace's rooms with every booking up to `until` known (the end of the time the dialog\n * looks at, rounded up to a UTC day so moving within it reads nothing again).\n */\nexport function useRoomsForEvent(\n until: Date | null,\n options: { skip?: boolean } = {}\n): RoomsForEvent {\n const client = useApolloClient();\n const revision = useCalendarEventsRevision();\n const dayEnd = until ? Math.ceil(until.getTime() / DAY_MS) * DAY_MS : 0;\n const key = options.skip ? null : `rooms|${dayEnd}`;\n const load = useKeyedLoad<RoomForEvent[]>(\n key,\n () => loadRooms(client, dayEnd ? new Date(dayEnd) : null),\n revision\n );\n const rooms = load.data ?? NO_ROOMS;\n return {\n rooms,\n status: options.skip\n ? 'idle'\n : load.error\n ? 'error'\n : load.data && load.dataKey === key\n ? 'ready'\n : 'loading',\n error: load.error,\n retry: load.reload,\n };\n}\n\nconst NO_ROOMS: RoomForEvent[] = [];\n\n// ── People ───────────────────────────────────────────────────────────────────\n\nexport interface MemberIdentity {\n userId: string;\n name: string;\n email: string | null;\n}\n\nexport interface Identities {\n /** Workspace members among the ids asked about; anyone else isn't (or is no longer) one. */\n byUserId: ReadonlyMap<string, MemberIdentity>;\n status: LoadStatus;\n retry: () => void;\n}\n\n/** The most ids one identity question carries. */\nconst IDENTITY_BATCH = 100;\n\n/** Names for these ids: only the workspace's active members come back. */\nexport async function loadIdentities(\n client: Client,\n userIds: readonly string[]\n): Promise<MemberIdentity[]> {\n const batches: string[][] = [];\n for (let index = 0; index < userIds.length; index += IDENTITY_BATCH) {\n batches.push(userIds.slice(index, index + IDENTITY_BATCH));\n }\n const answers = await Promise.all(\n batches.map((batch) =>\n client.query<CalendarV2MemberIdentitiesQuery, CalendarV2MemberIdentitiesQueryVariables>({\n query: CalendarV2MemberIdentitiesDocument,\n variables: { userIds: batch },\n fetchPolicy: 'cache-first',\n })\n )\n );\n return answers.flatMap((answer) => {\n if (!answer.data) throw new Error('Names could not be loaded');\n return answer.data.workspaceMemberIdentities.map((identity) => ({\n userId: identity.userId,\n name: identity.displayName.trim() || identity.email?.trim() || identity.userId,\n email: identity.email?.trim() || null,\n }));\n });\n}\n\n/** Names for these ids, and which of them are the workspace's members. */\nexport function useIdentities(userIds: readonly string[]): Identities {\n const client = useApolloClient();\n const ids = useMemo(() => [...new Set(userIds.filter(Boolean))].sort(), [userIds]);\n const key = ids.length === 0 ? null : ids.join('\\n');\n const load = useKeyedLoad<MemberIdentity[]>(key, () => loadIdentities(client, ids));\n const byUserId = useMemo(\n () => new Map((load.data ?? []).map((identity) => [identity.userId, identity])),\n [load.data]\n );\n return {\n byUserId,\n status:\n key === null ? 'idle' : load.error ? 'error' : load.dataKey === key ? 'ready' : 'loading',\n retry: load.reload,\n };\n}\n\n/** The most members the guest picker lists (100 a page). */\nconst MEMBER_PAGE = 100;\nconst MAX_MEMBER_PAGES = 10;\n\nasync function loadMembers(client: Client, workspaceId: string): Promise<MemberIdentity[]> {\n const userIds: string[] = [];\n for (let page = 0; page < MAX_MEMBER_PAGES; page += 1) {\n const result = await client.query<CalendarV2MembersQuery, CalendarV2MembersQueryVariables>({\n query: CalendarV2MembersDocument,\n variables: { workspaceId, pagination: { limit: MEMBER_PAGE, offset: page * MEMBER_PAGE } },\n fetchPolicy: 'network-only',\n });\n const list = result.data?.workspaceMembers;\n if (!list) throw new Error('The workspace’s members could not be loaded');\n for (const item of list.items) {\n if (item.status.toLowerCase() === 'active') userIds.push(item.userId);\n }\n if (!list.hasMore || list.items.length === 0) break;\n }\n const people = await loadIdentities(client, [...new Set(userIds)]);\n return people.sort((a, b) => a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }));\n}\n\nexport interface MemberDirectory {\n members: MemberIdentity[];\n status: LoadStatus;\n retry: () => void;\n}\n\n/** The workspace's active members, for the guest picker (read once it opens). */\nexport function useMemberDirectory(enabled: boolean): MemberDirectory {\n const client = useApolloClient();\n const { workspaceId } = useCalendar();\n const key = enabled && workspaceId ? `members|${workspaceId}` : null;\n const load = useKeyedLoad<MemberIdentity[]>(key, () => loadMembers(client, workspaceId ?? ''));\n return {\n members: load.data ?? NO_MEMBERS,\n status:\n key === null ? 'idle' : load.error ? 'error' : load.dataKey === key ? 'ready' : 'loading',\n retry: load.reload,\n };\n}\n\nconst NO_MEMBERS: MemberIdentity[] = [];\n\nexport interface TeamMatch {\n id: string;\n name: string;\n memberCount: number;\n}\n\nexport interface TeamSearch {\n teams: TeamMatch[];\n status: LoadStatus;\n}\n\n/** Teams whose name matches `query` (two letters at least). */\nexport function useTeamSearch(query: string): TeamSearch {\n const client = useApolloClient();\n const text = query.trim();\n const key = text.length >= 2 ? `teams|${text.toLowerCase()}` : null;\n const load = useKeyedLoad<TeamMatch[]>(key, async () => {\n const result = await client.query<\n CalendarV2SearchTeamsQuery,\n CalendarV2SearchTeamsQueryVariables\n >({\n query: CalendarV2SearchTeamsDocument,\n variables: { query: text },\n fetchPolicy: 'network-only',\n });\n if (!result.data) throw new Error('Teams could not be searched');\n return result.data.searchGroups.map((team) => ({\n id: team.id,\n name: team.name,\n memberCount: team.memberCount,\n }));\n });\n return {\n teams: key !== null && load.dataKey === key ? (load.data ?? []) : [],\n status:\n key === null ? 'idle' : load.error ? 'error' : load.dataKey === key ? 'ready' : 'loading',\n };\n}\n\n/** The most members a team adds at once. */\nexport const MAX_TEAM_GUESTS = 100;\n\n/** A team's members' ids (people only), for inviting each. */\nexport async function loadTeamMemberIds(\n client: Client,\n groupId: string\n): Promise<{ userIds: string[]; total: number }> {\n const result = await client.query<\n CalendarV2TeamMembersQuery,\n CalendarV2TeamMembersQueryVariables\n >({\n query: CalendarV2TeamMembersDocument,\n variables: { groupId },\n fetchPolicy: 'network-only',\n });\n const members = result.data?.groupMembers;\n if (!members) throw new Error('The team’s members could not be loaded');\n const userIds = members.edges\n .map((edge) => edge.node)\n .filter((node) => node.entityType.toLowerCase() === 'user')\n .map((node) => node.entityId);\n return { userIds: [...new Set(userIds)].slice(0, MAX_TEAM_GUESTS), total: members.totalCount };\n}\n"],"mappings":";;;;;;;;;;;AAmEA,IAAMA,IAAN,cAAgC,MAAM,CAAC;AAYvC,eAAeC,EACb,GACA,GACA,GACA,GACiC;CACjC,IAAMC,IAAWC,EAAmBC,GAAQC,CAAU;CACtD,IAAI,CAACH,GAAU,OAAO;CAStB,IAAMI,KAAS,MARMC,EAAO,MAG1B;EACA,OAAOC;EACP,WAAWN;EACX,aAAa;CACf,CAAC,EAAA,CACqB,MAAM;CAC5B,IAAI,CAACI,GAAQ,MAAU,MAAM,qCAAqC;CAClE,IAAMG,IAAKC,EAAaN,EAAO,SAAS,IAAI,KAAKC,CAAU,CAAC,GACtDM,IAAML,EAAO,YAAY,MAAM,MAAeM,EAAW,OAAOH,CAAE;CACxE,OAAOE,IAAME,EAAeF,GAAKG,CAAE,IAAI;AACzC;AAGA,eAAeC,EACb,GACA,GACA,GACA,GACqB;CACrB,IAAMC,IAAS,MAAMT,EAAO,MAA2D;EACrF,OAAOU;EACP,WAAW,EAAE,IAAIC,EAAQ;EACzB,aAAa;CACf,CAAC,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,OAAOuB,EAAQ;CAAW;AAC/F"}
@@ -0,0 +1,50 @@
1
+ import { CalendarEventV2 } from '../types';
2
+ import { EventSession } from './EventDialog';
3
+ import { EventDialogModel } from './dialogModel';
4
+ import { FooterNote, ReadBack } from './dialogLogic';
5
+ import { EventForm } from './eventForm';
6
+ import { EditedEvent } from './useEventData';
7
+ export interface EventDialogState {
8
+ model: EventDialogModel;
9
+ /** The event being edited (a series' date at that date, A4); null for a new one. */
10
+ event: CalendarEventV2 | null;
11
+ /** The stored event behind it: for a series' date, the series at its first date. */
12
+ row: CalendarEventV2 | null;
13
+ /** A date of a repeating event: the footer asks which events change. */
14
+ seriesDate: boolean;
15
+ readOnly: boolean;
16
+ /**
17
+ * Where reading the edited event back stands (`readBackOf`): null when the dialog holds it as
18
+ * the service has it now, or for a new event. Nothing saves until then: after a partial save a
19
+ * plan made on the older copy would send again what saved (or create a new event twice).
20
+ */
21
+ readBack: ReadBack | null;
22
+ /**
23
+ * Something would be lost by closing: the form isn't the event's (or as it opened), or a save
24
+ * left work for the next one.
25
+ */
26
+ dirty: boolean;
27
+ /**
28
+ * Save has something to send (an edit's plan isn't empty, or a save left work for the next
29
+ * one; a new event always).
30
+ */
31
+ toSave: boolean;
32
+ /** What the person's changes are told from (`baselineOf`). */
33
+ baseline: EventForm;
34
+ /** The calendar a new event goes on (the person's default until they pick). */
35
+ calendarId: string | null;
36
+ /** Why the person can't change it; null when they can. */
37
+ lock: string | null;
38
+ /** The footer's note; null while read-only. */
39
+ note: FooterNote | null;
40
+ heading: string;
41
+ description: string;
42
+ }
43
+ export declare function useEventDialogModel({ session, edited, onChange, onFindTime, onGuestsPending, showIssues, }: {
44
+ session: EventSession;
45
+ edited: EditedEvent;
46
+ onChange: (change: (session: EventSession) => EventSession) => void;
47
+ onFindTime: (session: EventSession) => void;
48
+ onGuestsPending: (pending: boolean) => void;
49
+ showIssues: boolean;
50
+ }): EventDialogState;
@@ -0,0 +1,144 @@
1
+ import { useFreeBusy as e } from "../data/useFreeBusy.js";
2
+ import { canEditEvent as t, isSeriesDate as n } from "../events/eventModel.js";
3
+ import { useCalendarPage as r } from "../page/CalendarPageContext.js";
4
+ import { baselineOf as i, dialogHeading as a, footerNote as o, headerDescription as s, lockReason as c, readBackOf as l, reloadNote as u, statusFrom as d } from "./dialogLogic.js";
5
+ import { availabilitySpan as f, endInstant as p, formFromEvent as m, formIssues as h, hasIssues as g, sameForm as _, startInstant as v } from "./eventForm.js";
6
+ import { freeBusyRangeFor as y } from "./findTime.js";
7
+ import { roomStateAt as b } from "./place.js";
8
+ import { carriesWork as x, isEmptyPlan as S, planEdit as C } from "./savePlan.js";
9
+ import { useIdentities as w, useRoomsForEvent as T } from "./useEventData.js";
10
+ import { useMemo as E } from "react";
11
+ // src/v2/event/useEventDialogModel.ts
12
+ var D = {
13
+ kind: "noFreeBusy",
14
+ span: null,
15
+ truncated: !1
16
+ };
17
+ function O(e, t, n) {
18
+ let r = n.flatMap((e) => e.userId ? [e.userId] : []).join("\n");
19
+ return E(() => [.../* @__PURE__ */ new Set([
20
+ ...e ? [e] : [],
21
+ ...t ? [t] : [],
22
+ ...r ? r.split("\n") : []
23
+ ])], [
24
+ r,
25
+ e,
26
+ t
27
+ ]);
28
+ }
29
+ function k(e, t) {
30
+ return e.status === "error" ? { kind: "error" } : e.status === "ready" ? {
31
+ kind: "ready",
32
+ person: e.byUserId.get(t)
33
+ } : { kind: "loading" };
34
+ }
35
+ function A(t, n) {
36
+ let { tr: i, timeZone: a, me: o } = r(), s = O(o, n?.organizerId ?? null, t.guests), c = w(s), l = f(t, a), u = y(l.start, l.end, a), p = e(s, u.from, u.to), m = n && !n.allDay ? {
37
+ start: n.start,
38
+ end: n.end
39
+ } : null;
40
+ return {
41
+ me: o ? d(k(p, o), l, a, m) : D,
42
+ guestStatus: (e) => {
43
+ if (!e.userId) return D;
44
+ if (c.status === "error") return {
45
+ kind: "error",
46
+ span: null,
47
+ truncated: !1
48
+ };
49
+ if (c.status !== "ready") return {
50
+ kind: "loading",
51
+ span: null,
52
+ truncated: !1
53
+ };
54
+ if (!c.byUserId.has(e.userId)) return D;
55
+ let t = e.attendeeId !== null && e.response !== "DECLINED";
56
+ return d(k(p, e.userId), l, a, t ? m : null);
57
+ },
58
+ guestName: (e) => (e.userId ? c.byUserId.get(e.userId)?.name : void 0) ?? e.name ?? e.email ?? i("calendar.v2.guest", "Guest"),
59
+ identities: c,
60
+ retry: () => {
61
+ p.refetch(), c.retry();
62
+ }
63
+ };
64
+ }
65
+ function j(e, t, n) {
66
+ return x(e.carry) || !_(e.form, t ? m(t, n) : e.initial);
67
+ }
68
+ function M(e, t) {
69
+ let { form: n, room: r } = e, i = r && !n.allDay ? {
70
+ name: r.name,
71
+ state: b(r, v(n), p(n), e.event?.eventId ?? null),
72
+ needsApproval: r.needsApproval
73
+ } : null, a = g(e.issues) || !e.event && !e.calendarId;
74
+ return o({
75
+ blocked: e.showIssues && a,
76
+ noCalendar: !e.calendarId,
77
+ title: n.title.trim(),
78
+ room: i,
79
+ busy: !n.allDay && (e.me.kind === "busy" || e.me.kind === "away"),
80
+ guestCount: n.guests.length
81
+ }, t);
82
+ }
83
+ function N(e, t) {
84
+ return !e.eventId || t.status !== "ready" ? {
85
+ event: null,
86
+ row: null,
87
+ seriesDate: !1
88
+ } : {
89
+ event: t.event,
90
+ row: t.row,
91
+ seriesDate: n(t.event)
92
+ };
93
+ }
94
+ function P({ session: e, edited: n, onChange: o, onFindTime: d, onGuestsPending: f, showIssues: m }) {
95
+ let g = r(), { tr: _, format: y, timeZone: b, me: w } = g, { form: E } = e, { event: D, row: O, seriesDate: k } = N(e, n), P = D ? g.calendarsById.get(D.calendarId) : void 0, F = D !== null && !t(D, P, w), I = e.eventId ? l(n) : null, L = A(E, D), R = T(p(E)), z = E.calendarId ?? g.defaultCalendarId, B = h(E), V = R.rooms.find((e) => e.id === E.roomId), H = I ? u(I, _) : M({
96
+ form: E,
97
+ event: D,
98
+ issues: B,
99
+ showIssues: m,
100
+ calendarId: z,
101
+ room: V,
102
+ me: L.me
103
+ }, _), U = {
104
+ form: E,
105
+ update: (e) => o((t) => ({
106
+ ...t,
107
+ form: e(t.form)
108
+ })),
109
+ readOnly: F,
110
+ event: D,
111
+ issues: B,
112
+ showIssues: m,
113
+ start: v(E),
114
+ end: p(E),
115
+ me: L.me,
116
+ guestStatus: L.guestStatus,
117
+ retryFreeBusy: L.retry,
118
+ identities: L.identities,
119
+ guestName: L.guestName,
120
+ rooms: R,
121
+ openFindTime: () => d(e),
122
+ guestsPending: f,
123
+ scope: k ? e.scope : null
124
+ }, W = D ? L.identities.byUserId.get(D.organizerId)?.name : null;
125
+ return {
126
+ model: U,
127
+ event: D,
128
+ row: O,
129
+ seriesDate: k,
130
+ readOnly: F,
131
+ readBack: I,
132
+ dirty: j(e, D, b),
133
+ toSave: !D || x(e.carry) || !S(C(E, D, b)),
134
+ baseline: i(e, n, b),
135
+ calendarId: z,
136
+ lock: F && D ? c(D, P, W ?? null, _) : null,
137
+ note: F ? null : H,
138
+ heading: a(e.eventId, F, _),
139
+ description: s(E, _, y)
140
+ };
141
+ }
142
+ export { P as useEventDialogModel };
143
+
144
+ //# sourceMappingURL=useEventDialogModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEventDialogModel.js","names":["NO_FREE_BUSY","useAskIds","guestKey","guests","guest","useMemo","me","organizerId","answerFrom","freeBusy","userId","usePeopleTime","useCalendarPage","askIds","event","form","identities","useIdentities","span","availabilitySpan","timeZone","range","freeBusyRangeFor","useFreeBusy","ownTime","statusFrom","invited","tr","isDirty","carriesWork","session","sameForm","formFromEvent","noteFor","input","roomThen","room","roomStateAt","startInstant","endInstant","blocked","hasIssues","footerNote","editedPair","edited","isSeriesDate","useEventDialogModel","page","calendar","readOnly","canEditEvent","readBack","readBackOf","people","rooms","useRoomsForEvent","calendarId","issues","formIssues","item","note","reloadNote","model","onChange","current","change","onFindTime","onGuestsPending","seriesDate","organizerName","isEmptyPlan","planEdit","baselineOf","lockReason","dialogHeading","headerDescription","format"],"sources":["../../../src/v2/event/useEventDialogModel.ts"],"sourcesContent":["/**\n * Everything the event dialog's tabs and footer read (BOFF-15698 A2), built from the session the\n * host keeps and the event as the service last returned it: who may change it, what each person's\n * time is then (free/busy), the rooms, what stops a save, and the header and footer words.\n */\nimport { useMemo } from 'react';\nimport type { Tr } from '../data/useEventActions';\nimport { useFreeBusy, type FreeBusyV2 } from '../data/useFreeBusy';\nimport { canEditEvent, isSeriesDate } from '../events/eventModel';\nimport { useCalendarPage } from '../page/CalendarPageContext';\nimport type { CalendarEventV2 } from '../types';\nimport type { EventSession } from './EventDialog';\nimport type { EventDialogModel, PersonStatus } from './dialogModel';\nimport {\n baselineOf,\n dialogHeading,\n footerNote,\n headerDescription,\n lockReason,\n readBackOf,\n reloadNote,\n statusFrom,\n type FooterNote,\n type FreeBusyAnswer,\n type ReadBack,\n} from './dialogLogic';\nimport {\n availabilitySpan,\n endInstant,\n formFromEvent,\n formIssues,\n hasIssues,\n sameForm,\n startInstant,\n type EventForm,\n type FormIssues,\n type GuestDraft,\n} from './eventForm';\nimport { freeBusyRangeFor } from './findTime';\nimport { roomStateAt, type RoomForEvent } from './place';\nimport { carriesWork, isEmptyPlan, planEdit } from './savePlan';\nimport { useIdentities, useRoomsForEvent, type EditedEvent, type Identities } from './useEventData';\n\nexport interface EventDialogState {\n model: EventDialogModel;\n /** The event being edited (a series' date at that date, A4); null for a new one. */\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 date of a repeating event: the footer asks which events change. */\n seriesDate: boolean;\n readOnly: boolean;\n /**\n * Where reading the edited event back stands (`readBackOf`): null when the dialog holds it as\n * the service has it now, or for a new event. Nothing saves until then: after a partial save a\n * plan made on the older copy would send again what saved (or create a new event twice).\n */\n readBack: ReadBack | null;\n /**\n * Something would be lost by closing: the form isn't the event's (or as it opened), or a save\n * left work for the next one.\n */\n dirty: boolean;\n /**\n * Save has something to send (an edit's plan isn't empty, or a save left work for the next\n * one; a new event always).\n */\n toSave: boolean;\n /** What the person's changes are told from (`baselineOf`). */\n baseline: EventForm;\n /** The calendar a new event goes on (the person's default until they pick). */\n calendarId: string | null;\n /** Why the person can't change it; null when they can. */\n lock: string | null;\n /** The footer's note; null while read-only. */\n note: FooterNote | null;\n heading: string;\n description: string;\n}\n\nconst NO_FREE_BUSY: PersonStatus = { kind: 'noFreeBusy', span: null, truncated: false };\n\n/** The ids to ask free/busy and names about: the person, the organiser, the guests. */\nfunction useAskIds(me: string | null, organizerId: string | null, guests: readonly GuestDraft[]) {\n const guestKey = guests.flatMap((guest) => (guest.userId ? [guest.userId] : [])).join('\\n');\n return useMemo(\n () => [\n ...new Set([\n ...(me ? [me] : []),\n ...(organizerId ? [organizerId] : []),\n ...(guestKey ? guestKey.split('\\n') : []),\n ]),\n ],\n [guestKey, me, organizerId]\n );\n}\n\n/** What free/busy has said about one person so far. */\nfunction answerFrom(freeBusy: FreeBusyV2, userId: string): FreeBusyAnswer {\n if (freeBusy.status === 'error') return { kind: 'error' };\n if (freeBusy.status !== 'ready') return { kind: 'loading' };\n return { kind: 'ready', person: freeBusy.byUserId.get(userId) };\n}\n\ninterface PeopleTime {\n me: PersonStatus;\n guestStatus: (guest: GuestDraft) => PersonStatus;\n guestName: (guest: GuestDraft) => string;\n identities: Identities;\n retry: () => void;\n}\n\n/** Each person's time while the event happens (free/busy), and the guests' names. */\nfunction usePeopleTime(form: EventForm, event: CalendarEventV2 | null): PeopleTime {\n const { tr, timeZone, me } = useCalendarPage();\n const askIds = useAskIds(me, event?.organizerId ?? null, form.guests);\n const identities = useIdentities(askIds);\n const span = availabilitySpan(form, timeZone);\n // Whole days, so moving the time within them asks nothing again (the hook keys on instants).\n const range = freeBusyRangeFor(span.start, span.end, timeZone);\n const freeBusy = useFreeBusy(askIds, range.from, range.to);\n // The event's own time doesn't make its organiser or its guests busy.\n const ownTime = event && !event.allDay ? { start: event.start, end: event.end } : null;\n const guestStatus = (guest: GuestDraft): PersonStatus => {\n if (!guest.userId) return NO_FREE_BUSY;\n // Only a member has free/busy: until that is known, nothing is said (never \"free\").\n if (identities.status === 'error') return { kind: 'error', span: null, truncated: false };\n if (identities.status !== 'ready') return { kind: 'loading', span: null, truncated: false };\n if (!identities.byUserId.has(guest.userId)) return NO_FREE_BUSY;\n const invited = guest.attendeeId !== null && guest.response !== 'DECLINED';\n return statusFrom(answerFrom(freeBusy, guest.userId), span, timeZone, invited ? ownTime : null);\n };\n const guestName = (guest: GuestDraft) => {\n const known = guest.userId ? identities.byUserId.get(guest.userId)?.name : undefined;\n return known ?? guest.name ?? guest.email ?? tr('calendar.v2.guest', 'Guest');\n };\n return {\n me: me ? statusFrom(answerFrom(freeBusy, me), span, timeZone, ownTime) : NO_FREE_BUSY,\n guestStatus,\n guestName,\n identities,\n retry: () => {\n freeBusy.refetch();\n identities.retry();\n },\n };\n}\n\n/**\n * Whether closing would lose something: the form differs from the event as the service has it\n * (a change, a time from Find a time, what a partial save left), or a new event's from how it\n * opened. A booking the save would only put right (`planEdit`) isn't the person's change.\n */\nfunction isDirty(session: EventSession, event: CalendarEventV2 | null, timeZone: string) {\n return (\n carriesWork(session.carry) ||\n !sameForm(session.form, event ? formFromEvent(event, timeZone) : session.initial)\n );\n}\n\n/** The footer's facts: what stops a save, the room then, the person's own time, the guests. */\nfunction noteFor(\n input: {\n form: EventForm;\n event: CalendarEventV2 | null;\n issues: FormIssues;\n showIssues: boolean;\n calendarId: string | null;\n room: RoomForEvent | undefined;\n me: PersonStatus;\n },\n tr: Tr\n): FooterNote {\n const { form, room } = input;\n const roomThen =\n room && !form.allDay\n ? {\n name: room.name,\n state: roomStateAt(\n room,\n startInstant(form),\n endInstant(form),\n input.event?.eventId ?? null\n ),\n needsApproval: room.needsApproval,\n }\n : null;\n const blocked = hasIssues(input.issues) || (!input.event && !input.calendarId);\n return footerNote(\n {\n blocked: input.showIssues && blocked,\n noCalendar: !input.calendarId,\n title: form.title.trim(),\n room: roomThen,\n busy: !form.allDay && (input.me.kind === 'busy' || input.me.kind === 'away'),\n guestCount: form.guests.length,\n },\n tr\n );\n}\n\n/** The event the dialog edits and the stored event behind it, once read; none for a new one. */\nfunction editedPair(\n session: EventSession,\n edited: EditedEvent\n): { event: CalendarEventV2 | null; row: CalendarEventV2 | null; seriesDate: boolean } {\n if (!session.eventId || edited.status !== 'ready') {\n return { event: null, row: null, seriesDate: false };\n }\n return { event: edited.event, row: edited.row, seriesDate: isSeriesDate(edited.event) };\n}\n\nexport function useEventDialogModel({\n session,\n edited,\n onChange,\n onFindTime,\n onGuestsPending,\n showIssues,\n}: {\n session: EventSession;\n edited: EditedEvent;\n onChange: (change: (session: EventSession) => EventSession) => void;\n onFindTime: (session: EventSession) => void;\n onGuestsPending: (pending: boolean) => void;\n showIssues: boolean;\n}): EventDialogState {\n const page = useCalendarPage();\n const { tr, format, timeZone, me } = page;\n const { form } = session;\n const { event, row, seriesDate } = editedPair(session, edited);\n const calendar = event ? page.calendarsById.get(event.calendarId) : undefined;\n const readOnly = event !== null && !canEditEvent(event, calendar, me);\n const readBack = session.eventId ? readBackOf(edited) : null;\n const people = usePeopleTime(form, event);\n const rooms = useRoomsForEvent(endInstant(form));\n const calendarId = form.calendarId ?? page.defaultCalendarId;\n const issues = formIssues(form);\n const room = rooms.rooms.find((item) => item.id === form.roomId);\n const note = readBack\n ? reloadNote(readBack, tr)\n : noteFor({ form, event, issues, showIssues, calendarId, room, me: people.me }, tr);\n\n const model: EventDialogModel = {\n form,\n update: (change: (form: EventForm) => EventForm) =>\n onChange((current) => ({ ...current, form: change(current.form) })),\n readOnly,\n event,\n issues,\n showIssues,\n start: startInstant(form),\n end: endInstant(form),\n me: people.me,\n guestStatus: people.guestStatus,\n retryFreeBusy: people.retry,\n identities: people.identities,\n guestName: people.guestName,\n rooms,\n openFindTime: () => onFindTime(session),\n guestsPending: onGuestsPending,\n scope: seriesDate ? session.scope : null,\n };\n const organizerName = event ? people.identities.byUserId.get(event.organizerId)?.name : null;\n return {\n model,\n event,\n row,\n seriesDate,\n readOnly,\n readBack,\n dirty: isDirty(session, event, timeZone),\n toSave: !event || carriesWork(session.carry) || !isEmptyPlan(planEdit(form, event, timeZone)),\n baseline: baselineOf(session, edited, timeZone),\n calendarId,\n lock: readOnly && event ? lockReason(event, calendar, organizerName ?? null, tr) : null,\n note: readOnly ? null : note,\n heading: dialogHeading(session.eventId, readOnly, tr),\n description: headerDescription(form, tr, format),\n };\n}\n"],"mappings":";;;;;;;;;;;AAgFA,IAAMA,IAA6B;CAAE,MAAM;CAAc,MAAM;CAAM,WAAW;AAAM;AAGtF,SAASC,EAAU,GAAmB,GAA4B,GAA+B;CAC/F,IAAMC,IAAWC,EAAO,SAAS,MAAWC,EAAM,SAAS,CAACA,EAAM,MAAM,IAAI,CAAC,CAAE,CAAC,CAAC,KAAK,IAAI;CAC1F,OAAOC,QACC,CACJ,mBAAG,IAAI,IAAI;EACT,GAAIC,IAAK,CAACA,CAAE,IAAI,CAAC;EACjB,GAAIC,IAAc,CAACA,CAAW,IAAI,CAAC;EACnC,GAAIL,IAAWA,EAAS,MAAM,IAAI,IAAI,CAAC;CACzC,CAAC,CACH,GACA;EAACA;EAAUI;EAAIC;CAAW,CAC5B;AACF;AAGA,SAASC,EAAW,GAAsB,GAAgC;CAGxE,OAFIC,EAAS,WAAW,UAAgB,EAAE,MAAM,QAAQ,IACpDA,EAAS,WAAW,UACjB;EAAE,MAAM;EAAS,QAAQA,EAAS,SAAS,IAAIC,CAAM;CAAE,IADtB,EAAE,MAAM,UAAU;AAE5D;AAWA,SAASC,EAAc,GAAiB,GAA2C;CACjF,IAAM,EAAE,OAAI,aAAU,UAAOC,EAAgB,GACvCC,IAASZ,EAAUK,GAAIQ,GAAO,eAAe,MAAMC,EAAK,MAAM,GAC9DC,IAAaC,EAAcJ,CAAM,GACjCK,IAAOC,EAAiBJ,GAAMK,CAAQ,GAEtCC,IAAQC,EAAiBJ,EAAK,OAAOA,EAAK,KAAK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WV,GAAUxB,CAAE,IACvBM,EAAQ;EAAE;EAAM;EAAO;EAAQ;EAAY;EAAY;EAAM,IAAIoB,EAAO;CAAG,GAAG1B,CAAE,GAE9EmC,IAA0B;EAC9B;EACA,SAAS,MACPC,GAAU,OAAa;GAAE,GAAGC;GAAS,MAAMC,EAAOD,EAAQ,IAAI;EAAE,EAAE;EACpE;EACA;EACA;EACA;EACA,OAAO1B,EAAavB,CAAI;EACxB,KAAKwB,EAAWxB,CAAI;EACpB,IAAIsC,EAAO;EACX,aAAaA,EAAO;EACpB,eAAeA,EAAO;EACtB,YAAYA,EAAO;EACnB,WAAWA,EAAO;EAClB;EACA,oBAAoBa,EAAWpC,CAAO;EACtC,eAAeqC;EACf,OAAOC,IAAatC,EAAQ,QAAQ;CACtC,GACMuC,IAAgBvD,IAAQuC,EAAO,WAAW,SAAS,IAAIvC,EAAM,WAAW,CAAC,EAAE,OAAO;CACxF,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA,OAAOc,EAAQE,GAAShB,GAAOM,CAAQ;EACvC,QAAQ,CAACN,KAASe,EAAYC,EAAQ,KAAK,KAAK,CAACwC,EAAYC,EAASxD,GAAMD,GAAOM,CAAQ,CAAC;EAC5F,UAAUoD,EAAW1C,GAASc,GAAQxB,CAAQ;EAC9C;EACA,MAAM6B,KAAYnC,IAAQ2D,EAAW3D,GAAOkC,GAAUqB,KAAiB,MAAM1C,CAAE,IAAI;EACnF,MAAMsB,IAAW,OAAOW;EACxB,SAASc,EAAc5C,EAAQ,SAASmB,GAAUtB,CAAE;EACpD,aAAagD,EAAkB5D,GAAMY,GAAIiD,CAAM;CACjD;AACF"}
@@ -0,0 +1,57 @@
1
+ import { Tr } from '../data/useEventActions';
2
+ import { CalendarFormat, DurationWords } from '../format';
3
+ import { CalendarEventV2 } from '../types';
4
+ import { EventForm, GuestDraft } from './eventForm';
5
+ import { SaveCarry, ScopeChoice } from './savePlan';
6
+ export interface EventSaveContext {
7
+ tr: Tr;
8
+ format: CalendarFormat;
9
+ durationWords: DurationWords;
10
+ /** The calendar's zone: where the toast says the event is. */
11
+ timeZone: string;
12
+ /** A calendar's name, for "Added … to Customer calls". */
13
+ calendarName: (calendarId: string) => string | null;
14
+ /** A room's name, for "Couldn't book Atlas". */
15
+ roomName: (roomId: string) => string | null;
16
+ /** A guest's name, for "Couldn't add Priya Raman". */
17
+ guestName: (guest: GuestDraft) => string;
18
+ /** The signed-in person: whose answer an event read back carries. */
19
+ me: string | null;
20
+ }
21
+ export interface SaveRequest {
22
+ form: EventForm;
23
+ /** The form as the dialog opened (for a series' date, at that date). */
24
+ initial: EventForm;
25
+ /** The event as the service last returned it (a series' date at that date); null when new. */
26
+ event: CalendarEventV2 | null;
27
+ /** The stored event behind it: for a series' date, the series at its first date. */
28
+ row: CalendarEventV2 | null;
29
+ /** A series' date: the answer to "Change …". */
30
+ scope: ScopeChoice;
31
+ /** What a save before left undone and the event read back can't show; null when nothing. */
32
+ carry: SaveCarry | null;
33
+ }
34
+ export type SaveOutcome = {
35
+ kind: 'saved';
36
+ eventId: string;
37
+ }
38
+ /**
39
+ * The event saved but not all of it did. The dialog goes on with `eventId` (at
40
+ * `instanceDate`, a series' date); `madeNew`: the service made that event from a series (a
41
+ * date on its own, or the later part of a split), so the guests and reminders the form holds
42
+ * are new to it. `carry`: what failed that the event read back won't show, for the next save.
43
+ */
44
+ | {
45
+ kind: 'partial';
46
+ eventId: string;
47
+ instanceDate: Date | null;
48
+ madeNew: boolean;
49
+ carry: SaveCarry | null;
50
+ }
51
+ /** Nothing changed on the service. */
52
+ | {
53
+ kind: 'failed';
54
+ };
55
+ /** The service's own words for a failed write; null when it never answered. */
56
+ export declare function serviceMessage(error: unknown): string | null;
57
+ export declare function useEventSave(context: EventSaveContext): (request: SaveRequest) => Promise<SaveOutcome>;
@@ -0,0 +1,276 @@
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";
15
+ // src/v2/event/useEventSave.ts
16
+ var M = 4;
17
+ function N(e) {
18
+ return A.is(e) ? e.errors.map((e) => e.message.trim()).find(Boolean) ?? null : null;
19
+ }
20
+ async function P(e, t) {
21
+ let n = 0, r = async () => {
22
+ let t = e[n];
23
+ n += 1, t && (await t(), await r());
24
+ };
25
+ await Promise.all(Array.from({ length: Math.min(t, e.length) }, r));
26
+ }
27
+ async function F(e, t, n = 0) {
28
+ let r = e[n];
29
+ if (r === void 0) return null;
30
+ let i = await t(r, n);
31
+ return i === null ? F(e, t, n + 1) : i;
32
+ }
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.");
46
+ }
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) });
49
+ }
50
+ function B(e, t, n, r, i = () => !1) {
51
+ return async () => {
52
+ try {
53
+ return await n(), e.wrote = !0, !0;
54
+ } catch (n) {
55
+ return i(n) ? !0 : (e.problems.push(r(R(n, t.tr))), !1);
56
+ }
57
+ };
58
+ }
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) {
79
+ let n = (await e.mutate({
80
+ mutation: i,
81
+ variables: { input: t }
82
+ })).data?.createEvent.id;
83
+ if (!n) throw Error("No event came back");
84
+ return n;
85
+ }
86
+ async function W(e, t, n, r, i, a) {
87
+ return F(n.updates, async (n, o) => {
88
+ try {
89
+ return await e.mutate({
90
+ mutation: u,
91
+ variables: {
92
+ id: t,
93
+ input: n.input,
94
+ scope: n.scope
95
+ }
96
+ }), r.wrote = !0, null;
97
+ } catch (e) {
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);
99
+ }
100
+ });
101
+ }
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,
106
+ variables: { attendeeId: e.attendeeId ?? "" }
107
+ }), (t) => o("calendar.v2.guestRemoveFailed", "Couldn’t remove {{name}}: {{reason}}", {
108
+ name: a.guestName(e),
109
+ reason: t
110
+ }))), ...r.addGuests.map((r) => B(i, a, () => t.mutate({
111
+ mutation: e,
112
+ variables: {
113
+ eventId: n,
114
+ userId: r.userId,
115
+ email: r.email,
116
+ name: r.name
117
+ }
118
+ }), (e) => o("calendar.v2.guestAddFailed", "Couldn’t invite {{name}}: {{reason}}", {
119
+ name: a.guestName(r),
120
+ reason: e
121
+ })))];
122
+ }
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,
127
+ variables: { id: t.reminderId ?? "" }
128
+ }), (e) => s("calendar.v2.reminderRemoveFailed", "Couldn’t remove the reminder {{when}}: {{reason}}", {
129
+ when: z(t, i),
130
+ reason: e
131
+ }))), ...n.addReminders.map((n) => B(r, i, () => e.mutate({
132
+ mutation: a,
133
+ variables: { input: {
134
+ eventId: t,
135
+ minutesBefore: n.minutesBefore,
136
+ channel: d[n.channel]
137
+ } }
138
+ }), (e) => s("calendar.v2.reminderAddFailed", "Couldn’t add the reminder {{when}}: {{reason}}", {
139
+ when: z(n, i),
140
+ reason: e
141
+ })))];
142
+ }
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({
184
+ mutation: t,
185
+ variables: { input: {
186
+ eventId: n,
187
+ resourceId: c.resourceId,
188
+ startTime: c.start.toISOString(),
189
+ endTime: c.end.toISOString()
190
+ } }
191
+ }), (e) => s("calendar.v2.roomBookFailed", "Couldn’t book {{room}}: {{reason}}", {
192
+ room: o.roomName(c.resourceId) ?? s("calendar.v2.theRoom", "The room"),
193
+ reason: e
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();
198
+ }];
199
+ }
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);
212
+ return i("calendar.v2.eventAdded", "Added “{{title}}” to {{calendar}}, {{day}} {{time}}.", {
213
+ title: a,
214
+ calendar: r.calendarName(e.calendarId ?? "") ?? i("calendar.v2.aCalendar", "a calendar"),
215
+ day: g(s, r.format, "short"),
216
+ time: c
217
+ });
218
+ }
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(() => {
226
+ r.current = e;
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),
231
+ tone: "error",
232
+ urgent: !0
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));
236
+ } catch (e) {
237
+ return h(e);
238
+ }
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.")}`,
257
+ tone: "warning",
258
+ urgent: !0
259
+ }), {
260
+ kind: "partial",
261
+ eventId: g,
262
+ instanceDate: Q(e, f, g),
263
+ madeNew: y,
264
+ carry: C(b.left) ? b.left : null
265
+ }) : (n({
266
+ title: Z(i, f, s, l),
267
+ tone: "success"
268
+ }), {
269
+ kind: "saved",
270
+ eventId: g
271
+ }));
272
+ }, [t, n]);
273
+ }
274
+ export { N as serviceMessage, $ as useEventSave };
275
+
276
+ //# sourceMappingURL=useEventSave.js.map