diff --git a/src/services/RoutingService.ts b/src/services/RoutingService.ts index 26d7c35..1ee5ad8 100644 --- a/src/services/RoutingService.ts +++ b/src/services/RoutingService.ts @@ -4,10 +4,19 @@ const fetchRoutingGroups = async (payload: any): Promise => { return api({ url: "groups", method: "GET", - data: payload + query: payload }); } +const createRoutingGroup = async (payload: any): Promise => { + return api({ + url: "groups", + method: "POST", + data: payload + }) +} + export const OrderRoutingService = { + createRoutingGroup, fetchRoutingGroups } \ No newline at end of file diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index 7368461..605510d 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -2,7 +2,7 @@ import { ActionTree } from "vuex" import RootState from "@/store/RootState" import OrderRoutingState from "./OrderRoutingState" import { OrderRoutingService } from "@/services/RoutingService" -import { hasError, sortSequence } from "@/utils" +import { hasError, showToast, sortSequence } from "@/utils" import * as types from './mutation-types' const actions: ActionTree = { @@ -28,6 +28,24 @@ const actions: ActionTree = { } commit(types.ORDER_ROUTING_GROUPS_UPDATED, routingGroups) + }, + + async createBrokeringGroup({ dispatch }, groupName) { + const payload = { + groupName, + productStoreId: "STORE" + } + try { + const resp = await OrderRoutingService.createRoutingGroup(payload) + + if(!hasError(resp)) { + showToast('Brokering run created') + dispatch("fetchOrderRoutingGroups") + } + } catch(err) { + showToast("Failed to create brokering run") + console.log('err', err) + } } } diff --git a/src/views/BrokeringRuns.vue b/src/views/BrokeringRuns.vue index e9b941e..46148cc 100644 --- a/src/views/BrokeringRuns.vue +++ b/src/views/BrokeringRuns.vue @@ -75,6 +75,12 @@ async function addNewRun() { }] }) + newRunAlert.onDidDismiss().then((result: any) => { + if(result.data?.values?.runName) { + store.dispatch('orderRouting/createBrokeringGroup', result.data.values.runName) + } + }) + return newRunAlert.present(); }