Skip to content

Commit

Permalink
Improved: Updated occurrences of ofbizInstanceName with omsInstanceName(
Browse files Browse the repository at this point in the history
  • Loading branch information
ravilodhi committed Oct 12, 2023
1 parent 67d9581 commit d447172
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/components/NotificationPreferenceModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export default defineComponent({
},
computed: {
...mapGetters({
userProfile: 'user/getUserProfile',
currentFacility: 'user/getCurrentFacility',
instanceUrl: 'user/getInstanceUrl',
notificationPrefs: 'user/getNotificationPrefs'
Expand Down Expand Up @@ -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))
})
Expand Down
3 changes: 1 addition & 2 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ const actions: ActionTree<UserState, RootState> = {

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 {
Expand All @@ -292,7 +291,7 @@ const actions: ActionTree<UserState, RootState> = {
// 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
}, [])
Expand Down
5 changes: 4 additions & 1 deletion src/utils/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d447172

Please sign in to comment.