From 7b8ee92ae5cb69fe57cc7949f5bc2695883ca17a Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 17 Nov 2023 09:35:41 +0530 Subject: [PATCH 01/20] Implemented: service and actions for fetching all product Stores and the associated one's (#10) --- src/components/SelectProductStoreModal.vue | 18 +++++++++--- src/services/FacilityService.ts | 10 +++++++ src/store/modules/facility/actions.ts | 31 ++++++++++++++++++++ src/store/modules/facility/getters.ts | 3 ++ src/store/modules/facility/mutation-types.ts | 3 +- src/store/modules/facility/mutations.ts | 3 ++ src/views/FacilityDetails.vue | 10 +++++-- 7 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/components/SelectProductStoreModal.vue b/src/components/SelectProductStoreModal.vue index 1b4edb16..6c35d6aa 100644 --- a/src/components/SelectProductStoreModal.vue +++ b/src/components/SelectProductStoreModal.vue @@ -12,12 +12,12 @@ - + - {{ "Demo Store" }} -

{{ "STORE_ID" }}

+ {{ productStore.storeName }} +

{{ productStore.productStoreId }}

- +
@@ -49,6 +49,7 @@ import { import { defineComponent } from "vue"; import { closeOutline, saveOutline } from "ionicons/icons"; import { translate } from '@hotwax/dxp-components' +import { mapGetters } from "vuex"; export default defineComponent({ name: "SelectProductStoreModal", @@ -67,9 +68,18 @@ export default defineComponent({ IonTitle, IonToolbar }, + computed: { + ...mapGetters({ + productStores: 'util/getProductStores' + }) + }, + props: ["selectedProductStores"], methods: { closeModal() { modalController.dismiss({ dismissed: true}); + }, + isSelected (productStoreId: any) { + return this.selectedProductStores.some((productStore :any) => productStore.productStoreId === productStoreId); } }, setup() { diff --git a/src/services/FacilityService.ts b/src/services/FacilityService.ts index 23ed7a45..42f620f0 100644 --- a/src/services/FacilityService.ts +++ b/src/services/FacilityService.ts @@ -1,6 +1,7 @@ import { api, hasError } from '@/adapter'; import logger from '@/logger'; import { DateTime } from 'luxon'; +import store from '@/store'; const fetchFacilities = async(query: any): Promise => { return api({ @@ -92,9 +93,18 @@ const updateFacility = async (payload: any): Promise => { }) } +const getFacilityProductStores = async (payload: any): Promise => { + return api({ + url: "performFind", + method: "POST", + data: payload + }) as any +} + export const FacilityService = { fetchFacilityOnlineGroupInformation, fetchFacilitiesOrderCount, fetchFacilities, + getFacilityProductStores, updateFacility } \ No newline at end of file diff --git a/src/store/modules/facility/actions.ts b/src/store/modules/facility/actions.ts index 874eb000..47c85ac1 100644 --- a/src/store/modules/facility/actions.ts +++ b/src/store/modules/facility/actions.ts @@ -141,6 +141,37 @@ const actions: ActionTree = { facilityTypeId: '' }) commit(types.FACILITY_LIST_UPDATED , { facilities: [], total: 0 }); + }, + + async getFacilityProductStores({ commit, state }, params) { + let productStores = [] + const payload = { + inputFields: { + facilityId: params.facilityId + }, + viewSize: 100, + entityName: 'ProductStoreFacility', + filterByDate: 'Y', + fieldList: ['productStoreId'] + } + + try { + const resp = await FacilityService.getFacilityProductStores(payload) + + // fetching stores and roles first as storeName and role description + // are required in the UI + // store.dispatch('util/getProductStores') + + if (!hasError(resp) || resp.data.error === 'No record found') { + productStores = resp.data.docs ? resp.data.docs : [] + } else { + throw resp.data + } + } catch (error) { + console.error('Failed to fetch user associated product stores.', error) + } + + commit(types.FACILITY_PRODUCT_STORES_UPDATED , productStores); } } diff --git a/src/store/modules/facility/getters.ts b/src/store/modules/facility/getters.ts index c3582cc9..09bdb912 100644 --- a/src/store/modules/facility/getters.ts +++ b/src/store/modules/facility/getters.ts @@ -6,6 +6,9 @@ const getters: GetterTree = { getFacilities(state) { return JSON.parse(JSON.stringify(state.facilities.list)) }, + getFacilityProductStores(state) { + return JSON.parse(JSON.stringify(state.current.productStores)) + }, getQuery(state) { return JSON.parse(JSON.stringify(state.query)) }, diff --git a/src/store/modules/facility/mutation-types.ts b/src/store/modules/facility/mutation-types.ts index 4676bdb0..55ab2801 100644 --- a/src/store/modules/facility/mutation-types.ts +++ b/src/store/modules/facility/mutation-types.ts @@ -1,4 +1,5 @@ export const SN_FACILITY = 'facility' export const FACILITY_LIST_UPDATED = SN_FACILITY + '/LIST_UPDATED' export const FACILITY_QUERY_UPDATED = SN_FACILITY + '/QUERY_UPDATED' -export const FACILITY_CURRENT_UPDATED = SN_FACILITY + '/CURRENT_UPDATED' \ No newline at end of file +export const FACILITY_CURRENT_UPDATED = SN_FACILITY + '/CURRENT_UPDATED' +export const FACILITY_PRODUCT_STORES_UPDATED = SN_FACILITY + '/PRODUCT_STORES_UPDATED' \ No newline at end of file diff --git a/src/store/modules/facility/mutations.ts b/src/store/modules/facility/mutations.ts index fab0e52c..356c0923 100644 --- a/src/store/modules/facility/mutations.ts +++ b/src/store/modules/facility/mutations.ts @@ -12,6 +12,9 @@ const mutations: MutationTree = { }, [types.FACILITY_CURRENT_UPDATED](state, payload) { state.current = payload + }, + [types.FACILITY_PRODUCT_STORES_UPDATED](state, payload) { + state.current.productStores = payload } } export default mutations; \ No newline at end of file diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index d09e9e33..73aab5e6 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -263,6 +263,7 @@ import AddGeoPointModal from '@/components/AddGeoPointModal.vue'; import SelectProductStoreModal from '@/components/SelectProductStoreModal.vue' import SelectOperatingTimeModal from '@/components/SelectOperatingTimeModal.vue'; import { mapGetters, useStore } from 'vuex'; +import { FacilityService } from '@/services/FacilityService'; export default defineComponent({ name: 'FacilityDetails', @@ -297,13 +298,15 @@ export default defineComponent({ }, computed: { ...mapGetters({ - current: 'facility/getCurrent' + current: 'facility/getCurrent', + facilityProductStores: 'facility/getFacilityProductStores' }) }, props: ["facilityId"], async ionViewWillEnter() { await this.store.dispatch('facility/fetchCurrentFacility', { facilityId: this.facilityId }) - this.isLoading = false + await this.store.dispatch('util/fetchProductStores') + await this.store.dispatch('facility/getFacilityProductStores', { facilityId: this.facilityId }) }, methods: { async openStorePopover(ev: Event) { @@ -330,7 +333,8 @@ export default defineComponent({ }, async addProductStore() { const addProductStoreModal = await modalController.create({ - component: SelectProductStoreModal + component: SelectProductStoreModal, + componentProps: { selectedProductStores: this.facilityProductStores } }) addProductStoreModal.present() From 1450c40f198c4d9409d1d220e04da10408ba7361 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 17 Nov 2023 12:09:02 +0530 Subject: [PATCH 02/20] Implemented: api and code for adding and removing product stores from facility association (#10) --- src/components/OpenStorePopover.vue | 3 +- src/components/SelectProductStoreModal.vue | 32 ++++++++++-- src/services/FacilityService.ts | 20 +++++++- src/store/modules/facility/actions.ts | 3 +- src/store/modules/facility/getters.ts | 2 +- src/views/FacilityDetails.vue | 60 +++++++++++++++++----- 6 files changed, 98 insertions(+), 22 deletions(-) diff --git a/src/components/OpenStorePopover.vue b/src/components/OpenStorePopover.vue index 0fd65112..32282d2b 100644 --- a/src/components/OpenStorePopover.vue +++ b/src/components/OpenStorePopover.vue @@ -1,7 +1,7 @@