diff --git a/src/components/NotificationPreferenceModal.vue b/src/components/NotificationPreferenceModal.vue index 6e9a26940..388d07ff7 100644 --- a/src/components/NotificationPreferenceModal.vue +++ b/src/components/NotificationPreferenceModal.vue @@ -84,7 +84,6 @@ export default defineComponent({ }, computed: { ...mapGetters({ - userProfile: 'user/getUserProfile', currentFacility: 'user/getCurrentFacility', instanceUrl: 'user/getInstanceUrl', notificationPrefs: 'user/getNotificationPrefs' @@ -141,17 +140,16 @@ export default defineComponent({ } }, async handleTopicSubscription() { - const ofbizInstanceName = this.userProfile.ofbizInstanceName const facilityId = (this.currentFacility as any).facilityId const subscribeRequests = [] as any this.notificationPrefToUpdate.subscribe.map(async (enumId: string) => { - const topicName = generateTopicName(ofbizInstanceName, facilityId, enumId) + const topicName = generateTopicName(facilityId, enumId) await subscribeRequests.push(subscribeTopic(topicName, process.env.VUE_APP_NOTIF_APP_ID)) }) const unsubscribeRequests = [] as any this.notificationPrefToUpdate.unsubscribe.map(async (enumId: string) => { - const topicName = generateTopicName(ofbizInstanceName, facilityId, enumId) + const topicName = generateTopicName(facilityId, enumId) await unsubscribeRequests.push(unsubscribeTopic(topicName, process.env.VUE_APP_NOTIF_APP_ID)) }) diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index af4af5975..f2286591b 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -277,7 +277,6 @@ const actions: ActionTree = { async fetchNotificationPreferences({ commit, state }) { let resp = {} as any - const ofbizInstanceName = state.current.ofbizInstanceName const facilityId = (state.currentFacility as any).facilityId let notificationPreferences = [], enumerationResp = [], userPrefIds = [] as any try { @@ -292,7 +291,7 @@ const actions: ActionTree = { // data and getNotificationUserPrefTypeIds fails or returns empty response (all disbaled) if (enumerationResp.length) { notificationPreferences = enumerationResp.reduce((notifactionPref: any, pref: any) => { - const userPrefTypeIdToSearch = generateTopicName(ofbizInstanceName, facilityId, pref.enumId) + const userPrefTypeIdToSearch = generateTopicName(facilityId, pref.enumId) notifactionPref.push({ ...pref, isEnabled: userPrefIds.includes(userPrefTypeIdToSearch) }) return notifactionPref }, []) diff --git a/src/utils/firebase.ts b/src/utils/firebase.ts index 6d027a0f3..fca501f8a 100644 --- a/src/utils/firebase.ts +++ b/src/utils/firebase.ts @@ -9,7 +9,10 @@ const addNotification = async (notification: any) => store.dispatch('user/addNot const generateDeviceId = () => (DateTime.now().toFormat('ddMMyy') + String(DateTime.now().toMillis()).slice(-6)) // topic name: oms-facilityId-enumId(enumCode) -const generateTopicName = (ofbizInstanceName: string, facilityId: string, enumId: string) => `${ofbizInstanceName}-${facilityId}-${enumId}` +const generateTopicName = (facilityId: string, enumId: string) => { + const userProfile = store.getters['user/getUserProfile']; + return `${userProfile.omsInstanceName}-${facilityId}-${enumId}`; +}; export { addNotification, diff --git a/src/views/Settings.vue b/src/views/Settings.vue index 7e0ae62fd..430cc1b0f 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -470,9 +470,8 @@ export default defineComponent({ }, async updateNotificationPref(enumId: string, event: any) { try { - const ofbizInstanceName = this.userProfile.ofbizInstanceName const facilityId = (this.currentFacility as any).facilityId - const topicName = generateTopicName(ofbizInstanceName, facilityId, enumId) + const topicName = generateTopicName(facilityId, enumId) // event.target.checked returns the initial value (the value that was there before clicking // and updating the toggle). But it returns the updated value on further references (if passed // as a parameter in other function, here in our case, passed from confirmNotificationPrefUpdate)