@meetelise/chat 1.69.0 → 1.69.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.
@@ -149,6 +149,11 @@ export declare class TourSchedulerV2 extends LitElement {
149
149
  private problems;
150
150
  private isMultiStop;
151
151
  private canSubmit;
152
+ /**
153
+ * The form offers this widget's building's layouts, so a building with none
154
+ * (a group's parent building) has no preference to ask for.
155
+ */
156
+ private get bedroomsRequired();
152
157
  private disclaimer;
153
158
  /** Today's scheduler's body area, which scrolls the whole sheet on phones. */
154
159
  private container;
@@ -77,7 +77,8 @@ export interface PlanRequest {
77
77
  tour_type: TourTypeId;
78
78
  date: string;
79
79
  start_time: string | null;
80
- stop_starts: Record<string, string> | null;
80
+ /** Times picked for later stops, by building id; empty when none are picked. */
81
+ stop_starts: Record<string, string>;
81
82
  fixed_first: {
82
83
  calendar_event_id: number;
83
84
  } | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetelise/chat",
3
- "version": "1.69.0",
3
+ "version": "1.69.2",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/MeetElise/chat-ui#readme",
@@ -6325,7 +6325,7 @@ xmlns="http://www.w3.org/2000/svg"
6325
6325
  }
6326
6326
  `,_d([pe({type:Number})],Od.prototype,"size",void 0),_d([pe({type:Number})],Od.prototype,"spinSpeed",void 0),Od=_d([ce("mega-loader")],Od);const Pd=(e="white")=>z`<svg aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" width="5" height="8" viewBox="0 0 5 8" fill="none">
6327
6327
  <path d="M3.68188 7L0.681885 4L3.68188 1" stroke="${e}" stroke-linecap="round" stroke-linejoin="round"/>
6328
- </svg>`,Id=e=>{const t=Object.fromEntries(e.buildingIds.slice(1).filter(t=>e.laterStarts[t]).map(t=>[String(t),e.laterStarts[t]])),i=e.existingEventIds[e.existingEventIds.length-1];return{building_ids:e.buildingIds,tour_type:e.tourType,date:e.date,start_time:e.firstStart,stop_starts:Object.keys(t).length>0?t:null,fixed_first:void 0===i?null:{calendar_event_id:i}}},Nd=({orgSlug:e,selectedLeadSource:t,currentLeadSource:i,touchpoints:n,search:r,referrer:o,googleReferral:a})=>{var s,l,u;const d=t||i||null,c=la(e);return{lead_sources:[...new Set(d?[d,c]:[c])],lead_sources_with_timestamps:n.map(e=>_r({...e})),query_params:Object.fromEntries(new URLSearchParams(r).entries()),referrer:o,google_rwg_token:null!==(s=null==a?void 0:a.rwgToken)&&void 0!==s?s:null,google_referral_building_id:null!==(l=null==a?void 0:a.buildingId)&&void 0!==l?l:null,google_environment:null!==(u=null==a?void 0:a.environment)&&void 0!==u?u:null}},Md=e=>0===e?0:Math.floor(e/10);var Dd=function(e,t,i,n){var r,o=arguments.length,a=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,i,a):r(t,i))||a);return o>3&&a&&Object.defineProperty(t,i,a),a};const Ld={bedrooms:[],moveIn:null,maxBudget:null},Rd={"escorted-tour":"WITH_AGENT","self-guided-tour":"SELF_GUIDED","live-virtual-tour":"VIRTUAL_SHOWING"};let Bd=class extends ue{constructor(){super(...arguments),this.orgSlug="",this.buildingSlug="",this.buildingId=0,this.orgId=0,this.buildingName="",this.sgtUrl="",this.selfGuidedToursTypeOffered="",this.escortedToursLink="",this.escortedToursTypeOffered="",this.virtualToursLink="",this.virtualToursTypeOffered="",this.tourTypeOptions=[],this.layoutOptions=[],this.currentLeadSource="",this.leadSources=[],this.featureFlagShowDropdown="",this.bedroomPreferenceRequired=!1,this.orgLegalName="",this.country=null,this.buildingState=null,this.primaryColor=Xi,this.foregroundColorOnPrimaryBackgroundColor="white",this.compactDesign=!1,this.leadSourceClient=null,this.leadSourceMultitouchClient=null,this.getSessionToken=()=>null,this.api=null,this.step="loading",this.loadError=null,this.mobile=Ir(),this.group=null,this.communities=new Map,this.selectedIds=[],this.picks=[],this.existingEventIds=[],this.tourType="escorted-tour",this.linkTourType=null,this.date=null,this.firstStart=null,this.laterStarts={},this.plan=null,this.planLoading=!1,this.planError=null,this.notice=null,this.contact=kd,this.submitting=!1,this.bookingError=null,this.reschedulePrompt=null,this.confirmed=[],this.bookedTourType=null,this.bookedEventIds=[],this.extendInitial=null,this.extendFrom=null,this.extending=!1,this.rescheduled=!1,this.rescheduleCanceled=!1,this.planRequestId=0,this.idempotency=null,this.onKeydown=e=>{du(e,this),"Escape"!==e.key||e.defaultPrevented||e.isComposing||(e.stopPropagation(),this.close())},this.loadSelectCommunities=e=>this.client.getCommunities(e).then(this.rememberPage),this.loadExtendCommunities=e=>{const t=this.extendFrom;return t?this.client.getCommunities({...e,extend:t}).then(this.rememberPage):Promise.reject(new Error("No booking to extend"))},this.rememberPage=e=>(this.remember(e.communities),e),this.onPicksChange=e=>{this.picks=e.detail.communities}}connectedCallback(){super.connectedCallback(),this.hasAttribute("role")||this.setAttribute("role","dialog"),this.hasAttribute("aria-modal")||this.setAttribute("aria-modal","true"),this.hasAttribute("aria-label")||this.setAttribute("aria-label","Schedule a Tour"),this.cleanupMobileListener=Nr(e=>this.mobile=e),this.addEventListener("keydown",this.onKeydown)}disconnectedCallback(){var e;null===(e=this.cleanupMobileListener)||void 0===e||e.call(this),this.removeEventListener("keydown",this.onKeydown),super.disconnectedCallback()}close(){var e;null===(e=this.onCloseClicked)||void 0===e||e.call(this,new MouseEvent("click"))}get client(){return this.api||(this.api=Zu({orgSlug:this.orgSlug,buildingSlug:this.buildingSlug,getSessionToken:()=>this.getSessionToken()})),this.api}willUpdate(e){if(e.has("primaryColor")||e.has("foregroundColorOnPrimaryBackgroundColor")){const e=this.primaryColor||Xi;this.style.setProperty("--primary-color",e),this.style.setProperty("--action-confirm-button-background",e),this.style.setProperty("--action-confirm-button-color",this.foregroundColorOnPrimaryBackgroundColor),this.style.setProperty("--on-primary-color",this.foregroundColorOnPrimaryBackgroundColor)}}firstUpdated(){this.start()}updated(e){e.has("step")&&void 0===e.get("step")?lu(this):(e.has("step")||e.has("reschedulePrompt")||e.has("rescheduleCanceled"))&&(this.hasAttribute("tabindex")||this.setAttribute("tabindex","-1"),this.focus({preventScroll:!0}))}async start(){this.step="loading",this.loadError=null;try{const e=await this.client.getCommunities(Ld);if(this.group=e,this.remember(e.communities),e.anchor.is_general_building)return void this.goTo("pick");this.rememberOne({building_id:e.anchor.building_id,name:e.anchor.name,address:null,timezone:null}),this.startSchedule([e.anchor.building_id])}catch(e){if(e instanceof Xu&&"NOT_IN_GROUP"===e.code)return this.group=null,this.rememberOne({building_id:this.buildingId,name:this.buildingName,address:null,timezone:null}),void this.startSchedule([this.buildingId]);this.loadError=e.message,this.step="error",this.log("TOUR_SCHEDULER_V2_LOAD_ERROR",e)}}goTo(e){this.step=e,"pick"===e?this.picks=this.selectedIds.map(e=>this.communities.get(e)).filter(e=>!!e):"booked"===e&&(this.picks=[]),_o("tourSchedulerStepViewed",{step:"schedule"===e&&this.extending?"extend-schedule":e,buildingId:this.buildingId})}remember(e){const t=new Map(this.communities);e.forEach(e=>t.set(e.building_id,Yu(e))),this.communities=t}rememberOne(e){const t=this.communities.get(e.building_id);(null==t?void 0:t.address)||(this.communities=new Map(this.communities).set(e.building_id,e))}startSchedule(e){this.selectedIds=e,this.plan=null,this.firstStart=null,this.laterStarts={},this.linkTourType=null,this.notice=null,this.bookingError=null,this.reschedulePrompt=null,this.goTo("schedule"),this.runPlan()}choice(){var e;return{buildingIds:this.selectedIds,tourType:this.tourType,date:null!==(e=this.date)&&void 0!==e?e:dd(new Date),firstStart:this.firstStart,laterStarts:this.laterStarts,existingEventIds:this.existingEventIds}}async runPlan(e=!1){if(0===this.selectedIds.length)return;const t=++this.planRequestId;this.planLoading=!0,this.planError=null,e||(this.notice=null);try{let e=this.choice(),i=await this.client.plan(Id(e));for(let n=0;n<2&&t===this.planRequestId;n++){if(i.tour_types.includes(e.tourType)){if(!(i.bookable_dates.length>0)||i.bookable_dates.includes(e.date))break;this.date=i.bookable_dates[0]}else{if(0===i.tour_types.length)break;this.tourType=i.tour_types[0]}this.firstStart=null,this.laterStarts={},e=this.choice(),i=await this.client.plan(Id(e))}if(t!==this.planRequestId)return;this.plan=i,i.bookable_dates.includes(e.date)&&(this.date=e.date),i.changed.length>0&&(this.notice=i.changed.map(e=>e.text).join(" "))}catch(e){if(t!==this.planRequestId)return;this.planError=e.message,this.log("TOUR_SCHEDULER_V2_PLAN_ERROR",e)}finally{t===this.planRequestId&&(this.planLoading=!1)}}tourLink(e){if(!this.tourTypeOptions.map(e=>e.value).includes(Rd[e]))return null;const[t,i]={"self-guided-tour":[this.sgtUrl,this.selfGuidedToursTypeOffered],"escorted-tour":[this.escortedToursLink,this.escortedToursTypeOffered],"live-virtual-tour":[this.virtualToursLink,this.virtualToursTypeOffered]}[e];return t&&ba(0,i)?t:null}get bookingOwnBuildingAlone(){return 0===this.existingEventIds.length&&1===this.selectedIds.length&&this.selectedIds[0]===this.buildingId}openTourLink(e){const t=this.tourLink(e);if(!t)return;const i="self-guided-tour"===e&&52===this.orgId?So(t,$o()):t;window.open(i,"_blank")}tourTypeChoices(){var e,t;const i=null!==(t=null===(e=this.plan)||void 0===e?void 0:e.tour_types)&&void 0!==t?t:[];return hd.filter(e=>i.includes(e)||this.bookingOwnBuildingAlone&&!!this.tourLink(e)).map(e=>({id:e,opensLink:this.bookingOwnBuildingAlone&&!!this.tourLink(e)}))}get shownTourType(){var e;return this.linkTourType?this.linkTourType:(null===(e=this.plan)||void 0===e?void 0:e.tour_types.includes(this.tourType))?this.tourType:null}get activeLinkType(){const e=this.shownTourType;return e&&this.bookingOwnBuildingAlone&&this.tourLink(e)?e:null}onTourType(e){if(_o("tourTypeSelected",{tourType:e,buildingId:this.buildingId}),this.bookingOwnBuildingAlone&&this.tourLink(e))return this.linkTourType=e,void this.openTourLink(e);this.linkTourType=null,e!==this.tourType&&(this.tourType=e,this.firstStart=null,this.laterStarts={},this.runPlan())}onDate(e){e!==this.date&&(_o("tourDateSelected",{tourType:this.tourType,buildingId:this.buildingId}),this.date=e,this.firstStart=null,this.laterStarts={},this.runPlan())}onStopTime(e,t){const i=this.selectedIds.indexOf(e);if(i<0)return;_o("tourTimeSelected",{tourType:this.tourType,buildingId:this.buildingId,stopNumber:i+1});const n=this.selectedIds.slice(1,i);0===i?(this.firstStart=ed(t),this.laterStarts={}):this.laterStarts={...Object.fromEntries(n.filter(e=>this.laterStarts[e]).map(e=>[e,this.laterStarts[e]])),[e]:t},this.runPlan()}onReorder(e){_o("tourStopsReordered",{buildingId:this.buildingId,stopCount:e.length});const t=this.selectedIds.filter(t=>!e.includes(t));this.selectedIds=[...e,...t],this.firstStart=null,this.laterStarts={},this.runPlan()}onRemove(e){const t=this.selectedIds.filter(t=>t!==e);if(_o("tourStopRemoved",{buildingId:this.buildingId,stopCount:t.length}),0===t.length)return this.selectedIds=[],this.plan=null,void this.goTo(this.extending?"booked":"pick");this.selectedIds[0]===e&&(this.firstStart=null),this.selectedIds=t,this.laterStarts={},this.runPlan()}onEditCommunities(){this.goTo("pick")}onCommunitiesSelected(e,t){var i;if(e.forEach(e=>this.rememberOne(e)),_o("tourCommunitiesSelected",{buildingId:this.buildingId,count:e.length,mode:t}),this.extending="extend"===t,this.extending){this.existingEventIds=this.bookedEventIds,this.tourType=null!==(i=this.bookedTourType)&&void 0!==i?i:this.tourType;const e=this.confirmed.filter(e=>e.start).slice(-1)[0];this.date=(null==e?void 0:e.start)?Ju(e.start):this.date}else this.existingEventIds=[];this.startSchedule(e.map(e=>e.building_id))}async submit(e,t=!1){var i,n,r,o,a,s;const l=this.plan;if(!l||this.submitting)return;const u=this.choice(),d=this.showLeadSourceDropdown()?e.leadSource:null,c=(({choice:e,plan:t,contact:i,attribution:n,conversationTrackingId:r,cancelExistingTours:o})=>({tour_type:e.tourType,stops:[...e.existingEventIds.map(e=>({existing_calendar_event_id:e})),...t.stops.filter(e=>!e.fixed).map(e=>({building_id:e.building_id,start:e.start}))],contact:i,lead_sources:n,conversation_tracking_id:r,cancel_existing_tours:o}))({choice:u,plan:l,contact:{first_name:e.firstName.trim(),last_name:e.lastName.trim(),email:e.email.trim(),phone_e164:null!==(i=e.phoneE164)&&void 0!==i?i:"",bedrooms:null===e.layout?[]:[Md(e.layout)],move_in:e.moveIn||null,notes:e.notes.trim()},attribution:Nd({orgSlug:this.orgSlug,selectedLeadSource:d,currentLeadSource:this.currentLeadSource,touchpoints:null!==(r=null===(n=this.leadSourceMultitouchClient)||void 0===n?void 0:n.getSafeLeadSourceTouchpointsWithDefault({includedUserSelectedLeadSource:d||null}))&&void 0!==r?r:[],search:window.location.search,referrer:document.referrer,googleReferral:is()}),conversationTrackingId:null!==(a=null===(o=this.leadSourceClient)||void 0===o?void 0:o.chatId)&&void 0!==a?a:null,cancelExistingTours:t}),h=JSON.stringify({tour_type:c.tour_type,stops:c.stops,contact:c.contact,cancel_existing_tours:c.cancel_existing_tours});(null===(s=this.idempotency)||void 0===s?void 0:s.booking)!==h&&(this.idempotency={booking:h,key:gs()}),_o("scheduleTourSubmitted",{tourType:u.tourType,stopCount:c.stops.length,buildingId:this.buildingId}),this.submitting=!0,this.bookingError=null;try{const e=await this.client.book(c,this.idempotency.key);this.idempotency=null,this.rescheduled=t,this.onBooked(e,u.tourType,l)}catch(t){this.onBookingError(t,e)}finally{this.submitting=!1}}onBooked(e,t,i){var n,r,o,a,s,l;if(this.reschedulePrompt=null,e.stops.every(e=>"failed"===e.status))return this.notice=null!==(o=null===(r=null===(n=e.stops.find(e=>e.error))||void 0===n?void 0:n.error)||void 0===r?void 0:r.message)&&void 0!==o?o:"We couldn't book your tour. Please pick another time.",this.log("TOUR_SCHEDULER_V2_BOOKING_ERROR",e.stops),void this.runPlan(!0);const u=new Map(i.stops.map(e=>[e.building_id,e]));this.confirmed=e.stops.map(e=>{var t,i,n,r,o,a,s,l;const d=null!==(t=this.communities.get(e.building_id))&&void 0!==t?t:{building_id:e.building_id,name:"",address:null,timezone:null},c=null!==(r=null!==(i=d.timezone)&&void 0!==i?i:null===(n=u.get(e.building_id))||void 0===n?void 0:n.timezone)&&void 0!==r?r:null;return{community:{...d,timezone:c},start:e.start,end:e.end,status:e.status,error:null!==(a=null===(o=e.error)||void 0===o?void 0:o.message)&&void 0!==a?a:null,distanceFromPrevMi:null!==(l=null===(s=u.get(e.building_id))||void 0===s?void 0:s.distance_from_prev_mi)&&void 0!==l?l:null}});const d=e.stops.filter(e=>"failed"!==e.status&&null!==e.calendar_event_id);this.bookedEventIds=d.map(e=>e.calendar_event_id),this.bookedTourType=t,this.extending=!1,this.extendInitial=null,_o("tourItineraryBooked",{buildingId:this.buildingId,stopCount:d.length,failedCount:e.stops.length-d.length}),d.length>0&&(null===(a=this.leadSourceClient)||void 0===a||a.checkAndHandleForLogLeadSource({webchatAction:"tour-scheduler",stateId:null}),null===(s=this.leadSourceClient)||void 0===s||s.resetLeadSource(),null===(l=this.leadSourceMultitouchClient)||void 0===l||l.resetLeadSourceTouchpoints()),this.goTo("booked"),this.loadExtension()}extendQueryFromBooking(){const e=this.confirmed.filter(e=>"failed"!==e.status),t=e[e.length-1];return(null==t?void 0:t.end)&&this.bookedTourType?{availableAfter:t.end,tourType:this.bookedTourType,nearBuildingId:t.community.building_id,excludeBuildingIds:e.map(e=>e.community.building_id)}:null}stopsRemaining(){return 3-this.bookedEventIds.length}async loadExtension(){const e=this.extendQueryFromBooking();this.extendFrom=e;const t=this.stopsRemaining();if(this.group&&e&&!(t<=0))try{const i=await this.client.getCommunities({...Ld,extend:e});this.remember(i.communities),i.communities.some(e=>e.tourable)&&(this.extendInitial=i,_o("tourExtensionOffered",{buildingId:this.buildingId,stopsRemaining:t}))}catch(e){this.log("TOUR_SCHEDULER_V2_EXTEND_LOAD_ERROR",e)}}onBookingError(e,t){const i=e instanceof Xu?e:new Xu(0,null,"Something went wrong. Please try again.");return"EXISTING_TOUR"===i.code?(this.reschedulePrompt=i.message,void(this.contact=t)):(this.reschedulePrompt=null,"SLOT_TAKEN"===i.code?(this.notice=i.message,void this.runPlan(!0)):(this.bookingError=i.message,void this.log("TOUR_SCHEDULER_V2_BOOKING_ERROR",e)))}showLeadSourceDropdown(){return this.featureFlagShowDropdown===bo.always||this.featureFlagShowDropdown===bo.onAttributionFailure&&0===this.currentLeadSource.length}log(e,t){ra({logTitle:e,logData:{error:t},logType:na.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:t})}backStep(){return this.rescheduleCanceled?null:"schedule"===this.step?this.extending?"booked":this.group?"pick":null:"pick"===this.step&&this.group&&!this.group.anchor.is_general_building&&this.plan&&this.selectedIds.length>0?"schedule":null}problems(){var e,t;return null!==(t=null===(e=this.plan)||void 0===e?void 0:e.unchainable)&&void 0!==t?t:[]}isMultiStop(){return this.selectedIds.length>1||this.existingEventIds.length>0}canSubmit(){const e=this.plan;return!!e&&!this.planLoading&&!this.planError&&e.stops.some(e=>!e.fixed)&&0===e.unchainable.length&&null===this.activeLinkType&&(t=this.contact,i=this.bedroomPreferenceRequired,(!!t.firstName.trim()||!!t.lastName.trim())&&Lr(t.email.trim())&&!!t.phoneE164&&(!i||null!==t.layout));var t,i}disclaimer(){return Yo({buildingName:this.buildingName,phoneNumberInput:this.contact.phone,emailInput:this.contact.email,orgLegalName:this.orgLegalName,orgSlug:this.orgSlug,country:this.country,buildingState:this.buildingState,clickingButtonText:"schedule tour"})}container(e){return H`<div
6328
+ </svg>`,Id=e=>{const t=Object.fromEntries(e.buildingIds.slice(1).filter(t=>e.laterStarts[t]).map(t=>[String(t),e.laterStarts[t]])),i=e.existingEventIds[e.existingEventIds.length-1];return{building_ids:e.buildingIds,tour_type:e.tourType,date:e.date,start_time:e.firstStart,stop_starts:t,fixed_first:void 0===i?null:{calendar_event_id:i}}},Nd=({orgSlug:e,selectedLeadSource:t,currentLeadSource:i,touchpoints:n,search:r,referrer:o,googleReferral:a})=>{var s,l,u;const d=t||i||null,c=la(e);return{lead_sources:[...new Set(d?[d,c]:[c])],lead_sources_with_timestamps:n.map(e=>_r({...e})),query_params:Object.fromEntries(new URLSearchParams(r).entries()),referrer:o,google_rwg_token:null!==(s=null==a?void 0:a.rwgToken)&&void 0!==s?s:null,google_referral_building_id:null!==(l=null==a?void 0:a.buildingId)&&void 0!==l?l:null,google_environment:null!==(u=null==a?void 0:a.environment)&&void 0!==u?u:null}},Md=e=>0===e?0:Math.floor(e/10);var Dd=function(e,t,i,n){var r,o=arguments.length,a=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,i,a):r(t,i))||a);return o>3&&a&&Object.defineProperty(t,i,a),a};const Ld={bedrooms:[],moveIn:null,maxBudget:null},Rd={"escorted-tour":"WITH_AGENT","self-guided-tour":"SELF_GUIDED","live-virtual-tour":"VIRTUAL_SHOWING"};let Bd=class extends ue{constructor(){super(...arguments),this.orgSlug="",this.buildingSlug="",this.buildingId=0,this.orgId=0,this.buildingName="",this.sgtUrl="",this.selfGuidedToursTypeOffered="",this.escortedToursLink="",this.escortedToursTypeOffered="",this.virtualToursLink="",this.virtualToursTypeOffered="",this.tourTypeOptions=[],this.layoutOptions=[],this.currentLeadSource="",this.leadSources=[],this.featureFlagShowDropdown="",this.bedroomPreferenceRequired=!1,this.orgLegalName="",this.country=null,this.buildingState=null,this.primaryColor=Xi,this.foregroundColorOnPrimaryBackgroundColor="white",this.compactDesign=!1,this.leadSourceClient=null,this.leadSourceMultitouchClient=null,this.getSessionToken=()=>null,this.api=null,this.step="loading",this.loadError=null,this.mobile=Ir(),this.group=null,this.communities=new Map,this.selectedIds=[],this.picks=[],this.existingEventIds=[],this.tourType="escorted-tour",this.linkTourType=null,this.date=null,this.firstStart=null,this.laterStarts={},this.plan=null,this.planLoading=!1,this.planError=null,this.notice=null,this.contact=kd,this.submitting=!1,this.bookingError=null,this.reschedulePrompt=null,this.confirmed=[],this.bookedTourType=null,this.bookedEventIds=[],this.extendInitial=null,this.extendFrom=null,this.extending=!1,this.rescheduled=!1,this.rescheduleCanceled=!1,this.planRequestId=0,this.idempotency=null,this.onKeydown=e=>{du(e,this),"Escape"!==e.key||e.defaultPrevented||e.isComposing||(e.stopPropagation(),this.close())},this.loadSelectCommunities=e=>this.client.getCommunities(e).then(this.rememberPage),this.loadExtendCommunities=e=>{const t=this.extendFrom;return t?this.client.getCommunities({...e,extend:t}).then(this.rememberPage):Promise.reject(new Error("No booking to extend"))},this.rememberPage=e=>(this.remember(e.communities),e),this.onPicksChange=e=>{this.picks=e.detail.communities}}connectedCallback(){super.connectedCallback(),this.hasAttribute("role")||this.setAttribute("role","dialog"),this.hasAttribute("aria-modal")||this.setAttribute("aria-modal","true"),this.hasAttribute("aria-label")||this.setAttribute("aria-label","Schedule a Tour"),this.cleanupMobileListener=Nr(e=>this.mobile=e),this.addEventListener("keydown",this.onKeydown)}disconnectedCallback(){var e;null===(e=this.cleanupMobileListener)||void 0===e||e.call(this),this.removeEventListener("keydown",this.onKeydown),super.disconnectedCallback()}close(){var e;null===(e=this.onCloseClicked)||void 0===e||e.call(this,new MouseEvent("click"))}get client(){return this.api||(this.api=Zu({orgSlug:this.orgSlug,buildingSlug:this.buildingSlug,getSessionToken:()=>this.getSessionToken()})),this.api}willUpdate(e){if(e.has("primaryColor")||e.has("foregroundColorOnPrimaryBackgroundColor")){const e=this.primaryColor||Xi;this.style.setProperty("--primary-color",e),this.style.setProperty("--action-confirm-button-background",e),this.style.setProperty("--action-confirm-button-color",this.foregroundColorOnPrimaryBackgroundColor),this.style.setProperty("--on-primary-color",this.foregroundColorOnPrimaryBackgroundColor)}}firstUpdated(){this.start()}updated(e){e.has("step")&&void 0===e.get("step")?lu(this):(e.has("step")||e.has("reschedulePrompt")||e.has("rescheduleCanceled"))&&(this.hasAttribute("tabindex")||this.setAttribute("tabindex","-1"),this.focus({preventScroll:!0}))}async start(){this.step="loading",this.loadError=null;try{const e=await this.client.getCommunities(Ld);if(this.group=e,this.remember(e.communities),e.anchor.is_general_building)return void this.goTo("pick");this.rememberOne({building_id:e.anchor.building_id,name:e.anchor.name,address:null,timezone:null}),this.startSchedule([e.anchor.building_id])}catch(e){if(e instanceof Xu&&"NOT_IN_GROUP"===e.code)return this.group=null,this.rememberOne({building_id:this.buildingId,name:this.buildingName,address:null,timezone:null}),void this.startSchedule([this.buildingId]);this.loadError=e.message,this.step="error",this.log("TOUR_SCHEDULER_V2_LOAD_ERROR",e)}}goTo(e){this.step=e,"pick"===e?this.picks=this.selectedIds.map(e=>this.communities.get(e)).filter(e=>!!e):"booked"===e&&(this.picks=[]),_o("tourSchedulerStepViewed",{step:"schedule"===e&&this.extending?"extend-schedule":e,buildingId:this.buildingId})}remember(e){const t=new Map(this.communities);e.forEach(e=>t.set(e.building_id,Yu(e))),this.communities=t}rememberOne(e){const t=this.communities.get(e.building_id);(null==t?void 0:t.address)||(this.communities=new Map(this.communities).set(e.building_id,e))}startSchedule(e){this.selectedIds=e,this.plan=null,this.firstStart=null,this.laterStarts={},this.linkTourType=null,this.notice=null,this.bookingError=null,this.reschedulePrompt=null,this.goTo("schedule"),this.runPlan()}choice(){var e;return{buildingIds:this.selectedIds,tourType:this.tourType,date:null!==(e=this.date)&&void 0!==e?e:dd(new Date),firstStart:this.firstStart,laterStarts:this.laterStarts,existingEventIds:this.existingEventIds}}async runPlan(e=!1){if(0===this.selectedIds.length)return;const t=++this.planRequestId;this.planLoading=!0,this.planError=null,e||(this.notice=null);try{let e=this.choice(),i=await this.client.plan(Id(e));for(let n=0;n<2&&t===this.planRequestId;n++){if(i.tour_types.includes(e.tourType)){if(!(i.bookable_dates.length>0)||i.bookable_dates.includes(e.date))break;this.date=i.bookable_dates[0]}else{if(0===i.tour_types.length)break;this.tourType=i.tour_types[0]}this.firstStart=null,this.laterStarts={},e=this.choice(),i=await this.client.plan(Id(e))}if(t!==this.planRequestId)return;this.plan=i,i.bookable_dates.includes(e.date)&&(this.date=e.date),i.changed.length>0&&(this.notice=i.changed.map(e=>e.text).join(" "))}catch(e){if(t!==this.planRequestId)return;this.planError=e.message,this.log("TOUR_SCHEDULER_V2_PLAN_ERROR",e)}finally{t===this.planRequestId&&(this.planLoading=!1)}}tourLink(e){if(!this.tourTypeOptions.map(e=>e.value).includes(Rd[e]))return null;const[t,i]={"self-guided-tour":[this.sgtUrl,this.selfGuidedToursTypeOffered],"escorted-tour":[this.escortedToursLink,this.escortedToursTypeOffered],"live-virtual-tour":[this.virtualToursLink,this.virtualToursTypeOffered]}[e];return t&&ba(0,i)?t:null}get bookingOwnBuildingAlone(){return 0===this.existingEventIds.length&&1===this.selectedIds.length&&this.selectedIds[0]===this.buildingId}openTourLink(e){const t=this.tourLink(e);if(!t)return;const i="self-guided-tour"===e&&52===this.orgId?So(t,$o()):t;window.open(i,"_blank")}tourTypeChoices(){var e,t;const i=null!==(t=null===(e=this.plan)||void 0===e?void 0:e.tour_types)&&void 0!==t?t:[];return hd.filter(e=>i.includes(e)||this.bookingOwnBuildingAlone&&!!this.tourLink(e)).map(e=>({id:e,opensLink:this.bookingOwnBuildingAlone&&!!this.tourLink(e)}))}get shownTourType(){var e;return this.linkTourType?this.linkTourType:(null===(e=this.plan)||void 0===e?void 0:e.tour_types.includes(this.tourType))?this.tourType:null}get activeLinkType(){const e=this.shownTourType;return e&&this.bookingOwnBuildingAlone&&this.tourLink(e)?e:null}onTourType(e){if(_o("tourTypeSelected",{tourType:e,buildingId:this.buildingId}),this.bookingOwnBuildingAlone&&this.tourLink(e))return this.linkTourType=e,void this.openTourLink(e);this.linkTourType=null,e!==this.tourType&&(this.tourType=e,this.firstStart=null,this.laterStarts={},this.runPlan())}onDate(e){e!==this.date&&(_o("tourDateSelected",{tourType:this.tourType,buildingId:this.buildingId}),this.date=e,this.firstStart=null,this.laterStarts={},this.runPlan())}onStopTime(e,t){const i=this.selectedIds.indexOf(e);if(i<0)return;_o("tourTimeSelected",{tourType:this.tourType,buildingId:this.buildingId,stopNumber:i+1});const n=this.selectedIds.slice(1,i);0===i?(this.firstStart=ed(t),this.laterStarts={}):this.laterStarts={...Object.fromEntries(n.filter(e=>this.laterStarts[e]).map(e=>[e,this.laterStarts[e]])),[e]:t},this.runPlan()}onReorder(e){_o("tourStopsReordered",{buildingId:this.buildingId,stopCount:e.length});const t=this.selectedIds.filter(t=>!e.includes(t));this.selectedIds=[...e,...t],this.firstStart=null,this.laterStarts={},this.runPlan()}onRemove(e){const t=this.selectedIds.filter(t=>t!==e);if(_o("tourStopRemoved",{buildingId:this.buildingId,stopCount:t.length}),0===t.length)return this.selectedIds=[],this.plan=null,void this.goTo(this.extending?"booked":"pick");this.selectedIds[0]===e&&(this.firstStart=null),this.selectedIds=t,this.laterStarts={},this.runPlan()}onEditCommunities(){this.goTo("pick")}onCommunitiesSelected(e,t){var i;if(e.forEach(e=>this.rememberOne(e)),_o("tourCommunitiesSelected",{buildingId:this.buildingId,count:e.length,mode:t}),this.extending="extend"===t,this.extending){this.existingEventIds=this.bookedEventIds,this.tourType=null!==(i=this.bookedTourType)&&void 0!==i?i:this.tourType;const e=this.confirmed.filter(e=>e.start).slice(-1)[0];this.date=(null==e?void 0:e.start)?Ju(e.start):this.date}else this.existingEventIds=[];this.startSchedule(e.map(e=>e.building_id))}async submit(e,t=!1){var i,n,r,o,a,s;const l=this.plan;if(!l||this.submitting)return;const u=this.choice(),d=this.showLeadSourceDropdown()?e.leadSource:null,c=(({choice:e,plan:t,contact:i,attribution:n,conversationTrackingId:r,cancelExistingTours:o})=>({tour_type:e.tourType,stops:[...e.existingEventIds.map(e=>({existing_calendar_event_id:e})),...t.stops.filter(e=>!e.fixed).map(e=>({building_id:e.building_id,start:e.start}))],contact:i,lead_sources:n,conversation_tracking_id:r,cancel_existing_tours:o}))({choice:u,plan:l,contact:{first_name:e.firstName.trim(),last_name:e.lastName.trim(),email:e.email.trim(),phone_e164:null!==(i=e.phoneE164)&&void 0!==i?i:"",bedrooms:null===e.layout?[]:[Md(e.layout)],move_in:e.moveIn||null,notes:e.notes.trim()},attribution:Nd({orgSlug:this.orgSlug,selectedLeadSource:d,currentLeadSource:this.currentLeadSource,touchpoints:null!==(r=null===(n=this.leadSourceMultitouchClient)||void 0===n?void 0:n.getSafeLeadSourceTouchpointsWithDefault({includedUserSelectedLeadSource:d||null}))&&void 0!==r?r:[],search:window.location.search,referrer:document.referrer,googleReferral:is()}),conversationTrackingId:null!==(a=null===(o=this.leadSourceClient)||void 0===o?void 0:o.chatId)&&void 0!==a?a:null,cancelExistingTours:t}),h=JSON.stringify({tour_type:c.tour_type,stops:c.stops,contact:c.contact,cancel_existing_tours:c.cancel_existing_tours});(null===(s=this.idempotency)||void 0===s?void 0:s.booking)!==h&&(this.idempotency={booking:h,key:gs()}),_o("scheduleTourSubmitted",{tourType:u.tourType,stopCount:c.stops.length,buildingId:this.buildingId}),this.submitting=!0,this.bookingError=null;try{const e=await this.client.book(c,this.idempotency.key);this.idempotency=null,this.rescheduled=t,this.onBooked(e,u.tourType,l)}catch(t){this.onBookingError(t,e)}finally{this.submitting=!1}}onBooked(e,t,i){var n,r,o,a,s,l;if(this.reschedulePrompt=null,e.stops.every(e=>"failed"===e.status))return this.notice=null!==(o=null===(r=null===(n=e.stops.find(e=>e.error))||void 0===n?void 0:n.error)||void 0===r?void 0:r.message)&&void 0!==o?o:"We couldn't book your tour. Please pick another time.",this.log("TOUR_SCHEDULER_V2_BOOKING_ERROR",e.stops),void this.runPlan(!0);const u=new Map(i.stops.map(e=>[e.building_id,e]));this.confirmed=e.stops.map(e=>{var t,i,n,r,o,a,s,l;const d=null!==(t=this.communities.get(e.building_id))&&void 0!==t?t:{building_id:e.building_id,name:"",address:null,timezone:null},c=null!==(r=null!==(i=d.timezone)&&void 0!==i?i:null===(n=u.get(e.building_id))||void 0===n?void 0:n.timezone)&&void 0!==r?r:null;return{community:{...d,timezone:c},start:e.start,end:e.end,status:e.status,error:null!==(a=null===(o=e.error)||void 0===o?void 0:o.message)&&void 0!==a?a:null,distanceFromPrevMi:null!==(l=null===(s=u.get(e.building_id))||void 0===s?void 0:s.distance_from_prev_mi)&&void 0!==l?l:null}});const d=e.stops.filter(e=>"failed"!==e.status&&null!==e.calendar_event_id);this.bookedEventIds=d.map(e=>e.calendar_event_id),this.bookedTourType=t,this.extending=!1,this.extendInitial=null,_o("tourItineraryBooked",{buildingId:this.buildingId,stopCount:d.length,failedCount:e.stops.length-d.length}),d.length>0&&(null===(a=this.leadSourceClient)||void 0===a||a.checkAndHandleForLogLeadSource({webchatAction:"tour-scheduler",stateId:null}),null===(s=this.leadSourceClient)||void 0===s||s.resetLeadSource(),null===(l=this.leadSourceMultitouchClient)||void 0===l||l.resetLeadSourceTouchpoints()),this.goTo("booked"),this.loadExtension()}extendQueryFromBooking(){const e=this.confirmed.filter(e=>"failed"!==e.status),t=e[e.length-1];return(null==t?void 0:t.end)&&this.bookedTourType?{availableAfter:t.end,tourType:this.bookedTourType,nearBuildingId:t.community.building_id,excludeBuildingIds:e.map(e=>e.community.building_id)}:null}stopsRemaining(){return 3-this.bookedEventIds.length}async loadExtension(){const e=this.extendQueryFromBooking();this.extendFrom=e;const t=this.stopsRemaining();if(this.group&&e&&!(t<=0))try{const i=await this.client.getCommunities({...Ld,extend:e});this.remember(i.communities),i.communities.some(e=>e.tourable)&&(this.extendInitial=i,_o("tourExtensionOffered",{buildingId:this.buildingId,stopsRemaining:t}))}catch(e){this.log("TOUR_SCHEDULER_V2_EXTEND_LOAD_ERROR",e)}}onBookingError(e,t){const i=e instanceof Xu?e:new Xu(0,null,"Something went wrong. Please try again.");return"EXISTING_TOUR"===i.code?(this.reschedulePrompt=i.message,void(this.contact=t)):(this.reschedulePrompt=null,"SLOT_TAKEN"===i.code?(this.notice=i.message,void this.runPlan(!0)):(this.bookingError=i.message,void this.log("TOUR_SCHEDULER_V2_BOOKING_ERROR",e)))}showLeadSourceDropdown(){return this.featureFlagShowDropdown===bo.always||this.featureFlagShowDropdown===bo.onAttributionFailure&&0===this.currentLeadSource.length}log(e,t){ra({logTitle:e,logData:{error:t},logType:na.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:t})}backStep(){return this.rescheduleCanceled?null:"schedule"===this.step?this.extending?"booked":this.group?"pick":null:"pick"===this.step&&this.group&&!this.group.anchor.is_general_building&&this.plan&&this.selectedIds.length>0?"schedule":null}problems(){var e,t;return null!==(t=null===(e=this.plan)||void 0===e?void 0:e.unchainable)&&void 0!==t?t:[]}isMultiStop(){return this.selectedIds.length>1||this.existingEventIds.length>0}canSubmit(){const e=this.plan;return!!e&&!this.planLoading&&!this.planError&&e.stops.some(e=>!e.fixed)&&0===e.unchainable.length&&null===this.activeLinkType&&(t=this.contact,i=this.bedroomsRequired,(!!t.firstName.trim()||!!t.lastName.trim())&&Lr(t.email.trim())&&!!t.phoneE164&&(!i||null!==t.layout));var t,i}get bedroomsRequired(){return this.bedroomPreferenceRequired&&this.layoutOptions.length>0}disclaimer(){return Yo({buildingName:this.buildingName,phoneNumberInput:this.contact.phone,emailInput:this.contact.email,orgLegalName:this.orgLegalName,orgSlug:this.orgSlug,country:this.country,buildingState:this.buildingState,clickingButtonText:"schedule tour"})}container(e){return H`<div
6329
6329
  id=${this.mobile?"mobile-body-container":"scheduler-container"}
6330
6330
  >
6331
6331
  ${e}
@@ -6397,7 +6397,7 @@ xmlns="http://www.w3.org/2000/svg"
6397
6397
  <contact-form
6398
6398
  .values=${this.contact}
6399
6399
  .layoutOptions=${this.layoutOptions}
6400
- ?bedroomsRequired=${this.bedroomPreferenceRequired}
6400
+ ?bedroomsRequired=${this.bedroomsRequired}
6401
6401
  .leadSources=${this.leadSources}
6402
6402
  ?showLeadSourceDropdown=${this.showLeadSourceDropdown()}
6403
6403
  currentLeadSource=${this.currentLeadSource}
@@ -38,7 +38,7 @@ export const buildPlanRequest = (choice: ItineraryChoice): PlanRequest => {
38
38
  tour_type: choice.tourType,
39
39
  date: choice.date,
40
40
  start_time: choice.firstStart,
41
- stop_starts: Object.keys(laterStarts).length > 0 ? laterStarts : null,
41
+ stop_starts: laterStarts,
42
42
  fixed_first:
43
43
  fixedEventId === undefined ? null : { calendar_event_id: fixedEventId },
44
44
  };
@@ -876,10 +876,18 @@ export class TourSchedulerV2 extends LitElement {
876
876
  plan.stops.some((s) => !s.fixed) &&
877
877
  plan.unchainable.length === 0 &&
878
878
  this.activeLinkType === null &&
879
- contactIsValid(this.contact, this.bedroomPreferenceRequired)
879
+ contactIsValid(this.contact, this.bedroomsRequired)
880
880
  );
881
881
  }
882
882
 
883
+ /**
884
+ * The form offers this widget's building's layouts, so a building with none
885
+ * (a group's parent building) has no preference to ask for.
886
+ */
887
+ private get bedroomsRequired(): boolean {
888
+ return this.bedroomPreferenceRequired && this.layoutOptions.length > 0;
889
+ }
890
+
883
891
  private disclaimer(): TemplateResult {
884
892
  return formDisclaimer({
885
893
  buildingName: this.buildingName,
@@ -982,7 +990,7 @@ export class TourSchedulerV2 extends LitElement {
982
990
  <contact-form
983
991
  .values=${this.contact}
984
992
  .layoutOptions=${this.layoutOptions}
985
- ?bedroomsRequired=${this.bedroomPreferenceRequired}
993
+ ?bedroomsRequired=${this.bedroomsRequired}
986
994
  .leadSources=${this.leadSources}
987
995
  ?showLeadSourceDropdown=${this.showLeadSourceDropdown()}
988
996
  currentLeadSource=${this.currentLeadSource}
@@ -92,7 +92,8 @@ export interface PlanRequest {
92
92
  tour_type: TourTypeId;
93
93
  date: string;
94
94
  start_time: string | null;
95
- stop_starts: Record<string, string> | null;
95
+ /** Times picked for later stops, by building id; empty when none are picked. */
96
+ stop_starts: Record<string, string>;
96
97
  fixed_first: { calendar_event_id: number } | null;
97
98
  }
98
99
 
@@ -190,6 +190,8 @@ const fakeBackend = ({
190
190
  return json(200, group(searchParams.has("available_after")));
191
191
  }
192
192
  if (pathname === "/platformApi/webchat/tour-itineraries/plan") {
193
+ // As the server's request model does: stop_starts may be empty, not null.
194
+ if (body.stop_starts === null) return json(422, null);
193
195
  plannedTourTypes.push(body.tour_type);
194
196
  return json(200, plan(body));
195
197
  }
@@ -258,7 +260,10 @@ const inScheduler = <T extends Element>(
258
260
  const clickButton = (button: Element | null | undefined) =>
259
261
  button?.shadowRoot?.querySelector<HTMLButtonElement>("button")?.click();
260
262
 
261
- const fillContactAndSubmit = async (scheduler: TourSchedulerV2) => {
263
+ const fillContactAndSubmit = async (
264
+ scheduler: TourSchedulerV2,
265
+ overrides: Partial<ContactForm["values"]> = {}
266
+ ) => {
262
267
  const form = await waitFor(() =>
263
268
  inScheduler<ContactForm>(scheduler, "contact-form")
264
269
  );
@@ -273,6 +278,7 @@ const fillContactAndSubmit = async (scheduler: TourSchedulerV2) => {
273
278
  phone: "(312) 555-0142",
274
279
  phoneE164: "+13125550142",
275
280
  layout: 10,
281
+ ...overrides,
276
282
  },
277
283
  },
278
284
  bubbles: true,
@@ -476,3 +482,57 @@ it("moves to the server's first tour type when escorted tours aren't offered", a
476
482
  ]);
477
483
  expect(bookings[0].tour_type).to.equal("self-guided-tour");
478
484
  });
485
+
486
+ it("books without a bedroom preference where one is required but the building has no layouts to offer", async () => {
487
+ const { bookings } = fakeBackend();
488
+ const scheduler = mount();
489
+ // A group's parent building: the org requires a preference, and there is nothing to pick.
490
+ scheduler.bedroomPreferenceRequired = true;
491
+
492
+ await fillContactAndSubmit(scheduler, { layout: null });
493
+ await waitFor(() => bookings.length === 1);
494
+
495
+ expect(bookings[0].contact.bedrooms).to.deep.equal([]);
496
+ });
497
+
498
+ it("still asks for a bedroom preference where one is required and the building has layouts", async () => {
499
+ fakeBackend();
500
+ const scheduler = mount();
501
+ scheduler.bedroomPreferenceRequired = true;
502
+ scheduler.layoutOptions = [{ value: 10, label: "One bedroom" }];
503
+
504
+ const form = await waitFor(() =>
505
+ inScheduler<ContactForm>(scheduler, "contact-form")
506
+ );
507
+ form.dispatchEvent(
508
+ new CustomEvent("contact-change", {
509
+ detail: {
510
+ values: {
511
+ ...form.values,
512
+ firstName: "Jane",
513
+ email: "jane@example.com",
514
+ phone: "(312) 555-0142",
515
+ phoneE164: "+13125550142",
516
+ layout: null,
517
+ },
518
+ },
519
+ bubbles: true,
520
+ composed: true,
521
+ })
522
+ );
523
+ // The plan has loaded, so only the missing preference holds the button back.
524
+ await waitFor(
525
+ () =>
526
+ inScheduler<HTMLElement & { stops: unknown[] }>(
527
+ scheduler,
528
+ "itinerary-editor"
529
+ )?.stops.length
530
+ );
531
+ await scheduler.updateComplete;
532
+
533
+ const button = inScheduler<HTMLElement & { disabled: boolean }>(
534
+ scheduler,
535
+ "#schedule-bttn"
536
+ );
537
+ expect(button?.disabled).to.equal(true);
538
+ });