@meetelise/chat 1.69.1 → 1.69.3

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.
@@ -112,12 +112,23 @@ export class ItineraryEditor extends LitElement {
112
112
  @property({ type: Boolean })
113
113
  loading = false;
114
114
 
115
+ /**
116
+ * The server has planned these choices. Until it has, as after a failed
117
+ * request, empty lists mean nothing is known yet, not that nothing is offered.
118
+ */
119
+ @property({ type: Boolean })
120
+ planned = false;
121
+
115
122
  @property({ attribute: false })
116
123
  primaryColor = defaultPrimaryColor;
117
124
 
118
125
  @property({ attribute: false })
119
126
  foregroundColorOnPrimaryBackgroundColor = "white";
120
127
 
128
+ private get offersKnown(): boolean {
129
+ return this.planned && !this.loading;
130
+ }
131
+
121
132
  @state() private editingTimeFor: number | null = null;
122
133
  @state() private dragIndex: number | null = null;
123
134
  @state() private dropIndex: number | null = null;
@@ -240,7 +251,7 @@ export class ItineraryEditor extends LitElement {
240
251
  </tour-type-option>`;
241
252
  })}
242
253
  </div>
243
- ${this.tourTypes.length === 0 && !this.loading
254
+ ${this.tourTypes.length === 0 && this.offersKnown
244
255
  ? html`<p class="explanation">
245
256
  No tour type is offered at every community you picked.
246
257
  </p>`
@@ -316,7 +327,7 @@ export class ItineraryEditor extends LitElement {
316
327
  ${stop
317
328
  ? html`<div>${this.renderTimePicker(stop)}</div>`
318
329
  : html`<p class="explanation">
319
- ${this.bookableDates.length === 0 && !this.loading
330
+ ${this.bookableDates.length === 0 && this.offersKnown
320
331
  ? "No tour times in the next 30 days."
321
332
  : ""}
322
333
  </p>`}
@@ -456,7 +467,7 @@ export class ItineraryEditor extends LitElement {
456
467
  private renderItineraryDate(): TemplateResult {
457
468
  return html`<h2 class="journey-header date-header">Date</h2>
458
469
  <div id="datePicker">${this.renderDatePicker()}</div>
459
- ${this.bookableDates.length === 0 && !this.loading
470
+ ${this.bookableDates.length === 0 && this.offersKnown
460
471
  ? html`<p class="explanation">
461
472
  These communities have no back-to-back tour times in the next 30
462
473
  days. Try removing one.
@@ -57,7 +57,10 @@ import { defaultPrimaryColor } from "../../themes";
57
57
  import type { LayoutOption } from "../../fetchBuildingWebchatView";
58
58
  import { isMobile, onMobileChange } from "../../utils";
59
59
  import { readGoogleReserveReferral } from "../../googleReserve";
60
- import { layoutToBedrooms } from "../../services/fees/utils";
60
+ import {
61
+ bedroomsToLayoutOption,
62
+ layoutToBedrooms,
63
+ } from "../../services/fees/utils";
61
64
  import { focusFirstTabStop, trapTabInside } from "../pubnub-chat";
62
65
  import type LeadSourceClient from "../LeadSourceClient";
63
66
  import type { LeadSourceMultitouchClient } from "../LeadSourceMultitouchClient";
@@ -234,6 +237,14 @@ export class TourSchedulerV2 extends LitElement {
234
237
  this.foregroundColorOnPrimaryBackgroundColor
235
238
  );
236
239
  }
240
+ // A preference picked for communities since swapped out may no longer be offered.
241
+ const layout = this.contact.layout;
242
+ if (
243
+ layout !== null &&
244
+ !this.bedroomOptions.some((option) => option.value === layout)
245
+ ) {
246
+ this.contact = { ...this.contact, layout: null };
247
+ }
237
248
  }
238
249
 
239
250
  firstUpdated(): void {
@@ -257,6 +268,13 @@ export class TourSchedulerV2 extends LitElement {
257
268
  if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "-1");
258
269
  this.focus({ preventScroll: true });
259
270
  }
271
+ // A notice explains the times above the form, which the prospect may be
272
+ // scrolled away from: down at the Schedule button, after a failed booking.
273
+ if (changed.has("notice") && this.notice) {
274
+ this.renderRoot
275
+ .querySelector(".notice")
276
+ ?.scrollIntoView({ block: "nearest" });
277
+ }
260
278
  }
261
279
 
262
280
  private async start(): Promise<void> {
@@ -876,10 +894,32 @@ export class TourSchedulerV2 extends LitElement {
876
894
  plan.stops.some((s) => !s.fixed) &&
877
895
  plan.unchainable.length === 0 &&
878
896
  this.activeLinkType === null &&
879
- contactIsValid(this.contact, this.bedroomPreferenceRequired)
897
+ contactIsValid(this.contact, this.bedroomsRequired)
880
898
  );
881
899
  }
882
900
 
901
+ /**
902
+ * What the form offers as a bedroom preference: the bedroom counts listed at
903
+ * the communities on this itinerary. Where the server sent none (a building
904
+ * outside a group, or communities with no listed units), this widget's own
905
+ * building's layouts.
906
+ */
907
+ private get bedroomOptions(): LayoutOption[] {
908
+ const toured = [
909
+ ...(this.extending ? this.confirmed.map((stop) => stop.community) : []),
910
+ ...this.selectedIds.map((id) => this.communities.get(id)),
911
+ ];
912
+ const counts = new Set(toured.flatMap((c) => c?.bedrooms ?? []));
913
+ return counts.size > 0
914
+ ? [...counts].sort((a, b) => a - b).map(bedroomsToLayoutOption)
915
+ : this.layoutOptions;
916
+ }
917
+
918
+ /** A preference can only be required where there is one to choose. */
919
+ private get bedroomsRequired(): boolean {
920
+ return this.bedroomPreferenceRequired && this.bedroomOptions.length > 0;
921
+ }
922
+
883
923
  private disclaimer(): TemplateResult {
884
924
  return formDisclaimer({
885
925
  buildingName: this.buildingName,
@@ -961,6 +1001,7 @@ export class TourSchedulerV2 extends LitElement {
961
1001
  ?canAddStop=${this.group !== null &&
962
1002
  totalStops < MAX_ITINERARY_STOPS}
963
1003
  ?loading=${this.planLoading}
1004
+ ?planned=${plan !== null}
964
1005
  .primaryColor=${this.primaryColor}
965
1006
  .foregroundColorOnPrimaryBackgroundColor=${this
966
1007
  .foregroundColorOnPrimaryBackgroundColor}
@@ -981,8 +1022,8 @@ export class TourSchedulerV2 extends LitElement {
981
1022
  ></itinerary-editor>
982
1023
  <contact-form
983
1024
  .values=${this.contact}
984
- .layoutOptions=${this.layoutOptions}
985
- ?bedroomsRequired=${this.bedroomPreferenceRequired}
1025
+ .layoutOptions=${this.bedroomOptions}
1026
+ ?bedroomsRequired=${this.bedroomsRequired}
986
1027
  .leadSources=${this.leadSources}
987
1028
  ?showLeadSourceDropdown=${this.showLeadSourceDropdown()}
988
1029
  currentLeadSource=${this.currentLeadSource}
@@ -26,6 +26,11 @@ export interface Community {
26
26
  distance_mi: number | null;
27
27
  /** In US dollars. */
28
28
  price_from: { bedrooms: number; amount: number } | null;
29
+ /**
30
+ * Every bedroom count with a listed unit, ascending (0 is a studio). Missing
31
+ * from a server that predates the field.
32
+ */
33
+ bedrooms?: number[];
29
34
  next_available: { date: string; time: string } | null;
30
35
  best_match: boolean;
31
36
  image_url: string | null;
@@ -40,6 +45,7 @@ export interface CommunitySummary {
40
45
  name: string;
41
46
  address: CommunityAddress | null;
42
47
  timezone: string | null;
48
+ bedrooms?: number[];
43
49
  }
44
50
 
45
51
  export const toCommunitySummary = (c: Community): CommunitySummary => ({
@@ -47,6 +53,7 @@ export const toCommunitySummary = (c: Community): CommunitySummary => ({
47
53
  name: c.name,
48
54
  address: c.address,
49
55
  timezone: c.timezone,
56
+ bedrooms: c.bedrooms,
50
57
  });
51
58
 
52
59
  export const formatAddress = (address: CommunityAddress | null): string =>
@@ -1,4 +1,21 @@
1
+ import type { LayoutOption } from "../../fetchBuildingWebchatView";
2
+
1
3
  export const layoutToBedrooms = (layout: number): number => {
2
4
  if (layout === 0) return 0; // Studio
3
5
  return Math.floor(layout / 10);
4
6
  };
7
+
8
+ const BEDROOM_LABELS = [
9
+ "Studio",
10
+ "One bedroom",
11
+ "Two bedroom",
12
+ "Three bedroom",
13
+ "Four bedroom",
14
+ "Five bedroom",
15
+ ];
16
+
17
+ /** The layout option for a bedroom count, valued and labelled as a building's own layout options are. */
18
+ export const bedroomsToLayoutOption = (bedrooms: number): LayoutOption => ({
19
+ value: bedrooms * 10,
20
+ label: BEDROOM_LABELS[bedrooms] ?? `${bedrooms} bedroom`,
21
+ });
@@ -44,9 +44,14 @@ const DATE = "2026-10-30";
44
44
  const ANCHOR = 12;
45
45
  const LINDEN = 40;
46
46
 
47
- const community = (building_id: number, name: string): Community => ({
47
+ const community = (
48
+ building_id: number,
49
+ name: string,
50
+ bedrooms?: number[]
51
+ ): Community => ({
48
52
  building_id,
49
53
  name,
54
+ bedrooms,
50
55
  address: { line1: "1 Main St", city: "Chicago", state: "IL" },
51
56
  timezone: "America/Chicago",
52
57
  distance_mi: building_id === ANCHOR ? 0 : 1.8,
@@ -73,11 +78,17 @@ const at = (minutes: number) =>
73
78
  const fakeBackend = ({
74
79
  tourTypes = ["escorted-tour"],
75
80
  dropFirstBooking = false,
81
+ failPlan = false,
82
+ bedrooms,
76
83
  }: {
77
84
  /** The tour types the building offers. */
78
85
  tourTypes?: TourTypeId[];
86
+ /** Each community's listed bedroom counts; a server without the field sends none. */
87
+ bedrooms?: number[];
79
88
  /** Drops the first booking's connection, as a timeout would. */
80
89
  dropFirstBooking?: boolean;
90
+ /** Fails every plan request, as an outage would. */
91
+ failPlan?: boolean;
81
92
  } = {}): {
82
93
  bookings: BookingRequest[];
83
94
  keys: string[];
@@ -99,10 +110,10 @@ const fakeBackend = ({
99
110
  is_general_building: false,
100
111
  },
101
112
  communities: extend
102
- ? [community(LINDEN, "The Linden")]
113
+ ? [community(LINDEN, "The Linden", bedrooms)]
103
114
  : [
104
- community(ANCHOR, "Parkside Commons"),
105
- community(LINDEN, "The Linden"),
115
+ community(ANCHOR, "Parkside Commons", bedrooms),
116
+ community(LINDEN, "The Linden", bedrooms),
106
117
  ],
107
118
  });
108
119
  const plan = (request: PlanRequest): PlanResponse => {
@@ -192,6 +203,7 @@ const fakeBackend = ({
192
203
  if (pathname === "/platformApi/webchat/tour-itineraries/plan") {
193
204
  // As the server's request model does: stop_starts may be empty, not null.
194
205
  if (body.stop_starts === null) return json(422, null);
206
+ if (failPlan) return json(500, null);
195
207
  plannedTourTypes.push(body.tour_type);
196
208
  return json(200, plan(body));
197
209
  }
@@ -231,6 +243,7 @@ const mount = (): TourSchedulerV2 => {
231
243
  buildingSlug: "parkside-commons",
232
244
  buildingId: ANCHOR,
233
245
  buildingName: "Parkside Commons",
246
+ layoutOptions: [{ value: 10, label: "One bedroom" }],
234
247
  currentLeadSource: "google",
235
248
  leadSourceClient: {
236
249
  chatId: "webchat_lead_test",
@@ -260,7 +273,10 @@ const inScheduler = <T extends Element>(
260
273
  const clickButton = (button: Element | null | undefined) =>
261
274
  button?.shadowRoot?.querySelector<HTMLButtonElement>("button")?.click();
262
275
 
263
- const fillContactAndSubmit = async (scheduler: TourSchedulerV2) => {
276
+ const fillContactAndSubmit = async (
277
+ scheduler: TourSchedulerV2,
278
+ overrides: Partial<ContactForm["values"]> = {}
279
+ ) => {
264
280
  const form = await waitFor(() =>
265
281
  inScheduler<ContactForm>(scheduler, "contact-form")
266
282
  );
@@ -275,6 +291,7 @@ const fillContactAndSubmit = async (scheduler: TourSchedulerV2) => {
275
291
  phone: "(312) 555-0142",
276
292
  phoneE164: "+13125550142",
277
293
  layout: 10,
294
+ ...overrides,
278
295
  },
279
296
  },
280
297
  bubbles: true,
@@ -478,3 +495,101 @@ it("moves to the server's first tour type when escorted tours aren't offered", a
478
495
  ]);
479
496
  expect(bookings[0].tour_type).to.equal("self-guided-tour");
480
497
  });
498
+
499
+ it("says only that planning failed when /plan errors, not that nothing is offered", async () => {
500
+ fakeBackend({ failPlan: true });
501
+ const scheduler = mount();
502
+
503
+ await waitFor(() =>
504
+ inScheduler(scheduler, "p.error-message")?.textContent?.includes(
505
+ "Try again"
506
+ )
507
+ );
508
+ const editor = await waitFor(() =>
509
+ inScheduler<HTMLElement>(scheduler, "itinerary-editor")
510
+ );
511
+ await (editor as unknown as { updateComplete: Promise<boolean> })
512
+ .updateComplete;
513
+
514
+ const explanations = [
515
+ ...(editor.shadowRoot?.querySelectorAll(".explanation") ?? []),
516
+ ].map((p) => p.textContent?.trim() ?? "");
517
+ expect(explanations.filter(Boolean)).to.deep.equal([]);
518
+ });
519
+
520
+ it("offers the toured communities' bedroom counts where this building has no layouts of its own", async () => {
521
+ // A group's parent building: no units of its own, and the org requires a preference.
522
+ const { bookings } = fakeBackend({ bedrooms: [0, 2] });
523
+ const scheduler = mount();
524
+ scheduler.layoutOptions = [];
525
+ scheduler.bedroomPreferenceRequired = true;
526
+
527
+ const form = await waitFor(() => {
528
+ const found = inScheduler<ContactForm>(scheduler, "contact-form");
529
+ return found?.layoutOptions.length ? found : null;
530
+ });
531
+ expect(form.layoutOptions).to.deep.equal([
532
+ { value: 0, label: "Studio" },
533
+ { value: 20, label: "Two bedroom" },
534
+ ]);
535
+ expect(form.bedroomsRequired).to.equal(true);
536
+
537
+ await fillContactAndSubmit(scheduler, { layout: 20 });
538
+ await waitFor(() => bookings.length === 1);
539
+
540
+ expect(bookings[0].contact.bedrooms).to.deep.equal([2]);
541
+ });
542
+
543
+ it("books without a bedroom preference where one is required but there are no layouts to offer", async () => {
544
+ const { bookings } = fakeBackend();
545
+ const scheduler = mount();
546
+ scheduler.layoutOptions = [];
547
+ scheduler.bedroomPreferenceRequired = true;
548
+
549
+ await fillContactAndSubmit(scheduler, { layout: null });
550
+ await waitFor(() => bookings.length === 1);
551
+
552
+ expect(bookings[0].contact.bedrooms).to.deep.equal([]);
553
+ });
554
+
555
+ it("still asks for a bedroom preference where one is required and the building has layouts", async () => {
556
+ fakeBackend();
557
+ const scheduler = mount();
558
+ scheduler.bedroomPreferenceRequired = true;
559
+ scheduler.layoutOptions = [{ value: 10, label: "One bedroom" }];
560
+
561
+ const form = await waitFor(() =>
562
+ inScheduler<ContactForm>(scheduler, "contact-form")
563
+ );
564
+ form.dispatchEvent(
565
+ new CustomEvent("contact-change", {
566
+ detail: {
567
+ values: {
568
+ ...form.values,
569
+ firstName: "Jane",
570
+ email: "jane@example.com",
571
+ phone: "(312) 555-0142",
572
+ phoneE164: "+13125550142",
573
+ layout: null,
574
+ },
575
+ },
576
+ bubbles: true,
577
+ composed: true,
578
+ })
579
+ );
580
+ // The plan has loaded, so only the missing preference holds the button back.
581
+ await waitFor(
582
+ () =>
583
+ inScheduler<HTMLElement & { stops: unknown[] }>(
584
+ scheduler,
585
+ "itinerary-editor"
586
+ )?.stops.length
587
+ );
588
+ await scheduler.updateComplete;
589
+
590
+ const button = inScheduler<HTMLElement & { disabled: boolean }>(
591
+ scheduler,
592
+ "#schedule-bttn"
593
+ );
594
+ expect(button?.disabled).to.equal(true);
595
+ });