Skip to content

Commit

Permalink
Improved: disabling ship now button based on the product store setting (
Browse files Browse the repository at this point in the history
  • Loading branch information
amansinghbais committed Sep 19, 2024
1 parent b94e8ea commit e158ba3
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ const getNewRejectionApiConfig = async (payload: any): Promise<any> => {
});
}

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

const createPartialOrderRejectionConfig = async (payload: any): Promise<any> => {
return api({
url: "service/createProductStoreSetting",
Expand Down Expand Up @@ -389,6 +397,7 @@ export const UserService = {
deleteFieldMapping,
login,
getCollateralRejectionConfig,
getDisableShipNowConfig,
getEComStores,
getFacilityDetails,
getFacilityOrderCount,
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export default interface UserState {
newRejectionApiConfig: any;
partialOrderRejectionConfig: any;
collateralRejectionConfig: any;
isShipNowDisabled: boolean;
}
28 changes: 28 additions & 0 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const actions: ActionTree<UserState, RootState> = {
await dispatch('getNewRejectionApiConfig')
await dispatch('getPartialOrderRejectionConfig')
await dispatch('getCollateralRejectionConfig')
await dispatch('getDisableShipNowConfig')

} 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 @@ -438,6 +439,33 @@ const actions: ActionTree<UserState, RootState> = {
}
commit(types.USER_NEW_REJECTION_API_CONFIG_UPDATED, config);
},

async getDisableShipNowConfig ({ commit }) {
let isShipNowDisabled = false;
const params = {
"inputFields": {
"productStoreId": this.state.user.currentEComStore.productStoreId,
"settingTypeEnumId": "DISABLE_SHIPNOW"
},
"filterByDate": 'Y',
"entityName": "ProductStoreSetting",
"fieldList": ["settingTypeEnumId", "settingValue"],
"viewSize": 1
} as any

try {
const resp = await UserService.getDisableShipNowConfig(params)

if (!hasError(resp)) {
isShipNowDisabled = resp.data?.docs[0]?.settingValue === "true";
} else {
logger.error('Failed to fetch disable ship now config.');
}
} catch (err) {
logger.error(err);
}
commit(types.USER_DISABLE_SHIP_NOW_CONFIG_UPDATED, isShipNowDisabled);
},
async updatePartialOrderRejectionConfig ({ dispatch }, payload) {
let resp = {} as any;
try {
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@ const getters: GetterTree <UserState, RootState> = {
getCollateralRejectionConfig(state) {
return state.collateralRejectionConfig;
},
isShipNowDisabled(state) {
return state.isShipNowDisabled;
}
}
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 @@ -36,7 +36,8 @@ const userModule: Module<UserState, RootState> = {
allNotificationPrefs: [],
newRejectionApiConfig: {},
partialOrderRejectionConfig: {},
collateralRejectionConfig: {}
collateralRejectionConfig: {},
isShipNowDisabled: false
},
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 @@ -18,4 +18,5 @@ export const USER_UNREAD_NOTIFICATIONS_STATUS_UPDATED = SN_USER + '/UNREAD_NOTIF
export const USER_ALL_NOTIFICATION_PREFS_UPDATED = SN_USER + '/ALL_NOTIFICATION_PREFS_UPDATED'
export const USER_NEW_REJECTION_API_CONFIG_UPDATED = SN_USER + '/NEW_REJECTION_API_CONFIG_UPDATED'
export const USER_PARTIAL_ORDER_REJECTION_CONFIG_UPDATED = SN_USER + '/PARTIAL_ORDER_REJECTION_CONFIG_UPDATED'
export const USER_COLLATERAL_REJECTION_CONFIG_UPDATED = SN_USER + '/COLLATERAL_REJECTION_CONFIG_UPDATED'
export const USER_COLLATERAL_REJECTION_CONFIG_UPDATED = SN_USER + '/COLLATERAL_REJECTION_CONFIG_UPDATED'
export const USER_DISABLE_SHIP_NOW_CONFIG_UPDATED = SN_USER + '/DISABLE_SHIP_NOW_CONFIG_UPDATED'
3 changes: 3 additions & 0 deletions src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const mutations: MutationTree <UserState> = {
},
[types.USER_COLLATERAL_REJECTION_CONFIG_UPDATED] (state, payload) {
state.collateralRejectionConfig = payload
},
[types.USER_DISABLE_SHIP_NOW_CONFIG_UPDATED] (state, payload) {
state.isShipNowDisabled = payload
}
}
export default mutations;
9 changes: 5 additions & 4 deletions src/views/Completed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</ion-item>
</div>
<div class="results">
<ion-button :disabled="!hasAnyPackedShipment() || hasAnyMissingInfo() || (hasAnyShipmentTrackingInfoMissing() && !hasPermission(Actions.APP_FORCE_SHIP_ORDER))" expand="block" class="bulk-action desktop-only" fill="outline" size="large" @click="bulkShipOrders()">{{ translate("Ship") }}</ion-button>
<ion-button :disabled="isShipNowDisabled || !hasAnyPackedShipment() || hasAnyMissingInfo() || (hasAnyShipmentTrackingInfoMissing() && !hasPermission(Actions.APP_FORCE_SHIP_ORDER))" expand="block" class="bulk-action desktop-only" fill="outline" size="large" @click="bulkShipOrders()">{{ translate("Ship") }}</ion-button>
<ion-card class="order" v-for="(order, index) in getCompletedOrders()" :key="index">
<div class="order-header">
<div class="order-primary-info">
Expand Down Expand Up @@ -126,7 +126,7 @@
<!-- TODO: implement functionality to mobile view -->
<div class="mobile-only">
<ion-item>
<ion-button :disabled="order.hasMissingShipmentInfo || order.hasMissingPackageInfo || ((isTrackingRequiredForAnyShipmentPackage(order) && !order.trackingCode) && !hasPermission(Actions.APP_FORCE_SHIP_ORDER))" fill="clear" >{{ translate("Ship Now") }}</ion-button>
<ion-button :disabled="isShipNowDisabled || order.hasMissingShipmentInfo || order.hasMissingPackageInfo || ((isTrackingRequiredForAnyShipmentPackage(order) && !order.trackingCode) && !hasPermission(Actions.APP_FORCE_SHIP_ORDER))" fill="clear" >{{ translate("Ship Now") }}</ion-button>
<ion-button slot="end" fill="clear" color="medium" @click.stop="shippingPopover">
<ion-icon slot="icon-only" :icon="ellipsisVerticalOutline" />
</ion-button>
Expand All @@ -137,7 +137,7 @@
<div class="actions">
<div class="desktop-only">
<ion-button v-if="!hasPackedShipments(order)" :disabled="true">{{ translate("Shipped") }}</ion-button>
<ion-button v-else :disabled="order.hasMissingShipmentInfo || order.hasMissingPackageInfo || ((isTrackingRequiredForAnyShipmentPackage(order) && !order.trackingCode) && !hasPermission(Actions.APP_FORCE_SHIP_ORDER))" @click.stop="shipOrder(order)">{{ translate("Ship Now") }}</ion-button>
<ion-button v-else :disabled="isShipNowDisabled || order.hasMissingShipmentInfo || order.hasMissingPackageInfo || ((isTrackingRequiredForAnyShipmentPackage(order) && !order.trackingCode) && !hasPermission(Actions.APP_FORCE_SHIP_ORDER))" @click.stop="shipOrder(order)">{{ translate("Ship Now") }}</ion-button>
<ion-button :disabled="order.hasMissingShipmentInfo || order.hasMissingPackageInfo" fill="outline" @click.stop="regenerateShippingLabel(order)">
{{ translate("Regenerate Shipping Label") }}
<ion-spinner color="primary" slot="end" v-if="order.isGeneratingShippingLabel" name="crescent" />
Expand Down Expand Up @@ -268,7 +268,8 @@ export default defineComponent({
getPartyName: 'util/getPartyName',
getShipmentMethodDesc: 'util/getShipmentMethodDesc',
getProductStock: 'stock/getProductStock',
productStoreShipmentMethCount: 'util/getProductStoreShipmentMethCount'
productStoreShipmentMethCount: 'util/getProductStoreShipmentMethCount',
isShipNowDisabled: 'user/isShipNowDisabled'
})
},
async mounted() {
Expand Down
7 changes: 4 additions & 3 deletions src/views/OrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
<div v-else-if="category === 'completed'" class="mobile-only">
<ion-item>
<ion-button :disabled="order.hasMissingShipmentInfo || order.hasMissingPackageInfo || ((isTrackingRequiredForAnyShipmentPackage(order) && !order.trackingCode) && !hasPermission(Actions.APP_FORCE_SHIP_ORDER))" fill="clear" >{{ translate("Ship Now") }}</ion-button>
<ion-button :disabled="isShipNowDisabled || order.hasMissingShipmentInfo || order.hasMissingPackageInfo || ((isTrackingRequiredForAnyShipmentPackage(order) && !order.trackingCode) && !hasPermission(Actions.APP_FORCE_SHIP_ORDER))" fill="clear" >{{ translate("Ship Now") }}</ion-button>
<ion-button slot="end" fill="clear" color="medium" @click.stop="shippingPopover">
<ion-icon slot="icon-only" :icon="ellipsisVerticalOutline" />
</ion-button>
Expand All @@ -191,7 +191,7 @@
<ion-icon slot="start" :icon="bagCheckOutline" />
{{ translate("Shipped") }}
</ion-button>
<ion-button v-else :disabled="order.hasMissingShipmentInfo || order.hasMissingPackageInfo || ((isTrackingRequiredForAnyShipmentPackage(order) && !order.trackingCode) && !hasPermission(Actions.APP_FORCE_SHIP_ORDER))" @click.stop="shipOrder(order)">
<ion-button v-else :disabled="isShipNowDisabled || order.hasMissingShipmentInfo || order.hasMissingPackageInfo || ((isTrackingRequiredForAnyShipmentPackage(order) && !order.trackingCode) && !hasPermission(Actions.APP_FORCE_SHIP_ORDER))" @click.stop="shipOrder(order)">
<ion-icon slot="start" :icon="bagCheckOutline" />
{{ translate("Ship order") }}
</ion-button>
Expand Down Expand Up @@ -514,7 +514,8 @@ export default defineComponent({
isForceScanEnabled: 'util/isForceScanEnabled',
productStoreShipmentMethods: 'carrier/getProductStoreShipmentMethods',
facilityCarriers: 'carrier/getFacilityCarriers',
userProfile: 'user/getUserProfile'
userProfile: 'user/getUserProfile',
isShipNowDisabled: 'user/isShipNowDisabled'
})
},
data() {
Expand Down

0 comments on commit e158ba3

Please sign in to comment.