Skip to content

Commit

Permalink
Improved: code to move the action to component(#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed Nov 21, 2023
1 parent 07f317b commit 3d52e49
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
31 changes: 28 additions & 3 deletions src/components/LocationDetailsPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -34,6 +38,11 @@ export default defineComponent({
IonList,
IonListHeader
},
computed: {
...mapGetters({
current: 'facility/getCurrent'
})
},
props: ["location"],
methods: {
async addLocationModal() {
Expand All @@ -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() {
Expand Down
20 changes: 0 additions & 20 deletions src/store/modules/facility/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,6 @@ const actions: ActionTree<FacilityState, RootState> = {
} 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)
}
}
}

Expand Down

0 comments on commit 3d52e49

Please sign in to comment.