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

Old PR: [Implemented: Clean up UI for BOPIS inventory lookup (#470)] #508

Closed
wants to merge 6 commits into from
Closed
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
20 changes: 19 additions & 1 deletion src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ const fetchEnumerations = async (payload: any): Promise<any> => {
});
}

const fetchCurrentFacilityLatLon = async (payload: any): Promise<any> => {
return api({
url: "performFind",
method: "post",
data: payload
});
}

const fetchStoreLookupByLatLon = async (payload: any): Promise<any> => {
return api({
url: "storeLookup",
method: "post",
data: payload
});
}

export const UtilService = {
createEnumeration,
createProductStoreSetting,
Expand All @@ -163,5 +179,7 @@ export const UtilService = {
isEnumExists,
resetPicker,
updateProductStoreSetting,
fetchReservedQuantity
fetchReservedQuantity,
fetchCurrentFacilityLatLon,
fetchStoreLookupByLatLon
}
2 changes: 2 additions & 0 deletions src/store/modules/util/UtilState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export default interface UtilState {
cancelReasons: Array<any>;
facilities: any;
enumerations: any;
currentFacilityLatLon: any;
storeLookupByLatLon: any;
}
53 changes: 52 additions & 1 deletion src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,58 @@ const actions: ActionTree<UtilState, RootState> = {

async clearEnumerations({ commit }) {
commit(types.UTIL_ENUMERATIONS_UPDATED, {})
}
},

async fetchCurrentFacilityLatLon({ commit }, facilityId) {
const payload = {
inputFields: {
facilityId: facilityId
},
entityName: "FacilityContactDetailByPurpose",
orderBy: "fromDate DESC",
filterByDate: "Y",
fieldList: ["latitude", "longitude"],
viewSize: 5
}

try {
const resp = await UtilService.fetchCurrentFacilityLatLon(payload)

if (!hasError(resp) && resp.data?.docs.length > 0) {
// Find first doc with non-null coordinates
const validCoords = resp.data.docs.find((doc: any) =>
doc.latitude !== null && doc.longitude !== null
)

if (validCoords) {
commit(types.UTIL_CURRENT_FACILITY_LATLON_UPDATED, validCoords)
}
} else {
throw resp.data
}
} catch (err) {
console.error("Failed to fetch facility lat/long information", err)
}
},

async fetchStoreLookupByLatLon({ commit }, point) {
const payload = {
viewSize: 250,
filters: ["storeType: RETAIL_STORE"],
point: `${point.latitude},${point.longitude}` }

try {
const resp = await UtilService.fetchStoreLookupByLatLon(payload)

if (!hasError(resp) && resp.data?.response?.docs?.length > 0) {
commit(types.UTIL_STORE_LOOKUP_BY_LATLON_UPDATED, resp.data.response.docs)
} else {
throw resp.data
}
} catch (err) {
console.error("Failed to fetch stores by lat/lon information", err)
}
},
}

export default actions;
6 changes: 6 additions & 0 deletions src/store/modules/util/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ const getters: GetterTree <UtilState, RootState> = {
getEnumDescription: (state) => (enumId: string) => {
return state.enumerations[enumId] ? state.enumerations[enumId] : enumId
},
getCurrentFacilityLatLon: (state) => {
return state.currentFacilityLatLon ? state.currentFacilityLatLon : {}
},
getStoreLookupByLatLon: (state) => {
return state.storeLookupByLatLon ? state.storeLookupByLatLon : {}
}
}
export default getters;
4 changes: 3 additions & 1 deletion src/store/modules/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const utilModule: Module<UtilState, RootState> = {
partyNames: {},
cancelReasons: [],
facilities: {},
enumerations: {}
enumerations: {},
currentFacilityLatLon: {},
storeLookupByLatLon: {}
},
getters,
actions,
Expand Down
2 changes: 2 additions & 0 deletions src/store/modules/util/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const UTIL_PARTY_NAMES_UPDATED = SN_UTIL + '/PARTY_NAMES_UPDATED'
export const UTIL_CANCEL_REASONS_UPDATED = SN_UTIL + '/CANCEL_REASONS_UPDATED'
export const UTIL_FACILITIES_UPDATED = SN_UTIL + '/FACILITIES_UPDATED'
export const UTIL_ENUMERATIONS_UPDATED = SN_UTIL + '/ENUMERATIONS_UPDATED'
export const UTIL_CURRENT_FACILITY_LATLON_UPDATED = SN_UTIL + '/CURRENT_FACILITY_LATLON_UPDATED'
export const UTIL_STORE_LOOKUP_BY_LATLON_UPDATED = SN_UTIL + '/STORE_LOOKUP_BY_LATLON_UPDATED'
6 changes: 6 additions & 0 deletions src/store/modules/util/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ const mutations: MutationTree <UtilState> = {
[types.UTIL_ENUMERATIONS_UPDATED] (state, payload) {
state.enumerations = payload
},
[types.UTIL_CURRENT_FACILITY_LATLON_UPDATED] (state, payload) {
state.currentFacilityLatLon = payload
},
[types.UTIL_STORE_LOOKUP_BY_LATLON_UPDATED] (state, payload) {
state.storeLookupByLatLon = payload
}
}
export default mutations;
Loading
Loading