@meetelise/chat 1.42.0 → 1.42.2

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.
@@ -15,6 +15,7 @@ import {
15
15
  Month,
16
16
  monthNames,
17
17
  } from "../utils";
18
+ import isSameDay from "date-fns/isSameDay";
18
19
 
19
20
  @customElement("date-picker")
20
21
  export class DatePicker extends LitElement {
@@ -58,11 +59,19 @@ export class DatePicker extends LitElement {
58
59
  return this._selectedDate;
59
60
  }
60
61
 
61
- protected firstUpdated(): void {
62
- if (!this.defaultDate) {
63
- return;
62
+ protected updated(
63
+ changedProperties: Map<string | number | symbol, unknown>
64
+ ): void {
65
+ if (changedProperties.has("defaultDate")) {
66
+ const previousDate = changedProperties.get("defaultDate") as Date | null;
67
+ if (!this.defaultDate) {
68
+ this.selectedDate = undefined;
69
+ return;
70
+ }
71
+ if (!previousDate || !isSameDay(this.defaultDate, previousDate)) {
72
+ this.selectedDate = this.defaultDate;
73
+ }
64
74
  }
65
- this.selectedDate = this.defaultDate;
66
75
  }
67
76
 
68
77
  now = new Date();
@@ -42,12 +42,29 @@ export class TimePicker extends LitElement {
42
42
  return this.selected;
43
43
  }
44
44
 
45
- willUpdate(changedProperties: Map<string, unknown>): void {
46
- if (
47
- changedProperties.has("defaultSelectedTime") &&
48
- this.selected === null
49
- ) {
50
- this.selected = this.defaultSelectedTime;
45
+ protected updated(
46
+ changedProperties: Map<string | number | symbol, unknown>
47
+ ): void {
48
+ if (changedProperties.has("defaultSelectedTime")) {
49
+ const previouslySelectedTime = changedProperties.get(
50
+ "defaultSelectedTime"
51
+ ) as TimePickerOption | null;
52
+ if (!this.selected && this.defaultSelectedTime) {
53
+ this.selected = this.defaultSelectedTime;
54
+ return;
55
+ }
56
+ if (!this.defaultSelectedTime) {
57
+ this.selected = undefined;
58
+ return;
59
+ }
60
+ if (
61
+ !previouslySelectedTime ||
62
+ this.defaultSelectedTime.displayTimeZoned !==
63
+ previouslySelectedTime.displayTimeZoned
64
+ ) {
65
+ this.selected = this.defaultSelectedTime;
66
+ return;
67
+ }
51
68
  }
52
69
  }
53
70
 
@@ -53,6 +53,7 @@ import { shouldOpenTourLink } from "../../fetchBuildingWebchatView";
53
53
  import formatInTimeZone from "date-fns-tz/formatInTimeZone";
54
54
  import { getTimezoneAbbreviation } from "../../getTimezoneString";
55
55
  import startOfDay from "date-fns/startOfDay";
56
+ import isSameDay from "date-fns/isSameDay";
56
57
 
57
58
  @customElement("tour-scheduler")
58
59
  export class TourScheduler extends LitElement {
@@ -243,40 +244,7 @@ export class TourScheduler extends LitElement {
243
244
  }
244
245
  }, 0) === 1;
245
246
 
246
- const availabilities = await getRawAvailabilities(this.buildingId);
247
- const highestRankedTourType =
248
- this._getHighestRankedTourType(availabilities);
249
- const availableTimesForHighestRankedTourType = highestRankedTourType
250
- ? availabilities.availability?.[highestRankedTourType]
251
- ?.availableTourStartTimes
252
- : [];
253
- const firstAvailableTimeSlotForHighestRankedTourType =
254
- availableTimesForHighestRankedTourType?.[0];
255
- if (
256
- highestRankedTourType &&
257
- firstAvailableTimeSlotForHighestRankedTourType &&
258
- highestRankedTourType !==
259
- TourAvailabilityResponseRankOrderedSupportedTourTypesEnum.Unknown &&
260
- highestRankedTourType !==
261
- TourAvailabilityResponseRankOrderedSupportedTourTypesEnum.MediaTour
262
- ) {
263
- this.selectedDate =
264
- typeof firstAvailableTimeSlotForHighestRankedTourType === "string"
265
- ? startOfDay(
266
- parseISO(firstAvailableTimeSlotForHighestRankedTourType)
267
- )
268
- : startOfDay(firstAvailableTimeSlotForHighestRankedTourType);
269
- this.tourType = rankedOrderTourTypeToTourType[highestRankedTourType];
270
- this.selectedTime =
271
- typeof firstAvailableTimeSlotForHighestRankedTourType === "string"
272
- ? dateStringToDateWithTimeZoneOffset(
273
- firstAvailableTimeSlotForHighestRankedTourType
274
- )
275
- : dateToDateWithTimeZoneOffset(
276
- firstAvailableTimeSlotForHighestRankedTourType
277
- );
278
- }
279
-
247
+ this._setDefaultSelectedDateAndTimes();
280
248
  if (hasOneShowTourType) {
281
249
  this.tourType = Object.keys(this.shouldShowTourType).find(
282
250
  (key) => this.shouldShowTourType[key as TourType]
@@ -314,6 +282,51 @@ export class TourScheduler extends LitElement {
314
282
  }
315
283
  };
316
284
 
285
+ _setDefaultSelectedDateAndTimes = async (
286
+ tourType?: TourAvailabilityResponseRankOrderedSupportedTourTypesEnum,
287
+ date?: Date
288
+ ): Promise<void> => {
289
+ const availabilities = await getRawAvailabilities(this.buildingId);
290
+ const highestRankedTourType =
291
+ tourType ?? this._getHighestRankedTourType(availabilities);
292
+ const availableTimesForHighestRankedTourType = highestRankedTourType
293
+ ? availabilities.availability?.[
294
+ highestRankedTourType
295
+ ]?.availableTourStartTimes?.filter((time) => {
296
+ if (!date) {
297
+ return true;
298
+ }
299
+ const timeDate = typeof time === "string" ? parseISO(time) : time;
300
+ return isSameDay(timeDate, date);
301
+ })
302
+ : [];
303
+ const firstAvailableTimeSlotForHighestRankedTourType =
304
+ availableTimesForHighestRankedTourType?.[0];
305
+
306
+ if (
307
+ highestRankedTourType &&
308
+ firstAvailableTimeSlotForHighestRankedTourType &&
309
+ highestRankedTourType !==
310
+ TourAvailabilityResponseRankOrderedSupportedTourTypesEnum.Unknown &&
311
+ highestRankedTourType !==
312
+ TourAvailabilityResponseRankOrderedSupportedTourTypesEnum.MediaTour
313
+ ) {
314
+ this.selectedDate =
315
+ typeof firstAvailableTimeSlotForHighestRankedTourType === "string"
316
+ ? startOfDay(parseISO(firstAvailableTimeSlotForHighestRankedTourType))
317
+ : startOfDay(firstAvailableTimeSlotForHighestRankedTourType);
318
+ this.tourType = rankedOrderTourTypeToTourType[highestRankedTourType];
319
+ this.selectedTime =
320
+ typeof firstAvailableTimeSlotForHighestRankedTourType === "string"
321
+ ? dateStringToDateWithTimeZoneOffset(
322
+ firstAvailableTimeSlotForHighestRankedTourType
323
+ )
324
+ : dateToDateWithTimeZoneOffset(
325
+ firstAvailableTimeSlotForHighestRankedTourType
326
+ );
327
+ }
328
+ };
329
+
317
330
  _getHighestRankedTourType = (
318
331
  availabilities: TourAvailabilityResponse
319
332
  ): TourAvailabilityResponseRankOrderedSupportedTourTypesEnum | null => {
@@ -736,6 +749,9 @@ export class TourScheduler extends LitElement {
736
749
  await getAvailabilitiesGroupedByDay(
737
750
  tourTypeMap[TourType.Self]
738
751
  );
752
+ this._setDefaultSelectedDateAndTimes(
753
+ tourTypeMap[TourType.Self]
754
+ );
739
755
  }}"
740
756
  @keydown="${(e: KeyboardEvent) => {
741
757
  if ([" ", "Enter"].includes(e.key)) {
@@ -772,6 +788,9 @@ export class TourScheduler extends LitElement {
772
788
  await getAvailabilitiesGroupedByDay(
773
789
  tourTypeMap[TourType.Guided]
774
790
  );
791
+ this._setDefaultSelectedDateAndTimes(
792
+ tourTypeMap[TourType.Guided]
793
+ );
775
794
  }}"
776
795
  @keydown="${(e: KeyboardEvent) => {
777
796
  if ([" ", "Enter"].includes(e.key)) {
@@ -809,6 +828,9 @@ export class TourScheduler extends LitElement {
809
828
  await getAvailabilitiesGroupedByDay(
810
829
  tourTypeMap[TourType.Virtual]
811
830
  );
831
+ this._setDefaultSelectedDateAndTimes(
832
+ tourTypeMap[TourType.Virtual]
833
+ );
812
834
  }}"
813
835
  @keydown="${(e: KeyboardEvent) => {
814
836
  if ([" ", "Enter"].includes(e.key)) {
@@ -853,7 +875,7 @@ export class TourScheduler extends LitElement {
853
875
  (dates) => dates.map((date) => new Date(date.offset))
854
876
  )}
855
877
  .defaultDate=${this.selectedDate}
856
- @change=${(e: Event) => {
878
+ @change=${async (e: Event) => {
857
879
  // if the user clicked a tour type that is suppose to redirect, we redirect that use when they select a date
858
880
  // This can happen if the user clicks, is redirect, and then comes back to the webchat
859
881
  if (
@@ -881,7 +903,22 @@ export class TourScheduler extends LitElement {
881
903
  }
882
904
 
883
905
  if (e.target instanceof DatePicker) {
906
+ const previousDate = this.selectedDate;
884
907
  this.selectedDate = e.target.selectedDate;
908
+ if (!this.tourType) {
909
+ return;
910
+ }
911
+ if (
912
+ previousDate &&
913
+ e.target.selectedDate &&
914
+ isSameDay(previousDate, e.target.selectedDate)
915
+ ) {
916
+ return;
917
+ }
918
+ this._setDefaultSelectedDateAndTimes(
919
+ tourTypeMap[this.tourType],
920
+ e.target.selectedDate
921
+ );
885
922
  }
886
923
  }}
887
924
  ></date-picker>
@@ -14,7 +14,12 @@ export default async function fetchPhoneNumberFromSource(
14
14
  const host = "https://app.meetelise.com";
15
15
  try {
16
16
  const phoneNumberResponse = await axios.get(
17
- `${host}/platformApi/webchat/${buildingSlug}/phone-number-by-source?source=${source}`
17
+ `${host}/platformApi/webchat/${buildingSlug}/phone-number-by-source`,
18
+ {
19
+ params: {
20
+ source,
21
+ },
22
+ }
18
23
  );
19
24
  if (phoneNumberResponse.data) {
20
25
  return {