Skip to content

Commit

Permalink
Merge pull request #372 from k2maan/#85zrmekh7
Browse files Browse the repository at this point in the history
Added support to subscribe to INVENTORY_LEVEL_UPDATE webhook (#85zrmekh7)
  • Loading branch information
adityasharma7 authored Feb 7, 2023
2 parents 3e37a92 + c1b667b commit b429025
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ VUE_APP_JOB_TITLES={"JOB_IMP_PROD_NEW":"Import products","JOB_IMP_PROD_UPD":"Syn
VUE_APP_INITIAL_JOB_TYPES={"JOB_IMP_PROD_NEW_BLK":"products","JOB_IMP_ORD_BLK":"orders"}
VUE_APP_BASE_URL=
VUE_APP_BATCH_JOB_ENUMS={"JOB_BKR_ORD_UNF":{"id":"JOB_BKR_ORD_UNF","facilityId":"_NA_","unfillable": true},"JOB_BKR_ORD":{"id": "JOB_BKR_ORD","facilityId":"_NA_","unfillable": false},"JOB_BKR_PREORD_UNF":{"id":"JOB_BKR_PREORD_UNF","facilityId":"PRE_ORDER_PARKING","unfillable":true},"JOB_BKR_PREORD":{"id":"JOB_BKR_PREORD","facilityId":"PRE_ORDER_PARKING","unfillable":false},"JOB_BKR_BACKORD_UNF":{"id":"JOB_BKR_BACKORD_UNF","facilityId":"BACKORDER_PARKING","unfillable":true},"JOB_BKR_BACKORD":{"id":"JOB_BKR_BACKORD","facilityId":"BACKORDER_PARKING","unfillable":false}}
VUE_APP_WEBHOOK_ENUMS={"NEW_PRODUCTS":"products/create","DELETE_PRODUCTS":"products/update","NEW_ORDERS":"orders/create","CANCELLED_ORDERS":"orders/cancelled","PAYMENT_STATUS":"orders/paid","RETURNS":"","BULK_OPERATIONS_FINISH":"bulk_operations/finish"}
VUE_APP_WEBHOOK_ENUMS={"NEW_PRODUCTS":"products/create","DELETE_PRODUCTS":"products/update","NEW_ORDERS":"orders/create","CANCELLED_ORDERS":"orders/cancelled","PAYMENT_STATUS":"orders/paid","RETURNS":"refunds/create","BULK_OPERATIONS_FINISH":"bulk_operations/finish", "INVENTORY_LEVEL_UPDATE":"inventory_levels/update"}
VUE_APP_PERMISSION_ID=
VUE_APP_ALIAS=
VUE_APP_DEFAULT_LOG_LEVEL="error"
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"Instance Url": "Instance Url",
"Inventory": "Inventory",
"Inventory cost": "Inventory cost",
"Inventory level update": "Inventory level update",
"Job details": "Job details",
"Job Manager": "Job Manager",
"Landed inventory cost": "Landed inventory cost",
Expand Down
34 changes: 32 additions & 2 deletions src/views/Inventory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
</ion-label>
</ion-item>
</ion-card>
<ion-card>
<ion-card-header>
<ion-card-title>{{ $t("Webhooks") }}</ion-card-title>
</ion-card-header>
<ion-item lines="none">
<ion-label class="ion-text-wrap">{{ $t("Inventory level update") }}</ion-label>
<ion-toggle :disabled="!hasPermission(Actions.APP_JOB_UPDATE)" :checked="isInventoryLevelUpdated" @ionChange="updateWebhook($event['detail'].checked, 'INVENTORY_LEVEL_UPDATE')" slot="end" color="secondary" />
</ion-item>
</ion-card>
<MoreJobs v-if="getMoreJobs(jobEnums, enumTypeId).length" :jobs="getMoreJobs(jobEnums, enumTypeId)" />
</section>

Expand Down Expand Up @@ -98,7 +107,8 @@ export default defineComponent({
freqType: '',
isJobDetailAnimationCompleted: false,
isDesktop: isPlatform('desktop'),
enumTypeId: 'INVENTORY_SYS_JOB'
enumTypeId: 'INVENTORY_SYS_JOB',
webhookEnums: JSON.parse(process.env?.VUE_APP_WEBHOOK_ENUMS as string) as any,
}
},
computed: {
Expand All @@ -108,14 +118,34 @@ export default defineComponent({
currentShopifyConfig: 'user/getCurrentShopifyConfig',
currentEComStore: 'user/getCurrentEComStore',
getTemporalExpr: 'job/getTemporalExpr',
getMoreJobs: 'job/getMoreJobs'
getMoreJobs: 'job/getMoreJobs',
getCachedWebhook: 'webhook/getCachedWebhook',
}),
bopisCorrections(): boolean {
const status = this.getJobStatus(this.jobEnums["BOPIS_CORRECTION"]);
return status && status !== "SERVICE_DRAFT";
},
isInventoryLevelUpdated (): boolean {
const webhookTopic = this.webhookEnums['INVENTORY_LEVEL_UPDATE']
return this.getCachedWebhook[webhookTopic]
}
},
methods: {
async updateWebhook(checked: boolean, enumId: string) {
const webhook = this.getCachedWebhook[this.webhookEnums[enumId]]
// TODO: added this condition to not call the api when the value of the select automatically changes
// need to handle this properly
if ((checked && webhook) || (!checked && !webhook)) {
return;
}
if (checked) {
await this.store.dispatch('webhook/subscribeWebhook', enumId)
} else {
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.currentShopifyConfig.shopifyConfigId })
}
},
async updateJob(checked: boolean, id: string, status="EVERY_15_MIN") {
const job = this.getJob(id);
Expand Down

0 comments on commit b429025

Please sign in to comment.