@@ -22,6 +22,7 @@ import Metrics from 'widgets/ClusterConfigForm/Sections/Metrics';
2222import CustomAuthentication from 'widgets/ClusterConfigForm/Sections/CustomAuthentication' ;
2323import Authentication from 'widgets/ClusterConfigForm/Sections/Authentication/Authentication' ;
2424import KSQL from 'widgets/ClusterConfigForm/Sections/KSQL' ;
25+ import { useConfirm } from 'lib/hooks/useConfirm' ;
2526
2627interface ClusterConfigFormProps {
2728 hasCustomConfig ?: boolean ;
@@ -52,12 +53,36 @@ const ClusterConfigForm: React.FC<ClusterConfigFormProps> = ({
5253
5354 const validate = useValidateAppConfig ( ) ;
5455 const update = useUpdateAppConfig ( { initialName : initialValues . name } ) ;
56+ const deleteCluster = useUpdateAppConfig ( {
57+ initialName : initialValues . name ,
58+ deleteCluster : true ,
59+ } ) ;
60+ const confirm = useConfirm ( true ) ;
61+
5562 const {
5663 value : isFormDisabled ,
5764 setTrue : disableForm ,
5865 setFalse : enableForm ,
5966 } = useBoolean ( ) ;
6067
68+ const confirmClusterDelete = ( ) =>
69+ confirm ( 'Are you sure want to delete this cluster?' , async ( ) => {
70+ if ( initialValues . name ) {
71+ const data = methods . getValues ( ) ;
72+ const config = transformFormDataToPayload ( data ) ;
73+ try {
74+ await deleteCluster . mutateAsync ( config ) ;
75+ navigate ( '/' ) ;
76+ } catch ( error ) {
77+ showAlert ( 'error' , {
78+ id : 'app-config-update-error' ,
79+ title : 'Error updating application config' ,
80+ message : 'There was an error updating the application config' ,
81+ } ) ;
82+ }
83+ }
84+ } ) ;
85+
6186 const onSubmit = async ( data : ClusterConfigFormValues ) => {
6287 const config = transformFormDataToPayload ( data ) ;
6388 try {
@@ -146,6 +171,16 @@ const ClusterConfigForm: React.FC<ClusterConfigFormProps> = ({
146171 >
147172 Submit
148173 </ Button >
174+ { initialValues . name && (
175+ < Button
176+ buttonSize = "L"
177+ buttonType = "danger"
178+ inProgress = { deleteCluster . isLoading }
179+ onClick = { confirmClusterDelete }
180+ >
181+ Delete
182+ </ Button >
183+ ) }
149184 </ S . ButtonWrapper >
150185 </ FlexFieldset >
151186 </ StyledForm >
0 commit comments