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WAC7CA,EAA6C,YAChD,CACF,EACA,KAAK,CAAC,CAAC,YAAAd,KAAiB,CACvB,OAAQA,EAAa,CACnB,KAAKe,EAA6C,QAChD,OACF,QACE,MAAApC,EACE,2EAA2E,OAAAqB,EAAW,KACtF,CACE,iBACA3B,CAAA,CAEJ,EACMD,EAAiB,eAC3B,CACD,EACA,KAAK,IAAM,CACVa,EAAW,qBAAqB,CAC9B,iBAAkB,KAAK,iBACvB,YAAAvB,CAAA,CACD,EACF,EACA,MAAOiD,GAAa,CACf,GAAAA,IAAavC,EAAiB,eAElC,IAAIuC,aAAoB,MAAO,CAC7BC,EACED,EACA,CACE,iBACAtC,CAAA,CAEJ,EACA,OAGFM,EACEgC,EAAS,SAAS,EAClB,CACE,iBACAtC,CAAA,CAEJ,EACD,GACA,KAAK,EAGA,oBAAqB,CACtB,kBAAa,UAAU,IAAI,WAAW,EAE3C,KAAK,KAAK,yBAAyB,EAE7B,uBAAwB,CACzB,kBAAa,UAAU,OAAO,WAAW,EAElD,CAEA,MAAM2C,GAAU,CACd,UAAW,KACX,SAASvC,EAAiB,CACpB,YAAK,YAAc,KAAe,KAAK,WAEtC,eAAY,KAAK,OAAOA,CAAQ,EAC9B,KAAK,UACd,EACA,OAAOA,EAAiB,CACf,WAAIF,EAAoBE,CAAQ,EAE3C","names":["FollowTypes","ResultTypeEnums","unsubscribe","user_authentication_handle","neighbourhood_id","follow_type","Promise","__vitePreload","Routes","q_ajax_3","I18n","http_status_code","AJAX_ERROR_HANDLER_ACTIONS","reason_or_error","response","RejectionReasons","SOURCE_FILE_PATH","DEFAULT_SELECTOR","NeighbourhoodButton","EventEmitter","selector","u","captureMessage","neighbourhood_following","$followButtonPrimary","$unfollowButtonPrimary","e","btn_el","EventStore","Modal","local_contact_info_data","getContactInfoData","isPresentString","Auth_callback_queue","getLastContactInfoSyncPromise","Auth_action","$modal","authentication_box","email_address","setContactInfoData","subscribe_neighbourhood_following_inputs","isSignedIn","create_user","result_type","CreateUserResultTypes","trackSignUp","refreshAndUpdateComponentPromise","inputs","SubscribeNeighbourhoodFollowingFollowTypes","subscribe_neighbourhood_following","SubscribeNeighbourhoodFollowingResultTypes","Google_Event","PageInstance","GA4_Event","whatever","captureException","unsubscribe_neighbourhood_following","UnsubscribeNeighbourhoodFollowingFollowTypes","UnsubscribeNeighbourhoodFollowingResultTypes","Factory"],"ignoreList":[],"sources":["../../../app/assets/javascripts/app/resources/neighbourhood_followings/unsubscribe/index.ts","../../../app/assets/javascripts/concepts/neighbourhoods/neighbourhood_follow_button/factory.ts"],"sourcesContent":["\nimport Promise from \"bluebird\"\nimport {\n q_ajax_3,\n ERROR_HANDLER_ACTIONS as AJAX_ERROR_HANDLER_ACTIONS,\n} from \"app/utils/q_ajax/q_ajax_3\"\n\n\nimport I18n from \"plugins/i18n-js\"\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\ninterface Input {\n user_authentication_handle: string,\n\n neighbourhood_id: string | number,\n\n follow_type: FollowTypes,\n}\n\n/* eslint-disable no-unused-vars */\nenum ResultTypeEnums {\n SUCCESS = \"SUCCESS\",\n UNAUTHENTICATED = \"UNAUTHENTICATED\",\n INVALID = \"INVALID\",\n SERVER_ERROR = \"SERVER_ERROR\",\n}\n/* eslint-enable no-unused-vars */\n\ninterface PromiseResolvePayload {\n result_type: ResultTypeEnums,\n data?: {},\n}\n\nconst unsubscribe = ({user_authentication_handle, neighbourhood_id, follow_type}: Input): Promise => {\n return Promise.resolve(\n import(\n \"plugins/js-routes\"\n )\n )\n .then((Routes) => {\n return q_ajax_3(\n {\n url: Routes.unsubscribe_api_web_app_neighbourhood_followings_path(),\n type: \"POST\",\n\n // Expect JSON in response\n dataType: \"JSON\",\n\n // Sending JSON to server\n contentType: \"application/json; charset=utf-8\",\n data: JSON.stringify({\n user_authentication_handle: user_authentication_handle,\n neighbourhood_id: neighbourhood_id,\n follow_type: follow_type,\n\n locale: I18n.locale,\n }),\n },\n {\n custom_error_handler: ({http_status_code}) => {\n if (http_status_code === 401) {\n return AJAX_ERROR_HANDLER_ACTIONS.STOP_RETRY\n }\n if (http_status_code === 422) {\n return AJAX_ERROR_HANDLER_ACTIONS.STOP_RETRY\n }\n\n return AJAX_ERROR_HANDLER_ACTIONS.CONTINUE_RETRY\n },\n },\n )\n })\n .then(() => {\n return (\n {\n result_type: ResultTypeEnums.SUCCESS,\n data: {},\n }\n )\n })\n .catch((reason_or_error) => {\n if (reason_or_error instanceof Error) {\n throw reason_or_error\n }\n\n const { response } = reason_or_error\n switch (response.status) {\n case 500:\n case 502:\n case 503:\n case 504:\n return ({\n result_type: ResultTypeEnums.SERVER_ERROR,\n })\n case 401:\n return ({\n result_type: ResultTypeEnums.UNAUTHENTICATED,\n })\n case 422:\n return ({\n result_type: ResultTypeEnums.INVALID,\n })\n default:\n return ({\n result_type: ResultTypeEnums.INVALID,\n })\n }\n })\n}\n\nexport {\n unsubscribe,\n ResultTypeEnums,\n}\n","\n// region JS Imports\n\n// region External Modules\nimport { EventEmitter } from \"events\"\n\nimport Promise from \"plugins/bluebird/index\"\nimport u from \"umbrellajs\"\n// endregion External Modules\n\n// Private Modules\nimport Google_Event from \"app/tracking/google/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\n/* eslint-disable no-unused-vars */\nimport {\n DataEntry as NeighbourhoodFollowingDataEntry,\n} from \"app/resources/current_authenticated_user/neighbourhood_followings/get_many/index\"\n/* eslint-enable no-unused-vars */\nimport EventStore from \"app/resources/neighbourhood_followings/event_store\"\n\nimport {\n isPresentString,\n} from \"app/utils/type_checking\"\n\nimport {\n isSignedIn,\n} from \"app/authentication/state\"\n\nimport {\n subscribe as subscribe_neighbourhood_following,\n ResultTypeEnums as SubscribeNeighbourhoodFollowingResultTypes,\n FollowTypes as SubscribeNeighbourhoodFollowingFollowTypes,\n} from \"app/resources/neighbourhood_followings/subscribe/index\"\n\nimport {\n unsubscribe as unsubscribe_neighbourhood_following,\n ResultTypeEnums as UnsubscribeNeighbourhoodFollowingResultTypes,\n FollowTypes as UnsubscribeNeighbourhoodFollowingFollowTypes,\n} from \"app/resources/neighbourhood_followings/unsubscribe/index\"\n\nimport {\n trackSignUp,\n} from \"app/authentication/tracking\"\n\nimport {\n getLastContactInfoSyncPromise,\n} from \"app/authentication/contact_info_caching\"\nimport GA4_Event from \"app/tracking/google/google_analytics_4/event\"\n// Private Modules\n\n// region Public Components\n// endregion Public Components\n\n// region Private Components\n// endregion Private Components\n\n// endregion JS Imports\n\n\nconst RejectionReasons = {\n ERROR_REPORTED: \"ERROR_REPORTED\",\n}\n\nconst SOURCE_FILE_PATH = \"concepts/neighbourhoods/neighbourhood_follow_button/factory\"\n\n\ninterface Inputs {\n container: HTMLElement,\n\n neighbourhood_followings?: NeighbourhoodFollowingDataEntry[],\n\n followButtonPrimary?: string,\n unfollowButtonPrimary?: string,\n}\n\ninterface Selector {\n container: HTMLElement,\n\n neighbourhood_followings: NeighbourhoodFollowingDataEntry[],\n\n followButtonPrimary: string,\n unfollowButtonPrimary: string,\n}\n\nconst DEFAULT_SELECTOR = {\n neighbourhood_followings: [],\n\n followButtonPrimary: \".follow-button-content.on-not-following .cell--neighbourhoods--following--button__link\",\n unfollowButtonPrimary: \".follow-button-content.on-following .cell--neighbourhoods--following--button__link\",\n}\n\nexport class NeighbourhoodButton extends EventEmitter {\n private selector: Selector\n\n private container_el: HTMLElement\n private $container: UmbrellaInstance\n private readonly neighbourhood_id: string\n private readonly follow_type: string\n\n private readonly $followButtonPrimary = null as UmbrellaInstance | null\n private readonly $unfollowButtonPrimary = null as UmbrellaInstance | null\n\n constructor(selector: Inputs) {\n super()\n\n this.selector = Object.assign({}, DEFAULT_SELECTOR, selector)\n\n this.container_el = this.selector.container\n this.$container = u(this.selector.container)\n this.neighbourhood_id = this.$container.data(\"neighbourhood-id\").toString()\n this.follow_type = this.$container.data(\"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.$followButtonPrimary =\n this.$container.find(this.selector.followButtonPrimary)\n this.$unfollowButtonPrimary =\n this.$container.find(this.selector.unfollowButtonPrimary)\n\n this.bind_action()\n\n const matched_followings_found =\n this.selector.neighbourhood_followings.length > 0 &&\n this.selector.neighbourhood_followings.some((neighbourhood_following) => {\n return neighbourhood_following.neighbourhood_id === this.neighbourhood_id && (\n (this.follow_type === \"commercial\" && neighbourhood_following.is_following_for_commercial_content) ||\n (this.follow_type !== \"commercial\" && neighbourhood_following.is_following_for_residential_content)\n )\n })\n if (matched_followings_found) {\n this.displayAsFollowing()\n }\n }\n\n private bind_action(){\n if (this.$followButtonPrimary == null) { return }\n if (this.$unfollowButtonPrimary == null) { return }\n\n const $followButtonPrimary = this.$followButtonPrimary\n const $unfollowButtonPrimary = this.$unfollowButtonPrimary\n\n $followButtonPrimary\n .on(\"click\", (e) => {\n e.preventDefault()\n\n const follow_type: string = this.$container.data(\"follow-type\")\n\n const btn_el = $followButtonPrimary.first() as HTMLButtonElement | false\n try {\n if (btn_el) {\n btn_el.disabled = true\n }\n this.onFollowClick(follow_type)\n }\n finally {\n if (btn_el) {\n btn_el.disabled = false\n }\n }\n })\n\n $unfollowButtonPrimary\n .on(\"click\", (e) => {\n e.preventDefault()\n\n const btn_el = $unfollowButtonPrimary.first() as HTMLButtonElement | false\n try {\n if (btn_el) {\n btn_el.disabled = true\n }\n this.onUnfollowClick(this.follow_type)\n }\n finally {\n if (btn_el) {\n btn_el.disabled = false\n }\n }\n })\n\n EventStore.onSubscribe(({neighbourhood_id, follow_type}) => {\n if (neighbourhood_id.toString() !== this.neighbourhood_id) { return }\n if (follow_type !== this.follow_type) { return }\n\n this.displayAsFollowing()\n })\n EventStore.onUnsubscribe(({neighbourhood_id, follow_type}) => {\n if (neighbourhood_id.toString() !== this.neighbourhood_id) { return }\n if (follow_type !== this.follow_type) { return }\n\n this.displayAsNotFollowing()\n })\n\n return this\n }\n\n private onFollowClick(follow_type: string) {\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.onFollowClick(follow_type))\n .done()\n }, \"event:create_neighbourhood_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.onFollowClick(follow_type)\n })\n })\n .done()\n return\n }\n\n let subscribe_neighbourhood_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 default:\n captureMessage(\n `unexpected/unhandled result_type: <${result_type}>`,\n {\n source_file_path:\n \"app/assets/javascripts/concepts/listings/contact/button/events/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 neighbourhood_id: this.neighbourhood_id,\n follow_type: follow_type === \"commercial\" ?\n SubscribeNeighbourhoodFollowingFollowTypes.COMMERCIAL :\n SubscribeNeighbourhoodFollowingFollowTypes.RESIDENTIAL,\n }\n subscribe_neighbourhood_following_inputs = inputs\n return subscribe_neighbourhood_following(inputs)\n })\n .then(({result_type}) => {\n switch (result_type) {\n case SubscribeNeighbourhoodFollowingResultTypes.SUCCESS:\n return\n default:\n captureMessage(\n `unexpected/unhandled result_type from create_neighbourhood_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_neighbourhood_following_inputs),\n )\n throw RejectionReasons.ERROR_REPORTED\n }\n })\n .then(() => {\n Modal.hideLoadingIndicator()\n EventStore.fireSubscribeEvent({\n neighbourhood_id: this.neighbourhood_id,\n follow_type: follow_type,\n })\n\n // # Tracking\n Google_Event.track({\n category: PageInstance.currentPageNameForTracking(),\n action: \"Follow\",\n options: {\n eventLabel: \"Follow Neighbourhood - Followed\",\n },\n })\n\n GA4_Event.track({\n event_name: \"neighbourhood_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 private onUnfollowClick(follow_type: string) {\n const local_contact_info_data = getContactInfoData()\n\n if (! isPresentString(local_contact_info_data.contact_email_address)) {\n // Do nothing but just pretend to have unfollow\n EventStore.fireUnsubscribeEvent({\n neighbourhood_id: this.neighbourhood_id,\n follow_type: follow_type,\n })\n return\n }\n\n Promise.resolve()\n .then(() => {\n return unsubscribe_neighbourhood_following({\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 neighbourhood_id: this.neighbourhood_id,\n follow_type: follow_type === \"commercial\" ?\n UnsubscribeNeighbourhoodFollowingFollowTypes.COMMERCIAL :\n UnsubscribeNeighbourhoodFollowingFollowTypes.RESIDENTIAL,\n })\n })\n .then(({result_type}) => {\n switch (result_type) {\n case UnsubscribeNeighbourhoodFollowingResultTypes.SUCCESS:\n return\n default:\n captureMessage(\n `unexpected/unhandled result_type from destroy_neighbourhood_following: <${result_type}>`,\n {\n source_file_path:\n SOURCE_FILE_PATH,\n }\n )\n throw RejectionReasons.ERROR_REPORTED\n }\n })\n .then(() => {\n EventStore.fireUnsubscribeEvent({\n neighbourhood_id: this.neighbourhood_id,\n follow_type: follow_type,\n })\n })\n .catch((whatever) => {\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 private displayAsFollowing() {\n this.container_el.classList.add(\"following\")\n\n this.emit(\"neighbourhood_following\")\n }\n private displayAsNotFollowing() {\n this.container_el.classList.remove(\"following\")\n }\n}\n\nconst Factory = {\n _instance: null as null | NeighbourhoodButton,\n instance(selector: Inputs){\n if (this._instance !== null) { return this._instance }\n\n this._instance = this.create(selector)\n return this._instance\n },\n create(selector: Inputs){\n return new NeighbourhoodButton(selector)\n },\n}\n\nexport {\n Factory,\n}\n"],"file":"assets/factory-MqJAId6d.js"}