|
113 | 113 | </ion-card-content>
|
114 | 114 | <ion-item lines="none">
|
115 | 115 | <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" /> |
117 | 117 | </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> |
118 | 130 | </ion-card>
|
119 | 131 | </section>
|
120 | 132 |
|
@@ -252,7 +264,7 @@ export default defineComponent({
|
252 | 264 | currentFacilityDetails: {} as any,
|
253 | 265 | orderLimitType: 'unlimited',
|
254 | 266 | fulfillmentOrderLimit: "" as number | string,
|
255 |
| - facilityGroupDetails: {} as any, |
| 267 | + facilityInventoryGroups: [] as any, |
256 | 268 | isEComInvEnabled: false
|
257 | 269 | };
|
258 | 270 | },
|
@@ -336,39 +348,23 @@ export default defineComponent({
|
336 | 348 | let resp: any;
|
337 | 349 | try {
|
338 | 350 | this.isEComInvEnabled = false
|
339 |
| - this.facilityGroupDetails = {} |
| 351 | + this.facilityInventoryGroups = [] |
340 | 352 |
|
341 |
| - resp = await UserService.getFacilityGroupDetails({ |
342 |
| - "entityName": "FacilityGroup", |
| 353 | + resp = await UserService.getFacilityGroupAndMemberDetails({ |
| 354 | + "entityName": "FacilityGroupAndMember", |
343 | 355 | "inputFields": {
|
344 |
| - "facilityGroupTypeId": 'SHOPIFY_GROUP_FAC' |
| 356 | + "facilityId": this.currentFacility.facilityId, |
| 357 | + "facilityGroupTypeId": 'CHANNEL_FAC_GROUP' |
345 | 358 | },
|
346 |
| - "fieldList": ["facilityGroupId", "facilityGroupTypeId"], |
347 |
| - "viewSize": 1, |
| 359 | + "filterByDate": 'Y', |
| 360 | + "fieldList": ["facilityGroupId", "facilityGroupName", "fromDate"] |
348 | 361 | })
|
349 | 362 |
|
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 |
372 | 368 | } else {
|
373 | 369 | throw resp.data
|
374 | 370 | }
|
@@ -449,44 +445,37 @@ export default defineComponent({
|
449 | 445 | logger.error('Failed to update facility', err)
|
450 | 446 | }
|
451 | 447 | },
|
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({ |
456 | 451 | "facilityId": this.currentFacility.facilityId,
|
457 |
| - "facilityGroupId": this.facilityGroupDetails.facilityGroupId, |
458 |
| - "fromDate": this.facilityGroupDetails.fromDate, |
| 452 | + "facilityGroupId": payload.facilityGroupId, |
| 453 | + "fromDate": payload.fromDate, |
459 | 454 | "thruDate": DateTime.now().toMillis()
|
460 |
| - }) |
| 455 | + })) |
| 456 | + ) |
461 | 457 |
|
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')) |
471 | 463 | }
|
| 464 | + await this.getEcomInvStatus() |
472 | 465 | },
|
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({ |
477 | 469 | "facilityId": this.currentFacility.facilityId,
|
478 |
| - "facilityGroupId": this.facilityGroupDetails.facilityGroupId |
479 |
| - }) |
| 470 | + "facilityGroupId": payload.facilityGroupId |
| 471 | + })) |
| 472 | + ) |
480 | 473 |
|
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')) |
490 | 479 | }
|
491 | 480 | },
|
492 | 481 | async updateEComInvStatus(event: any) {
|
@@ -514,7 +503,7 @@ export default defineComponent({
|
514 | 503 | const { role } = await alert.onDidDismiss();
|
515 | 504 |
|
516 | 505 | if(role) {
|
517 |
| - isChecked ? await this.addFacilityToGroup() : await this.updateFacilityToGroup() |
| 506 | + isChecked ? await this.addFacilityInvGroups() : await this.removeFacilityInvGroups() |
518 | 507 | }
|
519 | 508 |
|
520 | 509 | },
|
|
0 commit comments