@meetelise/chat 1.50.0 → 1.50.1
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.
- package/dist/src/services/fees/buildBuildingUnitsQuery.d.ts +11 -0
- package/dist/src/services/fees/fetchBuildingUnits.d.ts +3 -4
- package/package.json +1 -1
- package/public/dist/index.js +2 -2
- package/src/WebComponent/FeeCalculator/fee-calculator.ts +3 -12
- package/src/services/fees/buildBuildingUnitsQuery.ts +35 -0
- package/src/services/fees/fetchBuildingUnits.test.ts +30 -0
- package/src/services/fees/fetchBuildingUnits.ts +20 -27
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare type BuildingUnitsQueryParams = {
|
|
2
|
+
numBedrooms?: number[];
|
|
3
|
+
moveInDateString?: string;
|
|
4
|
+
leaseTerm?: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const buildBuildingUnitsQuery: ({ numBedrooms, moveInDateString, leaseTerm, }: BuildingUnitsQueryParams) => string;
|
|
7
|
+
export declare const sortUnitsByStartingPrice: <T extends {
|
|
8
|
+
id: number;
|
|
9
|
+
startingPrice: number;
|
|
10
|
+
}>(units: T[]) => T[];
|
|
11
|
+
export {};
|
|
@@ -21,9 +21,8 @@ export declare type Unit = {
|
|
|
21
21
|
declare type FetchPropertyUnitsParams = {
|
|
22
22
|
buildingSlug: string;
|
|
23
23
|
numBedrooms?: number[];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
leaseTermMin?: number;
|
|
24
|
+
moveInDateString?: string;
|
|
25
|
+
leaseTerm?: number;
|
|
27
26
|
};
|
|
28
|
-
declare const fetchBuildingUnits: ({ buildingSlug, numBedrooms,
|
|
27
|
+
declare const fetchBuildingUnits: ({ buildingSlug, numBedrooms, moveInDateString, leaseTerm, }: FetchPropertyUnitsParams) => Promise<Unit[]>;
|
|
29
28
|
export default fetchBuildingUnits;
|
package/package.json
CHANGED
package/public/dist/index.js
CHANGED
|
@@ -3508,7 +3508,7 @@ xmlns="http://www.w3.org/2000/svg"
|
|
|
3508
3508
|
`;class Yr{constructor(e={}){var t,n,i,r,o,a;this.id=null!==(t=e.id)&&void 0!==t?t:"",this.description=null!==(n=e.description)&&void 0!==n?n:"",this.type=null!==(i=e.type)&&void 0!==i?i:"",this.rent=null!==(r=e.rent)&&void 0!==r?r:0,this.rentFrequency=null!==(o=e.rentFrequency)&&void 0!==o?o:"monthly",this.available=null!==(a=e.available)&&void 0!==a&&a,this.reservedUntil=e.reservedUntil?new Date(e.reservedUntil):void 0}}class Kr{constructor(e={}){var t,n,i,r,o;this.description=null!==(t=e.description)&&void 0!==t?t:"",this.type=null!==(n=e.type)&&void 0!==n?n:"",this.minAvailableItem=e.minAvailableItem?new Yr(e.minAvailableItem):void 0,this.maxAvailableItem=e.maxAvailableItem?new Yr(e.maxAvailableItem):void 0,this.allItems=(null!==(i=e.allItems)&&void 0!==i?i:[]).map(e=>new Yr(e)),this.rent=null!==(r=e.rent)&&void 0!==r?r:0,this.priceDescription=null!==(o=e.priceDescription)&&void 0!==o?o:""}get displayName(){return this.description}get itemDescription(){return this.description}}var Xr,Zr;!function(e){e.NEVER="NEVER",e.AS_NEEDED="AS_NEEDED",e.ONE_TIME="ONE_TIME",e.MONTHLY="MONTHLY",e.WEEKLY="WEEKLY",e.BI_WEEKLY="BI_WEEKLY",e.ANNUALLY="ANNUALLY",e.DAILY="DAILY"}(Xr||(Xr={})),function(e){e.Rent="Rent",e.Utility="Utility",e.ApplicationFee="ApplicationFee",e.Parking="Parking",e.Insurance="Insurance",e.Storage="Storage",e.PetFee="PetFee",e.PetRent="PetRent",e.PetDeposit="PetDeposit",e.SecurityDeposit="SecurityDeposit",e.MoveInFee="MoveInFee",e.Other="Other"}(Zr||(Zr={}));class Jr{constructor(e={}){var t,n,i,r,o,a,s,l,u;this.id=null!==(t=e.id)&&void 0!==t?t:"",this.building_id=e.building_id,this.fee_name=null!==(n=e.fee_name)&&void 0!==n?n:"",this.amount=e.amount,this.amount_display=null!==(i=e.amount_display)&&void 0!==i?i:"",this.min_estimate=e.min_estimate,this.max_estimate=e.max_estimate,this.percent_rent=e.percent_rent,this.percent_rent_min=e.percent_rent_min,this.percent_rent_max=e.percent_rent_max,this.frequency=null!==(r=e.frequency)&&void 0!==r?r:Xr.ONE_TIME,this.category=null!==(o=e.category)&&void 0!==o?o:Zr.Other,this.description=e.description,this.additional_info=e.additional_info,this.refundable=null!==(a=e.refundable)&&void 0!==a&&a,this.hidden_reason=e.hidden_reason,this.unit_ids=e.unit_ids,this.layout_ids=e.layout_ids,this.public_facing=null===(s=e.public_facing)||void 0===s||s,this.per_applicant=null!==(l=e.per_applicant)&&void 0!==l&&l,this.required_for_quotes=null!==(u=e.required_for_quotes)&&void 0!==u&&u,this.charge_code=e.charge_code,this.bundle_key=e.bundle_key,this.external_key=e.external_key}get displayFrequency(){return this.frequency.replace(/_/g," ").toLowerCase().replace(/\b\w/g,e=>e.toUpperCase())}get isOptional(){return!this.required_for_quotes}}const eo=class{constructor(){this.params=new URLSearchParams}addSingle(e,t){return t?(this.params.append(e,t),this):this}addArray(e,t){return t?(t.forEach(t=>{t&&this.params.append(`${e}[]`,t)}),this):this}build(){return this.params.toString()?`?${this.params.toString()}`:""}},to=hn,no=e=>new Jr(e),io=e=>new Kr(e),ro=async(e,t)=>{try{const n=(new eo).addArray("layout_ids",null==t?void 0:t.map(e=>e.toString())),i=await r().get(`${to}/platformApi/webchat/${e}/marketable-fees?${n.build()}`);if(i.data){const e=fn(i.data);return{fees:e.fees.map(no),rentableItems:e.rentableItems.map(io),buildingIncentives:e.buildingIncentives}}}catch(t){Ti({logType:ki.error,buildingSlug:e,logTitle:"[ERROR_GETTING_FEES]",logData:{error:t}})}return{fees:[],rentableItems:[],buildingIncentives:[]}},oo=-1,ao=hn,so=async({buildingSlug:e,unitId:t,chargeInputs:n,rentableItems:i,leaseTerm:o,moveInDate:a},s)=>{try{const l=await r().post(`${ao}/platformApi/webchat/${e}/quote/calculate`,gn({unitId:t,chargeInputs:n,rentableItems:i,leaseTerm:o,moveInDate:a}),{signal:s});if(l.data){return fn(l.data)}}catch(t){"ERR_CANCELED"!==t.code&&Ti({logType:ki.error,buildingSlug:e,logTitle:"[ERROR_CALCULATING_QUOTE]",logData:{error:t}})}return{quote:{}}},lo=(e="black")=>j`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 15 15" fill="none">
|
|
3509
3509
|
<line x1="1.70782" y1="13.2254" x2="13.2376" y2="1.69554" stroke="${e}" stroke-width="2.13401"/>
|
|
3510
3510
|
<path d="M2.00929 1.99996L13.3328 13.3421" stroke="${e}" stroke-width="2.13401"/>
|
|
3511
|
-
</svg>`,uo=hn,co=async({buildingSlug:e,numBedrooms:t,
|
|
3511
|
+
</svg>`,uo=hn,co=async({buildingSlug:e,numBedrooms:t,moveInDateString:n,leaseTerm:i})=>{try{const a=(({numBedrooms:e,moveInDateString:t,leaseTerm:n})=>{const i=new eo;return i.addArray("num_bedrooms",null==e?void 0:e.map(e=>e.toString())).addSingle("move_in_date_earliest",t).addSingle("move_in_date_latest",t).addSingle("lease_term_min",null==n?void 0:n.toString()),i.build()})({numBedrooms:t,moveInDateString:n,leaseTerm:i}),s=await r().get(`${uo}/platformApi/webchat/${e}/units${a}`);if(s.data){const e=fn(s.data);return o=e.map(e=>({...e,id:parseInt(e.id.toString().substring(1))})),[...o].sort((e,t)=>e.startingPrice-t.startingPrice||e.id-t.id)}}catch(r){Ti({logType:ki.error,buildingSlug:e,logTitle:"[ERROR_GETTING_UNITS]",logData:{error:r,params:{numBedrooms:t,moveInDateString:n,leaseTerm:i}}})}var o;return[]},ho=({color:e="#347FF7",size:t=24}={})=>j`
|
|
3512
3512
|
<svg width="${t}" height="${t}" viewBox="0 0 24 25" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
3513
3513
|
<g id="Frame" clip-path="url(#clip0_18718_332018)">
|
|
3514
3514
|
<path id="Vector" d="M3 12.5C3 13.6819 3.23279 14.8522 3.68508 15.9442C4.13738 17.0361 4.80031 18.0282 5.63604 18.864C6.47177 19.6997 7.46392 20.3626 8.55585 20.8149C9.64778 21.2672 10.8181 21.5 12 21.5C13.1819 21.5 14.3522 21.2672 15.4442 20.8149C16.5361 20.3626 17.5282 19.6997 18.364 18.864C19.1997 18.0282 19.8626 17.0361 20.3149 15.9442C20.7672 14.8522 21 13.6819 21 12.5C21 11.3181 20.7672 10.1478 20.3149 9.05585C19.8626 7.96392 19.1997 6.97177 18.364 6.13604C17.5282 5.30031 16.5361 4.63738 15.4442 4.18508C14.3522 3.73279 13.1819 3.5 12 3.5C10.8181 3.5 9.64778 3.73279 8.55585 4.18508C7.46392 4.63738 6.47177 5.30031 5.63604 6.13604C4.80031 6.97177 4.13738 7.96392 3.68508 9.05585C3.23279 10.1478 3 11.3181 3 12.5Z" stroke="${e}" stroke-linecap="round" stroke-linejoin="round"/>
|
|
@@ -5020,7 +5020,7 @@ xmlns="http://www.w3.org/2000/svg"
|
|
|
5020
5020
|
</p>
|
|
5021
5021
|
</div>
|
|
5022
5022
|
</div>
|
|
5023
|
-
`:B``}};la.styles=aa,sa([ue({type:Object})],la.prototype,"incentive",void 0),la=sa([se("incentive-banner")],la);var ua=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a};let ca=class extends oe{constructor(){super(...arguments),this.buildingSlug="",this.orgSlug="",this.primaryColor=Ue,this.backgroundColor=Re,this.onCloseClicked=null,this.onClickEmailOption=null,this.onClickPhoneOption=null,this.onClickSSTOption=null,this.onClickTextUsOption=null,this.isCalculatingQuote=!1,this.isLoadingLayouts=!0,this.isExporting=!1,this.selectedLayoutIds=[oo],this.selectedUnit=null,this.chargeInputs={base_rent:0,num_pets:0,num_vehicles:0,num_applicants:1,num_cats:0,num_dogs:0,num_other_pets:0},this.desiredRentableItems=[],this.moveInDateString=pn.toISOString().split("T")[0],this.leaseTerm=12,this.buildingWebchatView=null,this.incentives=[],this.quote=null,this.pdfUrl=null,this.groupedFees={[Xr.ONE_TIME]:[],[Xr.MONTHLY]:[],[Xr.WEEKLY]:[],[Xr.BI_WEEKLY]:[],[Xr.ANNUALLY]:[],[Xr.DAILY]:[],[Xr.AS_NEEDED]:[],[Xr.NEVER]:[]},this.rentableItems=[],this.units=[],this.isLoadingUnits=!0,this.quoteAbortController=null,this.quoteDebounceTimer=null,this.startQuoteApiCall=async()=>{var e;null===(e=this.quoteAbortController)||void 0===e||e.abort(),this.quoteAbortController=new AbortController,this.isCalculatingQuote=!0,await this.performQuoteCalculation(this.quoteAbortController.signal)},this.firstUpdated=async()=>{this.style.setProperty("--primary-color",this.primaryColor),this.style.setProperty("--background-color",this.backgroundColor),await Promise.allSettled([this.setupCalculator(),this.fetchUnits()])},this.setupCalculator=async()=>{if(!this.buildingSlug||!this.orgSlug)return void(this.isLoadingLayouts=!1);const e=Bi(this.orgSlug,this.buildingSlug).then(e=>{e&&(this.buildingWebchatView=e)}).finally(()=>{this.isLoadingLayouts=!1}),t=ro(this.buildingSlug).then(e=>{e&&(this.groupedFees=this.groupFees(e.fees),this.rentableItems=e.rentableItems)});await Promise.allSettled([e,t])},this.requestQuoteCalculation=()=>{if(this.quoteDebounceTimer&&(clearTimeout(this.quoteDebounceTimer),this.quoteDebounceTimer=null),!this.selectedUnit||!this.moveInDateString)return this.quote=null,this.pdfUrl=null,void(this.isCalculatingQuote=!1);this.quoteDebounceTimer=window.setTimeout(()=>{this.startQuoteApiCall(),this.quoteDebounceTimer=null},1e3)},this.handleUnitSelect=e=>{const t=!this.selectedUnit;if(this.selectedUnit=e,t)return this.quoteDebounceTimer&&(clearTimeout(this.quoteDebounceTimer),this.quoteDebounceTimer=null),this.isCalculatingQuote=!0,void this.startQuoteApiCall();this.requestQuoteCalculation()},this.handleMoveInDateChange=async e=>{this.moveInDateString=e,this.quote=null,this.pdfUrl=null,await this.fetchUnits(),this.selectedUnit&&this.requestQuoteCalculation()},this.handleLeaseTermChange=async e=>{this.leaseTerm=e,this.quote=null,this.pdfUrl=null,await this.fetchUnits(),this.selectedUnit&&this.requestQuoteCalculation()},this.handleChargeInputsChange=e=>{this.chargeInputs={...this.chargeInputs,...e},this.requestQuoteCalculation()},this.handleRentableItemAdd=e=>{this.desiredRentableItems.some(t=>t.id===e.id)||this.desiredRentableItems.push(e),this.requestQuoteCalculation()},this.handleRentableItemRemove=e=>{this.desiredRentableItems=this.desiredRentableItems.filter(t=>t.id!==e.id),this.requestQuoteCalculation()},this.groupFees=e=>e.reduce((e,t)=>{const n=t.frequency||Xr.ONE_TIME;return e[n]=[...e[n]||[],t],e},{}),this.handleClickEmailOption=e=>{this.handleClose(),this.onClickEmailOption&&this.onClickEmailOption(e)},this.handleClickPhoneOption=e=>{this.handleClose(),this.onClickPhoneOption&&this.onClickPhoneOption(e)},this.handleClickSSTOption=e=>{this.handleClose(),this.onClickSSTOption&&this.onClickSSTOption(e)},this.handleClickTextUsOption=e=>{this.handleClose(),this.onClickTextUsOption&&this.onClickTextUsOption(e)},this.handleClose=()=>{var e;null===(e=this.onCloseClicked)||void 0===e||e.call(this)},this.handleSelectLayout=async e=>{this.selectedLayoutIds=e,await this.fetchUnits()},this.handleShare=async()=>{var e,t;this.selectedUnit&&this.moveInDateString&&this.pdfUrl&&(li("feeCalculatorPdfDownloaded",{buildingSlug:this.buildingSlug,quoteId:null!==(t=null===(e=this.quote)||void 0===e?void 0:e.id)&&void 0!==t?t:null}),window.open(this.pdfUrl,"_blank"))},this.fetchUnits=async()=>{let e;this.isLoadingUnits=!0,this.selectedLayoutIds.includes(oo)||(e=this.selectedLayoutIds.map(e=>{return 0===(t=e)?0:Math.floor(t/10);var t}));try{if(this.units=await co({buildingSlug:this.buildingSlug,
|
|
5023
|
+
`:B``}};la.styles=aa,sa([ue({type:Object})],la.prototype,"incentive",void 0),la=sa([se("incentive-banner")],la);var ua=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a};let ca=class extends oe{constructor(){super(...arguments),this.buildingSlug="",this.orgSlug="",this.primaryColor=Ue,this.backgroundColor=Re,this.onCloseClicked=null,this.onClickEmailOption=null,this.onClickPhoneOption=null,this.onClickSSTOption=null,this.onClickTextUsOption=null,this.isCalculatingQuote=!1,this.isLoadingLayouts=!0,this.isExporting=!1,this.selectedLayoutIds=[oo],this.selectedUnit=null,this.chargeInputs={base_rent:0,num_pets:0,num_vehicles:0,num_applicants:1,num_cats:0,num_dogs:0,num_other_pets:0},this.desiredRentableItems=[],this.moveInDateString=pn.toISOString().split("T")[0],this.leaseTerm=12,this.buildingWebchatView=null,this.incentives=[],this.quote=null,this.pdfUrl=null,this.groupedFees={[Xr.ONE_TIME]:[],[Xr.MONTHLY]:[],[Xr.WEEKLY]:[],[Xr.BI_WEEKLY]:[],[Xr.ANNUALLY]:[],[Xr.DAILY]:[],[Xr.AS_NEEDED]:[],[Xr.NEVER]:[]},this.rentableItems=[],this.units=[],this.isLoadingUnits=!0,this.quoteAbortController=null,this.quoteDebounceTimer=null,this.startQuoteApiCall=async()=>{var e;null===(e=this.quoteAbortController)||void 0===e||e.abort(),this.quoteAbortController=new AbortController,this.isCalculatingQuote=!0,await this.performQuoteCalculation(this.quoteAbortController.signal)},this.firstUpdated=async()=>{this.style.setProperty("--primary-color",this.primaryColor),this.style.setProperty("--background-color",this.backgroundColor),await Promise.allSettled([this.setupCalculator(),this.fetchUnits()])},this.setupCalculator=async()=>{if(!this.buildingSlug||!this.orgSlug)return void(this.isLoadingLayouts=!1);const e=Bi(this.orgSlug,this.buildingSlug).then(e=>{e&&(this.buildingWebchatView=e)}).finally(()=>{this.isLoadingLayouts=!1}),t=ro(this.buildingSlug).then(e=>{e&&(this.groupedFees=this.groupFees(e.fees),this.rentableItems=e.rentableItems)});await Promise.allSettled([e,t])},this.requestQuoteCalculation=()=>{if(this.quoteDebounceTimer&&(clearTimeout(this.quoteDebounceTimer),this.quoteDebounceTimer=null),!this.selectedUnit||!this.moveInDateString)return this.quote=null,this.pdfUrl=null,void(this.isCalculatingQuote=!1);this.quoteDebounceTimer=window.setTimeout(()=>{this.startQuoteApiCall(),this.quoteDebounceTimer=null},1e3)},this.handleUnitSelect=e=>{const t=!this.selectedUnit;if(this.selectedUnit=e,t)return this.quoteDebounceTimer&&(clearTimeout(this.quoteDebounceTimer),this.quoteDebounceTimer=null),this.isCalculatingQuote=!0,void this.startQuoteApiCall();this.requestQuoteCalculation()},this.handleMoveInDateChange=async e=>{this.moveInDateString=e,this.quote=null,this.pdfUrl=null,await this.fetchUnits(),this.selectedUnit&&this.requestQuoteCalculation()},this.handleLeaseTermChange=async e=>{this.leaseTerm=e,this.quote=null,this.pdfUrl=null,await this.fetchUnits(),this.selectedUnit&&this.requestQuoteCalculation()},this.handleChargeInputsChange=e=>{this.chargeInputs={...this.chargeInputs,...e},this.requestQuoteCalculation()},this.handleRentableItemAdd=e=>{this.desiredRentableItems.some(t=>t.id===e.id)||this.desiredRentableItems.push(e),this.requestQuoteCalculation()},this.handleRentableItemRemove=e=>{this.desiredRentableItems=this.desiredRentableItems.filter(t=>t.id!==e.id),this.requestQuoteCalculation()},this.groupFees=e=>e.reduce((e,t)=>{const n=t.frequency||Xr.ONE_TIME;return e[n]=[...e[n]||[],t],e},{}),this.handleClickEmailOption=e=>{this.handleClose(),this.onClickEmailOption&&this.onClickEmailOption(e)},this.handleClickPhoneOption=e=>{this.handleClose(),this.onClickPhoneOption&&this.onClickPhoneOption(e)},this.handleClickSSTOption=e=>{this.handleClose(),this.onClickSSTOption&&this.onClickSSTOption(e)},this.handleClickTextUsOption=e=>{this.handleClose(),this.onClickTextUsOption&&this.onClickTextUsOption(e)},this.handleClose=()=>{var e;null===(e=this.onCloseClicked)||void 0===e||e.call(this)},this.handleSelectLayout=async e=>{this.selectedLayoutIds=e,await this.fetchUnits()},this.handleShare=async()=>{var e,t;this.selectedUnit&&this.moveInDateString&&this.pdfUrl&&(li("feeCalculatorPdfDownloaded",{buildingSlug:this.buildingSlug,quoteId:null!==(t=null===(e=this.quote)||void 0===e?void 0:e.id)&&void 0!==t?t:null}),window.open(this.pdfUrl,"_blank"))},this.fetchUnits=async()=>{let e;this.isLoadingUnits=!0,this.selectedLayoutIds.includes(oo)||(e=this.selectedLayoutIds.map(e=>{return 0===(t=e)?0:Math.floor(t/10);var t}));try{if(this.units=await co({buildingSlug:this.buildingSlug,moveInDateString:this.moveInDateString,...e?{numBedrooms:e}:{},leaseTerm:this.leaseTerm}),this.selectedUnit){this.units.some(e=>{var t;return e.id===(null===(t=this.selectedUnit)||void 0===t?void 0:t.id)})||(this.selectedUnit=null,this.quote=null,this.pdfUrl=null)}}finally{this.isLoadingUnits=!1}}}async performQuoteCalculation(e){if(!this.selectedUnit||!this.moveInDateString)return this.quote=null,this.pdfUrl=null,void(this.isCalculatingQuote=!1);const t=this.moveInDateString,n=this.selectedUnit.id,i=this.leaseTerm;try{const r=await so({buildingSlug:this.buildingSlug,unitId:n,chargeInputs:this.chargeInputs,rentableItems:this.desiredRentableItems,leaseTerm:i,moveInDate:t},e);this.quote=r.quote,this.pdfUrl=r.pdfUrl||null,this.quote&&li("feeCalculatorQuoteGenerated",{buildingSlug:this.buildingSlug,unitId:n,leaseTerm:i})}catch(e){"AbortError"!==(null==e?void 0:e.name)&&(this.quote=null,this.pdfUrl=null,this.isCalculatingQuote=!1,Ti({logType:ki.error,buildingSlug:this.buildingSlug,logTitle:"[ERROR_CALCULATING_QUOTE]",logData:{error:e}}))}finally{e.aborted||(this.isCalculatingQuote=!1)}}get layouts(){var e,t;return null!==(t=null===(e=this.buildingWebchatView)||void 0===e?void 0:e.layoutOptions)&&void 0!==t?t:[]}updated(e){(e.has("primaryColor")||e.has("backgroundColor"))&&(this.style.setProperty("--primary-color",this.primaryColor),this.style.setProperty("--background-color",this.backgroundColor))}disconnectedCallback(){var e;super.disconnectedCallback(),this.quoteDebounceTimer&&(clearTimeout(this.quoteDebounceTimer),this.quoteDebounceTimer=null),null===(e=this.quoteAbortController)||void 0===e||e.abort(),this.quoteAbortController=null}render(){var e,t;const n=this.isExporting||this.isCalculatingQuote||!this.selectedUnit||!this.moveInDateString||!this.pdfUrl;return B`
|
|
5024
5024
|
<div
|
|
5025
5025
|
class="fee-calculator-container"
|
|
5026
5026
|
@keydown=${e=>e.stopPropagation()}
|
|
@@ -27,8 +27,6 @@ import { LogType } from "../../analytics";
|
|
|
27
27
|
import { pushGtmEvent } from "../../gtm";
|
|
28
28
|
import fetchBuildingUnits from "../../services/fees/fetchBuildingUnits";
|
|
29
29
|
import { layoutToBedrooms } from "../../services/fees/utils";
|
|
30
|
-
import parseISO from "date-fns/parseISO";
|
|
31
|
-
import isBefore from "date-fns/isBefore";
|
|
32
30
|
|
|
33
31
|
import "./components";
|
|
34
32
|
import "./components/fee-calculator-layout/fee-calculator-layout";
|
|
@@ -163,14 +161,7 @@ export class FeeCalculator extends LitElement {
|
|
|
163
161
|
return;
|
|
164
162
|
}
|
|
165
163
|
|
|
166
|
-
|
|
167
|
-
// use the unit's earliest available date (otherwise pricing will be incorrect)
|
|
168
|
-
const selectedMoveInDate = parseISO(this.moveInDateString);
|
|
169
|
-
const earliestAvailableDate = parseISO(this.selectedUnit.earliestAvailable);
|
|
170
|
-
|
|
171
|
-
const moveInDate = isBefore(selectedMoveInDate, earliestAvailableDate)
|
|
172
|
-
? this.selectedUnit.earliestAvailable
|
|
173
|
-
: this.moveInDateString;
|
|
164
|
+
const moveInDate = this.moveInDateString;
|
|
174
165
|
|
|
175
166
|
// Capture values before await to avoid race conditions
|
|
176
167
|
const unitId = this.selectedUnit.id;
|
|
@@ -439,9 +430,9 @@ export class FeeCalculator extends LitElement {
|
|
|
439
430
|
try {
|
|
440
431
|
this.units = await fetchBuildingUnits({
|
|
441
432
|
buildingSlug: this.buildingSlug,
|
|
442
|
-
|
|
433
|
+
moveInDateString: this.moveInDateString,
|
|
443
434
|
...(numBedrooms ? { numBedrooms } : {}),
|
|
444
|
-
|
|
435
|
+
leaseTerm: this.leaseTerm,
|
|
445
436
|
});
|
|
446
437
|
|
|
447
438
|
if (this.selectedUnit) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import QueryParamBuilder from "../../utils/queryParamBuilder";
|
|
2
|
+
|
|
3
|
+
type BuildingUnitsQueryParams = {
|
|
4
|
+
numBedrooms?: number[];
|
|
5
|
+
moveInDateString?: string;
|
|
6
|
+
leaseTerm?: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const buildBuildingUnitsQuery = ({
|
|
10
|
+
numBedrooms,
|
|
11
|
+
moveInDateString,
|
|
12
|
+
leaseTerm,
|
|
13
|
+
}: BuildingUnitsQueryParams): string => {
|
|
14
|
+
const queryParamBuilder = new QueryParamBuilder();
|
|
15
|
+
queryParamBuilder
|
|
16
|
+
.addArray(
|
|
17
|
+
"num_bedrooms",
|
|
18
|
+
numBedrooms?.map((num) => num.toString())
|
|
19
|
+
)
|
|
20
|
+
.addSingle("move_in_date_earliest", moveInDateString)
|
|
21
|
+
.addSingle("move_in_date_latest", moveInDateString)
|
|
22
|
+
.addSingle("lease_term_min", leaseTerm?.toString());
|
|
23
|
+
|
|
24
|
+
return queryParamBuilder.build();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const sortUnitsByStartingPrice = <
|
|
28
|
+
T extends { id: number; startingPrice: number }
|
|
29
|
+
>(
|
|
30
|
+
units: T[]
|
|
31
|
+
): T[] =>
|
|
32
|
+
[...units].sort((firstUnit, secondUnit) => {
|
|
33
|
+
const priceDifference = firstUnit.startingPrice - secondUnit.startingPrice;
|
|
34
|
+
return priceDifference || firstUnit.id - secondUnit.id;
|
|
35
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { expect } from "@esm-bundle/chai";
|
|
2
|
+
import {
|
|
3
|
+
buildBuildingUnitsQuery,
|
|
4
|
+
sortUnitsByStartingPrice,
|
|
5
|
+
} from "./buildBuildingUnitsQuery";
|
|
6
|
+
|
|
7
|
+
it("requests units for the selected move-in date", () => {
|
|
8
|
+
const queryString = buildBuildingUnitsQuery({
|
|
9
|
+
moveInDateString: "2026-08-01",
|
|
10
|
+
leaseTerm: 12,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
expect(queryString).to.include("move_in_date_earliest=2026-08-01");
|
|
14
|
+
expect(queryString).to.include("move_in_date_latest=2026-08-01");
|
|
15
|
+
expect(queryString).not.to.include("lease_term=12");
|
|
16
|
+
expect(queryString).to.include("lease_term_min=12");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("sorts the cheapest units first without mutating the API response", () => {
|
|
20
|
+
const units = [
|
|
21
|
+
{ id: 3, startingPrice: 2699 },
|
|
22
|
+
{ id: 2, startingPrice: 2574 },
|
|
23
|
+
{ id: 1, startingPrice: 2574 },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const sortedUnits = sortUnitsByStartingPrice(units);
|
|
27
|
+
|
|
28
|
+
expect(sortedUnits.map((unit) => unit.id)).to.deep.equal([1, 2, 3]);
|
|
29
|
+
expect(units.map((unit) => unit.id)).to.deep.equal([3, 2, 1]);
|
|
30
|
+
});
|
|
@@ -2,7 +2,10 @@ import axios from "axios";
|
|
|
2
2
|
import { LogType, sendLoggingEvent } from "../../analytics";
|
|
3
3
|
import { BASE_DOMAIN } from "../../globals";
|
|
4
4
|
import { camelize } from "../../utils";
|
|
5
|
-
import
|
|
5
|
+
import {
|
|
6
|
+
buildBuildingUnitsQuery,
|
|
7
|
+
sortUnitsByStartingPrice,
|
|
8
|
+
} from "./buildBuildingUnitsQuery";
|
|
6
9
|
|
|
7
10
|
const BASE_URL = BASE_DOMAIN;
|
|
8
11
|
|
|
@@ -30,44 +33,34 @@ export type Unit = {
|
|
|
30
33
|
type FetchPropertyUnitsParams = {
|
|
31
34
|
buildingSlug: string;
|
|
32
35
|
numBedrooms?: number[];
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
leaseTermMin?: number;
|
|
36
|
+
moveInDateString?: string;
|
|
37
|
+
leaseTerm?: number;
|
|
36
38
|
};
|
|
37
39
|
|
|
38
40
|
const fetchBuildingUnits = async ({
|
|
39
41
|
buildingSlug,
|
|
40
42
|
numBedrooms,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
leaseTermMin,
|
|
43
|
+
moveInDateString,
|
|
44
|
+
leaseTerm,
|
|
44
45
|
}: FetchPropertyUnitsParams): Promise<Unit[]> => {
|
|
45
46
|
try {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
queryParamBuilder
|
|
52
|
-
.addArray(
|
|
53
|
-
"num_bedrooms",
|
|
54
|
-
numBedrooms?.map((num) => num.toString())
|
|
55
|
-
)
|
|
56
|
-
.addSingle("move_in_date_earliest", moveInDateEarliestString)
|
|
57
|
-
.addSingle("move_in_date_latest", latestDateStr)
|
|
58
|
-
.addSingle("lease_term_min", leaseTermMin?.toString());
|
|
59
|
-
|
|
60
|
-
const queryString = queryParamBuilder.build();
|
|
47
|
+
const queryString = buildBuildingUnitsQuery({
|
|
48
|
+
numBedrooms,
|
|
49
|
+
moveInDateString,
|
|
50
|
+
leaseTerm,
|
|
51
|
+
});
|
|
61
52
|
const propertyUnitsResponse = await axios.get(
|
|
62
53
|
`${BASE_URL}/platformApi/webchat/${buildingSlug}/units${queryString}`
|
|
63
54
|
);
|
|
64
55
|
|
|
65
56
|
if (propertyUnitsResponse.data) {
|
|
66
57
|
const camelizedUnits = camelize<Unit[]>(propertyUnitsResponse.data);
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
return sortUnitsByStartingPrice(
|
|
59
|
+
camelizedUnits.map((unit) => ({
|
|
60
|
+
...unit,
|
|
61
|
+
id: parseInt(unit.id.toString().substring(1)),
|
|
62
|
+
}))
|
|
63
|
+
);
|
|
71
64
|
}
|
|
72
65
|
} catch (error) {
|
|
73
66
|
sendLoggingEvent({
|
|
@@ -76,7 +69,7 @@ const fetchBuildingUnits = async ({
|
|
|
76
69
|
logTitle: "[ERROR_GETTING_UNITS]",
|
|
77
70
|
logData: {
|
|
78
71
|
error,
|
|
79
|
-
params: { numBedrooms,
|
|
72
|
+
params: { numBedrooms, moveInDateString, leaseTerm },
|
|
80
73
|
},
|
|
81
74
|
});
|
|
82
75
|
}
|