diff --git a/src/components/ArchivedRoutingModal.vue b/src/components/ArchivedRoutingModal.vue new file mode 100644 index 0000000..a0f2508 --- /dev/null +++ b/src/components/ArchivedRoutingModal.vue @@ -0,0 +1,66 @@ + + + + + + + + + {{ "Archived Routes" }} + + + + + + + {{ routing.routingName }} + {{ "Unarchive" }} + + + + {{ "No archived routings" }} + + + + + diff --git a/src/services/RoutingService.ts b/src/services/RoutingService.ts index 27631ba..e0ec91a 100644 --- a/src/services/RoutingService.ts +++ b/src/services/RoutingService.ts @@ -35,6 +35,14 @@ const fetchOrderRoutings = async (payload: any): Promise => { }); } +const updateOrderRouting = async (payload: any): Promise => { + return api({ + url: `routings/${payload.orderRoutingId}`, + method: "POST", + data: payload + }) +} + const createRoutingRule = async (payload: any): Promise => { let routingRuleId = ''; try { @@ -56,23 +64,11 @@ const createRoutingRule = async (payload: any): Promise => { } const createOrderRouting = async (payload: any): Promise => { - let orderRoutingId = ''; - try { - const resp = await api({ - url: "routings", - method: "POST", - data: payload - }) - - if(!hasError(resp) && resp?.data.orderRoutingId) { - orderRoutingId = resp.data.orderRoutingId - } - } catch(err) { - showToast("Failed to create new route") - logger.error(err) - } - - return orderRoutingId + return await api({ + url: "routings", + method: "POST", + data: payload + }) } const fetchRoutingRules = async (payload: any): Promise => { @@ -117,5 +113,6 @@ export const OrderRoutingService = { fetchRoutingRules, fetchRuleActions, fetchRuleConditions, + updateOrderRouting, updateRoutingGroup } \ No newline at end of file diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index 82443cc..50f2dc5 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 { Group, RouteFilter } from "@/types" +import { Group, Route, RouteFilter } from "@/types" const actions: ActionTree = { async fetchOrderRoutingGroups({ commit }) { @@ -50,6 +50,33 @@ const actions: ActionTree = { } }, + 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 setCurrentRoutingGroupId({ commit }, payload) { commit(types.ORDER_ROUTING_CURRENT_GROUP_UPDATED, payload) }, @@ -80,6 +107,73 @@ const actions: ActionTree = { commit(types.ORDER_ROUTINGS_UPDATED, orderRoutings) }, + 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 + }) + 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) + } + + 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, + [field]: payload.value // only one field can be updated once for orderRouting + } + + try { + const resp = await OrderRoutingService.updateOrderRouting(params); + + if(!hasError(resp) && resp.data.orderRoutingId) { + orderRoutingId = resp.data.orderRoutingId + orderRoutings.map((routing: Route) => { + if(routing.orderRoutingId === orderRoutingId) { + routing[field] = payload.value + } + }) + showToast("Order routing information updated") + } else { + throw resp.data + } + } catch(err) { + showToast("Failed to update order routing") + logger.error(err); + } + + if(orderRoutings.length) { + orderRoutings = sortSequence(orderRoutings) + } + + commit(types.ORDER_ROUTINGS_UPDATED, orderRoutings) + return orderRoutingId; + }, + async fetchRoutingRules({ commit }, orderRoutingId) { let routingRules = [] as any; // filter groups on the basis of productStoreId @@ -144,33 +238,6 @@ 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/theme/variables.css b/src/theme/variables.css index bec267e..b41b219 100644 --- a/src/theme/variables.css +++ b/src/theme/variables.css @@ -254,6 +254,23 @@ http://ionicframework.com/docs/theming/ */ } } +.empty-state { + max-width: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 10px; +} + +.empty-state > img { + object-fit: contain; +} + +.empty-state > p { + text-align: center; +} + @media (prefers-color-scheme: dark) { ion-chip > ion-icon { color: var(--ion-color-dark); diff --git a/src/types/index.ts b/src/types/index.ts index a216dee..cd12740 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -34,7 +34,8 @@ type Route = { description: string, createdByUser: string, createdDate: string, - lastUpdatedStamp: string + lastUpdatedStamp: string, + [key: string]: string | number } type Rule = { diff --git a/src/views/BrokeringRoute.vue b/src/views/BrokeringRoute.vue index 7dae7e3..8727dfd 100644 --- a/src/views/BrokeringRoute.vue +++ b/src/views/BrokeringRoute.vue @@ -19,24 +19,32 @@ - - - - {{ routing.routingName }} - - {{ `${routing.sequenceNum}/4` }} - - - {{ routingStatus[routing.statusId]?.desc || routing.statusId }} - - {{ "Archive" }} - - - - + + + + + {{ routing.routingName }} + + + + {{ `${index + 1}/${routingsForReorder.length}` }} + + + + + + {{ routingStatus[routing.statusId]?.desc || routing.statusId }} + {{ routingStatus[routing.statusId]?.desc || routing.statusId }} + + {{ "Archive" }} + + + + + - + {{ "Archive" }} {{ getArchivedOrderRoutings().length }}{{ " rules" }} @@ -47,14 +55,13 @@ {{ "Description" }} - - {{ "Edit" }} + + {{ isDescUpdating ? "Save" : "Edit" }} - - {{ currentRoutingGroup.description ? currentRoutingGroup.description : "No description available" }} - + + {{ description }} + + + + +
+ {{ "No archived routings" }} +