Skip to content

Commit

Permalink
Implemented: support to edit the description for the group
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed Jan 18, 2024
1 parent 22d7433 commit fc72f63
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/services/RoutingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ const createRoutingGroup = async (payload: any): Promise<any> => {
})
}

const updateRoutingGroup = async (payload: any): Promise<any> => {
return api({
url: `groups/${payload.routingGroupId}`,
method: "POST",
data: payload
})
}

const fetchOrderRoutings = async (payload: any): Promise<any> => {
return api({
url: `groups/${payload.routingGroupId}/routings`,
Expand Down Expand Up @@ -108,5 +116,6 @@ export const OrderRoutingService = {
fetchRoutingGroups,
fetchRoutingRules,
fetchRuleActions,
fetchRuleConditions
fetchRuleConditions,
updateRoutingGroup
}
29 changes: 28 additions & 1 deletion src/store/modules/orderRouting/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OrderRoutingState, RootState> = {
async fetchOrderRoutingGroups({ commit }) {
Expand Down Expand Up @@ -144,6 +144,33 @@ const actions: ActionTree<OrderRoutingState, RootState> = {
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
Expand Down
34 changes: 33 additions & 1 deletion src/views/BrokeringRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<main>
<ion-item lines="none">
{{ "Description" }}
<ion-button fill="clear" slot="end">
<ion-button fill="clear" slot="end" @click="updateGroupDescription()">
{{ "Edit" }}
</ion-button>
</ion-item>
Expand Down Expand Up @@ -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();
}
</script>

<style scoped>
Expand Down

0 comments on commit fc72f63

Please sign in to comment.