@meetelise/chat 1.60.0 → 1.61.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.
@@ -37,7 +37,10 @@ import parseISO from "date-fns/parseISO";
37
37
  import compareAsc from "date-fns/compareAsc";
38
38
  import { InputStyles } from "../actions/InputStyles";
39
39
  import { classMap } from "lit/directives/class-map.js";
40
- import { FeatureFlagsShowDropdown } from "../../fetchFeatureFlag";
40
+ import {
41
+ FeatureFlagsShowDropdown,
42
+ fetchTrackedRolloutCoastalCustomTourTypes,
43
+ } from "../../fetchFeatureFlag";
41
44
  import {
42
45
  appendParamsToUrl,
43
46
  getUrlQueryParameters,
@@ -310,6 +313,14 @@ export class TourScheduler extends LitElement {
310
313
  selectedBuildingEl?: MESelect;
311
314
  @state()
312
315
  private statusMessage = "";
316
+ @state()
317
+ private useCoastalCustomTourTypes = false;
318
+
319
+ private confirmationTourName(tourType: TourType): string {
320
+ return tourType === TourType.Self && this.useCoastalCustomTourTypes
321
+ ? coastalSelfGuidedTourLabel
322
+ : defaultConfirmationTourNames[tourType];
323
+ }
313
324
 
314
325
  _setAvailabilities = async (): Promise<void> => {
315
326
  try {
@@ -560,11 +571,15 @@ export class TourScheduler extends LitElement {
560
571
  };
561
572
 
562
573
  private _loadForCurrentBuilding = async (): Promise<void> => {
574
+ const useCoastalCustomTourTypes = fetchTrackedRolloutCoastalCustomTourTypes(
575
+ this.buildingSlug
576
+ );
563
577
  try {
564
578
  await getRawAvailabilities(this.buildingId);
565
579
  } catch (e) {
566
580
  // noop
567
581
  }
582
+ this.useCoastalCustomTourTypes = await useCoastalCustomTourTypes;
568
583
  await Promise.all([
569
584
  this._setAvailabilities().then(async () => {
570
585
  try {
@@ -1020,8 +1035,10 @@ export class TourScheduler extends LitElement {
1020
1035
  >
1021
1036
  ${this.shouldShowTourType[TourType.Self]
1022
1037
  ? html` <tour-type-option
1023
- heading="Take a tour"
1024
- subtitle="on your own"
1038
+ heading=${this.useCoastalCustomTourTypes
1039
+ ? coastalSelfGuidedTourLabel
1040
+ : "Take a tour"}
1041
+ subtitle=${this.useCoastalCustomTourTypes ? "" : "on your own"}
1025
1042
  .primaryColor=${this.primaryColor}
1026
1043
  .foregroundColorOnPrimaryBackgroundColor=${this
1027
1044
  .foregroundColorOnPrimaryBackgroundColor}
@@ -1730,13 +1747,7 @@ export class TourScheduler extends LitElement {
1730
1747
  ? this.referralConfirmation(readableDateAndTime)
1731
1748
  : html`<p>Thank you!</p>
1732
1749
  <p>
1733
- Your
1734
- ${{
1735
- [TourType.Guided]: "guided",
1736
- [TourType.Self]: "self-guided",
1737
- [TourType.Virtual]: "virtual",
1738
- }[this.tourType]}
1739
- tour is
1750
+ Your ${this.confirmationTourName(this.tourType)} is
1740
1751
  ${this.promptForReschedule
1741
1752
  ? html`rescheduled`
1742
1753
  : html`scheduled`}
@@ -1759,13 +1770,7 @@ export class TourScheduler extends LitElement {
1759
1770
  if (this.tourType === null) return html``;
1760
1771
  return html`<p>Thank you for the referral!</p>
1761
1772
  <p>
1762
- Your client's
1763
- ${{
1764
- [TourType.Guided]: "guided",
1765
- [TourType.Self]: "self-guided",
1766
- [TourType.Virtual]: "virtual",
1767
- }[this.tourType]}
1768
- tour is
1773
+ Your client's ${this.confirmationTourName(this.tourType)} is
1769
1774
  ${this.promptForReschedule ? html`rescheduled` : html`scheduled`} for
1770
1775
  ${readableDateAndTime}
1771
1776
  ${getTimezoneAbbreviation(this.calendarTimeZone)}.
@@ -2177,6 +2182,14 @@ const rankedOrderTourTypeToTourType = {
2177
2182
  TourType.Virtual,
2178
2183
  };
2179
2184
 
2185
+ const coastalSelfGuidedTourLabel = "VIP Hard Hat Tour";
2186
+
2187
+ const defaultConfirmationTourNames: Record<TourType, string> = {
2188
+ [TourType.Guided]: "guided tour",
2189
+ [TourType.Self]: "self-guided tour",
2190
+ [TourType.Virtual]: "virtual tour",
2191
+ };
2192
+
2180
2193
  const tourTypeForSubmission = {
2181
2194
  [TourType.Guided]: "escorted-tour",
2182
2195
  [TourType.Self]: "self-guided-tour",
@@ -137,6 +137,24 @@ export async function fetchTrackedRolloutBedroomPreferenceRequired(
137
137
  }
138
138
  }
139
139
 
140
+ export async function fetchTrackedRolloutCoastalCustomTourTypes(
141
+ buildingSlug: string
142
+ ): Promise<boolean> {
143
+ if (!buildingSlug) return false;
144
+ try {
145
+ const response = await axios.get(trackedRolloutEndpoint(buildingSlug), {
146
+ params: {
147
+ rollout_name: "coastal_custom_tour_types",
148
+ default_value: false,
149
+ },
150
+ timeout: 3000,
151
+ });
152
+ return response.data === true;
153
+ } catch (_) {
154
+ return false;
155
+ }
156
+ }
157
+
140
158
  /** Whether the building has broker intake on, so the email form offers the broker referral fields. */
141
159
  export async function fetchTrackedRolloutBrokerIntake(
142
160
  buildingSlug: string
@@ -68,6 +68,30 @@ it("does not throw when removing a widget that already detached itself", async f
68
68
  ).removeWidget();
69
69
  });
70
70
 
71
+ it("keeps a widget started before an un-awaited remove() finishes", async function () {
72
+ const statics = MEChat as unknown as { meChat: HTMLElement | null };
73
+ // No organization, so the widget makes no API calls.
74
+ const opts = { building: "unit-test-building" };
75
+ MEChat.start(opts, false);
76
+ const oldWidget = statics.meChat;
77
+
78
+ // A single-page site switches buildings without awaiting remove().
79
+ const removing = MEChat.remove();
80
+ MEChat.start(opts, false);
81
+ const newWidget = statics.meChat;
82
+ await removing;
83
+
84
+ // Booleans only: a failing assertion that holds a widget element hangs the runner.
85
+ expect(oldWidget?.isConnected).to.equal(false);
86
+ expect(newWidget?.isConnected).to.equal(true);
87
+ expect(statics.meChat === newWidget).to.equal(true);
88
+
89
+ await MEChat.remove();
90
+
91
+ expect(newWidget?.isConnected).to.equal(false);
92
+ expect(statics.meChat === null).to.equal(true);
93
+ });
94
+
71
95
  it.skip("shows the launcher", async function () {
72
96
  // Given an API that returns this building theme
73
97
  stub(window, "fetch").resolves(stubResponse);
@@ -302,7 +302,10 @@ export default class MEChat {
302
302
  const meChat = this.meChat;
303
303
  await meChat.remove();
304
304
  meChat.parentNode?.removeChild(meChat);
305
- MEChat.meChat = null;
305
+ // A host that calls start() without awaiting remove() has already set a new widget.
306
+ if (MEChat.meChat === meChat) {
307
+ MEChat.meChat = null;
308
+ }
306
309
  }
307
310
 
308
311
  static handleStudioContext(opts: Options): void {