@meetelise/chat 1.73.0 → 1.75.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/dist/src/WebComponent/Scheduler/tour-scheduler.d.ts +6 -0
  2. package/dist/src/WebComponent/SchedulerV2/booking-confirmation.d.ts +2 -0
  3. package/dist/src/WebComponent/SchedulerV2/community-picker.d.ts +6 -0
  4. package/dist/src/WebComponent/SchedulerV2/contact-form.d.ts +8 -3
  5. package/dist/src/WebComponent/SchedulerV2/itinerary-editor.d.ts +3 -0
  6. package/dist/src/WebComponent/SchedulerV2/scheduler-popover.d.ts +9 -1
  7. package/dist/src/WebComponent/SchedulerV2/schedulerRequests.d.ts +2 -0
  8. package/dist/src/WebComponent/SchedulerV2/tour-scheduler-v2.d.ts +6 -5
  9. package/dist/src/WebComponent/SchedulerV2/tourItineraryApi.d.ts +12 -0
  10. package/dist/src/WebComponent/SchedulerV2/tourTimes.d.ts +2 -0
  11. package/package.json +1 -1
  12. package/public/dist/index.js +441 -426
  13. package/src/WebComponent/Scheduler/tour-scheduler.ts +60 -9
  14. package/src/WebComponent/SchedulerV2/booking-confirmation.ts +13 -8
  15. package/src/WebComponent/SchedulerV2/community-picker.ts +19 -2
  16. package/src/WebComponent/SchedulerV2/contact-form.ts +54 -22
  17. package/src/WebComponent/SchedulerV2/itinerary-editor.ts +40 -17
  18. package/src/WebComponent/SchedulerV2/scheduler-popover.ts +17 -1
  19. package/src/WebComponent/SchedulerV2/schedulerRequests.ts +10 -0
  20. package/src/WebComponent/SchedulerV2/tour-scheduler-v2.ts +82 -15
  21. package/src/WebComponent/SchedulerV2/tourItineraryApi.ts +12 -0
  22. package/src/WebComponent/SchedulerV2/tourTimes.ts +12 -0
  23. package/src/existingTourReschedulePrompt.test.ts +97 -0
  24. package/src/tourSchedulerV2Booking.test.ts +197 -13
@@ -35,6 +35,7 @@ import mapValues from "lodash/mapValues";
35
35
  import classnames from "classnames";
36
36
  import parseISO from "date-fns/parseISO";
37
37
  import compareAsc from "date-fns/compareAsc";
38
+ import isValid from "date-fns/isValid";
38
39
  import { InputStyles } from "../actions/InputStyles";
39
40
  import { classMap } from "lit/directives/class-map.js";
40
41
  import {
@@ -230,6 +231,12 @@ export class TourScheduler extends LitElement {
230
231
  private promptForReschedule = false;
231
232
  @state()
232
233
  private canceledReschedule = false;
234
+ /** The existing tour's community, from the "already has a tour" 409. */
235
+ @state()
236
+ private existingTourBuildingName?: string;
237
+ /** The existing tour's readable time, in its own UTC offset, from the same 409. */
238
+ @state()
239
+ private existingTourStartTime?: string;
233
240
  @state()
234
241
  isBrokerReferral = false;
235
242
  @state()
@@ -1026,6 +1033,13 @@ export class TourScheduler extends LitElement {
1026
1033
  !this.promptForReschedule &&
1027
1034
  message === "User already has a tour scheduled for this building"
1028
1035
  ) {
1036
+ const headers = typedError.response.headers;
1037
+ this.existingTourBuildingName = decodedHeader(
1038
+ headers["existing-tour-building-name"]
1039
+ );
1040
+ this.existingTourStartTime = readableTimeAtOwnOffset(
1041
+ headers["existing-tour-start-time"]
1042
+ );
1029
1043
  this.promptForReschedule = true;
1030
1044
  this.isSubmitting = false;
1031
1045
  this.tourIsBooked = false;
@@ -1752,11 +1766,9 @@ export class TourScheduler extends LitElement {
1752
1766
  confirmationMessage(): TemplateResult {
1753
1767
  if (!this.selectedDate || !this.selectedTime || this.tourType === null)
1754
1768
  return html``;
1755
- // format example: "November 9th, 2022 at 11:00pm"
1756
- const readableDateAndTime = formatInTimeZone(
1757
- parseISO(`${this.selectedTime.datetime}${this.selectedTime.offset}`),
1758
- this.calendarTimeZone,
1759
- "MMM d 'at' h:mmaaa"
1769
+ const readableDateAndTime = readableTourTime(
1770
+ `${this.selectedTime.datetime}${this.selectedTime.offset}`,
1771
+ this.calendarTimeZone
1760
1772
  );
1761
1773
 
1762
1774
  if (this.canceledReschedule) {
@@ -1818,6 +1830,16 @@ export class TourScheduler extends LitElement {
1818
1830
  `;
1819
1831
  }
1820
1832
 
1833
+ /** Names the existing tour's community and time when the 409 sent both. */
1834
+ rescheduleExplanation(): TemplateResult {
1835
+ if (this.existingTourBuildingName && this.existingTourStartTime) {
1836
+ return html`You already have a tour scheduled at one of our communities,
1837
+ ${this.existingTourBuildingName}, on ${this.existingTourStartTime}. Would
1838
+ you like to reschedule?`;
1839
+ }
1840
+ return html`You already have a tour scheduled. Would you like to reschedule?`;
1841
+ }
1842
+
1821
1843
  /** The broker isn't the one touring: the client gets the confirmation email. */
1822
1844
  private referralConfirmation(readableDateAndTime: string): TemplateResult {
1823
1845
  if (this.tourType === null) return html``;
@@ -2006,8 +2028,7 @@ export class TourScheduler extends LitElement {
2006
2028
  <div>
2007
2029
  <h2 class="journey-header">Reschedule Tour</h2>
2008
2030
  <div class="explanation">
2009
- You already have a tour scheduled. Would you like to
2010
- reschedule?
2031
+ ${this.rescheduleExplanation()}
2011
2032
  </div>
2012
2033
  </div>
2013
2034
  </div>
@@ -2149,8 +2170,7 @@ export class TourScheduler extends LitElement {
2149
2170
  <div>
2150
2171
  <h2 class="journey-header">Reschedule Tour</h2>
2151
2172
  <div class="explanation">
2152
- You already have a tour scheduled. Would you like to
2153
- reschedule?
2173
+ ${this.rescheduleExplanation()}
2154
2174
  </div>
2155
2175
  </div>
2156
2176
  </div>
@@ -2268,6 +2288,37 @@ const tourTypeForSubmission = {
2268
2288
  [TourType.Virtual]: "live-virtual-tour",
2269
2289
  };
2270
2290
 
2291
+ // format example: "Nov 9 at 11:00pm"
2292
+ function readableTourTime(isoDateTime: string, timeZone: string): string {
2293
+ return formatInTimeZone(
2294
+ parseISO(isoDateTime),
2295
+ timeZone,
2296
+ "MMM d 'at' h:mmaaa"
2297
+ );
2298
+ }
2299
+
2300
+ /**
2301
+ * An ISO 8601 time such as "2026-11-16T15:15:00-05:00", read in its own UTC
2302
+ * offset rather than the viewer's time zone. Undefined when absent or unreadable.
2303
+ */
2304
+ function readableTimeAtOwnOffset(
2305
+ value: string | undefined
2306
+ ): string | undefined {
2307
+ const offset = value?.match(/(Z|[+-]\d{2}:\d{2})$/)?.[1];
2308
+ if (!value || !offset || !isValid(parseISO(value))) return undefined;
2309
+ return readableTourTime(value, offset);
2310
+ }
2311
+
2312
+ /** A percent-encoded UTF-8 header value, or undefined when absent or malformed. */
2313
+ function decodedHeader(value: string | undefined): string | undefined {
2314
+ if (!value) return undefined;
2315
+ try {
2316
+ return decodeURIComponent(value) || undefined;
2317
+ } catch {
2318
+ return undefined;
2319
+ }
2320
+ }
2321
+
2271
2322
  // LayoutOption.value is bedrooms * 10; EliseAI classifier expects `studio` / `Nbr`.
2272
2323
  function layoutValueToCanonical(value: number): string {
2273
2324
  const bedrooms = Math.round(value / 10);
@@ -12,6 +12,7 @@ import {
12
12
  TourTypeId,
13
13
  } from "./tourItineraryApi";
14
14
  import {
15
+ formatLeg,
15
16
  formatMonthDay,
16
17
  formatTime,
17
18
  formatTimeRange,
@@ -28,6 +29,7 @@ export interface ConfirmedStop {
28
29
  /** The server's prospect-facing reason, for a failed stop. */
29
30
  error: string | null;
30
31
  distanceFromPrevMi: number | null;
32
+ travelMinutesFromPrev: number | null;
31
33
  }
32
34
 
33
35
  /**
@@ -62,7 +64,9 @@ export class BookingConfirmation extends LitElement {
62
64
  booked.length === 1 ? first.community.name : "",
63
65
  this.tourType ? TOUR_TYPES[this.tourType].heading : "",
64
66
  ];
65
- if (first.start) {
67
+ // Stops on different days each show their own date, so the summary names none.
68
+ const days = new Set(booked.map((s) => s.start && isoDate(s.start)));
69
+ if (first.start && days.size === 1) {
66
70
  const zone = first.community.timezone
67
71
  ? ` ${getTimezoneAbbreviation(first.community.timezone)}`
68
72
  : "";
@@ -77,6 +81,13 @@ export class BookingConfirmation extends LitElement {
77
81
  return parts.filter(Boolean).join(" · ");
78
82
  }
79
83
 
84
+ private renderLeg(stop: ConfirmedStop): TemplateResult | string {
85
+ const leg = formatLeg(stop.distanceFromPrevMi, stop.travelMinutesFromPrev);
86
+ return leg
87
+ ? html`${leg}<span class="sr-only"> from the previous stop</span>`
88
+ : "";
89
+ }
90
+
80
91
  private renderStops(): TemplateResult | string {
81
92
  if (this.stops.length < 2) return "";
82
93
  return html`<ol class="stops">
@@ -84,13 +95,7 @@ export class BookingConfirmation extends LitElement {
84
95
  (stop, i) => html`<li>
85
96
  ${i > 0
86
97
  ? html`<p class="image-card-subtitle leg">
87
- ${stop.distanceFromPrevMi !== null
88
- ? html`${stop.distanceFromPrevMi.toFixed(1)} mi<span
89
- class="sr-only"
90
- >
91
- from the previous stop</span
92
- >`
93
- : ""}
98
+ ${this.renderLeg(stop)}
94
99
  </p>`
95
100
  : ""}
96
101
  <div class="floorplan-image-card">
@@ -225,7 +225,7 @@ export class CommunityPicker extends LitElement {
225
225
  type="date"
226
226
  .value=${f.moveIn ?? ""}
227
227
  @change=${(e: Event) => {
228
- this.openFilter = null;
228
+ void this.closeCommittedFilter("moveIn");
229
229
  this.setFilters({
230
230
  moveIn: (e.target as HTMLInputElement).value || null,
231
231
  });
@@ -244,7 +244,7 @@ export class CommunityPicker extends LitElement {
244
244
  .value=${f.maxBudget === null ? "" : String(f.maxBudget)}
245
245
  @change=${(e: Event) => {
246
246
  const value = parseInt((e.target as HTMLInputElement).value, 10);
247
- this.openFilter = null;
247
+ void this.closeCommittedFilter("budget");
248
248
  this.setFilters({
249
249
  maxBudget: Number.isFinite(value) && value > 0 ? value : null,
250
250
  });
@@ -253,6 +253,23 @@ export class CommunityPicker extends LitElement {
253
253
  </div>`;
254
254
  }
255
255
 
256
+ /**
257
+ * A move-in date or budget, once set, closes its panel and so removes the
258
+ * input that had focus. Focus goes back to the chip, as on Escape, rather
259
+ * than out of the dialog, unless the prospect already moved it elsewhere.
260
+ */
261
+ private async closeCommittedFilter(id: FilterId): Promise<void> {
262
+ this.openFilter = null;
263
+ await this.updateComplete;
264
+ // A Tab that set it moves focus on after this event; let it land first.
265
+ await new Promise((resolve) => setTimeout(resolve));
266
+ if (!document.activeElement || document.activeElement === document.body) {
267
+ this.shadowRoot
268
+ ?.querySelector<HTMLElement>(`[aria-controls="filter-${id}"]`)
269
+ ?.focus();
270
+ }
271
+ }
272
+
256
273
  private renderFilters(): TemplateResult {
257
274
  const open = this.openFilter;
258
275
  return html`<div class="picker-toolbar" role="group" aria-label="Filters">
@@ -7,6 +7,7 @@ import "../me-select";
7
7
  import type { MESelect } from "../me-select";
8
8
  import { tourSchedulerStyles } from "../Scheduler/tourSchedulerStyles";
9
9
  import { InputStyles } from "../actions/InputStyles";
10
+ import floorPlanSelectorStyles from "../FeeCalculator/components/floor-plan-selector/floor-plan-selector-styles";
10
11
  import type { LayoutOption } from "../../fetchBuildingWebchatView";
11
12
  import { isValidEmail } from "../../utils";
12
13
 
@@ -17,8 +18,8 @@ export interface ContactValues {
17
18
  phone: string;
18
19
  phoneE164: string | null;
19
20
  phoneCountry: string | null;
20
- /** The building's layout option value picked, or null. */
21
- layout: number | null;
21
+ /** The building's layout option values picked, in the options' order. */
22
+ layouts: number[];
22
23
  moveIn: string;
23
24
  notes: string;
24
25
  /** Picked in "How did you hear about us?", when that is shown. */
@@ -32,7 +33,7 @@ export const EMPTY_CONTACT: ContactValues = {
32
33
  phone: "",
33
34
  phoneE164: null,
34
35
  phoneCountry: null,
35
- layout: null,
36
+ layouts: [],
36
37
  moveIn: "",
37
38
  notes: "",
38
39
  leadSource: null,
@@ -40,7 +41,7 @@ export const EMPTY_CONTACT: ContactValues = {
40
41
 
41
42
  /**
42
43
  * Today's scheduler's rules: a first or last name, a valid email and phone,
43
- * and a bedroom preference only where the building requires one.
44
+ * and at least one bedroom preference only where the building requires one.
44
45
  */
45
46
  export const contactIsValid = (
46
47
  values: ContactValues,
@@ -49,7 +50,7 @@ export const contactIsValid = (
49
50
  (!!values.firstName.trim() || !!values.lastName.trim()) &&
50
51
  isValidEmail(values.email.trim()) &&
51
52
  !!values.phoneE164 &&
52
- (!bedroomsRequired || values.layout !== null);
53
+ (!bedroomsRequired || values.layouts.length > 0);
53
54
 
54
55
  /**
55
56
  * The prospect's details, in today's scheduler's "Your Information" column
@@ -104,6 +105,44 @@ export class ContactForm extends LitElement {
104
105
  });
105
106
  }
106
107
 
108
+ /**
109
+ * The bedroom preferences as the filters' chips: each tap picks or clears
110
+ * one, as the Bedrooms filter does.
111
+ */
112
+ private renderLayouts(): TemplateResult {
113
+ const picked = this.values.layouts;
114
+ return html`<div class="inputContainer">
115
+ <span class="section-label" id="layout-label">
116
+ Bedroom preferences${this.bedroomsRequired ? "" : " (optional)"}
117
+ </span>
118
+ <div
119
+ id="layout"
120
+ class="floor-plan-selector-badges"
121
+ role="group"
122
+ aria-labelledby="layout-label"
123
+ >
124
+ ${this.layoutOptions.map((o) => {
125
+ const selected = picked.includes(o.value);
126
+ return html`<button
127
+ type="button"
128
+ class=${classMap({ "floor-plan-badge": true, selected })}
129
+ aria-pressed=${String(selected)}
130
+ @click=${() =>
131
+ this.setValues({
132
+ layouts: this.layoutOptions
133
+ .map((option) => option.value)
134
+ .filter((value) =>
135
+ value === o.value ? !selected : picked.includes(value)
136
+ ),
137
+ })}
138
+ >
139
+ ${o.label}
140
+ </button>`;
141
+ })}
142
+ </div>
143
+ </div>`;
144
+ }
145
+
107
146
  render(): TemplateResult {
108
147
  const v = this.values;
109
148
  const emailInvalid = !!v.email && !isValidEmail(v.email.trim());
@@ -174,23 +213,7 @@ export class ContactForm extends LitElement {
174
213
  ? html`<p class="error-message">Invalid phone number</p>`
175
214
  : ""}
176
215
  </div>
177
- ${this.layoutOptions.length > 0
178
- ? html`<me-select
179
- id="layout"
180
- placeholder=${this.bedroomsRequired
181
- ? "Bedroom preference"
182
- : "Bedroom preference (optional)"}
183
- value=${v.layout === null ? "" : String(v.layout)}
184
- .options=${this.layoutOptions.map((o) => ({
185
- label: o.label,
186
- value: String(o.value),
187
- }))}
188
- @change=${(e: Event) => {
189
- const value = (e.target as MESelect).value;
190
- this.setValues({ layout: value ? Number(value) : null });
191
- }}
192
- ></me-select>`
193
- : ""}
216
+ ${this.layoutOptions.length > 0 ? this.renderLayouts() : ""}
194
217
  <div class="inputContainer">
195
218
  <label class="section-label" for="move-in">
196
219
  Move-in date (optional)
@@ -243,6 +266,7 @@ export class ContactForm extends LitElement {
243
266
  static styles = [
244
267
  tourSchedulerStyles,
245
268
  InputStyles,
269
+ floorPlanSelectorStyles,
246
270
  css`
247
271
  :host {
248
272
  display: contents;
@@ -254,6 +278,14 @@ export class ContactForm extends LitElement {
254
278
  gap: 4px;
255
279
  }
256
280
 
281
+ /* The filters' chips, wrapping in the column rather than scrolling. */
282
+ #layout {
283
+ flex-wrap: wrap;
284
+ margin: 0;
285
+ max-width: none;
286
+ overflow: visible;
287
+ }
288
+
257
289
  textarea {
258
290
  resize: vertical;
259
291
  width: 100%;
@@ -32,6 +32,7 @@ import {
32
32
  } from "./tourItineraryApi";
33
33
  import {
34
34
  dateFromIsoDate,
35
+ formatLeg,
35
36
  formatMonthDay,
36
37
  formatTime,
37
38
  formatTimeRange,
@@ -255,25 +256,36 @@ export class ItineraryEditor extends LitElement {
255
256
  : ""}`;
256
257
  }
257
258
 
258
- private renderDatePicker(): TemplateResult {
259
+ /** Today's date picker over `dates`, reporting a picked day other than `date`. */
260
+ private renderDatePicker(
261
+ dates: string[] = this.bookableDates,
262
+ date: string | null = this.date,
263
+ pick: (picked: string) => void = (picked) =>
264
+ emit(this, "date-change", { date: picked })
265
+ ): TemplateResult {
259
266
  // The month of the chosen or first bookable date, which may not be this month.
260
- const shown = this.date ?? this.bookableDates[0];
267
+ const shown = date ?? dates[0];
261
268
  return html`<date-picker
262
269
  outlined
263
270
  .shownMonth=${shown?.slice(0, 7)}
264
271
  .availabilities=${Object.fromEntries(
265
- this.bookableDates.map((d) => [d, [dateFromIsoDate(d)]])
272
+ dates.map((d) => [d, [dateFromIsoDate(d)]])
266
273
  )}
267
- .defaultDate=${this.date ? dateFromIsoDate(this.date) : undefined}
274
+ .defaultDate=${date ? dateFromIsoDate(date) : undefined}
268
275
  @change=${(e: Event) => {
269
276
  const picked = (e.target as DatePicker).selectedDate;
270
- if (picked && toIsoDate(picked) !== this.date) {
271
- emit(this, "date-change", { date: toIsoDate(picked) });
272
- }
277
+ if (picked && toIsoDate(picked) !== date) pick(toIsoDate(picked));
273
278
  }}
274
279
  ></date-picker>`;
275
280
  }
276
281
 
282
+ /** One stop's own day: moving it there makes it a separate tour. */
283
+ private renderStopDatePicker(stop: PlanStop): TemplateResult {
284
+ return this.renderDatePicker(stop.dates, isoDate(stop.start), (date) =>
285
+ emit(this, "stop-date-change", { buildingId: stop.building_id, date })
286
+ );
287
+ }
288
+
277
289
  private renderTimePicker(stop: PlanStop): TemplateResult {
278
290
  const times = [...new Set([stop.start, ...stop.alternatives])].sort();
279
291
  return html`<time-picker
@@ -338,14 +350,20 @@ export class ItineraryEditor extends LitElement {
338
350
  const newIndex = ids.indexOf(stop.building_id);
339
351
  const editing = this.editingTimeFor === stop.building_id;
340
352
  const canReorder = !stop.fixed && ids.length > 1;
341
- // With no other time to pick, the time is plain text rather than a picker.
353
+ // With no other day or time to pick, they're plain text rather than a picker.
342
354
  const canChangeTime =
343
355
  !stop.fixed && stop.alternatives.some((t) => t !== stop.start);
356
+ const canChangeDate =
357
+ !stop.fixed && (stop.dates ?? []).some((d) => d !== isoDate(stop.start));
344
358
  const time = `${formatMonthDay(isoDate(stop.start))} · ${formatTimeRange(
345
359
  stop.start,
346
360
  stop.end
347
361
  )}`;
348
362
  const dragging = this.dragIndex !== null;
363
+ const leg = formatLeg(
364
+ stop.distance_from_prev_mi,
365
+ stop.travel_minutes_from_prev
366
+ );
349
367
  return html`<li
350
368
  class=${classMap({
351
369
  "stop-item": true,
@@ -359,12 +377,8 @@ export class ItineraryEditor extends LitElement {
359
377
  >
360
378
  ${index > 0
361
379
  ? html`<p class="image-card-subtitle leg">
362
- ${stop.distance_from_prev_mi !== null
363
- ? html`${stop.distance_from_prev_mi.toFixed(1)} mi<span
364
- class="sr-only"
365
- >
366
- from the previous stop</span
367
- >`
380
+ ${leg
381
+ ? html`${leg}<span class="sr-only"> from the previous stop</span>`
368
382
  : ""}
369
383
  </p>`
370
384
  : ""}
@@ -412,7 +426,7 @@ export class ItineraryEditor extends LitElement {
412
426
  <p class="image-card-subtitle">
413
427
  ${formatAddress(community?.address ?? null)}
414
428
  </p>
415
- ${!canChangeTime
429
+ ${!canChangeTime && !canChangeDate
416
430
  ? html`<p class="stop-time">
417
431
  ${time}
418
432
  ${stop.fixed
@@ -422,13 +436,22 @@ export class ItineraryEditor extends LitElement {
422
436
  : html`<button
423
437
  class="stop-time edit-time"
424
438
  aria-expanded=${String(editing)}
425
- aria-label=${`Change the time at ${community?.name ?? ""}`}
439
+ aria-label=${`Change the ${
440
+ canChangeDate ? "date or time" : "time"
441
+ } at ${community?.name ?? ""}`}
426
442
  @click=${() =>
427
443
  (this.editingTimeFor = editing ? null : stop.building_id)}
428
444
  >
429
445
  ${time} ${PencilIcon()}
430
446
  </button>`}
431
- ${editing ? this.renderTimePicker(stop) : ""}
447
+ ${editing && canChangeDate ? this.renderStopDatePicker(stop) : ""}
448
+ ${
449
+ // While /plan answers, these are the old plan's times, which may
450
+ // be on the stop's old day.
451
+ editing && canChangeTime && !this.loading
452
+ ? this.renderTimePicker(stop)
453
+ : ""
454
+ }
432
455
  </div>
433
456
  ${!stop.fixed &&
434
457
  (ids.length > 1 || this.problems.length > 0 || this.stopsOnly)
@@ -4,7 +4,9 @@ import { customElement, property } from "lit/decorators.js";
4
4
  /**
5
5
  * A trigger and the small panel it opens, for the v2 scheduler's secondary
6
6
  * choices. The panel floats under the trigger with `me-select`'s list surface
7
- * and closes, as that list does, on a click outside it, or on Escape. With
7
+ * and closes, as that list does, on a click outside it, or on Escape, and
8
+ * when focus moves out of it, so a later Escape closes the scheduler only
9
+ * once no panel is open. With
8
10
  * `inline` (phones) it opens in place instead, after its siblings in the
9
11
  * parent's flex row, as the filter row always did there.
10
12
  *
@@ -24,11 +26,13 @@ export class SchedulerPopover extends LitElement {
24
26
  super.connectedCallback();
25
27
  document.addEventListener("click", this.onDocumentClick);
26
28
  this.addEventListener("keydown", this.onKeydown);
29
+ this.addEventListener("focusout", this.onFocusout);
27
30
  }
28
31
 
29
32
  disconnectedCallback(): void {
30
33
  document.removeEventListener("click", this.onDocumentClick);
31
34
  this.removeEventListener("keydown", this.onKeydown);
35
+ this.removeEventListener("focusout", this.onFocusout);
32
36
  super.disconnectedCallback();
33
37
  }
34
38
 
@@ -43,6 +47,18 @@ export class SchedulerPopover extends LitElement {
43
47
  }
44
48
  };
45
49
 
50
+ /**
51
+ * Tabbing on to another control. Not when focus goes nowhere (a click on
52
+ * the panel's own text), nor inline, where closing would move what is
53
+ * being tapped.
54
+ */
55
+ private onFocusout = (e: FocusEvent): void => {
56
+ const to = e.relatedTarget;
57
+ if (this.open && !this.inline && to instanceof Node && !this.contains(to)) {
58
+ this.requestClose();
59
+ }
60
+ };
61
+
46
62
  private onKeydown = (e: KeyboardEvent): void => {
47
63
  if (!this.open || e.key !== "Escape" || e.isComposing) return;
48
64
  // The scheduler closes on Escape; here it only closes the panel.
@@ -20,6 +20,8 @@ export interface ItineraryChoice {
20
20
  firstStart: string | null;
21
21
  /** ISO starts picked for later new stops, by building id. */
22
22
  laterStarts: Record<number, string>;
23
+ /** "YYYY-MM-DD" days new stops moved to on their own, away from `date`, by building id. */
24
+ stopDates: Record<number, string>;
23
25
  /** Booked events this itinerary extends, in order; the last one is fixed first. */
24
26
  existingEventIds: number[];
25
27
  }
@@ -31,6 +33,13 @@ export const buildPlanRequest = (choice: ItineraryChoice): PlanRequest => {
31
33
  .filter((id) => choice.laterStarts[id])
32
34
  .map((id) => [String(id), choice.laterStarts[id]])
33
35
  );
36
+ const stopDates = Object.fromEntries(
37
+ choice.buildingIds
38
+ .filter(
39
+ (id) => choice.stopDates[id] && choice.stopDates[id] !== choice.date
40
+ )
41
+ .map((id) => [String(id), choice.stopDates[id]])
42
+ );
34
43
  const fixedEventId =
35
44
  choice.existingEventIds[choice.existingEventIds.length - 1];
36
45
  return {
@@ -39,6 +48,7 @@ export const buildPlanRequest = (choice: ItineraryChoice): PlanRequest => {
39
48
  date: choice.date,
40
49
  start_time: choice.firstStart,
41
50
  stop_starts: laterStarts,
51
+ stop_dates: stopDates,
42
52
  fixed_first:
43
53
  fixedEventId === undefined ? null : { calendar_event_id: fixedEventId },
44
54
  };