From 3d52e499e00ee53755c3d7fe410e6cd2e7f9504c Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Tue, 21 Nov 2023 10:49:26 +0530 Subject: [PATCH] Improved: code to move the action to component(#18) --- src/components/LocationDetailsPopover.vue | 31 ++++++++++++++++++++--- src/store/modules/facility/actions.ts | 20 --------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/components/LocationDetailsPopover.vue b/src/components/LocationDetailsPopover.vue index fc906fd8..2a05110c 100644 --- a/src/components/LocationDetailsPopover.vue +++ b/src/components/LocationDetailsPopover.vue @@ -24,7 +24,11 @@ popoverController import { defineComponent } from "vue"; import { translate } from "@hotwax/dxp-components"; import AddLocationModal from "./AddLocationModal.vue"; -import { useStore } from "vuex"; +import { mapGetters, useStore } from "vuex"; +import { FacilityService } from "@/services/FacilityService"; +import { hasError } from "@/adapter"; +import { showToast } from "@/utils"; +import logger from "@/logger"; export default defineComponent({ name: "LocationDetailsPopover", @@ -34,6 +38,11 @@ export default defineComponent({ IonList, IonListHeader }, + computed: { + ...mapGetters({ + current: 'facility/getCurrent' + }) + }, props: ["location"], methods: { async addLocationModal() { @@ -51,8 +60,24 @@ export default defineComponent({ }) }, async removeLocation() { - await this.store.dispatch('facility/deleteFacilityLocation', this.location) - popoverController.dismiss(); + const params = { + facilityId: this.location.facilityId, + locationSeqId: this.location.locationSeqId + } + + try { + const resp = await FacilityService.deleteFacilityLocation(params) + + if(!hasError(resp)) { + this.store.dispatch('facility/fetchFacilityLocation') + popoverController.dismiss(); + } else { + throw resp.data + } + } catch(err) { + showToast(translate('Failed to remove facility location')) + logger.error('Failed to remove facility location', err) + } } }, setup() { diff --git a/src/store/modules/facility/actions.ts b/src/store/modules/facility/actions.ts index b394d87d..7f0ee344 100644 --- a/src/store/modules/facility/actions.ts +++ b/src/store/modules/facility/actions.ts @@ -186,26 +186,6 @@ const actions: ActionTree = { } catch(err) { logger.error('Failed to find the facility locations', err) } - }, - - async deleteFacilityLocation({ dispatch }, payload) { - const params = { - facilityId: payload.facilityId, - locationSeqId: payload.locationSeqId - } - - try { - const resp = await FacilityService.deleteFacilityLocation(params) - - if(!hasError(resp)) { - dispatch('fetchFacilityLocation') - } else { - throw resp.data - } - } catch(err) { - showToast(translate('Failed to remove facility location')) - logger.error('Failed to remove facility location', err) - } } }