Skip to content

Commit

Permalink
Merge pull request #103 from disha1202/userPreference
Browse files Browse the repository at this point in the history
Implemented: code to get and set user preference (#2g4w5hz)
  • Loading branch information
adityasharma7 authored Jun 27, 2022
2 parents d8f01c7 + 11e46eb commit 21a60b9
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 12 deletions.
17 changes: 17 additions & 0 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,26 @@ const setUserTimeZone = async (payload: any): Promise <any> => {
});
}

const getUserPreference = async (payload: any): Promise<any> => {
return api({
url: "service/getUserPreference",
method: "post",
data: payload
});
}
const setUserPreference = async (payload: any): Promise<any> => {
return api({
url: "service/setUserPreference",
method: "post",
data: payload
});
}

export const UserService = {
login,
getAvailableTimeZones,
getProfile,
setUserTimeZone,
getUserPreference,
setUserPreference
}
4 changes: 2 additions & 2 deletions src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const actions: ActionTree<OrderState , RootState> ={
let resp;

try {
const shippingOrdersStatus = store.state.user.shippingOrders;
if(!shippingOrdersStatus){
const showShippingOrders = store.state.user.preference.showShippingOrders;
if(!showShippingOrders){
payload.shipmentMethodTypeId= "STOREPICKUP"
}
resp = await OrderService.getOpenOrders(payload)
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export default interface UserState {
current: object | null;
currentFacility: object;
instanceUrl: string;
shippingOrders: boolean;
preference: any;
packingSlipEnabled: boolean;
}
16 changes: 14 additions & 2 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ const actions: ActionTree<UserState, RootState> = {
if (resp.data.userTimeZone !== localTimeZone) {
emitter.emit('timeZoneDifferent', { profileTimeZone: resp.data.userTimeZone, localTimeZone});
}
const userPreferenceResp = await UserService.getUserPreference({
'userPrefTypeId': 'BOPIS_PREFERENCE'
});

if (userPreferenceResp.status == 200 && !hasError(userPreferenceResp) && userPreferenceResp.data?.userPrefValue) {
const userPreference = JSON.parse(userPreferenceResp.data.userPrefValue)
commit(types.USER_PREFERENCE_UPDATED, userPreference)
}
commit(types.USER_INFO_UPDATED, resp.data);
commit(types.USER_CURRENT_FACILITY_UPDATED, resp.data.facilities.length > 0 ? resp.data.facilities[0] : {});
}
Expand Down Expand Up @@ -95,8 +103,12 @@ const actions: ActionTree<UserState, RootState> = {
}
},

setShippingOrdersStatus( { commit }, payload){
commit(types.USER_SHIPPING_ORDERS_STATUS_UPDATED, payload)
setUserPreference( {state, commit }, payload){
commit(types.USER_PREFERENCE_UPDATED, payload)
UserService.setUserPreference({
'userPrefTypeId': 'BOPIS_PREFERENCE',
'userPrefValue': JSON.stringify(state.preference)
});
}
}
export default actions;
2 changes: 1 addition & 1 deletion src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const getters: GetterTree <UserState, RootState> = {
return state.instanceUrl;
},
getShippingOrders (state) {
return state.shippingOrders
return state.preference.showShippingOrders;
},
getPackingSlipEnabled (state) {
return state.packingSlipEnabled;
Expand Down
6 changes: 4 additions & 2 deletions src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ const userModule: Module<UserState, RootState> = {
current: null,
currentFacility: {},
instanceUrl: '',
shippingOrders: true,
packingSlipEnabled: false
packingSlipEnabled: false,
preference: {
showShippingOrders: true,
}
},
getters,
actions,
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/user/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export const USER_END_SESSION = SN_USER + '/END_SESSION'
export const USER_INFO_UPDATED = SN_USER + '/INFO_UPDATED'
export const USER_CURRENT_FACILITY_UPDATED = SN_USER + '/CURRENT_FACILITY_UPDATED'
export const USER_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED'
export const USER_SHIPPING_ORDERS_STATUS_UPDATED = SN_USER + '/SHIPPING_ORDERS_STATUS_UPDATED'
export const USER_PREFERENCE_UPDATED = SN_USER + '/PREFERENCE_UPDATED'
export const USER_PACKING_SLIP_ENABLED_UPDATED = SN_USER + '/PACKING_SLIP_ENABLED_UPDATED'
4 changes: 2 additions & 2 deletions src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const mutations: MutationTree <UserState> = {
[types.USER_PACKING_SLIP_ENABLED_UPDATED] (state, payload) {
state.packingSlipEnabled = payload;
},
[types.USER_SHIPPING_ORDERS_STATUS_UPDATED] (state, payload) {
state.shippingOrders = payload
[types.USER_PREFERENCE_UPDATED] (state, payload) {
state.preference = {...state.preference, ...payload};
}
}
export default mutations;
2 changes: 1 addition & 1 deletion src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default defineComponent({
})
},
showShippingOrders (ev: any){
this.store.dispatch('user/setShippingOrdersStatus', ev.detail.checked)
this.store.dispatch('user/setUserPreference', { showShippingOrders: ev.detail.checked })
}
},
setup () {
Expand Down

0 comments on commit 21a60b9

Please sign in to comment.