Skip to content

Commit

Permalink
Improved: code to fetch inventory groups from firestore api in case o…
Browse files Browse the repository at this point in the history
…f no associated groups found (hotwax#382)
  • Loading branch information
amansinghbais committed Jan 15, 2024
1 parent 60fea7d commit cc46e3c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ const getFieldMappings = async (payload: any): Promise <any> => {
});
}

const fetchFacilityPreferredInvGroups = async (payload: any): Promise <any> => {
return api({
url: "/service/fetchFacilityPreferredInvGroups",
method: "POST",
data: payload
});
}

export const UserService = {
addFacilityToGroup,
createFieldMapping,
Expand All @@ -330,5 +338,6 @@ export const UserService = {
getUserPermissions,
updateFacility,
updateFacilityToGroup,
updateFieldMapping
updateFieldMapping,
fetchFacilityPreferredInvGroups
}
29 changes: 24 additions & 5 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@
</ion-card-content>
<ion-item lines="none">
<ion-label>{{ translate("Sell online") }}</ion-label>
<ion-toggle :disabled="!hasPermission(Actions.APP_UPDT_ECOM_INV_CONFIG) || !isEComInvEnabled" v-model="isEComInvEnabled" @click="updateEComInvStatus($event)" slot="end" />
<ion-toggle :disabled="!hasPermission(Actions.APP_UPDT_ECOM_INV_CONFIG) || (!isEComInvEnabled && !facilityPreferredInvGroups)" v-model="isEComInvEnabled" @click="updateEComInvStatus($event)" slot="end" />
</ion-item>
<ion-list v-if="isEComInvEnabled">
<ion-list v-if="isEComInvEnabled || facilityPreferredInvGroups.length">
<ion-item-divider color="light">
<ion-label>{{ translate("Channels") }}</ion-label>
</ion-item-divider>
<ion-item lines="none">
<ion-row>
<ion-chip v-for="group in facilityInventoryGroups" :key="group.facilityId">
<ion-chip v-for="group in facilityInventoryGroups.length ? facilityInventoryGroups : facilityPreferredInvGroups" :key="group.facilityId">
{{ group.facilityGroupName }}
</ion-chip>
</ion-row>
Expand Down Expand Up @@ -271,7 +271,8 @@ export default defineComponent({
orderLimitType: 'unlimited',
fulfillmentOrderLimit: "" as number | string,
facilityInventoryGroups: [] as any,
isEComInvEnabled: false
isEComInvEnabled: false,
facilityPreferredInvGroups: [] as any
};
},
computed: {
Expand Down Expand Up @@ -377,6 +378,24 @@ export default defineComponent({
} catch (err) {
logger.error('Failed to fetch eCom inventory config', err)
}
try {
if(!this.isEComInvEnabled) {
resp = await UserService.fetchFacilityPreferredInvGroups({
facilityId: this.currentFacility.facilityId,
oms: this.instanceUrl,
collection: 'FACILITY_PREFERENCE'
})
if(!hasError(resp)) {
this.facilityPreferredInvGroups = resp.data.docs
} else {
throw resp.data
}
}
} catch(err) {
logger.error(err)
}
},
logout () {
this.store.dispatch('user/logout', { isUserUnauthorised: false }).then((redirectionUrl) => {
Expand Down Expand Up @@ -470,7 +489,7 @@ export default defineComponent({
await this.getEcomInvStatus()
},
async addFacilityInvGroups() {
const addResponses = await Promise.allSettled(this.facilityInventoryGroups
const addResponses = await Promise.allSettled(this.facilityPreferredInvGroups
.map(async (payload: any) => await UserService.addFacilityToGroup({
"facilityId": this.currentFacility.facilityId,
"facilityGroupId": payload.facilityGroupId
Expand Down

0 comments on commit cc46e3c

Please sign in to comment.