Skip to content

Commit

Permalink
Improved: migrated bopis settings from the user preference to the pro…
Browse files Browse the repository at this point in the history
…duct store settings (hotwax#433)
  • Loading branch information
amansinghbais committed Oct 10, 2024
1 parent 7c9c3e1 commit 793abd2
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 19 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ VUE_APP_NOTIF_APP_ID=BOPIS
VUE_APP_NOTIF_ENUM_TYPE_ID=NOTIF_BOPIS
VUE_APP_FIREBASE_CONFIG={"apiKey": "","authDomain": "","databaseURL": "","projectId": "","storageBucket": "","messagingSenderId": "","appId": ""}
VUE_APP_FIREBASE_VAPID_KEY=""
VUE_APP_PRODUCT_STORE_SETTING_ENUMS={"ENABLE_TRACKING": {"enumId": "ENABLE_TRACKING","enumName": "Enable tracking","enumTypeId": "PROD_STR_STNG","description": "Enable tracking in BOPIS app"}, "PRINT_PACKING_SLIPS": {"enumId": "PRINT_PACKING_SLIPS","enumName": "Generate packing slips","enumTypeId": "PROD_STR_STNG","description": "Generate packing slips in BOPIS app"}, "PRINT_PICKLISTS": {"enumId": "wPRINT_PICKLISTS","enumName": "Print picklists","enumTypeId": "PROD_STR_STNG","description": "Print picklists in BOPIS app"}, "SHOW_SHIPPING_ORDERS": {"enumId": "SHOW_SHIPPING_ORDERS","enumName": "Show shipping orders","enumTypeId": "PROD_STR_STNG","description": "Show shipping orders in BOPIS app"}}
63 changes: 63 additions & 0 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { api } from '@/adapter';
import { hasError } from '@/adapter';

const fetchRejectReasons = async (query: any): Promise<any> => {
return api({
Expand Down Expand Up @@ -57,12 +58,74 @@ const fetchReservedQuantity = async (query: any): Promise <any> => {
});
}

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

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

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

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

const isEnumExists = async (enumId: string): Promise<any> => {
try {
const resp = await api({
url: 'performFind',
method: 'POST',
data: {
entityName: "Enumeration",
inputFields: {
enumId
},
viewSize: 1,
fieldList: ["enumId"],
noConditionFind: 'Y'
}
}) as any

if (!hasError(resp) && resp.data.docs.length) {
return true
}
return false
} catch (err) {
return false
}
}

export const UtilService = {
createEnumeration,
createProductStoreSetting,
fetchFacilityTypeInformation,
fetchPartyInformation,
fetchPaymentMethodTypeDesc,
fetchRejectReasons,
fetchStatusDesc,
getProductStoreSettings,
isEnumExists,
resetPicker,
updateProductStoreSetting,
fetchReservedQuantity
}
1 change: 1 addition & 0 deletions src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export default interface UserState {
firebaseDeviceId: string;
hasUnreadNotifications: boolean;
allNotificationPrefs: any;
bopisProductStoreSettings: any;
}
133 changes: 133 additions & 0 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { UserService } from '@/services/UserService'
import { UtilService } from '@/services/UtilService'
import { ActionTree } from 'vuex'
import RootState from '@/store/RootState'
import store from '@/store';
Expand Down Expand Up @@ -108,6 +109,7 @@ const actions: ActionTree<UserState, RootState> = {
//fetching partial order rejection config for BOPIS orders
await dispatch("getPartialOrderRejectionConfig");
await dispatch("fetchAllNotificationPrefs");
await dispatch("fetchBopisProductStoreSettings");

} catch (err: any) {
// If any of the API call in try block has status code other than 2xx it will be handled in common catch block.
Expand Down Expand Up @@ -337,6 +339,137 @@ const actions: ActionTree<UserState, RootState> = {
commit(types.USER_ALL_NOTIFICATION_PREFS_UPDATED, allNotificationPrefs)
},

async fetchBopisProductStoreSettings({ commit, dispatch }) {
const productStoreSettings = JSON.parse(process.env.VUE_APP_PRODUCT_STORE_SETTING_ENUMS);
const settingValues = {} as any;

const payload = {
"inputFields": {
"productStoreId": this.state.user.currentEComStore.productStoreId,
"settingTypeEnumId": Object.keys(productStoreSettings),
"settingTypeEnumId_op": "in"
},
"filterByDate": 'Y',
"entityName": "ProductStoreSetting",
"fieldList": ["settingTypeEnumId", "settingValue", "fromDate"]
}

try {
const resp = await UtilService.getProductStoreSettings(payload) as any
if(!hasError(resp)) {
resp.data.docs.map((setting: any) => {
settingValues[setting.settingTypeEnumId] = setting.settingValue === "true"
})
} else {
throw resp.data;
}
} catch(err) {
logger.error(err)
}

const enumIdsToCreate = Object.keys(productStoreSettings).filter((settingTypeEnumId) => !Object.keys(settingValues).includes(settingTypeEnumId));

await Promise.allSettled(enumIdsToCreate.map(async (enumId: any) => {
await dispatch("createProductStoreSetting", productStoreSettings[enumId])
}))

enumIdsToCreate.map((enumId: any) => settingValues[enumId] = false)

commit(types.USER_BOPIS_PRODUCT_STORE_SETTINGS_UPDATED, settingValues)
},

async createProductStoreSetting({ commit }, enumeration) {
const fromDate = Date.now()

try {
if(!await UtilService.isEnumExists(enumeration.enumId)) {
const resp = await UtilService.createEnumeration({
"enumId": enumeration.enumId,
"enumTypeId": "PROD_STR_STNG",
"description": enumeration.description,
"enumName": enumeration.enumName
})

if(hasError(resp)) {
throw resp.data;
}
}

const params = {
fromDate,
"productStoreId": this.state.user.currentEComStore.productStoreId,
"settingTypeEnumId": enumeration.enumId,
"settingValue": "false"
}

await UtilService.createProductStoreSetting(params) as any
} catch(err) {
logger.error(err)
}

return fromDate;
},

async setProductStoreSetting({ commit, dispatch, state }, payload) {
const productStoreSettings = JSON.parse(process.env.VUE_APP_PRODUCT_STORE_SETTING_ENUMS);
let prefValue = state.bopisProductStoreSettings[payload.enumId]
const eComStoreId = this.state.user.currentEComStore.productStoreId;

// when selecting none as ecom store, not updating the pref as it's not possible to save pref with empty productStoreId
if(!eComStoreId) {
showToast(translate("Unable to update product store setting."))
return;
}

let fromDate;

try {
const resp = await UtilService.getProductStoreSettings({
"inputFields": {
"productStoreId": this.state.user.currentEComStore.productStoreId,
"settingTypeEnumId": payload.enumId
},
"filterByDate": 'Y',
"entityName": "ProductStoreSetting",
"fieldList": ["fromDate"],
"viewSize": 1
}) as any
if(!hasError(resp)) {
fromDate = resp.data.docs[0]?.fromDate
}
} catch(err) {
logger.error(err)
}

if(!fromDate) {
fromDate = await dispatch("createProductStoreSetting", productStoreSettings[payload.enumId]);
}

const params = {
"fromDate": fromDate,
"productStoreId": eComStoreId,
"settingTypeEnumId": payload.enumId,
"settingValue": `${payload.value}`
}

try {
const resp = await UtilService.updateProductStoreSetting(params) as any

if((!hasError(resp))) {
prefValue = payload.value
} else {
throw resp.data;
}
} catch(err) {
showToast(translate("Failed to product store setting."))
logger.error(err)
}

const settingValues = JSON.parse(JSON.stringify(state.bopisProductStoreSettings))
settingValues[payload.enumId] = prefValue
commit(types.USER_BOPIS_PRODUCT_STORE_SETTINGS_UPDATED, settingValues)
},

async updateNotificationPreferences({ commit }, payload) {
commit(types.USER_NOTIFICATIONS_PREFERENCES_UPDATED, payload)
},
Expand Down
6 changes: 5 additions & 1 deletion src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ const getters: GetterTree <UserState, RootState> = {
},
getAllNotificationPrefs(state) {
return state.allNotificationPrefs
}
},
getBopisProductStoreSettings: (state) => (enumId: string) => {
return state.bopisProductStoreSettings[enumId]
},

}
export default getters;
3 changes: 2 additions & 1 deletion src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const userModule: Module<UserState, RootState> = {
notificationPrefs: [],
firebaseDeviceId: '',
hasUnreadNotifications: true,
allNotificationPrefs: []
allNotificationPrefs: [],
bopisProductStoreSettings: {}
},
getters,
actions,
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/user/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export const USER_NOTIFICATIONS_UPDATED = SN_USER + '/NOTIFICATIONS_UPDATED'
export const USER_NOTIFICATIONS_PREFERENCES_UPDATED = SN_USER + '/NOTIFICATIONS_PREFERENCES_UPDATED'
export const USER_ALL_NOTIFICATION_PREFS_UPDATED = SN_USER + '/ALL_NOTIFICATION_PREFS_UPDATED'
export const USER_FIREBASE_DEVICEID_UPDATED = SN_USER + '/FIREBASE_DEVICEID_UPDATED'
export const USER_UNREAD_NOTIFICATIONS_STATUS_UPDATED = SN_USER + '/UNREAD_NOTIFICATIONS_STATUS_UPDATED'
export const USER_UNREAD_NOTIFICATIONS_STATUS_UPDATED = SN_USER + '/UNREAD_NOTIFICATIONS_STATUS_UPDATED'
export const USER_BOPIS_PRODUCT_STORE_SETTINGS_UPDATED = SN_USER + '/BOPIS_PRODUCT_STORE_SETTINGS_UPDATED'
6 changes: 5 additions & 1 deletion src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const mutations: MutationTree <UserState> = {
configurePicker: false,
printPicklistPref: false
},
state.allNotificationPrefs = []
state.allNotificationPrefs = [],
state.bopisProductStoreSettings = {}
},
[types.USER_INFO_UPDATED] (state, payload) {
state.current = payload
Expand Down Expand Up @@ -54,6 +55,9 @@ const mutations: MutationTree <UserState> = {
},
[types.USER_ALL_NOTIFICATION_PREFS_UPDATED] (state, payload) {
state.allNotificationPrefs = payload
},
[types.USER_BOPIS_PRODUCT_STORE_SETTINGS_UPDATED] (state, payload) {
state.bopisProductStoreSettings = payload
}

}
Expand Down
22 changes: 7 additions & 15 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
{{ translate('View shipping orders along with pickup orders.') }}
</ion-card-content>
<ion-item lines="none">
<ion-toggle label-placement="start" :checked="showShippingOrders" @ionChange="setShowShippingOrdersPreference($event)">{{ translate("Show shipping orders") }}</ion-toggle>
<ion-toggle label-placement="start" :checked="getBopisProductStoreSettings('SHOW_SHIPPING_ORDERS')" @ionChange="setBopisProductStoreSettings($event, 'SHOW_SHIPPING_ORDERS')">{{ translate("Show shipping orders") }}</ion-toggle>
</ion-item>
</ion-card>

Expand All @@ -138,7 +138,7 @@
{{ translate('Packing slips help customer reconcile their order against the delivered items.') }}
</ion-card-content>
<ion-item lines="none">
<ion-toggle label-placement="start" :checked="showPackingSlip" @ionChange="setShowPackingSlipPreference($event)">{{ translate("Generate packing slips") }}</ion-toggle>
<ion-toggle label-placement="start" :checked="getBopisProductStoreSettings('PRINT_PACKING_SLIPS')" @ionChange="setBopisProductStoreSettings($event, 'PRINT_PACKING_SLIPS')">{{ translate("Generate packing slips") }}</ion-toggle>
</ion-item>
</ion-card>

Expand All @@ -152,10 +152,10 @@
{{ translate('Track who picked orders by entering picker IDs when packing an order.') }}
</ion-card-content>
<ion-item>
<ion-toggle label-placement="start" :checked="configurePicker" @ionChange="setConfigurePickerPreference($event)">{{ translate("Enable tracking") }}</ion-toggle>
<ion-toggle label-placement="start" :checked="getBopisProductStoreSettings('ENABLE_TRACKING')" @ionChange="setBopisProductStoreSettings($event, 'ENABLE_TRACKING')">{{ translate("Enable tracking") }}</ion-toggle>
</ion-item>
<ion-item lines="none">
<ion-toggle label-placement="start" :checked="printPicklistPref" @ionChange="setPrintPicklistPreference($event)">{{ translate("Print picklists") }}</ion-toggle>
<ion-toggle label-placement="start" :checked="getBopisProductStoreSettings('PRINT_PICKLISTS')" @ionChange="setBopisProductStoreSettings($event, 'PRINT_PICKLISTS')">{{ translate("Print picklists") }}</ion-toggle>
</ion-item>
</ion-card>

Expand Down Expand Up @@ -276,6 +276,7 @@ export default defineComponent({
notificationPrefs: 'user/getNotificationPrefs',
allNotificationPrefs: 'user/getAllNotificationPrefs',
printPicklistPref: "user/printPicklistPref",
getBopisProductStoreSettings: "user/getBopisProductStoreSettings"
})
},
mounted() {
Expand Down Expand Up @@ -328,17 +329,8 @@ export default defineComponent({
goToLaunchpad() {
window.location.href = `${process.env.VUE_APP_LOGIN_URL}`
},
setShowShippingOrdersPreference (ev: any) {
this.store.dispatch('user/setUserPreference', { showShippingOrders: ev.detail.checked })
},
setShowPackingSlipPreference (ev: any){
this.store.dispatch('user/setUserPreference', { showPackingSlip: ev.detail.checked })
},
setConfigurePickerPreference (ev: any){
this.store.dispatch('user/setUserPreference', { configurePicker: ev.detail.checked })
},
setPrintPicklistPreference (ev: any){
this.store.dispatch('user/setUserPreference', { printPicklistPref: ev.detail.checked })
setBopisProductStoreSettings (ev: any, enumId: any) {
this.store.dispatch('user/setProductStoreSetting', { enumId, value: ev.detail.checked })
},
getDateTime(time: any) {
return DateTime.fromMillis(time).toLocaleString(DateTime.DATETIME_MED);
Expand Down

0 comments on commit 793abd2

Please sign in to comment.