Skip to content

Commit

Permalink
Implemented: support to select the order parking from settings page a…
Browse files Browse the repository at this point in the history
…nd create a user pref for the same(hotwax#204)
  • Loading branch information
ymaheshwari1 committed Aug 29, 2023
1 parent 2e81604 commit 5d6b564
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,21 @@ const createPreOrdPhyInvHoldConfig = async (): Promise<any> => {
})
}

const fetchFacilities = async (payload: any): Promise<any> => {
return await api({
url: "performFind",
method: "get",
params: payload
})
}


export const UtilService = {
getServiceStatusDesc,
getReserveInvConfig,
getPreOrdPhyInvHoldConfig,
updateReserveInvConfig,
updatePreOrdPhyInvHoldConfig,
createPreOrdPhyInvHoldConfig
createPreOrdPhyInvHoldConfig,
fetchFacilities
}
2 changes: 2 additions & 0 deletions src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ export default interface UserState {
current: object | null;
instanceUrl: string;
currentEComStore: object;
virtualFacilities: object | null;
currentOrderParking: string;
}
56 changes: 55 additions & 1 deletion src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { translate } from '@/i18n'
import { Settings } from 'luxon'
import { updateInstanceUrl, updateToken, resetConfig } from '@/adapter'
import { useAuthStore } from '@hotwax/dxp-components';
import { UtilService } from '@/services/UtilService'

const actions: ActionTree<UserState, RootState> = {

Expand Down Expand Up @@ -78,7 +79,7 @@ const actions: ActionTree<UserState, RootState> = {
/**
* Get User profile
*/
async getProfile ( { commit }) {
async getProfile ( { commit, dispatch }) {
const resp = await UserService.getProfile()
const userProfile = JSON.parse(JSON.stringify(resp.data));

Expand Down Expand Up @@ -117,6 +118,9 @@ const actions: ActionTree<UserState, RootState> = {
console.error(err)
}
}

await dispatch('fetchVirtualFacilities')

commit(types.USER_CURRENT_ECOM_STORE_UPDATED, userPrefStore);
commit(types.USER_INFO_UPDATED, userProfile);
}
Expand Down Expand Up @@ -157,5 +161,55 @@ const actions: ActionTree<UserState, RootState> = {
commit(types.USER_INSTANCE_URL_UPDATED, payload)
updateInstanceUrl(payload)
},

async fetchVirtualFacilities({ commit, dispatch }) {
const payload = {
inputFields: {
parentTypeId: "VIRTUAL_FACILITY"
},
viewSize: 20, // expecting that there will be no more than 20 virtual facilities
fieldList: ["facilityTypeId", "description"],
entityName: "FacilityType"
}

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

if(resp.status == 200 && !hasError(resp) && resp.data?.docs?.length) {
const facilities = resp.data.docs.reduce((facilities: any, facility: any) => {
facilities[facility.facilityTypeId] = facility.description
return facilities
}, {})

let currentOrderParking = Object.keys(facilities)[0] as string | string[]

const userPrefResponse = await UserService.getUserPreference({
'userPrefTypeId': 'SELECTED_ORDER_PARKING'
});

// if we already have a preference for order parking then updating it, otherwise, creating a new preference for order parking
if(userPrefResponse.data.userPrefValue) {
currentOrderParking = Object.keys(facilities).filter((facilityId: any) => userPrefResponse.data.userPrefValue.includes(facilityId))
commit(types.USER_CURRENT_PARKING_UPDATED, currentOrderParking);
} else {
dispatch('setOrderParking', currentOrderParking)
}

commit(types.USER_VIRTUAL_FACILITIES_UPDATED, facilities)
} else {
throw resp.data
}
} catch(err) {
console.error('Failed to fetch facilities for selection', err)
}
},

async setOrderParking({ commit }, payload) {
commit(types.USER_CURRENT_PARKING_UPDATED, payload);
await UserService.setUserPreference({
'userPrefTypeId': 'SELECTED_ORDER_PARKING',
'userPrefValue': JSON.stringify(payload)
});
},
}
export default actions;
6 changes: 6 additions & 0 deletions src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const getters: GetterTree <UserState, RootState> = {
},
getCurrentEComStore(state) {
return state.currentEComStore
},
getVirtualFacilities(state) {
return state.virtualFacilities
},
getCurrentOrderParking(state) {
return state.currentOrderParking
}
}
export default getters;
4 changes: 3 additions & 1 deletion src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const userModule: Module<UserState, RootState> = {
token: '',
current: null,
instanceUrl: '',
currentEComStore: {}
currentEComStore: {},
virtualFacilities: {},
currentOrderParking: ''
},
getters,
actions,
Expand Down
4 changes: 3 additions & 1 deletion src/store/modules/user/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export const USER_END_SESSION = SN_USER + '/END_SESSION'
export const USER_INFO_UPDATED = SN_USER + '/INFO_UPDATED'
export const USER_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED'
export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UPDATED'
export const USER_STORE_RSRV_INV_STATUS_UPDATED = SN_USER + '/STORE_RSRV_INV_STATUS_UPDATED'
export const USER_STORE_RSRV_INV_STATUS_UPDATED = SN_USER + '/STORE_RSRV_INV_STATUS_UPDATED'
export const USER_VIRTUAL_FACILITIES_UPDATED = SN_USER + '/VIRTUAL_FACILITIES_UPDATED'
export const USER_CURRENT_PARKING_UPDATED = SN_USER + '/CURRENT_PARKING_UPDATED'
8 changes: 8 additions & 0 deletions src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const mutations: MutationTree <UserState> = {
state.token = ''
state.current = {}
state.currentEComStore = {}
state.currentOrderParking = ''
state.virtualFacilities = {}
},
[types.USER_INFO_UPDATED] (state, payload) {
state.current = payload
Expand All @@ -19,6 +21,12 @@ const mutations: MutationTree <UserState> = {
},
[types.USER_CURRENT_ECOM_STORE_UPDATED] (state, payload) {
state.currentEComStore = payload;
},
[types.USER_VIRTUAL_FACILITIES_UPDATED] (state, payload) {
state.virtualFacilities = payload;
},
[types.USER_CURRENT_PARKING_UPDATED] (state, payload) {
state.currentOrderParking = payload;
}
}
export default mutations;
28 changes: 27 additions & 1 deletion src/views/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@
<ion-button @click="changeTimeZone()" slot="end" fill="outline" color="dark">{{ $t("Change") }}</ion-button>
</ion-item>
</ion-card>

<ion-card>
<ion-card-header>
<ion-card-title>
{{ $t('Order parking') }}
</ion-card-title>
</ion-card-header>

<ion-card-content>
{{ $t('Choose the parking for importing orders. After selection, the Orders and Products page will retrieve orders from the selected parking.') }}
</ion-card-content>

<ion-item lines="none">
<ion-label>{{ $t("Select parking") }}</ion-label>
<ion-select multiple interface="popover" :value="currentOrderParking" @ionChange="updateOrderParking($event)">
<ion-select-option v-for="(facility, id) in virtualFacilities" :key="id" :value="id" >{{ facility }}</ion-select-option>
</ion-select>
</ion-item>
</ion-card>
</section>
</ion-content>
</ion-page>
Expand Down Expand Up @@ -183,6 +202,8 @@ export default defineComponent({
userProfile: 'user/getUserProfile',
instanceUrl: 'user/getInstanceUrl',
currentEComStore: 'user/getCurrentEComStore',
currentOrderParking: 'user/getCurrentOrderParking',
virtualFacilities: 'user/getVirtualFacilities'
})
},
methods: {
Expand Down Expand Up @@ -213,7 +234,12 @@ export default defineComponent({
},
getDateTime(time: any) {
return DateTime.fromMillis(time).toLocaleString(DateTime.DATETIME_MED);
}
},
updateOrderParking(event: any) {
if(event.detail.value && this.userProfile && this.currentOrderParking !== event.detail.value) {
this.store.dispatch('user/setOrderParking', event.detail.value)
}
},
}
});
</script>
Expand Down

0 comments on commit 5d6b564

Please sign in to comment.