Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useParams } from 'react-router';

// Service
import { updateLegacyCMSData } from '../../../services/api/migration.service';
import { fileValidation } from '../../../services/api/upload.service';
import { fileValidation, getConfig } from '../../../services/api/upload.service';

// Utilities
import { isEmptyString, validateArray } from '../../../utilities/functions';
Expand Down Expand Up @@ -44,7 +44,7 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
const [searchText, setSearchText] = useState<string>('');
const [cmsFilterStatus, setCmsFilterStatus] = useState<IFilterStatusType>({});
const [cmsFilter, setCmsFilter] = useState<string[]>([]);
const [cmsType, setCmsType] = useState<string | null>(
const [cmsType, setCmsType] = useState<string>(
newMigrationData?.legacy_cms?.selectedCms?.title?.toLowerCase()
);

Expand All @@ -63,9 +63,10 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
}
});

await updateLegacyCMSData(selectedOrganisation?.value, projectId, { legacy_cms: cms?.cms_id });

props?.handleStepChange(props?.currentStep);

if (!isEmptyString(cms?.title)) {
props?.handleStepChange(props?.currentStep);
}
};

//Handle CMS Filter Updation in local storage.
Expand All @@ -89,10 +90,11 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
const filterCMSData = async (searchText: string) => {
const { all_cms = [] } = migrationData?.legacyCMSData || {};

const res: any = await fileValidation();
const cms = res?.data?.file_details?.cmsType?.toLowerCase();
setCmsType(cms);
const cmstype = cms; // Fetch the specific CMS type
const apiRes: any = await getConfig(); // api call to get cms type from upload service

const cms = apiRes?.data?.cmsType?.toLowerCase();

const cmstype = !isEmptyString(cmsType) ? cmsType : cms; // Fetch the specific CMS type

let filteredCmsData: ICMSType[] = [];
if (isEmptyString(searchText) && !validateArray(cmsFilter) && !cmstype) {
Expand Down Expand Up @@ -158,16 +160,6 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
}
}, [cmsType, selectedCard]);

useEffect(() => {
const getCmsType = async () => {
const res: any = await fileValidation();
const cms = res?.data?.file_details?.cmsType?.toLowerCase();
setCmsType(cms);
filterCMSData(cms);
return cmsType;
};
getCmsType();
}, [cmsType]);

return (
<div>
Expand Down
5 changes: 4 additions & 1 deletion ui/src/components/LegacyCms/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { isEmptyString, validateArray } from '../../utilities/functions';
import { ICardType, defaultCardType } from '../Common/Card/card.interface';
import './legacyCms.scss';
import { IFilterType } from '../Common/Modal/FilterModal/filterModal.interface';
import { updateCurrentStepData } from '../../services/api/migration.service';
import { updateCurrentStepData, updateLegacyCMSData } from '../../services/api/migration.service';
import { MigrationResponse } from '../../services/api/service.interface';
import { getCMSDataFromFile } from '../../cmsData/cmsSelector';

Expand Down Expand Up @@ -60,6 +60,9 @@ const LegacyCMSComponent = ({ legacyCMSData, projectData }: LegacyCMSComponentPr
event.preventDefault();

//Update Data in backend
await updateLegacyCMSData(selectedOrganisation?.value, projectId, {
legacy_cms: newMigrationData?.legacy_cms?.selectedCms?.cms_id
});
const res = await updateCurrentStepData(selectedOrganisation.value, projectId);
if (res) {
const url = `/projects/${projectId}/migration/steps/2`;
Expand Down
8 changes: 8 additions & 0 deletions ui/src/services/api/upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ export const fileValidation = () => {
return error;
}
};

export const getConfig = () => {
try {
return getCall(`${UPLOAD_FILE_RELATIVE_URL}config`);
} catch (error) {
return error;
}
};