Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: Updated occurrences of ofbizInstanceName with omsInstanceName(#301). #313

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading