@@ -26,59 +26,69 @@ const AddStaticRouteModal = () => {
2626 const navigate = useNavigate ( ) ;
2727 const dispatch = useDispatch ( ) ;
2828 const [ form ] = Form . useForm ( ) ;
29- const [ createStaticRoute , { error , isError, reset} ] = useCreateStaticRouteMutation ( ) ;
29+ const [ createStaticRoute , { isError, reset} ] = useCreateStaticRouteMutation ( ) ;
3030 const [ currentStep , setCurrentStep ] = useState ( 0 ) ;
3131 const step = currentStep === 0 ? 'routeInfo' : currentStep === 1 ? 'pathInfo' : 'targetInfo' ;
3232
3333 const okText = currentStep === 0 ? 'Add path' : currentStep === 1 ? 'Add target' : 'Create static route' ;
3434
3535 const onSubmitHandler = async ( ) => {
36- await form . validateFields ( ) ;
37- if ( step !== 'targetInfo' ) {
38- setCurrentStep ( currentStep + 1 ) ;
39- return ;
40- }
41- const { name, namespace, deployment, path, methods, upstream, redirect} = await form . getFieldsValue ( true ) ;
42-
43- const newStaticRouteDefinition : StaticRoute = {
44- apiVersion : 'gateway.kusk.io/v1alpha1' ,
45- kind : 'StaticRoute' ,
46- metadata : {
47- name,
48- } ,
49- spec : {
50- fleet : {
51- name : deployment . split ( ',' ) [ 1 ] ,
52- namespace : deployment . split ( ',' ) [ 0 ] ,
36+ try {
37+ await form . validateFields ( ) ;
38+ if ( step !== 'targetInfo' ) {
39+ setCurrentStep ( currentStep + 1 ) ;
40+ return ;
41+ }
42+ const { name, namespace, deployment, path, methods, upstream, redirect} = await form . getFieldsValue ( true ) ;
43+
44+ const newStaticRouteDefinition : StaticRoute = {
45+ apiVersion : 'gateway.kusk.io/v1alpha1' ,
46+ kind : 'StaticRoute' ,
47+ metadata : {
48+ name,
5349 } ,
54- hosts : [ ] ,
55- paths : {
56- [ path ] : methods . reduce ( ( acc : any , item : any ) => {
57- acc [ item ] = redirect ? { redirect} : { route : { upstream} } ;
58- return acc ;
59- } , { } ) ,
50+ spec : {
51+ fleet : {
52+ name : deployment . split ( ',' ) [ 1 ] ,
53+ namespace : deployment . split ( ',' ) [ 0 ] ,
54+ } ,
55+ hosts : [ ] ,
56+ paths : {
57+ [ path ] : methods . reduce ( ( acc : any , item : any ) => {
58+ acc [ item ] = redirect ? { redirect} : { route : { upstream} } ;
59+ return acc ;
60+ } , { } ) ,
61+ } ,
6062 } ,
61- } ,
62- } ;
63-
64- const result = await createStaticRoute ( {
65- body : {
66- name,
67- namespace,
68- envoyFleetNamespace : deployment . split ( ',' ) [ 0 ] ,
69- envoyFleetName : deployment . split ( ',' ) [ 1 ] ,
70- openapi : YAML . stringify ( newStaticRouteDefinition ) ,
71- } ,
72- } ) . unwrap ( ) ;
73- dispatch (
74- setAlert ( {
75- title : 'Static route deployed successfully' ,
76- description : `${ name } was deployed successfully in ${ namespace } namespace` ,
77- type : AlertEnum . Success ,
78- } )
79- ) ;
80- dispatch ( closeStaticRouteModal ( ) ) ;
81- navigate ( `${ AppRoutes . STATIC_ROUTE } /${ result . namespace } /${ result . name } ` ) ;
63+ } ;
64+
65+ const result = await createStaticRoute ( {
66+ body : {
67+ name,
68+ namespace,
69+ envoyFleetNamespace : deployment . split ( ',' ) [ 0 ] ,
70+ envoyFleetName : deployment . split ( ',' ) [ 1 ] ,
71+ openapi : YAML . stringify ( newStaticRouteDefinition ) ,
72+ } ,
73+ } ) . unwrap ( ) ;
74+ dispatch (
75+ setAlert ( {
76+ title : 'Static route deployed successfully' ,
77+ description : `${ name } was deployed successfully in ${ namespace } namespace` ,
78+ type : AlertEnum . Success ,
79+ } )
80+ ) ;
81+ dispatch ( closeStaticRouteModal ( ) ) ;
82+ navigate ( `${ AppRoutes . STATIC_ROUTE } /${ result . namespace } /${ result . name } ` ) ;
83+ } catch ( e : any ) {
84+ dispatch (
85+ setAlert ( {
86+ title : 'Unable to deploy Static Route' ,
87+ description : e ?. message ,
88+ type : AlertEnum . Error ,
89+ } )
90+ ) ;
91+ }
8292 } ;
8393
8494 const onBackHandler = ( ) => {
@@ -92,14 +102,13 @@ const AddStaticRouteModal = () => {
92102
93103 return (
94104 < S . Modal
95- visible
105+ open
96106 title = "Create static route"
97107 width = "824px"
98108 onCancel = { onBackHandler }
99109 okText = { okText }
100110 onOk = { onSubmitHandler }
101111 >
102- { isError && < S . Alert description = { error ?. message } message = "Error" showIcon type = "error" closable /> }
103112 < S . Container >
104113 < S . StepsContainer >
105114 < Steps direction = "vertical" current = { currentStep } >
0 commit comments