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CA,EAAwC,YAC3C,CACF,EACA,KAAK,CAAC,CAAC,YAAAb,KAAiB,CACvB,OAAQA,EAAa,CACnB,KAAKc,EAAwC,QAC3C,OACF,QACE,MAAAnC,EACE,0EAA0E,OAAAqB,EAAW,KACrF,CACE,iBACA3B,CAAA,CAEJ,EACMD,EAAiB,eAC3B,CACD,EACA,KAAK,IAAM,CACVa,EAAW,qBAAqB,CAC9B,YAAa,KAAK,YAClB,YAAAvB,CAAA,CACD,EACF,EACA,MAAOgD,GAAa,CACf,GAAAA,IAAatC,EAAiB,eAElC,IAAIsC,aAAoB,MAAO,CAC7BC,EACED,EACA,CACE,iBACArC,CAAA,CAEJ,EACA,OAGFM,EACE+B,EAAS,SAAS,EAClB,CACE,iBACArC,CAAA,CAEJ,EACD,GACA,KAAK,EAGA,oBAAqB,CACtB,kBAAa,UAAU,IAAI,WAAW,EAE3C,KAAK,KAAK,oBAAoB,EAExB,uBAAwB,CACzB,kBAAa,UAAU,OAAO,WAAW,EAElD,CAEA,MAAM0C,GAAU,CACd,UAAW,KACX,SAASC,EAAiB,CACpB,YAAK,YAAc,KAAe,KAAK,WAEtC,eAAY,KAAK,OAAOA,CAAQ,EAC9B,KAAK,UACd,EACA,OAAOA,EAAiB,CACf,WAAIzC,EAAeyC,CAAQ,EAEtC","names":["FollowTypes","ResultTypeEnums","unsubscribe","user_authentication_handle","building_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","BuildingButton","EventEmitter","inputs","u","captureMessage","building_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_building_following_inputs","isSignedIn","create_user","result_type","CreateUserResultTypes","trackSignUp","refreshAndUpdateComponentPromise","SubscribeBuildingFollowingFollowTypes","subscribe_building_following","SubscribeBuildingFollowingResultTypes","Google_Event","PageInstance","GA4_Event","whatever","captureException","unsubscribe_building_following","UnsubscribeBuildingFollowingFollowTypes","UnsubscribeBuildingFollowingResultTypes","Factory","selector"],"ignoreList":[],"sources":["../../../app/assets/javascripts/app/resources/building_followings/unsubscribe/index.ts","../../../app/assets/javascripts/concepts/buildings/building_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  building_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, building_id, follow_type}: Input): Promise<any> => {\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_building_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          building_id:                building_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\"\n\nimport {\n  getContactInfoData,\n  setContactInfoData,\n} from \"app/local_storages/contact_info_storage\"\n\nimport {\n  create as create_user,\n  ResultTypeEnums as CreateUserResultTypes,\n} from \"app/resources/users/create/index\"\n\nimport {\n  DataEntry as BuildingFollowingDataEntry,\n} from \"app/resources/current_authenticated_user/building_followings/get_many/index\"\n\nimport EventStore from \"app/resources/building_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_building_following,\n  ResultTypeEnums as SubscribeBuildingFollowingResultTypes,\n  FollowTypes as SubscribeBuildingFollowingFollowTypes,\n} from \"app/resources/building_followings/subscribe/index\"\n\nimport {\n  unsubscribe as unsubscribe_building_following,\n  ResultTypeEnums as UnsubscribeBuildingFollowingResultTypes,\n  FollowTypes as UnsubscribeBuildingFollowingFollowTypes,\n} from \"app/resources/building_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/buildings/building_follow_button/factory\"\n\n\ninterface Inputs {\n  container: HTMLElement,\n\n  building_followings?: BuildingFollowingDataEntry[],\n\n  followBuildingButtonPrimary?: string,\n  unfollowBuildingButtonPrimary?: string,\n}\n\ninterface Selector {\n  container: HTMLElement,\n\n  building_followings: BuildingFollowingDataEntry[],\n\n  followButtonPrimary: string,\n  unfollowButtonPrimary: string,\n}\n\nconst DEFAULT_SELECTOR = {\n  building_followings: [],\n\n  followButtonPrimary:    \".follow-button-content.on-not-following .cell--buildings--following--button__link\",\n  unfollowButtonPrimary:  \".follow-button-content.on-following .cell--buildings--following--button__link\",\n}\n\nexport class BuildingButton extends EventEmitter {\n  private selector: Selector\n\n  private container_el: HTMLElement\n  private $container: UmbrellaInstance\n  private readonly building_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(inputs: Inputs) {\n    super()\n\n    this.selector = Object.assign({}, DEFAULT_SELECTOR, inputs)\n\n    this.container_el = this.selector.container\n    this.$container = u(this.selector.container)\n    this.building_id = this.$container.data(\"building-id\").toString()\n    this.follow_type = this.$container.data(\"follow-type\")\n\n    if (this.$container.length === 1) {\n      this.$followButtonPrimary = this.$container.find(this.selector.followButtonPrimary)\n      this.$unfollowButtonPrimary = this.$container.find(this.selector.unfollowButtonPrimary)\n\n      this.bind_action()\n      this.created()\n    }\n    else {\n      captureMessage(\n        `$container contains non 1 (${this.$container.length}) elements`,\n        {\n          source_file_path: SOURCE_FILE_PATH,\n        }\n      )\n    }\n  }\n\n  private created() {\n    if ( this.selector.building_followings.length <= 0) {\n      return\n    }\n\n    const matched_followings_found = this.selector.building_followings.some((building_following) => {\n      return building_following.building_id === this.building_id && (\n        (this.follow_type === \"commercial\" && building_following.is_following_commercial_updates) ||\n        (this.follow_type !== \"commercial\" && building_following.is_following_residential_updates)\n      )\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    this.$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(({building_id, follow_type}) => {\n      if (building_id.toString() !== this.building_id) { return }\n      if (follow_type !== this.follow_type) { return }\n\n      this.displayAsFollowing()\n    })\n    EventStore.onUnsubscribe(({building_id, follow_type}) => {\n      if (building_id.toString() !== this.building_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_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.onFollowClick(follow_type)\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          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        building_id: this.building_id,\n        follow_type: 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          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      EventStore.fireSubscribeEvent({\n        building_id: this.building_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 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  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        building_id: this.building_id,\n        follow_type: follow_type,\n      })\n      return\n    }\n\n    Promise.resolve()\n    .then(() => {\n      return unsubscribe_building_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        building_id: this.building_id,\n        follow_type: follow_type === \"commercial\" ?\n          UnsubscribeBuildingFollowingFollowTypes.COMMERCIAL :\n          UnsubscribeBuildingFollowingFollowTypes.RESIDENTIAL,\n      })\n    })\n    .then(({result_type}) => {\n      switch (result_type) {\n        case UnsubscribeBuildingFollowingResultTypes.SUCCESS:\n          return\n        default:\n          captureMessage(\n            `unexpected/unhandled result_type from unsubscribe_building_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        building_id: this.building_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(\"building_following\")\n  }\n  private displayAsNotFollowing() {\n    this.container_el.classList.remove(\"following\")\n  }\n}\n\nconst Factory = {\n  _instance: null as null | BuildingButton,\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 BuildingButton(selector)\n  },\n}\n\nexport {\n  Factory,\n}\n"],"file":"assets/factory-D9xPjw1D.js"}