{"version":3,"file":"index-Bk_VCVtm.js","sources":["../../../app/assets/javascripts/concepts/buildings/following/modal/components/remote_submit_form/index.ts","../../../app/assets/javascripts/concepts/buildings/following/modal/index.ts"],"sourcesContent":["\nimport { EventEmitter } from \"events\"\n\nimport Promise from \"plugins/bluebird/index\"\nimport $ from \"jquery\"\nimport \"bootstrap-modal\"\nimport \"bootstrap-modalmanager\"\n\nimport Google_Event from \"app/tracking/google/event\"\nimport GA4_Event from \"app/tracking/google/google_analytics_4/event\"\nimport PageInstance from \"app/page_instance/index\"\nimport Modal from \"app/modal/show-modal\"\nimport Auth_action from \"app/authentication/action\"\nimport Auth_callback_queue from \"app/authentication/callback_queue\"\n\nimport {\n refreshAndUpdateComponentPromise,\n} from \"app/authentication/remote_state\"\n\nimport {\n captureMessage,\n captureException,\n} from \"app/error_reporting/index\"\n\nimport {\n getContactInfoData,\n setContactInfoData,\n} from \"app/local_storages/contact_info_storage/index\"\n\nimport {\n create as create_user,\n ResultTypeEnums as CreateUserResultTypes,\n} from \"app/resources/users/create/index\"\n\nimport {\n isPresentString,\n} from \"app/utils/type_checking/index\"\n\nimport {\n isSignedIn,\n} from \"app/authentication/state\"\n\nimport {\n subscribe as subscribe_building_following,\n ResultTypeEnums as SubscribeBuildingFollowingResultTypes,\n FollowTypes as SubscribeBuildingFollowingFollowTypes,\n} from \"app/resources/building_followings/subscribe/index\"\nimport EventStore from \"app/resources/building_followings/event_store\"\n\nimport {\n trackSignUp,\n} from \"app/authentication/tracking\"\n\nimport {\n getLastContactInfoSyncPromise,\n} from \"app/authentication/contact_info_caching\"\n\n\nconst RejectionReasons = {\n ERROR_REPORTED: \"ERROR_REPORTED\",\n}\n\nconst SOURCE_FILE_PATH = \"concepts/buildings/following/modal/components/remote_submit_form/index\"\n\n\ninterface Selector {\n container: string | JQuery\n form: string\n create_button: string\n}\ninterface InputSelector {\n container?: string | JQuery\n form?: string\n create_button?: string\n}\nconst DEFAULT_SELECTOR = {\n container: \".cell--buildings--following--modal\",\n form: \".cell--buildings--following--modal__form\",\n create_button: \".cell--buildings--following--modal__btn-create\",\n}\n\n/* eslint-disable no-unused-vars */\nexport enum FollowTypes {\n RESIDENTIAL = \"residential\",\n COMMERCIAL = \"commercial\",\n}\n/* eslint-enable no-unused-vars */\ninterface Options {\n follow_type: FollowTypes,\n}\n\nclass FollowBuildingModal extends EventEmitter {\n protected selector: Selector\n\n protected $container: JQuery\n protected $form: JQuery\n protected $create_button: JQuery\n protected building_id: any\n\n protected follow_type: string\n\n constructor(selector: InputSelector, options: Options) {\n super()\n\n this.selector = Object.assign({}, DEFAULT_SELECTOR, selector)\n\n this.$container = $(this.selector.container)\n\n this.building_id = this.$container.data(\"building-id\")\n\n this.$form = this.$container.find(this.selector.form)\n this.$create_button = this.$container.find(this.selector.create_button)\n\n this.follow_type = options.follow_type\n\n if (this.$container.length !== 1){\n captureMessage(\n `$container contains non 1 (${this.$container.length}) elements`,\n {\n source_file_path: SOURCE_FILE_PATH,\n }\n )\n return\n }\n\n this.bind_action()\n }\n\n protected bind_action(){\n this.$create_button\n .on(\"click\", (e) => {\n e.preventDefault()\n\n try {\n this.$create_button.prop(\"disabled\", true)\n this.onFormSubmit()\n }\n finally {\n this.$create_button.prop(\"disabled\", false)\n }\n })\n\n return this\n }\n\n protected onFormSubmit() {\n Modal.showLoadingIndicator()\n\n const local_contact_info_data = getContactInfoData()\n\n if (! isPresentString(local_contact_info_data.contact_email_address)) {\n Auth_callback_queue.add(() => {\n getLastContactInfoSyncPromise()\n .then(() => this.onFormSubmit())\n .done()\n }, \"event:create_building_following\")\n\n Auth_action.showSignUpModal({\n enable_account_already_exists_error_message: false,\n })\n .then(({$modal, authentication_box}) => {\n authentication_box.on(\"sign_up:fail:account_conflict\", ({email_address}) => {\n $modal.modal(\"hide\")\n // Retry AFTER setting local contact email\n setContactInfoData({\n contact_email_address: email_address,\n })\n this.onFormSubmit()\n })\n })\n .done()\n return\n }\n\n let subscribe_building_following_inputs = {}\n Promise.resolve()\n .then(() => {\n Modal.showLoadingIndicator()\n\n if (isSignedIn()) {\n return Promise.resolve()\n }\n\n return create_user({\n authentication_handle: local_contact_info_data.user_authentication_handle || local_contact_info_data.contact_email_address || \"\",\n email_address: local_contact_info_data.contact_email_address || \"\",\n sign_in_on_success: true,\n })\n .then(({result_type}) => {\n switch (result_type) {\n case CreateUserResultTypes.SUCCESS:\n trackSignUp()\n refreshAndUpdateComponentPromise().done()\n return\n case CreateUserResultTypes.CONFLICT:\n return\n case CreateUserResultTypes.PARAMS_INVALID:\n return\n case CreateUserResultTypes.INVALID:\n return\n default:\n captureMessage(\n `unexpected/unhandled result_type: <${result_type}>`,\n {\n source_file_path:\n \"app/assets/javascripts/concepts/buildings/following/modal/components/remote_submit_form/index\",\n }\n )\n throw RejectionReasons.ERROR_REPORTED\n }\n })\n })\n .then(() => {\n const inputs = {\n // Need `||` to make flow happy\n user_authentication_handle: local_contact_info_data.user_authentication_handle || local_contact_info_data.contact_email_address || \"\",\n\n building_id: this.building_id,\n follow_type: this.follow_type === \"commercial\" ?\n SubscribeBuildingFollowingFollowTypes.COMMERCIAL :\n SubscribeBuildingFollowingFollowTypes.RESIDENTIAL,\n }\n subscribe_building_following_inputs = inputs\n return subscribe_building_following(inputs)\n })\n .then(({result_type}) => {\n switch (result_type) {\n case SubscribeBuildingFollowingResultTypes.SUCCESS:\n case SubscribeBuildingFollowingResultTypes.UNAUTHENTICATED:\n return\n default:\n captureMessage(\n `unexpected/unhandled result_type from subscribe_building_following: <${result_type}>`,\n Object.assign({\n \"source_file_path\":\n SOURCE_FILE_PATH,\n \"local_contact_info_data.contact_email_address\":\n local_contact_info_data.contact_email_address || \"unknown\",\n }, subscribe_building_following_inputs),\n )\n throw RejectionReasons.ERROR_REPORTED\n }\n })\n .then(() => {\n Modal.hideLoadingIndicator()\n Modal.hideTopModal()\n EventStore.fireSubscribeEvent({\n building_id: this.building_id,\n follow_type: this.follow_type,\n })\n\n // # Tracking\n Google_Event.track({\n category: PageInstance.currentPageNameForTracking(),\n action: \"Follow\",\n options: {\n eventLabel: \"Follow Building - Followed\",\n },\n })\n\n GA4_Event.track({\n event_name: \"building_followed\",\n options: {\n page: PageInstance.currentPageNameForTracking(),\n },\n })\n })\n .catch((whatever) => {\n Modal.hideLoadingIndicator()\n if (whatever === RejectionReasons.ERROR_REPORTED) { return }\n\n if (whatever instanceof Error) {\n captureException(\n whatever,\n {\n source_file_path:\n SOURCE_FILE_PATH,\n }\n )\n return\n }\n\n captureMessage(\n whatever.toString(),\n {\n source_file_path:\n SOURCE_FILE_PATH,\n }\n )\n })\n .done()\n }\n}\n\n\nconst Factory = {\n create(selector: InputSelector, options: Options){\n return new FollowBuildingModal(selector, options)\n },\n}\n\n\nconst init = (selector: InputSelector, options: Options) => {\n return Factory.create(selector, options)\n}\n\nexport default {init}\n","\n// region JS Imports\n\n// region External Modules\nimport $ from \"jquery\"\nimport u from \"umbrellajs\"\n\nimport I18n from \"plugins/i18n-js\"\nimport * as Routes from \"plugins/js-routes\"\n// endregion External Modules\n\n// Private Modules\nimport Modal from \"app/modal/show-modal\"\nimport Google_Event from \"app/tracking/google/event\"\nimport DataRetriever from \"app/data_retriever\"\nimport PageInstance from \"app/page_instance/index\"\n\nimport {\n q_ajax_3,\n} from \"app/utils/q_ajax/q_ajax_3\"\n// Private Modules\n\n// region Public Components\n// endregion Public Components\n\n// region Private Components\nimport RemoteSubmitForm from \"./components/remote_submit_form/index\"\nimport GA4_Event from \"app/tracking/google/google_analytics_4/event\"\n// endregion Private Components\n\n// endregion JS Imports\n\n\n\n/* eslint-disable no-unused-vars */\nexport enum FollowTypes {\n RESIDENTIAL = \"residential\",\n COMMERCIAL = \"commercial\",\n}\n/* eslint-enable no-unused-vars */\n\nconst CELL_CLASS_NAME = \"cell--buildings--following--modal\"\nconst CELL_INITIALIZED_CLASS_NAME = `${CELL_CLASS_NAME}--js-spacious-initialized`\n\nconst init = (scope: string | JQuery = `.${CELL_CLASS_NAME}`, follow_type: FollowTypes) => {\n $(scope).each((idx, el) => {\n const $el = $(el)\n\n if (el.classList.contains(CELL_INITIALIZED_CLASS_NAME)) { return }\n el.classList.add(CELL_INITIALIZED_CLASS_NAME)\n\n RemoteSubmitForm.init(\n {\n container: $el,\n },\n {\n follow_type: follow_type,\n },\n )\n })\n}\n\nconst show = (follow_type: FollowTypes) => {\n const city_id = DataRetriever.get(\"current-city-id\")\n const neighbourhood_id = DataRetriever.get(\"neighbourhood-id\")\n const building_id = DataRetriever.get(\"building-id\")\n\n // Special treatment when accessed through google translate\n if (city_id == null || neighbourhood_id == null || building_id == null) {\n return\n }\n\n const url = Routes.follow_city_neighbourhood_building_path(I18n.locale, city_id, neighbourhood_id, building_id, {\n follow_type: follow_type,\n })\n\n q_ajax_3({\n url: url,\n method: \"GET\",\n dataType: \"html\",\n })\n .then(({data}) => {\n if (u(`.${CELL_CLASS_NAME}`).length !== 0) { return }\n const $modal = Modal.showModalWithContent(data, {customContent: true})\n\n init($modal, follow_type)\n // Tracking\n Google_Event.track({\n category: PageInstance.currentPageNameForTracking(),\n action: \"Follow Building\",\n options: {\n eventLabel: \"Modal Pop Up\",\n },\n })\n\n GA4_Event.track({\n event_name: \"building_follow_modal_displayed\",\n options: {\n page: PageInstance.currentPageNameForTracking(),\n },\n })\n })\n .done()\n}\n\n\nexport default {\n show,\n}\n"],"names":["RejectionReasons","SOURCE_FILE_PATH","DEFAULT_SELECTOR","FollowBuildingModal","EventEmitter","selector","options","$","captureMessage","e","Modal","local_contact_info_data","getContactInfoData","isPresentString","Auth_callback_queue","getLastContactInfoSyncPromise","Auth_action","$modal","authentication_box","email_address","setContactInfoData","subscribe_building_following_inputs","Promise","isSignedIn","create_user","result_type","CreateUserResultTypes","trackSignUp","refreshAndUpdateComponentPromise","inputs","SubscribeBuildingFollowingFollowTypes","subscribe_building_following","SubscribeBuildingFollowingResultTypes","EventStore","Google_Event","PageInstance","GA4_Event","whatever","captureException","Factory","init","RemoteSubmitForm","FollowTypes","CELL_CLASS_NAME","CELL_INITIALIZED_CLASS_NAME","scope","follow_type","idx","el","$el","show","city_id","DataRetriever","neighbourhood_id","building_id","url","Routes.follow_city_neighbourhood_building_path","I18n","q_ajax_3","data","u","Buildings_Following_Modal"],"mappings":"u8BA0DA,MAAMA,EAAmB,CACvB,eAAgB,gBAClB,EAEMC,EAAmB,yEAanBC,EAAmB,CACvB,UAAgB,qCAChB,KAAgB,2CAChB,cAAgB,gDAClB,EAYA,MAAMC,UAA4BC,EAAAA,YAAa,CAU7C,YAAYC,EAAyBC,EAAkB,CAcjD,GAbE,MAAA,EAEN,KAAK,SAAW,OAAO,OAAO,CAAC,EAAGJ,EAAkBG,CAAQ,EAE5D,KAAK,WAAaE,EAAE,KAAK,SAAS,SAAS,EAE3C,KAAK,YAAc,KAAK,WAAW,KAAK,aAAa,EAErD,KAAK,MAAQ,KAAK,WAAW,KAAK,KAAK,SAAS,IAAI,EACpD,KAAK,eAAiB,KAAK,WAAW,KAAK,KAAK,SAAS,aAAa,EAEtE,KAAK,YAAcD,EAAQ,YAEvB,KAAK,WAAW,SAAW,EAAE,CAC/BE,EACE,8BAA8B,YAAK,WAAW,OAAM,cACpD,CACE,iBAAkBP,CAAA,CAEtB,EACA,MAAA,CAGF,KAAK,YAAY,CAAA,CAGT,aAAa,CACrB,YAAK,eACJ,GAAG,QAAUQ,GAAM,CAClBA,EAAE,eAAe,EAEb,GAAA,CACG,KAAA,eAAe,KAAK,WAAY,EAAI,EACzC,KAAK,aAAa,CAAA,QAEpB,CACO,KAAA,eAAe,KAAK,WAAY,EAAK,CAAA,CAC5C,CACD,EAEM,IAAA,CAGC,cAAe,CACvBC,EAAM,qBAAqB,EAE3B,MAAMC,EAA0BC,EAAmB,EAEnD,GAAI,CAAEC,EAAgBF,EAAwB,qBAAqB,EAAG,CACpEG,EAAoB,IAAI,IAAM,CAC5BC,EAAA,EACC,KAAK,IAAM,KAAK,aAAa,CAAC,EAC9B,KAAK,GACL,iCAAiC,EAEpCC,EAAY,gBAAgB,CAC1B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