Skip to content

Commit

Permalink
Implemented: support to archive an route and fixed wrong number being…
Browse files Browse the repository at this point in the history
… displayed
  • Loading branch information
ymaheshwari1 committed Jan 19, 2024
1 parent ed773e2 commit e35e12f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
23 changes: 16 additions & 7 deletions src/store/modules/orderRouting/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,38 @@ const actions: ActionTree<OrderRoutingState, RootState> = {

async createOrderRouting({ commit, state }, payload) {
let orderRoutings = JSON.parse(JSON.stringify(state.routes))
let orderRoutingId = ''

try {
const resp = await OrderRoutingService.createOrderRouting(payload)

if(!hasError(resp) && resp?.data.orderRoutingId) {
orderRoutingId = resp.data.orderRoutingId
orderRoutings.push({
...payload,
orderRoutingId: resp.data.orderRoutingId
orderRoutingId
})
showToast('New Order Routing Created')
}

// Sort the routings and update the state only on success
if(orderRoutings.length) {
orderRoutings = sortSequence(orderRoutings)
}

commit(types.ORDER_ROUTINGS_UPDATED, orderRoutings)
} catch(err) {
showToast("Failed to create order routing")
logger.error('err', err)
}

if(orderRoutings.length) {
orderRoutings = sortSequence(orderRoutings)
}

commit(types.ORDER_ROUTINGS_UPDATED, orderRoutings)
return orderRoutingId;
},

async updateOrderRouting({ commit, state }, payload) {
let orderRoutings = JSON.parse(JSON.stringify(state.routes))
const field: Route[keyof Route] = payload.fieldToUpdate
let orderRoutingId = ''

const params = {
orderRoutingId: payload.orderRoutingId,
Expand All @@ -145,8 +151,9 @@ const actions: ActionTree<OrderRoutingState, RootState> = {
const resp = await OrderRoutingService.updateOrderRouting(params);

if(!hasError(resp) && resp.data.orderRoutingId) {
orderRoutingId = resp.data.orderRoutingId
orderRoutings.map((routing: Route) => {
if(routing.orderRoutingId === resp.data.orderRoutingId) {
if(routing.orderRoutingId === orderRoutingId) {
routing[field] = payload.value
}
})
Expand All @@ -155,6 +162,7 @@ const actions: ActionTree<OrderRoutingState, RootState> = {
throw resp.data
}
} catch(err) {
showToast("Failed to update order routing")
logger.error(err);
}

Expand All @@ -163,6 +171,7 @@ const actions: ActionTree<OrderRoutingState, RootState> = {
}

commit(types.ORDER_ROUTINGS_UPDATED, orderRoutings)
return orderRoutingId;
},

async fetchRoutingRules({ commit }, orderRoutingId) {
Expand Down
31 changes: 24 additions & 7 deletions src/views/BrokeringRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
</ion-button>
</ion-list-header>
<ion-reorder-group @ionItemReorder="doReorder($event)" :disabled="false">
<ion-card v-for="(routing, index) in routingsForReorder" :key="routing.orderRoutingId" @click="redirect(routing.orderRoutingId)">
<ion-card v-for="(routing, index) in routingsForReorder" :key="routing.orderRoutingId" @click.prevent="redirect(routing.orderRoutingId)">
<ion-item lines="full">
<ion-label>
<h1>{{ routing.routingName }}</h1>
</ion-label>
<ion-chip outline>
<ion-label>{{ `${index}/4` }}</ion-label>
<ion-label>{{ `${index + 1}/4` }}</ion-label>
<ion-reorder></ion-reorder>
</ion-chip>
</ion-item>
<ion-item>
<ion-badge :color="routingStatus[routing.statusId]?.color">{{ routingStatus[routing.statusId]?.desc || routing.statusId }}</ion-badge>
<ion-button fill="clear" color="medium" slot="end">
<ion-button fill="clear" color="medium" slot="end" @click.stop="updateOrderRouting(routing, 'statusId', 'ROUTING_ARCHIVED')">
{{ "Archive" }}
<ion-icon :icon="archiveOutline" />
</ion-button>
Expand Down Expand Up @@ -121,15 +121,20 @@ const orderRoutings = computed(() => store.getters["orderRouting/getOrderRouting
onIonViewWillEnter(async () => {
await store.dispatch("orderRouting/fetchOrderRoutings", props.routingGroupId)
initialRoutingsOrder.value = JSON.parse(JSON.stringify(getActiveAndDraftOrderRoutings()))
routingsForReorder.value = JSON.parse(JSON.stringify(getActiveAndDraftOrderRoutings()))
initializeOrderRoutings();
// On refresh, the groups list is removed thus resulting is not fetching the current group information
if(!currentRoutingGroup.value.routingGroupId) {
await store.dispatch("orderRouting/fetchOrderRoutingGroups")
}
})
function initializeOrderRoutings() {
initialRoutingsOrder.value = JSON.parse(JSON.stringify(getActiveAndDraftOrderRoutings()))
routingsForReorder.value = JSON.parse(JSON.stringify(getActiveAndDraftOrderRoutings()))
}
async function redirect(orderRoutingId: string) {
await store.dispatch('orderRouting/setCurrentOrderRoutingId', orderRoutingId)
router.push(`${orderRoutingId}/rules`)
Expand Down Expand Up @@ -164,11 +169,16 @@ async function createOrderRoute() {
routingGroupId: props.routingGroupId,
statusId: "ROUTING_DRAFT",
routingName,
sequenceNum: 0,
sequenceNum: orderRoutings.value.length && orderRoutings.value[orderRoutings.value.length - 1].sequenceNum >= 0 ? orderRoutings.value[orderRoutings.value.length - 1].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new route seqNum to 0
description: ""
}
await store.dispatch("orderRouting/createOrderRouting", payload)
const orderRoutingId = await store.dispatch("orderRouting/createOrderRouting", payload)
// update the routing order for reordering
if(orderRoutingId) {
initializeOrderRoutings();
}
}
})
Expand Down Expand Up @@ -252,6 +262,13 @@ async function openArchivedRoutingModal() {
})
archivedRoutingModal.present();
}
async function updateOrderRouting(routing: Route, fieldToUpdate: string, value: string) {
const orderRoutingId = await store.dispatch("orderRouting/updateOrderRouting", { orderRoutingId: routing.orderRoutingId, fieldToUpdate, value })
if(orderRoutingId) {
initializeOrderRoutings()
}
}
</script>

<style scoped>
Expand Down

0 comments on commit e35e12f

Please sign in to comment.