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

Fixed: Removed default setting creation from the BOPIS app to prevent duplicate settings (#459). #460

Merged
merged 1 commit into from
Nov 13, 2024
Merged
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
49 changes: 18 additions & 31 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/**
* Login user and return token
*/
async login ({ commit, dispatch, getters }, payload) {

Check warning on line 37 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'getters' is defined but never used

Check warning on line 37 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'getters' is defined but never used
try {
const {token, oms} = payload;
dispatch("setUserInstanceUrl", oms);
Expand Down Expand Up @@ -328,7 +328,7 @@
commit(types.USER_ALL_NOTIFICATION_PREFS_UPDATED, allNotificationPrefs)
},

async fetchBopisProductStoreSettings({ commit, dispatch }) {

Check warning on line 331 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'dispatch' is defined but never used

Check warning on line 331 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'dispatch' is defined but never used
const productStoreSettings = JSON.parse(process.env.VUE_APP_PRODUCT_STORE_SETTING_ENUMS);
const settingValues = {} as any;

Expand Down Expand Up @@ -356,18 +356,13 @@
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)
},

async createProductStoreSetting({ commit }, enumeration) {

Check warning on line 365 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'commit' is defined but never used

Check warning on line 365 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'commit' is defined but never used
const fromDate = Date.now()

try {
Expand Down Expand Up @@ -399,8 +394,8 @@
return fromDate;
},

async setProductStoreSetting({ commit, dispatch, state }, payload) {

Check warning on line 397 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'dispatch' is defined but never used

Check warning on line 397 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'dispatch' is defined but never used
const productStoreSettings = JSON.parse(process.env.VUE_APP_PRODUCT_STORE_SETTING_ENUMS);

Check warning on line 398 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'productStoreSettings' is assigned a value but never used

Check warning on line 398 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'productStoreSettings' is assigned a value but never used
let prefValue = state.bopisProductStoreSettings[payload.enumId]
const eComStoreId = this.state.user.currentEComStore.productStoreId;

Expand All @@ -413,7 +408,7 @@
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 @@
}) 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
Loading