From e35e12fb7eb279fcfb4fa299730e07a6b1d9cd78 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 19 Jan 2024 15:16:35 +0530 Subject: [PATCH] Implemented: support to archive an route and fixed wrong number being displayed --- src/store/modules/orderRouting/actions.ts | 23 ++++++++++++----- src/views/BrokeringRoute.vue | 31 ++++++++++++++++++----- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index 0ed1e32..50f2dc5 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -109,32 +109,38 @@ const actions: ActionTree = { 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, @@ -145,8 +151,9 @@ const actions: ActionTree = { 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 } }) @@ -155,6 +162,7 @@ const actions: ActionTree = { throw resp.data } } catch(err) { + showToast("Failed to update order routing") logger.error(err); } @@ -163,6 +171,7 @@ const actions: ActionTree = { } commit(types.ORDER_ROUTINGS_UPDATED, orderRoutings) + return orderRoutingId; }, async fetchRoutingRules({ commit }, orderRoutingId) { diff --git a/src/views/BrokeringRoute.vue b/src/views/BrokeringRoute.vue index c2440ca..9291873 100644 --- a/src/views/BrokeringRoute.vue +++ b/src/views/BrokeringRoute.vue @@ -20,19 +20,19 @@ - +

{{ routing.routingName }}

- {{ `${index}/4` }} + {{ `${index + 1}/4` }}
{{ routingStatus[routing.statusId]?.desc || routing.statusId }} - + {{ "Archive" }} @@ -121,8 +121,8 @@ 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) { @@ -130,6 +130,11 @@ onIonViewWillEnter(async () => { } }) +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`) @@ -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(); + } } }) @@ -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() + } +}