Skip to content

Commit

Permalink
Fixed: Removed default setting creation from the BOPIS app to prevent…
Browse files Browse the repository at this point in the history
… duplicate settings (#459).
  • Loading branch information
ravilodhi committed Nov 13, 2024
1 parent 836f20f commit 4001ba6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
49 changes: 18 additions & 31 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,9 @@ const actions: ActionTree<UserState, RootState> = {
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)

//Set default to false if there is no product setting exists
const missingSettings = Object.keys(productStoreSettings).filter((settingTypeEnumId) => !Object.keys(settingValues).includes(settingTypeEnumId));
missingSettings.map((settingTypeEnumId: any) => settingValues[settingTypeEnumId] = false)
commit(types.USER_BOPIS_PRODUCT_STORE_SETTINGS_UPDATED, settingValues)
},

Expand Down Expand Up @@ -413,7 +408,7 @@ const actions: ActionTree<UserState, RootState> = {
let fromDate;

try {
const resp = await UtilService.getProductStoreSettings({
let resp = await UtilService.getProductStoreSettings({
"inputFields": {
"productStoreId": this.state.user.currentEComStore.productStoreId,
"settingTypeEnumId": payload.enumId
Expand All @@ -425,29 +420,21 @@ const actions: ActionTree<UserState, RootState> = {
}) 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
const params = {
"fromDate": fromDate,
"productStoreId": eComStoreId,
"settingTypeEnumId": payload.enumId,
"settingValue": `${payload.value}`
}

resp = await UtilService.updateProductStoreSetting(params) as any
if((!hasError(resp))) {
prefValue = payload.value
} else {
throw resp.data;
}
} else {
throw resp.data;
throw resp.data
}
} catch(err) {
showToast(translate("Failed to update product store setting."))
Expand Down
11 changes: 6 additions & 5 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" :disabled="!hasPermission(Actions.APP_SHOW_SHIPPING_ORD_PREF_UPDATE)">
<ion-toggle label-placement="start" :checked="getBopisProductStoreSettings('SHOW_SHIPPING_ORDERS')" @ionChange="setBopisProductStoreSettings($event, 'SHOW_SHIPPING_ORDERS')">{{ translate("Show shipping orders") }}</ion-toggle>
<ion-toggle label-placement="start" :checked="getBopisProductStoreSettings('SHOW_SHIPPING_ORDERS')" @click.prevent="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" :disabled="!hasPermission(Actions.APP_PRINT_PACKING_SLIP_PREF_UPDATE)">
<ion-toggle label-placement="start" :checked="getBopisProductStoreSettings('PRINT_PACKING_SLIPS')" @ionChange="setBopisProductStoreSettings($event, 'PRINT_PACKING_SLIPS')">{{ translate("Generate packing slips") }}</ion-toggle>
<ion-toggle label-placement="start" :checked="getBopisProductStoreSettings('PRINT_PACKING_SLIPS')" @click.prevent="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 :disabled="!hasPermission(Actions.APP_ENABLE_TRACKING_PREF_UPDATE)">
<ion-toggle label-placement="start" :checked="getBopisProductStoreSettings('ENABLE_TRACKING')" @ionChange="setBopisProductStoreSettings($event, 'ENABLE_TRACKING')">{{ translate("Enable tracking") }}</ion-toggle>
<ion-toggle label-placement="start" :checked="getBopisProductStoreSettings('ENABLE_TRACKING')" @click.prevent="setBopisProductStoreSettings($event, 'ENABLE_TRACKING')">{{ translate("Enable tracking") }}</ion-toggle>
</ion-item>
<ion-item lines="none" :disabled="!hasPermission(Actions.APP_PRINT_PICKLIST_PREF_UPDATE)">
<ion-toggle label-placement="start" :checked="getBopisProductStoreSettings('PRINT_PICKLISTS')" @ionChange="setBopisProductStoreSettings($event, 'PRINT_PICKLISTS')">{{ translate("Print picklists") }}</ion-toggle>
<ion-toggle label-placement="start" :checked="getBopisProductStoreSettings('PRINT_PICKLISTS')" @click.prevent="setBopisProductStoreSettings($event, 'PRINT_PICKLISTS')">{{ translate("Print picklists") }}</ion-toggle>
</ion-item>
</ion-card>

Expand Down Expand Up @@ -326,7 +326,8 @@ export default defineComponent({
window.location.href = `${process.env.VUE_APP_LOGIN_URL}`
},
setBopisProductStoreSettings (ev: any, enumId: any) {
this.store.dispatch('user/setProductStoreSetting', { enumId, value: ev.detail.checked })
ev.stopImmediatePropagation();
this.store.dispatch('user/setProductStoreSetting', { enumId, value: !this.getBopisProductStoreSettings(enumId) })
},
getDateTime(time: any) {
return DateTime.fromMillis(time).toLocaleString(DateTime.DATETIME_MED);
Expand Down

0 comments on commit 4001ba6

Please sign in to comment.