Skip to content

Commit cc46e3c

Browse files
committed
Improved: code to fetch inventory groups from firestore api in case of no associated groups found (hotwax#382)
1 parent 60fea7d commit cc46e3c

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/services/UserService.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ const getFieldMappings = async (payload: any): Promise <any> => {
309309
});
310310
}
311311

312+
const fetchFacilityPreferredInvGroups = async (payload: any): Promise <any> => {
313+
return api({
314+
url: "/service/fetchFacilityPreferredInvGroups",
315+
method: "POST",
316+
data: payload
317+
});
318+
}
319+
312320
export const UserService = {
313321
addFacilityToGroup,
314322
createFieldMapping,
@@ -330,5 +338,6 @@ export const UserService = {
330338
getUserPermissions,
331339
updateFacility,
332340
updateFacilityToGroup,
333-
updateFieldMapping
341+
updateFieldMapping,
342+
fetchFacilityPreferredInvGroups
334343
}

src/views/Settings.vue

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@
113113
</ion-card-content>
114114
<ion-item lines="none">
115115
<ion-label>{{ translate("Sell online") }}</ion-label>
116-
<ion-toggle :disabled="!hasPermission(Actions.APP_UPDT_ECOM_INV_CONFIG) || !isEComInvEnabled" v-model="isEComInvEnabled" @click="updateEComInvStatus($event)" slot="end" />
116+
<ion-toggle :disabled="!hasPermission(Actions.APP_UPDT_ECOM_INV_CONFIG) || (!isEComInvEnabled && !facilityPreferredInvGroups)" v-model="isEComInvEnabled" @click="updateEComInvStatus($event)" slot="end" />
117117
</ion-item>
118-
<ion-list v-if="isEComInvEnabled">
118+
<ion-list v-if="isEComInvEnabled || facilityPreferredInvGroups.length">
119119
<ion-item-divider color="light">
120120
<ion-label>{{ translate("Channels") }}</ion-label>
121121
</ion-item-divider>
122122
<ion-item lines="none">
123123
<ion-row>
124-
<ion-chip v-for="group in facilityInventoryGroups" :key="group.facilityId">
124+
<ion-chip v-for="group in facilityInventoryGroups.length ? facilityInventoryGroups : facilityPreferredInvGroups" :key="group.facilityId">
125125
{{ group.facilityGroupName }}
126126
</ion-chip>
127127
</ion-row>
@@ -271,7 +271,8 @@ export default defineComponent({
271271
orderLimitType: 'unlimited',
272272
fulfillmentOrderLimit: "" as number | string,
273273
facilityInventoryGroups: [] as any,
274-
isEComInvEnabled: false
274+
isEComInvEnabled: false,
275+
facilityPreferredInvGroups: [] as any
275276
};
276277
},
277278
computed: {
@@ -377,6 +378,24 @@ export default defineComponent({
377378
} catch (err) {
378379
logger.error('Failed to fetch eCom inventory config', err)
379380
}
381+
382+
try {
383+
if(!this.isEComInvEnabled) {
384+
resp = await UserService.fetchFacilityPreferredInvGroups({
385+
facilityId: this.currentFacility.facilityId,
386+
oms: this.instanceUrl,
387+
collection: 'FACILITY_PREFERENCE'
388+
})
389+
390+
if(!hasError(resp)) {
391+
this.facilityPreferredInvGroups = resp.data.docs
392+
} else {
393+
throw resp.data
394+
}
395+
}
396+
} catch(err) {
397+
logger.error(err)
398+
}
380399
},
381400
logout () {
382401
this.store.dispatch('user/logout', { isUserUnauthorised: false }).then((redirectionUrl) => {
@@ -470,7 +489,7 @@ export default defineComponent({
470489
await this.getEcomInvStatus()
471490
},
472491
async addFacilityInvGroups() {
473-
const addResponses = await Promise.allSettled(this.facilityInventoryGroups
492+
const addResponses = await Promise.allSettled(this.facilityPreferredInvGroups
474493
.map(async (payload: any) => await UserService.addFacilityToGroup({
475494
"facilityId": this.currentFacility.facilityId,
476495
"facilityGroupId": payload.facilityGroupId

0 commit comments

Comments
 (0)