From 6f38fdf631a4b3e47b481a26bfabfffab55ba3bc Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 17 Nov 2023 17:42:56 +0530 Subject: [PATCH 01/13] Implemented: service, store and code for fetching and removing parties of a facility (#12) --- src/components/AddStaffMemberModal.vue | 2 +- src/locales/en.json | 2 + src/services/FacilityService.ts | 20 +++++++- src/store/modules/facility/actions.ts | 28 +++++++++++ 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 | 51 ++++++++++++++++---- 8 files changed, 100 insertions(+), 12 deletions(-) diff --git a/src/components/AddStaffMemberModal.vue b/src/components/AddStaffMemberModal.vue index 7b41ee2c..693fe11e 100644 --- a/src/components/AddStaffMemberModal.vue +++ b/src/components/AddStaffMemberModal.vue @@ -73,7 +73,7 @@ export default defineComponent({ IonToolbar }, methods: { - closeModal() { + async closeModal() { modalController.dismiss() } }, diff --git a/src/locales/en.json b/src/locales/en.json index 900c4086..8b46b329 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -42,6 +42,7 @@ "Facility name": "Facility name", "Facility Management": "Facility Management", "Failed to fetch facility information": "Failed to fetch facility information", + "Failed to remove party from facility.": "Failed to remove party from facility.", "Fetching TimeZones": "Fetching TimeZones", "Find Facilities": "Find Facilities", "Friday": "Friday", @@ -90,6 +91,7 @@ "Parking": "Parking", "party id": "party id", "Party Id": "Party Id", + "Party successfully removed from facility.": "Party successfully removed from facility.", "Password": "Password", "Please contact the administrator.": "Please contact the administrator.", "primary store": "primary store", diff --git a/src/services/FacilityService.ts b/src/services/FacilityService.ts index 23ed7a45..ab72f2fd 100644 --- a/src/services/FacilityService.ts +++ b/src/services/FacilityService.ts @@ -84,6 +84,22 @@ const fetchFacilitiesOrderCount = async(facilityIds: Array): Promise => { + return api({ + url: "performFind", + method: "post", + data: payload + }); +} + +const removePartyFromFacility = async (payload: any): Promise => { + return api({ + url: "service/removePartyFromFacility", + method: "post", + data: payload + }); +} + const updateFacility = async (payload: any): Promise => { return api({ url: "service/updateFacility", @@ -96,5 +112,7 @@ export const FacilityService = { fetchFacilityOnlineGroupInformation, fetchFacilitiesOrderCount, fetchFacilities, - updateFacility + getFacilityParties, + removePartyFromFacility, + updateFacility, } \ No newline at end of file diff --git a/src/store/modules/facility/actions.ts b/src/store/modules/facility/actions.ts index 15d3932d..e95d30a2 100644 --- a/src/store/modules/facility/actions.ts +++ b/src/store/modules/facility/actions.ts @@ -141,6 +141,34 @@ const actions: ActionTree = { facilityTypeId: '' }) commit(types.FACILITY_LIST_UPDATED , { facilities: [], total: 0 }); + }, + + async getFacilityParties({ commit, state }, payload) { + let parties = [] + const params = { + inputFields: { + facilityId: payload.facilityId + }, + entityName: "FacilityAndParty", + filterByDate: 'Y', + orderBy: 'partyId DESC', + fieldList: ['facilityId', 'firstName', 'fromDate', 'lastName', 'groupName', 'partyId', 'roleTypeId'], + viewSize: 100 + } + + try { + const resp = await FacilityService.getFacilityParties(params) + + if(!hasError(resp) && resp.data.count){ + parties = resp.data.docs + } else { + throw resp.data + } + } catch(err) { + logger.error + } + + commit(types.FACILITY_PARTIES_UPDATED, parties) } } diff --git a/src/store/modules/facility/getters.ts b/src/store/modules/facility/getters.ts index c3582cc9..e60df7a8 100644 --- a/src/store/modules/facility/getters.ts +++ b/src/store/modules/facility/getters.ts @@ -16,6 +16,9 @@ const getters: GetterTree = { }, getCurrent(state) { return state.current ? JSON.parse(JSON.stringify(state.current)) : {} + }, + getFacilityParties(state) { + return state.current.parties } } export default getters; \ No newline at end of file diff --git a/src/store/modules/facility/mutation-types.ts b/src/store/modules/facility/mutation-types.ts index 4676bdb0..7fb42e74 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_PARTIES_UPDATED = SN_FACILITY + '/PARTIES_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..c7b867a8 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_PARTIES_UPDATED](state, payload) { + state.current.parties = payload } } export default mutations; \ No newline at end of file diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index 80f2bc7c..d26198f3 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -285,30 +285,29 @@ {{ translate("Add staff member to facility") }} -
+
- {{ "party name" }} -

{{ translate("party id") }}

+ {{ party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` }} +

{{ party.partyId }}

- {{ "fulfillment" }} + {{ party.roleTypeId }}

{{ translate("role") }}

- {{ "3rd June 2023" }} + {{ getDate(party.fromDate) }}

{{ "added" }}

- +
-
@@ -418,6 +417,11 @@ import SelectOperatingTimeModal from '@/components/SelectOperatingTimeModal.vue' import AddLocationModal from '@/components/AddLocationModal.vue'; import AddStaffMemberModal from '@/components/AddStaffMemberModal.vue'; import { mapGetters, useStore } from 'vuex'; +import { DateTime } from 'luxon'; +import { FacilityService } from '@/services/FacilityService'; +import { hasError } from '@/adapter'; +import logger from '@/logger'; +import { showToast } from '@/utils'; export default defineComponent({ name: 'FacilityDetails', @@ -456,12 +460,14 @@ export default defineComponent({ }, computed: { ...mapGetters({ - current: 'facility/getCurrent' + current: 'facility/getCurrent', + facilityParties: 'facility/getFacilityParties' }) }, props: ["facilityId"], async ionViewWillEnter() { await this.store.dispatch('facility/fetchCurrentFacility', { facilityId: this.facilityId }) + await this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }) this.isLoading = false }, methods: { @@ -530,6 +536,33 @@ export default defineComponent({ showBackdrop: false }); return externalMappingPopover.present() + }, + getDate(date: any) { + return DateTime.fromMillis(date).toFormat('dd LLL yyyy') + }, + async removePartyFromFacility(party: any) { + console.log(party) + try { + const resp = FacilityService.removePartyFromFacility({ + facilityId: party.facilityId, + fromDate: party.fromDate, + thruDate: DateTime.now().toMillis(), + partyId: party.partyId, + roleTypeId: party.roleTypeId + }) + + if(!hasError(resp)){ + showToast("Party successfully removed from facility.") + + // Refreshes the parties in facility + await this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }) + } else { + throw resp + } + } catch(err) { + showToast("Failed to remove party from facility.") + logger.error(err) + } } }, setup() { @@ -592,7 +625,7 @@ ion-segment { } .staff { - --columns-desktop: 5; + --columns-desktop: 4; } .external-mappings { From b801c3aa402b0afb00f123a6b6401f32067f7536 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 17 Nov 2023 18:03:40 +0530 Subject: [PATCH 02/13] Improved: css for border bottom of list item (#12) --- src/theme/variables.css | 2 ++ src/views/FacilityDetails.vue | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/theme/variables.css b/src/theme/variables.css index 5fbb21f2..e8c868ad 100644 --- a/src/theme/variables.css +++ b/src/theme/variables.css @@ -334,6 +334,7 @@ hr { grid-template-columns: repeat(var(--implicit-columns), 1fr) max-content; justify-items: center; align-items: center; + border-bottom: var(--border-medium); } .list-item > * { @@ -343,6 +344,7 @@ hr { .list-item > *:last-child { display: unset; justify-self: end; + border-bottom: none; } .list-item > ion-label { diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index d26198f3..8863544d 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -275,8 +275,7 @@ {{ translate("Edit") }} {{ translate("Remove") }} -
-
+
@@ -354,7 +353,6 @@
-
From 64592133527ec5e89b46b57bfd55b9e82c5813d9 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 17 Nov 2023 19:20:46 +0530 Subject: [PATCH 03/13] Improved: code for adding support for party selection (#12) --- src/components/AddStaffMemberModal.vue | 125 +++++++++++++++++++++---- src/services/FacilityService.ts | 9 ++ src/views/FacilityDetails.vue | 2 +- 3 files changed, 119 insertions(+), 17 deletions(-) diff --git a/src/components/AddStaffMemberModal.vue b/src/components/AddStaffMemberModal.vue index 693fe11e..d9b2832c 100644 --- a/src/components/AddStaffMemberModal.vue +++ b/src/components/AddStaffMemberModal.vue @@ -10,17 +10,35 @@ - - - {{ translate("Party Id") }} * - - - - {{ translate("Role") }} * - - {{ "Fulfillment" }} - - + + + + + {{ party.groupName ? party.groupName : `${party.firstName} : ${party.lastName}` }} + + + + + + {{ translate("Staff") }} + +
{{ translate("No party found") }}
+
+ + + {{ party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` }} +

{{ party.partyId }}

+
+ + {{ "None" }} + {{ "Fulfillment" }} + {{ "WAREHOUSE_MANAGER" }} + +
+
+
@@ -34,51 +52,126 @@ import { IonButton, IonButtons, + IonChip, IonContent, IonFab, IonFabButton, IonHeader, IonIcon, - IonInput, IonItem, IonLabel, + IonList, + IonListHeader, + IonRow, + IonSearchbar, IonSelect, IonSelectOption, - IonText, IonTitle, IonToolbar, modalController } from "@ionic/vue"; import { defineComponent } from "vue"; -import { closeOutline, saveOutline } from "ionicons/icons"; +import { closeCircle, closeOutline, saveOutline } from "ionicons/icons"; import { translate } from '@hotwax/dxp-components' +import { FacilityService } from "@/services/FacilityService"; +import { hasError } from "@/adapter"; +import logger from "@/logger"; export default defineComponent({ name: "AddStaffMemberModal", components: { IonButton, IonButtons, + IonChip, IonContent, IonFab, IonFabButton, IonHeader, IonIcon, - IonInput, IonItem, IonLabel, + IonList, + IonListHeader, + IonRow, + IonSearchbar, IonSelect, IonSelectOption, - IonText, IonTitle, IonToolbar }, + data () { + return { + selectedParties: [] as any, + queryString: '', + parties: [] + } + }, methods: { async closeModal() { modalController.dismiss() + }, + async findParties() { + this.parties = [] + let inputFields = {} + if(this.queryString.length > 0) { + inputFields = { + groupName_value: this.queryString, + groupName_op: 'contains', + groupName_ic: 'Y', + groupName_grp: '1', + firstName_value: this.queryString, + firstName_op: 'contains', + firstName_ic: 'Y', + firstName_grp: '2', + lastName_value: this.queryString, + lastName_op: 'contains', + lastName_ic: 'Y', + lastName_grp: '3' + } + } + + const payload = { + inputFields, + viewSize: 10, + entityName: 'PartyRoleAndPartyDetail', + noConditionFind: 'Y', + distinct: 'Y', + orderBy: "firstName ASC", + fieldList: ['firstName', 'groupName', 'lastName', 'partyId'] + } + + try { + const resp = await FacilityService.getPartyRoleAndPartyDetails(payload) + if(!hasError(resp)) { + this.parties = resp.data.docs + } else { + throw resp.data + } + } catch(err) { + logger.error(err) + } + }, + updateSelectedParties(event: CustomEvent, id: string) { + if(event.detail.value !== ''){ + if (!this.isPartySelected(id)) this.selectedParties.push(this.parties.find((party: any) => party.partyId === id)) + } else { + if(this.isPartySelected(id)) { + // if party is already selected then removing that party from the list on click + this.selectedParties = this.selectedParties.filter((party: any) => party.partyId !== id) + } + } + }, + isPartySelected(partyId: any) { + return this.selectedParties.find((party: any) => party.partyId === partyId) } }, + async mounted() { + // getting picker information on initial load + await this.findParties() + }, setup() { return { + closeCircle, closeOutline, saveOutline, translate diff --git a/src/services/FacilityService.ts b/src/services/FacilityService.ts index ab72f2fd..5422d335 100644 --- a/src/services/FacilityService.ts +++ b/src/services/FacilityService.ts @@ -92,6 +92,14 @@ const getFacilityParties = async(payload: any): Promise => { }); } +const getPartyRoleAndPartyDetails = async(payload: any): Promise => { + return api({ + url: "performFind", + method: "post", + data: payload + }); +} + const removePartyFromFacility = async (payload: any): Promise => { return api({ url: "service/removePartyFromFacility", @@ -113,6 +121,7 @@ export const FacilityService = { fetchFacilitiesOrderCount, fetchFacilities, getFacilityParties, + getPartyRoleAndPartyDetails, removePartyFromFacility, updateFacility, } \ No newline at end of file diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index 8863544d..a208a1b2 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -453,7 +453,7 @@ export default defineComponent({ return { isTimeModalOpen: false as boolean, isLoading: true, // shows whether the facility information fetching is completed or not - segment: 'external-mappings' + segment: 'staff' } }, computed: { From b1270e8d8fc8de9eece80aa29506939b88b5c411 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Mon, 20 Nov 2023 14:46:41 +0530 Subject: [PATCH 04/13] Implemented: logic, store and service for fetching, adding, removing roles (#12) --- src/components/AddStaffMemberModal.vue | 80 ++++++++++++++++++------ src/locales/en.json | 4 ++ src/services/FacilityService.ts | 9 +++ src/services/UtilService.ts | 12 +++- src/store/modules/util/UtilState.ts | 3 +- src/store/modules/util/actions.ts | 41 ++++++++++++ src/store/modules/util/getters.ts | 3 + src/store/modules/util/index.ts | 1 + src/store/modules/util/mutation-types.ts | 1 + src/store/modules/util/mutations.ts | 5 +- src/views/FacilityDetails.vue | 49 +++++++++++++-- 11 files changed, 182 insertions(+), 26 deletions(-) diff --git a/src/components/AddStaffMemberModal.vue b/src/components/AddStaffMemberModal.vue index d9b2832c..bd845b14 100644 --- a/src/components/AddStaffMemberModal.vue +++ b/src/components/AddStaffMemberModal.vue @@ -13,9 +13,9 @@ - - {{ party.groupName ? party.groupName : `${party.firstName} : ${party.lastName}` }} - + + {{ party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` }} + @@ -31,17 +31,15 @@ {{ party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` }}

{{ party.partyId }}

- - {{ "None" }} - {{ "Fulfillment" }} - {{ "WAREHOUSE_MANAGER" }} + + {{ role.description }}
- + @@ -76,6 +74,8 @@ import { translate } from '@hotwax/dxp-components' import { FacilityService } from "@/services/FacilityService"; import { hasError } from "@/adapter"; import logger from "@/logger"; +import { mapGetters, useStore } from "vuex"; +import { showToast } from "@/utils"; export default defineComponent({ name: "AddStaffMemberModal", @@ -99,13 +99,19 @@ export default defineComponent({ IonTitle, IonToolbar }, + props: ['selectedParties'], data () { return { - selectedParties: [] as any, + selectedPartyValues: JSON.parse(JSON.stringify(this.selectedParties)), queryString: '', parties: [] } }, + computed: { + ...mapGetters({ + roles: 'util/getRoles', + }) + }, methods: { async closeModal() { modalController.dismiss() @@ -151,31 +157,69 @@ export default defineComponent({ logger.error(err) } }, + removeSelectedParty(id: string) { + this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== id) + }, + saveParties() { + const partiesToCreate = this.selectedPartyValues.filter((selectedParty: any) => !this.selectedParties.some((party: any) => party.partyId === selectedParty.partyId && party.roleTypeId === selectedParty.roleTypeId)) + const partiesToRemove = this.selectedParties.filter((party: any) => !this.selectedPartyValues.some((selectedParty: any) => party.partyId === selectedParty.partyId)) + const partiesRoleChanged = this.selectedParties.filter((party: any) => this.selectedPartyValues.some((selectedParty: any) => selectedParty.partyId === party.partyId && selectedParty.roleTypeId !== party.roleTypeId)) + partiesRoleChanged.map((party: any) => partiesToRemove.push(party)) + + if(!(partiesToCreate.length > 0 || partiesToRemove.length > 0)) { + showToast(translate("Please update atleast one party role.")) + return; + } + + modalController.dismiss({ + dismissed: true, + value: { + partiesToCreate, + partiesToRemove + } + }); + }, updateSelectedParties(event: CustomEvent, id: string) { - if(event.detail.value !== ''){ - if (!this.isPartySelected(id)) this.selectedParties.push(this.parties.find((party: any) => party.partyId === id)) - } else { - if(this.isPartySelected(id)) { - // if party is already selected then removing that party from the list on click - this.selectedParties = this.selectedParties.filter((party: any) => party.partyId !== id) + let party = {} as any + if(this.isPartySelected(id)){ + party = this.selectedPartyValues.find((party: any) => party.partyId === id) + if(event.detail.value === 'none') { + this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== id) + } else if(event.detail.value !== party.roleTypeId) { + this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== id) + this.selectedPartyValues.push({...party, roleTypeId: event.detail.value}) } + } else { + party = this.parties.find((party: any) => party.partyId === id) + this.selectedPartyValues.push({...party, roleTypeId: event.detail.value}) } }, isPartySelected(partyId: any) { - return this.selectedParties.find((party: any) => party.partyId === partyId) + return this.selectedPartyValues.find((party: any) => party.partyId === partyId) + }, + getPartyRoleId(partyId: any) { + return this.selectedPartyValues.find((party: any) => party.partyId === partyId) ? this.selectedPartyValues.find((party: any) => party.partyId === partyId).roleTypeId : 'none' } }, async mounted() { - // getting picker information on initial load await this.findParties() }, setup() { + const store = useStore() + return { closeCircle, closeOutline, saveOutline, + store, translate }; }, }); - \ No newline at end of file + + + \ No newline at end of file diff --git a/src/locales/en.json b/src/locales/en.json index 8b46b329..3c2698e1 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -43,6 +43,7 @@ "Facility Management": "Facility Management", "Failed to fetch facility information": "Failed to fetch facility information", "Failed to remove party from facility.": "Failed to remove party from facility.", + "Failed to update some role(s).": "Failed to update some role(s).", "Fetching TimeZones": "Fetching TimeZones", "Find Facilities": "Find Facilities", "Friday": "Friday", @@ -81,6 +82,7 @@ "No facilities found": "No facilities found", "No fulfillment capacity": "No fulfillment capacity", "No capacity sets the fulfillment capacity to 0, preventing any new orders from being allocated to this facility. Use the \"Reject all orders\" option in the fulfillment pages to clear your facilities fulfillment queue. To add a fulfillment capacity to this facility, use the custom option.": "No capacity sets the fulfillment capacity to 0, preventing any new orders from being allocated to this facility. Use the \"Reject all orders\" option in the fulfillment pages to clear your facilities fulfillment queue. To add a fulfillment capacity to this facility, use the custom option.", + "No party found": "No party found", "No time zone found": "No time zone found", "OMS": "OMS", "OMS instance": "OMS instance", @@ -94,6 +96,7 @@ "Party successfully removed from facility.": "Party successfully removed from facility.", "Password": "Password", "Please contact the administrator.": "Please contact the administrator.", + "Please update atleast one party role.": "Please update atleast one party role.", "primary store": "primary store", "Product Store": "Product Store", "Product Stores": "Product Stores", @@ -103,6 +106,7 @@ "Remove location": "Remove location", "role": "role", "Role": "Role", + "Role(s) updated successfully.": "Role(s) updated successfully.", "Saturday": "Saturday", "Save": "Save", "section": "section", diff --git a/src/services/FacilityService.ts b/src/services/FacilityService.ts index 5422d335..717862f3 100644 --- a/src/services/FacilityService.ts +++ b/src/services/FacilityService.ts @@ -100,6 +100,14 @@ const getPartyRoleAndPartyDetails = async(payload: any): Promise => { }); } +const addPartyToFacility = async (payload: any): Promise => { + return api({ + url: "service/addPartyToFacility", + method: "post", + data: payload + }); +} + const removePartyFromFacility = async (payload: any): Promise => { return api({ url: "service/removePartyFromFacility", @@ -117,6 +125,7 @@ const updateFacility = async (payload: any): Promise => { } export const FacilityService = { + addPartyToFacility, fetchFacilityOnlineGroupInformation, fetchFacilitiesOrderCount, fetchFacilities, diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts index 85365974..38692b56 100644 --- a/src/services/UtilService.ts +++ b/src/services/UtilService.ts @@ -18,8 +18,18 @@ const fetchProductStores = async (payload: any): Promise => { }) } +const fetchRoles = async (payload: any): Promise => { + return api({ + url: 'performFind', + method: 'POST', + data: payload, + cache: true + }) +} + export const UtilService = { fetchFacilityTypes, - fetchProductStores + fetchProductStores, + fetchRoles } diff --git a/src/store/modules/util/UtilState.ts b/src/store/modules/util/UtilState.ts index d6f63851..93389930 100644 --- a/src/store/modules/util/UtilState.ts +++ b/src/store/modules/util/UtilState.ts @@ -1,4 +1,5 @@ export default interface UtilState { - productStores: any[]; facilityTypes: object; + productStores: any[]; + roles: any[]; } \ No newline at end of file diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index 5375800b..ad65f69f 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -5,6 +5,8 @@ import UtilState from './UtilState' import * as types from './mutation-types' import { hasError } from '@/adapter' import logger from '@/logger' +import { showToast } from '@/utils' +import { translate } from '@hotwax/dxp-components' const actions: ActionTree = { async fetchProductStores({ commit }) { @@ -62,6 +64,45 @@ const actions: ActionTree = { commit(types.UTIL_FACILITY_TYPES_UPDATED, facilityTypes) }, + async fetchRoles({ commit, state }) { + if (state.roles.length) { + return + } + + let roles = [] + const params = { + inputFields: { + roleTypeGroupId: 'FACILITY_PARTY_ROLE' + }, + viewSize: 100, + entityName: 'RoleTypeGroupMemberAndRoleType', + orderBy: 'sequenceNum', + filterByDate: 'Y', + fieldList: ['roleTypeId', 'description'] + } + + try { + const resp = await UtilService.fetchRoles(params) + if (!hasError(resp)) { + roles = resp.data.docs + + // pushing none explicitly to show on UI + roles.push({ + roleTypeId: 'none', + parentTypeId: 'none', + description: 'None', + }) + } else { + throw resp.data + } + } catch (error) { + showToast(translate('Something went wrong.')); + console.error(error) + } + + commit(types.UTIL_ROLES_UPDATED, roles) + }, + clearUtilState({ commit }) { commit(types.UTIL_PRODUCT_STORES_UPDATED, []) commit(types.UTIL_FACILITY_TYPES_UPDATED, []) diff --git a/src/store/modules/util/getters.ts b/src/store/modules/util/getters.ts index 0b2f9c6d..b92abba8 100644 --- a/src/store/modules/util/getters.ts +++ b/src/store/modules/util/getters.ts @@ -6,6 +6,9 @@ const getters: GetterTree = { getProductStores(state) { return state.productStores; }, + getRoles(state) { + return state.roles; + }, getFacilityTypes(state) { return state.facilityTypes } diff --git a/src/store/modules/util/index.ts b/src/store/modules/util/index.ts index 5470f963..fdd9e637 100644 --- a/src/store/modules/util/index.ts +++ b/src/store/modules/util/index.ts @@ -8,6 +8,7 @@ import RootState from '@/store/RootState' const utilModule: Module = { namespaced: true, state: { + roles: [], productStores: [], facilityTypes: {} }, diff --git a/src/store/modules/util/mutation-types.ts b/src/store/modules/util/mutation-types.ts index 0901fa26..d723be5c 100644 --- a/src/store/modules/util/mutation-types.ts +++ b/src/store/modules/util/mutation-types.ts @@ -1,3 +1,4 @@ export const SN_UTIL = 'util' export const UTIL_PRODUCT_STORES_UPDATED = SN_UTIL + '/PRODUCT_STORES_UPDATED' +export const UTIL_ROLES_UPDATED = SN_UTIL + '/ROLES_UPDATED' export const UTIL_FACILITY_TYPES_UPDATED = SN_UTIL + '/FACILITY_TYPES_UPDATED' \ No newline at end of file diff --git a/src/store/modules/util/mutations.ts b/src/store/modules/util/mutations.ts index 5d84d496..c62d9cd0 100644 --- a/src/store/modules/util/mutations.ts +++ b/src/store/modules/util/mutations.ts @@ -8,6 +8,9 @@ const mutations: MutationTree = { }, [types.UTIL_FACILITY_TYPES_UPDATED](state, payload) { state.facilityTypes = payload - } + }, + [types.UTIL_ROLES_UPDATED](state, payload) { + state.roles = payload + }, } export default mutations; \ No newline at end of file diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index a208a1b2..6e45ea8a 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -294,7 +294,7 @@ - {{ party.roleTypeId }} + {{ getRoleTypeDesc(party.roleTypeId) }}

{{ translate("role") }}

@@ -459,13 +459,15 @@ export default defineComponent({ computed: { ...mapGetters({ current: 'facility/getCurrent', - facilityParties: 'facility/getFacilityParties' + facilityParties: 'facility/getFacilityParties', + roles: 'util/getRoles', }) }, props: ["facilityId"], async ionViewWillEnter() { await this.store.dispatch('facility/fetchCurrentFacility', { facilityId: this.facilityId }) await this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }) + await this.store.dispatch('util/fetchRoles') this.isLoading = false }, methods: { @@ -507,7 +509,42 @@ export default defineComponent({ }, async addStaffMemberModal() { const addStaffModal = await modalController.create({ - component: AddStaffMemberModal + component: AddStaffMemberModal, + componentProps: { selectedParties: this.facilityParties } + }) + + addStaffModal.onDidDismiss().then(async (result: any) => { + if (result.data && result.data.value) { + const partiesToAdd = result.data.value.partiesToCreate + const partiesToRemove = result.data.value.partiesToRemove + + const removeResponses = await Promise.allSettled(partiesToRemove + .map(async (party: any) => await FacilityService.removePartyFromFacility({ + facilityId: this.facilityId, + fromDate: party.fromDate, + thruDate: DateTime.now().toMillis(), + partyId: party.partyId, + roleTypeId: party.roleTypeId + })) + ) + + const addResponses = await Promise.allSettled(partiesToAdd + .map(async (party: any) => await FacilityService.addPartyToFacility({ + facilityId: this.facilityId, + partyId: party.partyId, + roleTypeId: party.roleTypeId + })) + ) + + const hasFailedResponse = [...removeResponses, ...addResponses].some((response: any) => response.status === 'rejected') + if (hasFailedResponse) { + showToast(translate("Failed to update some role(s).")) + } else { + showToast(translate("Role(s) updated successfully.")) + } + // refetching parties with updated roles + await this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }) + } }) addStaffModal.present() @@ -539,9 +576,8 @@ export default defineComponent({ return DateTime.fromMillis(date).toFormat('dd LLL yyyy') }, async removePartyFromFacility(party: any) { - console.log(party) try { - const resp = FacilityService.removePartyFromFacility({ + const resp = await FacilityService.removePartyFromFacility({ facilityId: party.facilityId, fromDate: party.fromDate, thruDate: DateTime.now().toMillis(), @@ -561,6 +597,9 @@ export default defineComponent({ showToast("Failed to remove party from facility.") logger.error(err) } + }, + getRoleTypeDesc(id: any) { + return this.roles.find((role: any) => role.roleTypeId === id)?.description } }, setup() { From c6844fa7a76176801eac0506fbbcb353ef10e340 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Mon, 20 Nov 2023 15:39:45 +0530 Subject: [PATCH 05/13] Improved: code for better syntax, variable names and ordering (#12) --- src/components/AddStaffMemberModal.vue | 51 +++++++++++++------------- src/store/modules/facility/actions.ts | 7 +++- src/store/modules/util/actions.ts | 2 +- src/views/FacilityDetails.vue | 8 ++-- 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/components/AddStaffMemberModal.vue b/src/components/AddStaffMemberModal.vue index bd845b14..7c02f9d5 100644 --- a/src/components/AddStaffMemberModal.vue +++ b/src/components/AddStaffMemberModal.vue @@ -21,9 +21,6 @@ {{ translate("Staff") }} -
{{ translate("No party found") }}
@@ -31,15 +28,15 @@ {{ party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` }}

{{ party.partyId }}

- - {{ role.description }} + + {{ role.description }}
- + @@ -102,9 +99,9 @@ export default defineComponent({ props: ['selectedParties'], data () { return { - selectedPartyValues: JSON.parse(JSON.stringify(this.selectedParties)), + parties: [], queryString: '', - parties: [] + selectedPartyValues: JSON.parse(JSON.stringify(this.selectedParties)) } }, computed: { @@ -150,6 +147,7 @@ export default defineComponent({ const resp = await FacilityService.getPartyRoleAndPartyDetails(payload) if(!hasError(resp)) { this.parties = resp.data.docs + } else { throw resp.data } @@ -157,16 +155,16 @@ export default defineComponent({ logger.error(err) } }, - removeSelectedParty(id: string) { - this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== id) + removeSelectedParty(partyId: string) { + this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== partyId) }, saveParties() { - const partiesToCreate = this.selectedPartyValues.filter((selectedParty: any) => !this.selectedParties.some((party: any) => party.partyId === selectedParty.partyId && party.roleTypeId === selectedParty.roleTypeId)) + const partiesToAdd = this.selectedPartyValues.filter((selectedParty: any) => !this.selectedParties.some((party: any) => party.partyId === selectedParty.partyId && party.roleTypeId === selectedParty.roleTypeId)) const partiesToRemove = this.selectedParties.filter((party: any) => !this.selectedPartyValues.some((selectedParty: any) => party.partyId === selectedParty.partyId)) const partiesRoleChanged = this.selectedParties.filter((party: any) => this.selectedPartyValues.some((selectedParty: any) => selectedParty.partyId === party.partyId && selectedParty.roleTypeId !== party.roleTypeId)) partiesRoleChanged.map((party: any) => partiesToRemove.push(party)) - if(!(partiesToCreate.length > 0 || partiesToRemove.length > 0)) { + if(!(partiesToAdd.length > 0 || partiesToRemove.length > 0)) { showToast(translate("Please update atleast one party role.")) return; } @@ -174,30 +172,33 @@ export default defineComponent({ modalController.dismiss({ dismissed: true, value: { - partiesToCreate, + partiesToAdd, partiesToRemove } }); }, - updateSelectedParties(event: CustomEvent, id: string) { + updateSelectedParties(event: CustomEvent, selectedPartyId: string) { let party = {} as any - if(this.isPartySelected(id)){ - party = this.selectedPartyValues.find((party: any) => party.partyId === id) - if(event.detail.value === 'none') { - this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== id) - } else if(event.detail.value !== party.roleTypeId) { - this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== id) - this.selectedPartyValues.push({...party, roleTypeId: event.detail.value}) + const selectedRoleTypeId = event.detail.value + + if(this.isPartySelected(selectedPartyId)) { + party = this.selectedPartyValues.find((party: any) => party.partyId === selectedPartyId) + + if(selectedRoleTypeId === 'none') { + this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== selectedPartyId) + } else if(selectedPartyId !== party.roleTypeId) { + this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== selectedPartyId) + this.selectedPartyValues.push({...party, roleTypeId: selectedRoleTypeId}) } } else { - party = this.parties.find((party: any) => party.partyId === id) - this.selectedPartyValues.push({...party, roleTypeId: event.detail.value}) + party = this.parties.find((party: any) => party.partyId === selectedPartyId) + this.selectedPartyValues.push({...party, roleTypeId: selectedRoleTypeId}) } }, - isPartySelected(partyId: any) { + isPartySelected(partyId: string) { return this.selectedPartyValues.find((party: any) => party.partyId === partyId) }, - getPartyRoleId(partyId: any) { + getPartyRoleTypeId(partyId: string) { return this.selectedPartyValues.find((party: any) => party.partyId === partyId) ? this.selectedPartyValues.find((party: any) => party.partyId === partyId).roleTypeId : 'none' } }, diff --git a/src/store/modules/facility/actions.ts b/src/store/modules/facility/actions.ts index e95d30a2..0b691ee7 100644 --- a/src/store/modules/facility/actions.ts +++ b/src/store/modules/facility/actions.ts @@ -6,6 +6,8 @@ import { FacilityService } from '@/services/FacilityService' import { hasError } from '@/adapter' import * as types from './mutation-types' import logger from '@/logger' +import { showToast } from '@/utils' +import { translate } from '@hotwax/dxp-components' const actions: ActionTree = { async fetchFacilities({ commit, state }, payload) { @@ -143,7 +145,7 @@ const actions: ActionTree = { commit(types.FACILITY_LIST_UPDATED , { facilities: [], total: 0 }); }, - async getFacilityParties({ commit, state }, payload) { + async getFacilityParties({ commit }, payload) { let parties = [] const params = { inputFields: { @@ -159,12 +161,13 @@ const actions: ActionTree = { try { const resp = await FacilityService.getFacilityParties(params) - if(!hasError(resp) && resp.data.count){ + if(!hasError(resp) && resp.data.count) { parties = resp.data.docs } else { throw resp.data } } catch(err) { + showToast(translate("Something went wrong")) logger.error } diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index ad65f69f..e4ee22a8 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -96,7 +96,7 @@ const actions: ActionTree = { throw resp.data } } catch (error) { - showToast(translate('Something went wrong.')); + showToast(translate('Something went wrong')); console.error(error) } diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index 6e45ea8a..4722cbcf 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -284,7 +284,7 @@ {{ translate("Add staff member to facility") }} -
+
@@ -453,7 +453,7 @@ export default defineComponent({ return { isTimeModalOpen: false as boolean, isLoading: true, // shows whether the facility information fetching is completed or not - segment: 'staff' + segment: 'external-mappings' } }, computed: { @@ -515,7 +515,7 @@ export default defineComponent({ addStaffModal.onDidDismiss().then(async (result: any) => { if (result.data && result.data.value) { - const partiesToAdd = result.data.value.partiesToCreate + const partiesToAdd = result.data.value.partiesToAdd const partiesToRemove = result.data.value.partiesToRemove const removeResponses = await Promise.allSettled(partiesToRemove @@ -662,7 +662,7 @@ ion-segment { } .staff { - --columns-desktop: 4; + --columns-desktop: 5; } .external-mappings { From 1336159009ad35fb66d5f4d61b6201cd30aa4082 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Mon, 20 Nov 2023 16:02:54 +0530 Subject: [PATCH 06/13] Improved: code for unnecessary spaces (#12) --- src/services/FacilityService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/FacilityService.ts b/src/services/FacilityService.ts index 4ea60358..d4694605 100644 --- a/src/services/FacilityService.ts +++ b/src/services/FacilityService.ts @@ -109,13 +109,13 @@ const fetchFacilityOrderCounts = async(facilityId: string): Promise => { fieldList: ["entryDate", "facilityId", "lastOrderCount"], orderBy: "entryDate DESC" } - + resp = await api({ url: "performFind", method: "post", data: params }) - + if (!hasError(resp) && resp.data.count > 0) { facilityOrderCounts = resp.data.docs.map((facilityOrderCount: any) => { facilityOrderCount.entryDate = DateTime.fromMillis(facilityOrderCount.entryDate).toFormat('MMM dd yyyy') @@ -127,7 +127,7 @@ const fetchFacilityOrderCounts = async(facilityId: string): Promise => { } catch(err) { logger.error("Failed to fetch order consumed history for this facility", err); } - + return facilityOrderCounts; } From ef079e825645fa85041380bd52011b518ac43ba8 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Tue, 21 Nov 2023 10:39:05 +0530 Subject: [PATCH 07/13] Improved: code for fullName creation at actions, roles state format (#12) --- src/components/AddStaffMemberModal.vue | 16 ++++++++++------ src/store/modules/facility/actions.ts | 4 ++++ src/store/modules/util/actions.ts | 15 ++++++--------- src/views/FacilityDetails.vue | 10 +++------- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/components/AddStaffMemberModal.vue b/src/components/AddStaffMemberModal.vue index 7c02f9d5..345876d9 100644 --- a/src/components/AddStaffMemberModal.vue +++ b/src/components/AddStaffMemberModal.vue @@ -14,7 +14,7 @@ - {{ party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` }} + {{ party.fullName }} @@ -25,11 +25,11 @@
- {{ party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` }} + {{ party.fullName }}

{{ party.partyId }}

- {{ role.description }} + {{ description }}
@@ -146,8 +146,12 @@ export default defineComponent({ try { const resp = await FacilityService.getPartyRoleAndPartyDetails(payload) if(!hasError(resp)) { - this.parties = resp.data.docs + let parties = resp.data.docs + parties.map((party: any) => { + party.fullName = party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` + }) + this.parties = parties } else { throw resp.data } @@ -184,7 +188,7 @@ export default defineComponent({ if(this.isPartySelected(selectedPartyId)) { party = this.selectedPartyValues.find((party: any) => party.partyId === selectedPartyId) - if(selectedRoleTypeId === 'none') { + if(selectedRoleTypeId === '') { this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== selectedPartyId) } else if(selectedPartyId !== party.roleTypeId) { this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== selectedPartyId) @@ -199,7 +203,7 @@ export default defineComponent({ return this.selectedPartyValues.find((party: any) => party.partyId === partyId) }, getPartyRoleTypeId(partyId: string) { - return this.selectedPartyValues.find((party: any) => party.partyId === partyId) ? this.selectedPartyValues.find((party: any) => party.partyId === partyId).roleTypeId : 'none' + return this.selectedPartyValues.find((party: any) => party.partyId === partyId) ? this.selectedPartyValues.find((party: any) => party.partyId === partyId).roleTypeId : '' } }, async mounted() { diff --git a/src/store/modules/facility/actions.ts b/src/store/modules/facility/actions.ts index 93269cb8..4f0e9479 100644 --- a/src/store/modules/facility/actions.ts +++ b/src/store/modules/facility/actions.ts @@ -182,6 +182,10 @@ const actions: ActionTree = { if(!hasError(resp) && resp.data.count) { parties = resp.data.docs + + parties.map((party: any) => { + party.fullName = party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` + }); } else { throw resp.data } diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index e4ee22a8..5473f0ff 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -69,7 +69,7 @@ const actions: ActionTree = { return } - let roles = [] + const roles = {} as any const params = { inputFields: { roleTypeGroupId: 'FACILITY_PARTY_ROLE' @@ -84,20 +84,17 @@ const actions: ActionTree = { try { const resp = await UtilService.fetchRoles(params) if (!hasError(resp)) { - roles = resp.data.docs + resp.data.docs.map((doc:any) => { + roles[doc.roleTypeId] = doc.description + }) // pushing none explicitly to show on UI - roles.push({ - roleTypeId: 'none', - parentTypeId: 'none', - description: 'None', - }) + roles[''] = 'none' } else { throw resp.data } } catch (error) { - showToast(translate('Something went wrong')); - console.error(error) + logger.error(error) } commit(types.UTIL_ROLES_UPDATED, roles) diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index 8bbd1df2..bcb9a5f0 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -296,13 +296,13 @@ - {{ party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` }} + {{ party.fullName }}

{{ party.partyId }}

- {{ getRoleTypeDesc(party.roleTypeId) }} + {{ roles[party.roleTypeId] }}

{{ translate("role") }}

@@ -476,8 +476,7 @@ export default defineComponent({ props: ["facilityId"], async ionViewWillEnter() { await this.store.dispatch('facility/fetchCurrentFacility', { facilityId: this.facilityId }) - await this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }) - await this.store.dispatch('util/fetchRoles') + await Promise.all([ this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }), this.store.dispatch('util/fetchRoles')]) this.isLoading = false }, methods: { @@ -608,9 +607,6 @@ export default defineComponent({ logger.error(err) } }, - getRoleTypeDesc(id: any) { - return this.roles.find((role: any) => role.roleTypeId === id)?.description - }, async changeOrderLimitPopover(ev: Event) { const popover = await popoverController.create({ component: OrderLimitPopover, From d67070a60590df929acee39212fdcb92bffe9cd0 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Tue, 21 Nov 2023 12:38:59 +0530 Subject: [PATCH 08/13] Improved: roles looping logic (#12) --- src/components/AddStaffMemberModal.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AddStaffMemberModal.vue b/src/components/AddStaffMemberModal.vue index 345876d9..4062253b 100644 --- a/src/components/AddStaffMemberModal.vue +++ b/src/components/AddStaffMemberModal.vue @@ -29,7 +29,7 @@

{{ party.partyId }}

- {{ description }} + {{ description }}
From b2bca7768292e38bbd6043348d484bd295d42a5b Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Wed, 22 Nov 2023 15:26:24 +0530 Subject: [PATCH 09/13] Improved: code to handle parties adding removing action call at modal level (#12) --- src/components/AddStaffMemberModal.vue | 40 ++++++++++++++++++++------ src/views/FacilityDetails.vue | 36 +---------------------- 2 files changed, 32 insertions(+), 44 deletions(-) diff --git a/src/components/AddStaffMemberModal.vue b/src/components/AddStaffMemberModal.vue index 4062253b..7226fb19 100644 --- a/src/components/AddStaffMemberModal.vue +++ b/src/components/AddStaffMemberModal.vue @@ -73,6 +73,7 @@ import { hasError } from "@/adapter"; import logger from "@/logger"; import { mapGetters, useStore } from "vuex"; import { showToast } from "@/utils"; +import { DateTime } from "luxon"; export default defineComponent({ name: "AddStaffMemberModal", @@ -96,7 +97,7 @@ export default defineComponent({ IonTitle, IonToolbar }, - props: ['selectedParties'], + props: ['facilityId', 'selectedParties'], data () { return { parties: [], @@ -162,7 +163,7 @@ export default defineComponent({ removeSelectedParty(partyId: string) { this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== partyId) }, - saveParties() { + async saveParties() { const partiesToAdd = this.selectedPartyValues.filter((selectedParty: any) => !this.selectedParties.some((party: any) => party.partyId === selectedParty.partyId && party.roleTypeId === selectedParty.roleTypeId)) const partiesToRemove = this.selectedParties.filter((party: any) => !this.selectedPartyValues.some((selectedParty: any) => party.partyId === selectedParty.partyId)) const partiesRoleChanged = this.selectedParties.filter((party: any) => this.selectedPartyValues.some((selectedParty: any) => selectedParty.partyId === party.partyId && selectedParty.roleTypeId !== party.roleTypeId)) @@ -173,13 +174,34 @@ export default defineComponent({ return; } - modalController.dismiss({ - dismissed: true, - value: { - partiesToAdd, - partiesToRemove - } - }); + const removeResponses = await Promise.allSettled(partiesToRemove + .map(async (party: any) => await FacilityService.removePartyFromFacility({ + facilityId: this.facilityId, + fromDate: party.fromDate, + thruDate: DateTime.now().toMillis(), + partyId: party.partyId, + roleTypeId: party.roleTypeId + })) + ) + + const addResponses = await Promise.allSettled(partiesToAdd + .map(async (party: any) => await FacilityService.addPartyToFacility({ + facilityId: this.facilityId, + partyId: party.partyId, + roleTypeId: party.roleTypeId + })) + ) + + const hasFailedResponse = [...removeResponses, ...addResponses].some((response: any) => response.status === 'rejected') + if (hasFailedResponse) { + showToast(translate("Failed to update some role(s).")) + } else { + showToast(translate("Role(s) updated successfully.")) + } + + // refetching parties with updated roles + await this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }) + modalController.dismiss() }, updateSelectedParties(event: CustomEvent, selectedPartyId: string) { let party = {} as any diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index 8eec1191..6297c87c 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -522,41 +522,7 @@ export default defineComponent({ async addStaffMemberModal() { const addStaffModal = await modalController.create({ component: AddStaffMemberModal, - componentProps: { selectedParties: this.facilityParties } - }) - - addStaffModal.onDidDismiss().then(async (result: any) => { - if (result.data && result.data.value) { - const partiesToAdd = result.data.value.partiesToAdd - const partiesToRemove = result.data.value.partiesToRemove - - const removeResponses = await Promise.allSettled(partiesToRemove - .map(async (party: any) => await FacilityService.removePartyFromFacility({ - facilityId: this.facilityId, - fromDate: party.fromDate, - thruDate: DateTime.now().toMillis(), - partyId: party.partyId, - roleTypeId: party.roleTypeId - })) - ) - - const addResponses = await Promise.allSettled(partiesToAdd - .map(async (party: any) => await FacilityService.addPartyToFacility({ - facilityId: this.facilityId, - partyId: party.partyId, - roleTypeId: party.roleTypeId - })) - ) - - const hasFailedResponse = [...removeResponses, ...addResponses].some((response: any) => response.status === 'rejected') - if (hasFailedResponse) { - showToast(translate("Failed to update some role(s).")) - } else { - showToast(translate("Role(s) updated successfully.")) - } - // refetching parties with updated roles - await this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }) - } + componentProps: { facilityId: this.facilityId, selectedParties: this.facilityParties } }) addStaffModal.present() From 7c651e976095e07d1796e6d33dcc08872538ec05 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Thu, 23 Nov 2023 09:50:57 +0530 Subject: [PATCH 10/13] Improved: variable, getter, mutation name and reverted unused imports (#12) --- src/components/AddStaffMemberModal.vue | 2 +- src/services/UtilService.ts | 6 +++--- src/store/modules/util/actions.ts | 8 +++----- src/store/modules/util/getters.ts | 2 +- src/store/modules/util/mutation-types.ts | 2 +- src/store/modules/util/mutations.ts | 2 +- src/views/FacilityDetails.vue | 4 ++-- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/components/AddStaffMemberModal.vue b/src/components/AddStaffMemberModal.vue index 7226fb19..c2a79e8b 100644 --- a/src/components/AddStaffMemberModal.vue +++ b/src/components/AddStaffMemberModal.vue @@ -107,7 +107,7 @@ export default defineComponent({ }, computed: { ...mapGetters({ - roles: 'util/getRoles', + roles: 'util/getPartyRoles', }) }, methods: { diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts index c37fb214..7440a9b2 100644 --- a/src/services/UtilService.ts +++ b/src/services/UtilService.ts @@ -18,7 +18,7 @@ const fetchProductStores = async (payload: any): Promise => { }) } -const fetchRoles = async (payload: any): Promise => { +const fetchPartyRoles = async (payload: any): Promise => { return api({ url: 'performFind', method: 'POST', @@ -38,7 +38,7 @@ const fetchLocationTypes = async (payload: any): Promise => { export const UtilService = { fetchFacilityTypes, fetchLocationTypes, - fetchProductStores, - fetchRoles + fetchPartyRoles, + fetchProductStores } diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index f116be27..60b9c3a7 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -5,8 +5,6 @@ import UtilState from './UtilState' import * as types from './mutation-types' import { hasError } from '@/adapter' import logger from '@/logger' -import { showToast } from '@/utils' -import { translate } from '@hotwax/dxp-components' const actions: ActionTree = { async fetchProductStores({ commit }) { @@ -100,7 +98,7 @@ const actions: ActionTree = { commit(types.UTIL_LOCATION_TYPES_UPDATED, locationTypes) }, - async fetchRoles({ commit, state }) { + async fetchPartyRoles({ commit, state }) { if (state.roles.length) { return } @@ -118,7 +116,7 @@ const actions: ActionTree = { } try { - const resp = await UtilService.fetchRoles(params) + const resp = await UtilService.fetchPartyRoles(params) if (!hasError(resp)) { resp.data.docs.map((doc:any) => { roles[doc.roleTypeId] = doc.description @@ -132,7 +130,7 @@ const actions: ActionTree = { } catch (error) { logger.error(error) } - commit(types.UTIL_ROLES_UPDATED, roles) + commit(types.UTIL_PARTY_ROLES_UPDATED, roles) }, clearUtilState({ commit }) { diff --git a/src/store/modules/util/getters.ts b/src/store/modules/util/getters.ts index 7661caef..9abcdc0e 100644 --- a/src/store/modules/util/getters.ts +++ b/src/store/modules/util/getters.ts @@ -6,7 +6,7 @@ const getters: GetterTree = { getProductStores(state) { return state.productStores; }, - getRoles(state) { + getPartyRoles(state) { return state.roles; }, getFacilityTypes(state) { diff --git a/src/store/modules/util/mutation-types.ts b/src/store/modules/util/mutation-types.ts index adf199f0..46e28e9a 100644 --- a/src/store/modules/util/mutation-types.ts +++ b/src/store/modules/util/mutation-types.ts @@ -2,4 +2,4 @@ export const SN_UTIL = 'util' export const UTIL_PRODUCT_STORES_UPDATED = SN_UTIL + '/PRODUCT_STORES_UPDATED' export const UTIL_FACILITY_TYPES_UPDATED = SN_UTIL + '/FACILITY_TYPES_UPDATED' export const UTIL_LOCATION_TYPES_UPDATED = SN_UTIL + '/LOCATION_TYPES_UPDATED' -export const UTIL_ROLES_UPDATED = SN_UTIL + '/ROLES_UPDATED' +export const UTIL_PARTY_ROLES_UPDATED = SN_UTIL + '/PARTY_ROLES_UPDATED' diff --git a/src/store/modules/util/mutations.ts b/src/store/modules/util/mutations.ts index f1cc40c4..3a0b36ea 100644 --- a/src/store/modules/util/mutations.ts +++ b/src/store/modules/util/mutations.ts @@ -12,7 +12,7 @@ const mutations: MutationTree = { [types.UTIL_LOCATION_TYPES_UPDATED](state, payload) { state.locationTypes = payload }, - [types.UTIL_ROLES_UPDATED](state, payload) { + [types.UTIL_PARTY_ROLES_UPDATED](state, payload) { state.roles = payload } } diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index 6297c87c..65b9bbb1 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -472,13 +472,13 @@ export default defineComponent({ current: 'facility/getCurrent', facilityParties: 'facility/getFacilityParties', locationTypes: 'util/getLocationTypes', - roles: 'util/getRoles' + roles: 'util/getPartyRoles' }) }, props: ["facilityId"], async ionViewWillEnter() { await this.store.dispatch('facility/fetchCurrentFacility', { facilityId: this.facilityId }) - await Promise.all([this.store.dispatch('facility/fetchFacilityLocations', { facilityId: this.facilityId }), this.store.dispatch('util/fetchLocationTypes'), this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }), this.store.dispatch('util/fetchRoles')]) + await Promise.all([this.store.dispatch('facility/fetchFacilityLocations', { facilityId: this.facilityId }), this.store.dispatch('util/fetchLocationTypes'), this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }), this.store.dispatch('util/fetchPartyRoles')]) this.defaultDaysToShip = this.current.defaultDaysToShip this.isLoading = false }, From cceca14d05f4287e76bcd4074c24356a13bbe983 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Thu, 23 Nov 2023 14:24:36 +0530 Subject: [PATCH 11/13] Improved: state name for roles to partyRoles (#12) --- src/components/AddStaffMemberModal.vue | 4 ++-- src/store/modules/util/UtilState.ts | 2 +- src/store/modules/util/actions.ts | 2 +- src/store/modules/util/getters.ts | 2 +- src/store/modules/util/index.ts | 2 +- src/store/modules/util/mutations.ts | 2 +- src/views/FacilityDetails.vue | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/AddStaffMemberModal.vue b/src/components/AddStaffMemberModal.vue index c2a79e8b..86c8de72 100644 --- a/src/components/AddStaffMemberModal.vue +++ b/src/components/AddStaffMemberModal.vue @@ -29,7 +29,7 @@

{{ party.partyId }}

- {{ description }} + {{ description }}
@@ -107,7 +107,7 @@ export default defineComponent({ }, computed: { ...mapGetters({ - roles: 'util/getPartyRoles', + partyRoles: 'util/getPartyRoles', }) }, methods: { diff --git a/src/store/modules/util/UtilState.ts b/src/store/modules/util/UtilState.ts index 677fb7fb..0efb66fe 100644 --- a/src/store/modules/util/UtilState.ts +++ b/src/store/modules/util/UtilState.ts @@ -2,5 +2,5 @@ export default interface UtilState { facilityTypes: object; locationTypes: object; productStores: any[]; - roles: any[]; + partyRoles: any[]; } \ No newline at end of file diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index 60b9c3a7..78a071d1 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -99,7 +99,7 @@ const actions: ActionTree = { commit(types.UTIL_LOCATION_TYPES_UPDATED, locationTypes) }, async fetchPartyRoles({ commit, state }) { - if (state.roles.length) { + if (state.partyRoles.length) { return } diff --git a/src/store/modules/util/getters.ts b/src/store/modules/util/getters.ts index 9abcdc0e..b38e3c43 100644 --- a/src/store/modules/util/getters.ts +++ b/src/store/modules/util/getters.ts @@ -7,7 +7,7 @@ const getters: GetterTree = { return state.productStores; }, getPartyRoles(state) { - return state.roles; + return state.partyRoles; }, getFacilityTypes(state) { return state.facilityTypes diff --git a/src/store/modules/util/index.ts b/src/store/modules/util/index.ts index 85480c6e..ded1a803 100644 --- a/src/store/modules/util/index.ts +++ b/src/store/modules/util/index.ts @@ -8,7 +8,7 @@ import RootState from '@/store/RootState' const utilModule: Module = { namespaced: true, state: { - roles: [], + partyRoles: [], productStores: [], facilityTypes: {}, locationTypes: {} diff --git a/src/store/modules/util/mutations.ts b/src/store/modules/util/mutations.ts index 3a0b36ea..4e0d3208 100644 --- a/src/store/modules/util/mutations.ts +++ b/src/store/modules/util/mutations.ts @@ -13,7 +13,7 @@ const mutations: MutationTree = { state.locationTypes = payload }, [types.UTIL_PARTY_ROLES_UPDATED](state, payload) { - state.roles = payload + state.partyRoles = payload } } export default mutations; \ No newline at end of file diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index 65b9bbb1..276e811c 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -302,7 +302,7 @@ - {{ roles[party.roleTypeId] }} + {{ partyRoles[party.roleTypeId] }}

{{ translate("role") }}

@@ -472,7 +472,7 @@ export default defineComponent({ current: 'facility/getCurrent', facilityParties: 'facility/getFacilityParties', locationTypes: 'util/getLocationTypes', - roles: 'util/getPartyRoles' + partyRoles: 'util/getPartyRoles' }) }, props: ["facilityId"], From 8e5e0f484510451bb7408ea1ff47b2436a69eb0f Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Thu, 23 Nov 2023 15:27:47 +0530 Subject: [PATCH 12/13] Improved: syntax and simplified if conditions (#12) --- src/components/AddStaffMemberModal.vue | 21 ++++++++++----------- src/store/modules/util/actions.ts | 10 +++++----- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/components/AddStaffMemberModal.vue b/src/components/AddStaffMemberModal.vue index 86c8de72..6782829f 100644 --- a/src/components/AddStaffMemberModal.vue +++ b/src/components/AddStaffMemberModal.vue @@ -30,14 +30,14 @@ {{ description }} - + - - + + @@ -98,7 +98,7 @@ export default defineComponent({ IonToolbar }, props: ['facilityId', 'selectedParties'], - data () { + data() { return { parties: [], queryString: '', @@ -207,13 +207,12 @@ export default defineComponent({ let party = {} as any const selectedRoleTypeId = event.detail.value - if(this.isPartySelected(selectedPartyId)) { + party = this.getParty(selectedPartyId) + if(party?.partyId) { party = this.selectedPartyValues.find((party: any) => party.partyId === selectedPartyId) + this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== selectedPartyId) - if(selectedRoleTypeId === '') { - this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== selectedPartyId) - } else if(selectedPartyId !== party.roleTypeId) { - this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== selectedPartyId) + if(selectedRoleTypeId) { this.selectedPartyValues.push({...party, roleTypeId: selectedRoleTypeId}) } } else { @@ -221,11 +220,11 @@ export default defineComponent({ this.selectedPartyValues.push({...party, roleTypeId: selectedRoleTypeId}) } }, - isPartySelected(partyId: string) { + getParty(partyId: string) { return this.selectedPartyValues.find((party: any) => party.partyId === partyId) }, getPartyRoleTypeId(partyId: string) { - return this.selectedPartyValues.find((party: any) => party.partyId === partyId) ? this.selectedPartyValues.find((party: any) => party.partyId === partyId).roleTypeId : '' + return this.getParty(partyId) ? this.getParty(partyId).roleTypeId : '' } }, async mounted() { diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index 78a071d1..87ee4878 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -103,7 +103,7 @@ const actions: ActionTree = { return } - const roles = {} as any + const partyRoles = {} as any const params = { inputFields: { roleTypeGroupId: 'FACILITY_PARTY_ROLE' @@ -118,19 +118,19 @@ const actions: ActionTree = { try { const resp = await UtilService.fetchPartyRoles(params) if (!hasError(resp)) { - resp.data.docs.map((doc:any) => { - roles[doc.roleTypeId] = doc.description + resp.data.docs.map((role: any) => { + partyRoles[role.roleTypeId] = role.description }) // pushing none explicitly to show on UI - roles[''] = 'none' + partyRoles[''] = 'none' } else { throw resp.data } } catch (error) { logger.error(error) } - commit(types.UTIL_PARTY_ROLES_UPDATED, roles) + commit(types.UTIL_PARTY_ROLES_UPDATED, partyRoles) }, clearUtilState({ commit }) { From a83fa49d16da5565f5a17d5281e224ec87400888 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Thu, 23 Nov 2023 16:17:56 +0530 Subject: [PATCH 13/13] Improved: translated the static text in showToast (#12) --- src/views/FacilityDetails.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index 276e811c..84e65efb 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -565,7 +565,7 @@ export default defineComponent({ }) if(!hasError(resp)){ - showToast("Party successfully removed from facility.") + showToast(translate("Party successfully removed from facility.")) // Refreshes the parties in facility await this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }) @@ -573,7 +573,7 @@ export default defineComponent({ throw resp } } catch(err) { - showToast("Failed to remove party from facility.") + showToast(translate("Failed to remove party from facility.")) logger.error(err) } },