Skip to content

Commit 9748ae0

Browse files
committed
Implemented: support for multi channel inventory in sell inventory card (hotwax#382)
1 parent ed17aa5 commit 9748ae0

File tree

2 files changed

+52
-62
lines changed

2 files changed

+52
-62
lines changed

src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"Click the backdrop to dismiss.": "Click the backdrop to dismiss.",
3535
"Change": "Change",
3636
"Changes to the CSV mapping has been saved.": "Changes to the CSV mapping has been saved.",
37+
"Channels": "Channels",
3738
"Check stock": "Check stock",
3839
"Choose language": "Choose language",
3940
"City": "City",

src/views/Settings.vue

Lines changed: 51 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,20 @@
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) || !facilityGroupDetails?.facilityGroupId" v-model="isEComInvEnabled" @click="updateEComInvStatus($event)" slot="end" />
116+
<ion-toggle :disabled="!hasPermission(Actions.APP_UPDT_ECOM_INV_CONFIG) || !isEComInvEnabled" v-model="isEComInvEnabled" @click="updateEComInvStatus($event)" slot="end" />
117117
</ion-item>
118+
<ion-list v-if="isEComInvEnabled">
119+
<ion-item-divider color="light">
120+
<ion-label>{{ translate("Channels") }}</ion-label>
121+
</ion-item-divider>
122+
<ion-item lines="none">
123+
<ion-row>
124+
<ion-chip v-for="group in facilityInventoryGroups" :key="group.facilityId">
125+
{{ group.facilityGroupName }}
126+
</ion-chip>
127+
</ion-row>
128+
</ion-item>
129+
</ion-list>
118130
</ion-card>
119131
</section>
120132

@@ -252,7 +264,7 @@ export default defineComponent({
252264
currentFacilityDetails: {} as any,
253265
orderLimitType: 'unlimited',
254266
fulfillmentOrderLimit: "" as number | string,
255-
facilityGroupDetails: {} as any,
267+
facilityInventoryGroups: [] as any,
256268
isEComInvEnabled: false
257269
};
258270
},
@@ -336,39 +348,23 @@ export default defineComponent({
336348
let resp: any;
337349
try {
338350
this.isEComInvEnabled = false
339-
this.facilityGroupDetails = {}
351+
this.facilityInventoryGroups = []
340352
341-
resp = await UserService.getFacilityGroupDetails({
342-
"entityName": "FacilityGroup",
353+
resp = await UserService.getFacilityGroupAndMemberDetails({
354+
"entityName": "FacilityGroupAndMember",
343355
"inputFields": {
344-
"facilityGroupTypeId": 'SHOPIFY_GROUP_FAC'
356+
"facilityId": this.currentFacility.facilityId,
357+
"facilityGroupTypeId": 'CHANNEL_FAC_GROUP'
345358
},
346-
"fieldList": ["facilityGroupId", "facilityGroupTypeId"],
347-
"viewSize": 1,
359+
"filterByDate": 'Y',
360+
"fieldList": ["facilityGroupId", "facilityGroupName", "fromDate"]
348361
})
349362
350-
if (!hasError(resp)) {
351-
// using facilityGroupId as a flag for getting data from getFacilityGroupDetails
352-
this.facilityGroupDetails.facilityGroupId = resp.data.docs[0].facilityGroupId
353-
resp = await UserService.getFacilityGroupAndMemberDetails({
354-
"entityName": "FacilityGroupAndMember",
355-
"inputFields": {
356-
"facilityId": this.currentFacility.facilityId,
357-
"facilityGroupId": this.facilityGroupDetails.facilityGroupId
358-
},
359-
"fieldList": ["facilityId", "fromDate"],
360-
"viewSize": 1,
361-
"filterByDate": 'Y'
362-
})
363-
364-
if (!hasError(resp)) {
365-
this.facilityGroupDetails = { ...this.facilityGroupDetails, ...resp.data.docs[0] }
366-
367-
// When getting data from group member enabling the eCom inventory
368-
this.isEComInvEnabled = true
369-
} else {
370-
throw resp.data
371-
}
363+
if (!hasError(resp) && resp.data.docs.length) {
364+
this.facilityInventoryGroups = resp.data.docs
365+
366+
// When getting data from group member enabling the eCom inventory
367+
this.isEComInvEnabled = true
372368
} else {
373369
throw resp.data
374370
}
@@ -449,44 +445,37 @@ export default defineComponent({
449445
logger.error('Failed to update facility', err)
450446
}
451447
},
452-
async updateFacilityToGroup() {
453-
let resp;
454-
try {
455-
resp = await UserService.updateFacilityToGroup({
448+
async removeFacilityInvGroups() {
449+
const updateResponses = await Promise.allSettled(this.facilityInventoryGroups
450+
.map(async (payload: any) => await UserService.updateFacilityToGroup({
456451
"facilityId": this.currentFacility.facilityId,
457-
"facilityGroupId": this.facilityGroupDetails.facilityGroupId,
458-
"fromDate": this.facilityGroupDetails.fromDate,
452+
"facilityGroupId": payload.facilityGroupId,
453+
"fromDate": payload.fromDate,
459454
"thruDate": DateTime.now().toMillis()
460-
})
455+
}))
456+
)
461457
462-
if (!hasError(resp)) {
463-
this.isEComInvEnabled = false
464-
showToast(translate('ECom inventory status updated successfully'))
465-
} else {
466-
throw resp.data
467-
}
468-
} catch (err) {
469-
showToast(translate('Failed to update eCom inventory status'))
470-
logger.error('Failed to update eCom inventory status', err)
458+
const hasFailedResponse = updateResponses.some((response: any) => response.status === 'rejected')
459+
if (hasFailedResponse) {
460+
showToast(translate('Failed to update some eCom inventory status'))
461+
} else {
462+
showToast(translate('ECom inventory status updated successfully'))
471463
}
464+
await this.getEcomInvStatus()
472465
},
473-
async addFacilityToGroup() {
474-
let resp;
475-
try {
476-
resp = await UserService.addFacilityToGroup({
466+
async addFacilityInvGroups() {
467+
const addResponses = await Promise.allSettled(this.facilityInventoryGroups
468+
.map(async (payload: any) => await UserService.addFacilityToGroup({
477469
"facilityId": this.currentFacility.facilityId,
478-
"facilityGroupId": this.facilityGroupDetails.facilityGroupId
479-
})
470+
"facilityGroupId": payload.facilityGroupId
471+
}))
472+
)
480473
481-
if (!hasError(resp)) {
482-
this.isEComInvEnabled = true
483-
showToast(translate('ECom inventory status updated successfully'))
484-
} else {
485-
throw resp.data
486-
}
487-
} catch (err) {
488-
showToast(translate('Failed to update eCom inventory status'))
489-
logger.error('Failed to update eCom inventory status', err)
474+
const hasFailedResponse = addResponses.some((response: any) => response.status === 'rejected')
475+
if (hasFailedResponse) {
476+
showToast(translate('Failed to update some eCom inventory status'))
477+
} else {
478+
showToast(translate('ECom inventory status updated successfully'))
490479
}
491480
},
492481
async updateEComInvStatus(event: any) {
@@ -514,7 +503,7 @@ export default defineComponent({
514503
const { role } = await alert.onDidDismiss();
515504
516505
if(role) {
517-
isChecked ? await this.addFacilityToGroup() : await this.updateFacilityToGroup()
506+
isChecked ? await this.addFacilityInvGroups() : await this.removeFacilityInvGroups()
518507
}
519508
520509
},

0 commit comments

Comments
 (0)