From fc72f6389abb1c66deab9bc40c2bdcf78ce5c9b9 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Thu, 18 Jan 2024 19:32:13 +0530 Subject: [PATCH] Implemented: support to edit the description for the group --- src/services/RoutingService.ts | 11 +++++++- src/store/modules/orderRouting/actions.ts | 29 ++++++++++++++++++- src/views/BrokeringRoute.vue | 34 ++++++++++++++++++++++- 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/services/RoutingService.ts b/src/services/RoutingService.ts index 2c42afa..27631ba 100644 --- a/src/services/RoutingService.ts +++ b/src/services/RoutingService.ts @@ -19,6 +19,14 @@ const createRoutingGroup = async (payload: any): Promise => { }) } +const updateRoutingGroup = async (payload: any): Promise => { + return api({ + url: `groups/${payload.routingGroupId}`, + method: "POST", + data: payload + }) +} + const fetchOrderRoutings = async (payload: any): Promise => { return api({ url: `groups/${payload.routingGroupId}/routings`, @@ -108,5 +116,6 @@ export const OrderRoutingService = { fetchRoutingGroups, fetchRoutingRules, fetchRuleActions, - fetchRuleConditions + fetchRuleConditions, + updateRoutingGroup } \ No newline at end of file diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index d1ccee6..82443cc 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -5,7 +5,7 @@ import { OrderRoutingService } from "@/services/RoutingService" import { hasError, showToast, sortSequence } from "@/utils" import * as types from './mutation-types' import logger from "@/logger" -import { RouteFilter } from "@/types" +import { Group, RouteFilter } from "@/types" const actions: ActionTree = { async fetchOrderRoutingGroups({ commit }) { @@ -144,6 +144,33 @@ const actions: ActionTree = { commit(types.ORDER_ROUTING_FILTERS_UPDATED, routingFilters) }, + async updateRoutingGroup({ commit, state }, payload) { + let routingGroups = JSON.parse(JSON.stringify(state.groups)) + + try { + const resp = await OrderRoutingService.updateRoutingGroup(payload); + + if(!hasError(resp) && resp.data.routingGroupId) { + routingGroups.map((group: Group) => { + if(group.routingGroupId === resp.data.routingGroupId) { + group.description = payload.description + } + }) + showToast("Rounting group information updated") + } else { + throw resp.data + } + } catch(err) { + logger.error(err); + } + + if(routingGroups.length) { + routingGroups = sortSequence(routingGroups) + } + + commit(types.ORDER_ROUTING_GROUPS_UPDATED, routingGroups) + }, + async fetchRuleConditions({ commit }, routingRuleId) { let ruleConditions = [] as any; // filter groups on the basis of productStoreId diff --git a/src/views/BrokeringRoute.vue b/src/views/BrokeringRoute.vue index 0a901be..7dae7e3 100644 --- a/src/views/BrokeringRoute.vue +++ b/src/views/BrokeringRoute.vue @@ -47,7 +47,7 @@
{{ "Description" }} - + {{ "Edit" }} @@ -167,6 +167,38 @@ function getActiveAndDraftOrderRoutings() { function getArchivedOrderRoutings() { return orderRoutings.value.filter((routing: Route) => routing.statusId === 'ROUTING_ARCHIVED') } + +async function updateGroupDescription() { + const newRouteAlert = await alertController.create({ + header: "Add Group Description", + buttons: [{ + text: "Cancel", + role: "cancel" + }, { + text: "Save" + }], + inputs: [{ + type: "textarea", + name: "groupDescription", + placeholder: "description" + }] + }) + + newRouteAlert.onDidDismiss().then(async (result: any) => { + const groupDescription = result.data?.values?.groupDescription; + if(groupDescription && props.routingGroupId) { + // TODO: check for the default value of params + const payload = { + routingGroupId: props.routingGroupId, + description: groupDescription, + } + + await store.dispatch("orderRouting/updateRoutingGroup", payload) + } + }) + + return newRouteAlert.present(); +}