From c1b667b8a919617d3d4ba3089097d330a7767a76 Mon Sep 17 00:00:00 2001 From: k2maan Date: Tue, 7 Feb 2023 12:39:17 +0530 Subject: [PATCH] Updated: support to subscribe to INVENTORY_LEVEL_UPDATE webhook (#85zrmekh7) --- .env.example | 2 +- src/locales/en.json | 1 + src/views/Inventory.vue | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 730d3567..b6c0ede0 100644 --- a/.env.example +++ b/.env.example @@ -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" \ No newline at end of file diff --git a/src/locales/en.json b/src/locales/en.json index 59f051a1..c068fc34 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -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", diff --git a/src/views/Inventory.vue b/src/views/Inventory.vue index fe274847..7df80412 100644 --- a/src/views/Inventory.vue +++ b/src/views/Inventory.vue @@ -33,6 +33,15 @@ + + + {{ $t("Webhooks") }} + + + {{ $t("Inventory level update") }} + + + @@ -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: { @@ -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);