diff --git a/ui/src/components/Common/AddStack/addStack.tsx b/ui/src/components/Common/AddStack/addStack.tsx index 2d206bd90..99798ea50 100644 --- a/ui/src/components/Common/AddStack/addStack.tsx +++ b/ui/src/components/Common/AddStack/addStack.tsx @@ -56,7 +56,7 @@ const AddStack = (props: any): JSX.Element => { locale: formData?.locale?.value || props?.defaultValues?.locale }); - if (resp) { + if (resp === true) { Notification({ notificationContent: { text: 'Stack created successfully' }, notificationProps: { @@ -67,8 +67,9 @@ const AddStack = (props: any): JSX.Element => { }); props?.closeModal(); } else { + Notification({ - notificationContent: { text: 'Stack creation failed. Please try again.' }, + notificationContent: { text: resp }, notificationProps: { position: 'bottom-center', hideProgressBar: true diff --git a/ui/src/components/DestinationStack/Actions/LoadStacks.tsx b/ui/src/components/DestinationStack/Actions/LoadStacks.tsx index 89dc581e3..e52284c24 100644 --- a/ui/src/components/DestinationStack/Actions/LoadStacks.tsx +++ b/ui/src/components/DestinationStack/Actions/LoadStacks.tsx @@ -35,6 +35,15 @@ interface LoadFileFormatProps { handleStepChange: (stepIndex: number, closeStep?: boolean) => void; } +interface ErrorObject { + error_message?: string; + errors?: Errors; +} +interface Errors { + org_uid?: string[]; +} + + const defaultStack = { description: 'Created from Migration Destination Stack Step', locale: '', @@ -108,6 +117,21 @@ const LoadStacks = (props: LoadFileFormatProps) => { // setAllStack(newMigrationData?.destination_stack?.stackArray) }, [newMigrationData?.destination_stack?.selectedStack]); + /** + * Function to format the error message + */ + const formatErrorMessage = (errorData: ErrorObject) => { + let message = errorData.error_message; + + if (errorData.errors) { + Object.entries(errorData.errors).forEach(([key, value]) => { + message += `\n${key}: ${(value as string[]).join(", ")}`; + }); + } + + return message; + } + //Handle new stack details const handleOnSave = async (data: Stack) => { try { @@ -159,8 +183,12 @@ const LoadStacks = (props: LoadFileFormatProps) => { setIsStackLoading(false); return true; } - } catch (error) { - return error; + else { + const errorMessage = formatErrorMessage(resp?.data?.data); + return errorMessage; + } + } catch (error: any) { + return error?.response?.data; } }; diff --git a/ui/src/components/LegacyCms/Actions/LoadPrefix.tsx b/ui/src/components/LegacyCms/Actions/LoadPrefix.tsx index 29369aac5..d9e4e9eee 100644 --- a/ui/src/components/LegacyCms/Actions/LoadPrefix.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadPrefix.tsx @@ -106,23 +106,7 @@ const LoadPreFix = (props: LoadSelectCmsProps) => { } }); - const handleOnBlur = (value: string) => { - if (isEmptyString(value?.trim())) { - setIsError(false); - setErrorMessage(''); - setIsRestrictedKey(false); - setPrefix('cs'); - const newMigrationDataObj: INewMigration = { - ...newMigrationData, - legacy_cms: { - ...newMigrationData?.legacy_cms, - affix: 'cs', - isRestictedKeywordCheckboxChecked: isCheckedBoxChecked - } - }; - dispatch(updateNewMigrationData(newMigrationDataObj)); - } - }; + /**** ALL USEEffects HERE ****/ @@ -144,9 +128,7 @@ const LoadPreFix = (props: LoadSelectCmsProps) => { aria-label="affix" disabled={newMigrationData?.legacy_cms?.uploadedFile?.isValidated} isReadOnly={newMigrationData?.legacy_cms?.uploadedFile?.isValidated} - onBlur={(e: React.FocusEvent) => { - handleOnBlur(e.target.value); - }} + /> {isError &&

{errorMessage}

} diff --git a/ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx b/ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx index 6008eba64..f6a1ef67f 100644 --- a/ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx @@ -536,7 +536,7 @@ const LoadUploadFile = ( props: LoadUploadFileProps ) => { setValidationMessage( '' ); } - if ( !newMigrationData?.legacy_cms?.uploadedFile?.isValidated && !newMigrationData?.legacy_cms?.uploadedFile?.reValidate ) + if (!isEmptyString(newMigrationData?.legacy_cms?.affix) && !newMigrationData?.legacy_cms?.uploadedFile?.isValidated && !newMigrationData?.legacy_cms?.uploadedFile?.reValidate ) { setIsDisabled( false ); } @@ -630,7 +630,7 @@ const LoadUploadFile = ( props: LoadUploadFileProps ) => isLoading={ isLoading } loadingColor="#6c5ce7" version="v2" - disabled={ !( reValidate || ( !isDisabled ) ) } + disabled={!(reValidate || (!isDisabled && !isEmptyString(newMigrationData?.legacy_cms?.affix)))} > { fileFormat?.toLowerCase() === 'sql' ? 'Check Connection' : 'File Validate' } diff --git a/ui/src/components/LegacyCms/index.tsx b/ui/src/components/LegacyCms/index.tsx index 0e3a1b202..35275e0b8 100644 --- a/ui/src/components/LegacyCms/index.tsx +++ b/ui/src/components/LegacyCms/index.tsx @@ -198,11 +198,12 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll //Make Step 2 complete if ( !isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id) + && !isEmptyString(newMigrationData?.legacy_cms?.affix) ) { setInternalActiveStepIndex(1); } - if(!isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id) && newMigrationData?.legacy_cms?.uploadedFile?.isValidated){ + if(!isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id) && newMigrationData?.legacy_cms?.uploadedFile?.isValidated && !isEmptyString(newMigrationData?.legacy_cms?.affix)){ setInternalActiveStepIndex(3); } setisProjectMapped(newMigrationData?.isprojectMapped) @@ -212,7 +213,7 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll useEffect(()=>{ if( !isEmptyString(newMigrationData?.legacy_cms?.selectedFileFormat?.title) && ! isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.title) && - newMigrationData?.legacy_cms?.uploadedFile?.isValidated){ + newMigrationData?.legacy_cms?.uploadedFile?.isValidated && !isEmptyString(newMigrationData?.legacy_cms?.affix) && !isEmptyString(newMigrationData?.legacy_cms?.selectedFileFormat?.fileformat_id)){ setIsAllStepsCompleted(true); handleAllStepsComplete(true); }