Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: support to fetch current facility information and make basic information dynamic on details page(#8) #11

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
"Facilities": "Facilities",
"Facility": "Facility",
"Facility Management": "Facility Management",
"Fetching TimeZones": "Fetching TimeZones",
"Facility details": "Facility details",
"Failed to fetch facility information": "Failed to fetch facility information",
"Fetching TimeZones": "Fetching TimeZones",
"Find Facilities": "Find Facilities",
"Friday": "Friday",
"Fulfillment Capacity": "Fulfillment Capacity",
Expand Down
4 changes: 2 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import mutations from './mutations'
import getters from './getters'
import actions from './actions'
import RootState from './RootState'
import createPersistedState from "vuex-persistedstate";
import createPersistedState from 'vuex-persistedstate';
import userModule from './modules/user';
import { setPermissions } from '@/authorization'
import facilityModule from "./modules/facility"
import facilityModule from './modules/facility'
import utilModule from "./modules/util"


Expand Down
1 change: 1 addition & 0 deletions src/store/modules/facility/FacilityState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export default interface FacilityState {
list: Array<object>,
total: number
};
current: any;
}
42 changes: 41 additions & 1 deletion src/store/modules/facility/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const actions: ActionTree<FacilityState, RootState> = {
"entityName": "FacilityAndProductStore",
"noConditionFind": "Y",
"distinct": "Y",
"fieldList": ['facilityId', 'facilityName', 'facilityTypeId', 'maximumOrderLimit'],
"fieldList": ['defaultDaysToShip', 'facilityId', 'facilityName', 'facilityTypeId', 'maximumOrderLimit'],
...payload
}

Expand Down Expand Up @@ -90,6 +90,46 @@ const actions: ActionTree<FacilityState, RootState> = {
commit(types.FACILITY_LIST_UPDATED , { facilities, total });
},

async fetchCurrentFacility({ commit, state }, payload) {
// checking that if the list contains basic information for facility then not fetching the same information again
const cachedFacilities = JSON.parse(JSON.stringify(state.facilities.list))
const current = cachedFacilities.find((facility: any) => facility.facilityId === payload.facilityId)
if(current?.facilityId) {
commit(types.FACILITY_CURRENT_UPDATED, current);
return;
}

emitter.emit("presentLoader");

const params = {
inputFields: {
facilityId: payload.facilityId
},
entityName: "FacilityAndProductStore",
noConditionFind: "Y",
distinct: "Y",
fieldList: ['defaultDaysToShip', 'facilityId', 'facilityName', 'facilityTypeId', 'maximumOrderLimit'],
viewSize: 1
}

let facility = {};

try {
const resp = await FacilityService.fetchFacilities(params)

if(!hasError(resp) && resp.data.count > 0) {
facility = resp.data.docs[0]
} else {
throw resp.data
}
} catch(error) {
logger.error(error)
}

emitter.emit("dismissLoader");
commit(types.FACILITY_CURRENT_UPDATED, facility);
},

updateQuery({ commit }, query) {
commit(types.FACILITY_QUERY_UPDATED, query)
},
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/facility/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ const getters: GetterTree <FacilityState, RootState> = {
state.facilities.list?.length > 0 && state.facilities.list?.length < state.facilities.total
);
},
getCurrent(state) {
return state.current ? JSON.parse(JSON.stringify(state.current)) : {}
}
}
export default getters;
3 changes: 2 additions & 1 deletion src/store/modules/facility/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const facilityModule: Module<FacilityState, RootState> = {
facilities: {
list: [],
total: 0
}
},
current: {}
},
getters,
actions,
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/facility/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
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_QUERY_UPDATED = SN_FACILITY + '/QUERY_UPDATED'
export const FACILITY_CURRENT_UPDATED = SN_FACILITY + '/CURRENT_UPDATED'
3 changes: 3 additions & 0 deletions src/store/modules/facility/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const mutations: MutationTree <FacilityState> = {
},
[types.FACILITY_QUERY_UPDATED](state, payload) {
state.query = payload
},
[types.FACILITY_CURRENT_UPDATED](state, payload) {
state.current = payload
}
}
export default mutations;
Loading
Loading