11/* eslint-disable dot-notation */
2- import { Box , Button , Divider , Grid } from '@mui/material'
2+ import { Box , Divider , Grid } from '@mui/material'
33import { LandingHeader } from 'components/LandingHeader'
44import PaperLayout from 'layouts/Paper'
55import React , { useEffect , useMemo , useState } from 'react'
@@ -27,11 +27,12 @@ import { MenuItem } from 'components/List'
2727import { Typography } from 'components/Typography'
2828import KeyValue from 'components/forms/KeyValue'
2929import ControlledCheckbox from 'components/forms/ControlledCheckbox'
30- import { isEmpty } from 'lodash'
30+ import { cloneDeep , isEmpty , isEqual } from 'lodash'
3131import LinkedNumberField from 'components/forms/LinkedNumberField'
3232import AdvancedSettings from 'components/AdvancedSettings'
3333import font from 'theme/font'
3434import { Autocomplete } from 'components/forms/Autocomplete'
35+ import { LoadingButton } from '@mui/lab'
3536import { useStyles } from './create-edit.styles'
3637import { serviceApiResponseSchema } from './create-edit.validator'
3738
@@ -143,6 +144,8 @@ export default function ({
143144 if ( path . includes ( '/' ) ) setValue ( `spec.paths.${ index } ` , path . replace ( / ^ \/ + / , '' ) )
144145 } )
145146 }
147+
148+ if ( teamId !== 'admin' && ! serviceName ) setValue ( 'spec.namespace' , `team-${ teamId } ` )
146149 } , [ data , setValue ] )
147150
148151 useEffect ( ( ) => {
@@ -181,17 +184,20 @@ export default function ({
181184 }
182185 }
183186 const onSubmit = ( submitData : CreateAplServiceApiResponse ) => {
184- if ( ! isEmpty ( submitData . spec ?. paths ) ) {
185- submitData . spec ?. paths . forEach ( ( path , index ) => {
186- submitData . spec . paths [ index ] = `/${ path } `
187+ const body = cloneDeep ( submitData )
188+ if ( ! isEmpty ( body . spec ?. paths ) ) {
189+ body . spec ?. paths . forEach ( ( path , index ) => {
190+ body . spec . paths [ index ] = `/${ path } `
187191 } )
188192 }
189- if ( submitData . spec ?. cname ?. tlsSecretName === '' ) submitData . spec . cname . tlsSecretName = undefined
190- if ( submitData . spec ?. ingressClassName === '' ) submitData . spec . ingressClassName = undefined
191- if ( isPreInstalled ) submitData . spec . ingressClassName = 'platform'
192- // eslint-disable-next-line object-shorthand
193- if ( serviceName ) update ( { teamId, serviceName : serviceName , body : submitData } )
194- else create ( { teamId, body : submitData } )
193+ if ( body . spec ?. cname ?. tlsSecretName === '' ) {
194+ body . spec . cname . tlsSecretName = undefined
195+ body . spec . useCname = false
196+ } else if ( body . spec ?. cname ?. tlsSecretName ) body . spec . useCname = true
197+
198+ if ( body . spec ?. ingressClassName === '' ) body . spec . ingressClassName = undefined
199+ if ( serviceName ) update ( { teamId, serviceName, body } )
200+ else create ( { teamId, body } )
195201 }
196202 const mutating = isLoadingCreate || isLoadingUpdate || isLoadingDelete
197203 if ( ! mutating && ( isSuccessCreate || isSuccessUpdate || isSuccessDelete ) )
@@ -202,7 +208,7 @@ export default function ({
202208 const error = isError || isErrorK8sServices || isErrorTeamSecrets || isErrorSettingsInfo
203209
204210 if ( loading || fetching ) return < PaperLayout loading title = { t ( 'TITLE_SERVICE' ) } />
205- if ( teamId !== 'admin' ) setValue ( 'spec.namespace' , `team- ${ teamId } ` )
211+
206212 return (
207213 < Grid className = { classes . root } >
208214 < PaperLayout loading = { loading || error } title = { t ( 'TITLE_SERVICE' ) } >
@@ -454,17 +460,20 @@ export default function ({
454460 resourceType = 'service'
455461 data-cy = 'button-delete-service'
456462 sx = { { marginRight : '10px' , textTransform : 'capitalize' , ml : 2 } }
463+ loading = { isLoadingDelete }
464+ disabled = { isLoadingDelete || isLoadingCreate || isLoadingUpdate }
457465 />
458466 ) }
459- < Button
460- disabled = { isEmpty ( service ) }
467+ < LoadingButton
461468 type = 'submit'
462469 variant = 'contained'
463470 color = 'primary'
464471 sx = { { textTransform : 'none' } }
472+ loading = { isLoadingCreate || isLoadingUpdate }
473+ disabled = { isLoadingCreate || isLoadingUpdate || isLoadingDelete || isEqual ( watch ( ) , data ) }
465474 >
466475 { serviceName ? 'Save Changes' : 'Create Service' }
467- </ Button >
476+ </ LoadingButton >
468477 </ Box >
469478 </ form >
470479 </ FormProvider >
0 commit comments