@@ -26,6 +26,8 @@ import {
2626    usePrompt , 
2727    checkIfPathIsMatching , 
2828    useUrlFilters , 
29+     UseFormErrorHandler , 
30+     UseFormSubmitHandler , 
2931}  from  '@devtron-labs/devtron-fe-common-lib' 
3032
3133import  {  URLS  }  from  '@Config/routes' 
@@ -682,7 +684,7 @@ export const ConfigMapSecretContainer = ({
682684        } 
683685    } 
684686
685-     const  onSubmit : ConfigMapSecretFormProps [ 'onSubmit' ]  =  async  ( data )  =>  { 
687+     const  onSubmit : UseFormSubmitHandler < ConfigMapSecretUseFormProps >  =  async  ( data )  =>  { 
686688        const  payloadData  =  getConfigMapSecretPayload ( data ) 
687689
688690        if  ( isApprovalPolicyConfigured )  { 
@@ -739,7 +741,7 @@ export const ConfigMapSecretContainer = ({
739741        } 
740742    } 
741743
742-     const  onError : ConfigMapSecretFormProps [ 'onError' ]  =  ( errors )  =>  { 
744+     const  onError : UseFormErrorHandler < ConfigMapSecretUseFormProps >  =  ( errors )  =>  { 
743745        if  ( errors . currentData ?. [ 0 ]  ===  CONFIG_MAP_SECRET_NO_DATA_ERROR )  { 
744746            ToastManager . showToast ( { 
745747                variant : ToastVariantType . error , 
@@ -755,6 +757,19 @@ export const ConfigMapSecretContainer = ({
755757        } 
756758    } 
757759
760+     const  onDryRunError : UseFormErrorHandler < ConfigMapSecretUseFormProps >  =  ( errors )  =>  { 
761+         const  hasErrors  =  Object . keys ( errors ) . some ( ( key )  =>  ! ! errors [ key ] ) 
762+         if  ( hasErrors )  { 
763+             ToastManager . showToast ( { 
764+                 variant : ToastVariantType . error , 
765+                 description : 'Please resolve form errors before saving.' , 
766+             } ) 
767+         } 
768+     } 
769+ 
770+     const  formSubmitHandler  =  handleSubmit ( onSubmit ,  onError ) 
771+     const  dryRunSubmitHandler  =  handleSubmit ( onSubmit ,  onDryRunError ) 
772+ 
758773    // CONFIG TOOLBAR POPUP MENU 
759774    const  toolbarPopupConfig : ConfigToolbarProps [ 'popupConfig' ]  =  { 
760775        menuConfig : getConfigToolbarPopupConfig ( { 
@@ -802,8 +817,7 @@ export const ConfigMapSecretContainer = ({
802817                draftData = { resolvedDraftData  ??  draftData } 
803818                inheritedConfigMapSecretData = { resolvedInheritedConfigMapSecretData  ??  inheritedConfigMapSecretData } 
804819                id = { id } 
805-                 onError = { onError } 
806-                 onSubmit = { onSubmit } 
820+                 onSubmit = { formSubmitHandler } 
807821                selectedProtectionViewTab = { selectedProtectionViewTab } 
808822                updateCMSecret = { updateCMSecret } 
809823                componentType = { componentType } 
@@ -826,8 +840,7 @@ export const ConfigMapSecretContainer = ({
826840                isApprovalPolicyConfigured = { isApprovalPolicyConfigured } 
827841                isSubmitting = { isSubmitting } 
828842                disableDataTypeChange = { isDeleteDisabled } 
829-                 onSubmit = { onSubmit } 
830-                 onError = { onError } 
843+                 onSubmit = { formSubmitHandler } 
831844                onCancel = { onCancel } 
832845                areScopeVariablesResolving = { resolvedScopeVariablesResLoading } 
833846                appChartRef = { appChartRef } 
@@ -886,7 +899,7 @@ export const ConfigMapSecretContainer = ({
886899                        handleChangeDryRunEditorMode = { setDryRunEditorMode } 
887900                        showCrudButtons = { ! showNoOverride } 
888901                        isSubmitting = { isSubmitting } 
889-                         onSubmit = { onSubmit } 
902+                         onSubmit = { dryRunSubmitHandler } 
890903                        parentName = { parentName } 
891904                        updateCMSecret = { updateCMSecret } 
892905                        formData = { resolvedFormData  ??  formData } 
0 commit comments