diff --git a/ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx b/ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx index be540caa3..b1b4a99a1 100644 --- a/ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx +++ b/ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx @@ -234,9 +234,13 @@ const Mapper = ({ updatedMappings[selectedLocaleKey] = existingLocale?.[index]?.label; delete updatedMappings?.[CS_ENTRIES?.UNMAPPED_LOCALE_KEY]; }else{ - updatedMappings[selectedLocaleKey] = existingLocale?.[index]?.label - ? existingLocale?.[index]?.label - : ''; + const oldlabel = Object?.keys?.(updatedMappings)?.[index - 1]; + + // Delete old key and assign to new key + delete updatedMappings?.[oldlabel]; + updatedMappings[selectedLocaleKey] = existingLocale?.[index]?.label + ? existingLocale?.[index]?.label + : ''; } } @@ -295,7 +299,7 @@ const Mapper = ({ } else if (selectedLocaleKey) { - updatedMappings[existingLabel?.value] = selectedValue?.label + updatedMappings[existingLabel?.value ?? index] = selectedValue?.label ? selectedValue?.label : ''; } diff --git a/ui/src/pages/Login/index.tsx b/ui/src/pages/Login/index.tsx index f22dc8baa..adebbcb48 100644 --- a/ui/src/pages/Login/index.tsx +++ b/ui/src/pages/Login/index.tsx @@ -3,7 +3,7 @@ import { FC, useEffect, useState } from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; import { useDispatch, useSelector } from 'react-redux'; -import { clearOrganisationData, getUserDetails, setAuthToken, setUser } from '../../store/slice/authSlice'; +import { clearOrganisationData, getUserDetails, setAuthToken, setUser, clearAuthToken } from '../../store/slice/authSlice'; import { Button, Field, @@ -22,7 +22,7 @@ import { TFA_VIA_SMS_MESSAGE, CS_ENTRIES } from '../../utilities/constants'; -import { failtureNotification, setDataInLocalStorage } from '../../utilities/functions'; +import { clearLocalStorage, failtureNotification, setDataInLocalStorage } from '../../utilities/functions'; // API Service import { getCMSDataFromFile } from '../../cmsData/cmsSelector'; @@ -153,7 +153,8 @@ const Login: FC = () => { setIsLoading(false); failtureNotification(response?.data?.error_message || response?.data?.error?.message); } - + dispatch(clearAuthToken()); + localStorage?.removeItem('app_token'); if (response?.status === 200 && response?.data?.message === LOGIN_SUCCESSFUL_MESSAGE) { setIsLoading(false); setDataInLocalStorage('app_token', response?.data?.app_token); diff --git a/ui/src/pages/Migration/index.tsx b/ui/src/pages/Migration/index.tsx index 07f6d8ea0..b9d20c5e0 100644 --- a/ui/src/pages/Migration/index.tsx +++ b/ui/src/pages/Migration/index.tsx @@ -587,7 +587,8 @@ const Migration = () => { value !== '' && value !== null && value !== undefined && - label !== 'undefined' + label !== 'undefined' && + isNaN(Number(label)) ); const master_locale: LocalesType = {}; diff --git a/ui/src/services/api/migration.service.ts b/ui/src/services/api/migration.service.ts index 3723190b7..ee701c669 100644 --- a/ui/src/services/api/migration.service.ts +++ b/ui/src/services/api/migration.service.ts @@ -3,15 +3,15 @@ import { API_VERSION, EXECUTION_LOGS_ERROR_TEXT } from '../../utilities/constant import { getDataFromLocalStorage } from '../../utilities/functions'; import { getCall, postCall, putCall, patchCall } from './service'; -const options = { +const options = () => ({ headers: { app_token: getDataFromLocalStorage('app_token') } -}; +}); export const getMigrationData = (orgId: string, projectId: string) => { try { - return getCall(`${API_VERSION}/org/${orgId}/project/${projectId}/`, options); + return getCall(`${API_VERSION}/org/${orgId}/project/${projectId}`, options()); } catch (error) { if (error instanceof Error) { throw new Error(`Error in getting migrationData: ${error.message}`); @@ -23,7 +23,7 @@ export const getMigrationData = (orgId: string, projectId: string) => { export const updateLegacyCMSData = (orgId: string, projectId: string, data: ObjectType) => { try { - return putCall(`${API_VERSION}/org/${orgId}/project/${projectId}/legacy-cms`, data, options); + return putCall(`${API_VERSION}/org/${orgId}/project/${projectId}/legacy-cms`, data, options()); } catch (error) { if (error instanceof Error) { throw new Error(`${error.message}`); @@ -35,7 +35,7 @@ export const updateLegacyCMSData = (orgId: string, projectId: string, data: Obje export const updateAffixData = (orgId: string, projectId: string, data: ObjectType) => { try { - return putCall(`${API_VERSION}/org/${orgId}/project/${projectId}/affix`, data, options); + return putCall(`${API_VERSION}/org/${orgId}/project/${projectId}/affix`, data, options()); } catch (error) { if (error instanceof Error) { throw new Error(`${error.message}`); @@ -47,7 +47,7 @@ export const updateAffixData = (orgId: string, projectId: string, data: ObjectTy export const updateFileFormatData = (orgId: string, projectId: string, data: ObjectType) => { try { - return putCall(`${API_VERSION}/org/${orgId}/project/${projectId}/file-format`, data, options); + return putCall(`${API_VERSION}/org/${orgId}/project/${projectId}/file-format`, data, options()); } catch (error) { if (error instanceof Error) { throw new Error(`${error.message}`); @@ -62,7 +62,7 @@ export const updateDestinationStack = (orgId: string, projectId: string, data: O return putCall( `${API_VERSION}/org/${orgId}/project/${projectId}/destination-stack`, data, - options + options() ); } catch (error) { if (error instanceof Error) { @@ -75,7 +75,7 @@ export const updateDestinationStack = (orgId: string, projectId: string, data: O export const updateCurrentStepData = (orgId: string, projectId: string, data: ObjectType = {}) => { try { - return putCall(`${API_VERSION}/org/${orgId}/project/${projectId}/current-step`, data, options); + return putCall(`${API_VERSION}/org/${orgId}/project/${projectId}/current-step`, data, options()); } catch (error) { if (error instanceof Error) { throw new Error(`${error.message}`); @@ -90,7 +90,7 @@ export const affixConfirmation = (orgId: string, projectId: string, data: Object return putCall( `${API_VERSION}/org/${orgId}/project/${projectId}/affix_confirmation`, data, - options + options() ); } catch (error) { return error; @@ -102,7 +102,7 @@ export const fileformatConfirmation = (orgId: string, projectId: string, data: O return putCall( `${API_VERSION}/org/${orgId}/project/${projectId}/fileformat_confirmation`, data, - options + options() ); } catch (error) { return error; @@ -119,7 +119,7 @@ export const getContentTypes = ( const encodedSearchText = encodeURIComponent(searchText); return getCall( `${API_VERSION}/mapper/contentTypes/${projectId}/${skip}/${limit}/${encodedSearchText}?`, - options + options() ); } catch (error) { if (error instanceof Error) { @@ -141,7 +141,7 @@ export const getFieldMapping = async ( const encodedSearchText = encodeURIComponent(searchText); return await getCall( `${API_VERSION}/mapper/fieldMapping/${projectId}/${contentTypeId}/${skip}/${limit}/${encodedSearchText}?`, - options + options() ); } catch (error) { if (error instanceof Error) { @@ -187,7 +187,7 @@ export const updateContentType = async ( return await putCall( `${API_VERSION}/mapper/contentTypes/${orgId}/${projectId}/${contentTypeId}`, data, - options + options() ); } catch (error) { if (error instanceof Error) { @@ -208,7 +208,7 @@ export const resetToInitialMapping = async ( return await putCall( `${API_VERSION}/mapper/resetFields/${orgId}/${projectId}/${contentTypeId}`, data, - options + options() ); } catch (error) { if (error instanceof Error) { @@ -221,7 +221,7 @@ export const resetToInitialMapping = async ( export const getExistingContentTypes = async (projectId: string, contentTypeUid?: string) => { try { - return await getCall(`${API_VERSION}/mapper/${projectId}/contentTypes/${contentTypeUid ?? ''}`, options); + return await getCall(`${API_VERSION}/mapper/${projectId}/contentTypes/${contentTypeUid ?? ''}`, options()); } catch (error) { if (error instanceof Error) { throw new Error(`${error.message}`); @@ -233,7 +233,7 @@ export const getExistingContentTypes = async (projectId: string, contentTypeUid? export const getExistingGlobalFields = async (projectId: string, globalFieldUid?: string) => { try { - return await getCall(`${API_VERSION}/mapper/${projectId}/globalFields/${globalFieldUid ?? ''}`, options); + return await getCall(`${API_VERSION}/mapper/${projectId}/globalFields/${globalFieldUid ?? ''}`, options()); } catch (error) { if (error instanceof Error) { throw new Error(`${error.message}`); @@ -246,7 +246,7 @@ export const getExistingGlobalFields = async (projectId: string, globalFieldUid? export const removeContentMapper = async (orgId: string, projectId: string) => { try { - return await getCall(`${API_VERSION}/mapper/${orgId}/${projectId}/content-mapper`, options); + return await getCall(`${API_VERSION}/mapper/${orgId}/${projectId}/content-mapper`, options()); } catch (error) { return error; @@ -264,7 +264,7 @@ export const updateContentMapper = async ( return await patchCall( `${API_VERSION}/mapper/${orgId}/${projectId}/mapper_keys`, mapperKeys, - options + options() ); } catch (error) { if (error instanceof Error) { @@ -278,7 +278,7 @@ export const updateContentMapper = async ( export const updateStackDetails = async (orgId: string, projectId: string, data: ObjectType) => { try { const Data = { stack_details: data }; - return await patchCall(`${API_VERSION}/org/${orgId}/project/${projectId}/stack-details`, Data, options); + return await patchCall(`${API_VERSION}/org/${orgId}/project/${projectId}/stack-details`, Data, options()); } catch (error) { return error; @@ -287,7 +287,7 @@ export const updateStackDetails = async (orgId: string, projectId: string, data: export const getOrgDetails = async (orgId: string) => { try { - return await getCall(`${API_VERSION}/org/${orgId}/get_org_details`, options); + return await getCall(`${API_VERSION}/org/${orgId}/get_org_details`, options()); } catch (error) { return error; } @@ -298,7 +298,7 @@ export const createTestStack = async (orgId: string, projectId: string, data: Ob return await postCall( `${API_VERSION}/migration/create-test-stack/${orgId}/${projectId}`, data, - options + options() ); } catch (error) { return error; @@ -308,7 +308,7 @@ export const createTestStack = async (orgId: string, projectId: string, data: Ob export const createTestMigration = async (orgId: string, projectId: string) => { try { return await postCall( - `${API_VERSION}/migration/test-stack/${orgId}/${projectId}`, {}, options); + `${API_VERSION}/migration/test-stack/${orgId}/${projectId}`, {}, options()); } catch (error) { return error; } @@ -317,7 +317,7 @@ export const createTestMigration = async (orgId: string, projectId: string) => { export const startMigration = async (orgId: string, projectId: string) => { try { return await postCall( - `${API_VERSION}/migration/start/${orgId}/${projectId}`, {}, options); + `${API_VERSION}/migration/start/${orgId}/${projectId}`, {}, options()); } catch (error) { return error; } @@ -326,7 +326,7 @@ export const startMigration = async (orgId: string, projectId: string) => { export const updateMigrationKey = async (orgId: string, projectId: string) => { try { return await putCall( - `${API_VERSION}/org/${orgId}/project/${projectId}/migration-excution`, {}, options); + `${API_VERSION}/org/${orgId}/project/${projectId}/migration-excution`, {}, options()); } catch (error) { return error; } @@ -335,7 +335,7 @@ export const updateMigrationKey = async (orgId: string, projectId: string) => { export const updateLocaleMapper = async(projectId: string, data: any) => { try { return await postCall( - `${API_VERSION}/migration/updateLocales/${projectId}`, data, options); + `${API_VERSION}/migration/updateLocales/${projectId}`, data, options()); } catch (error) { return error; } @@ -345,7 +345,7 @@ export const getMigrationLogs = async (orgId: string, projectId: string, stackId try { return await getCall( `${API_VERSION}/migration/get_migration_logs/${orgId}/${projectId}/${stackId}/${skip}/${limit}/${startIndex}/${stopIndex}/${searchText}/${filter}`, - options + options() ); } catch (error) { if (error instanceof Error) { diff --git a/ui/src/services/api/stacks.service.ts b/ui/src/services/api/stacks.service.ts index bc0528402..324fd9bc4 100644 --- a/ui/src/services/api/stacks.service.ts +++ b/ui/src/services/api/stacks.service.ts @@ -3,15 +3,15 @@ import { getDataFromLocalStorage } from '../../utilities/functions'; import { getCall, postCall } from './service'; import { Stack } from '../../components/Common/AddStack/addStack.interface'; -const options = { +const options = () => ({ headers: { app_token: getDataFromLocalStorage('app_token') } -}; +}); export const getAllStacksInOrg = async (orgId: string, searchText: string) => { try { - return await getCall(`${API_VERSION}/org/${orgId}/stacks/${searchText}?`, options); + return await getCall(`${API_VERSION}/org/${orgId}/stacks/${searchText}?`, options()); } catch (error) { return error; } @@ -19,7 +19,7 @@ export const getAllStacksInOrg = async (orgId: string, searchText: string) => { export const createStacksInOrg = async (orgId: string, data: Stack) => { try { - return await postCall(`${API_VERSION}/org/${orgId}/stacks`, data, options); + return await postCall(`${API_VERSION}/org/${orgId}/stacks`, data, options()); } catch (error) { if (error instanceof Error) { throw new Error(`Error in userSession: ${error.message}`); @@ -34,7 +34,7 @@ export const getStackStatus = async (orgId: string, data: string) => { const stack_api = { stack_api_key: data }; - return await postCall(`${API_VERSION}/org/${orgId}/stack_status`, stack_api, options); + return await postCall(`${API_VERSION}/org/${orgId}/stack_status`, stack_api, options()); } catch (error) { if (error instanceof Error) { throw new Error(`Error in userSession: ${error.message}`); diff --git a/ui/src/store/slice/authSlice.tsx b/ui/src/store/slice/authSlice.tsx index c501979d4..8f0bbb145 100644 --- a/ui/src/store/slice/authSlice.tsx +++ b/ui/src/store/slice/authSlice.tsx @@ -101,6 +101,10 @@ const authSlice = createSlice({ clearOrganisationData: (state) => { state.organisationsList = []; state.selectedOrganisation = DEFAULT_DROPDOWN; + }, + clearAuthToken: (state) => { + state.authToken = ''; + state.isAuthenticated = false; } @@ -120,7 +124,7 @@ const authSlice = createSlice({ }, }) -export const { setAuthToken, reInitiliseState, setOrganisationsList, setSelectedOrganisation, setUser, clearOrganisationData } = authSlice.actions; +export const { setAuthToken, reInitiliseState, setOrganisationsList, setSelectedOrganisation, setUser, clearOrganisationData, clearAuthToken } = authSlice.actions; export {getUserDetails}; export default authSlice.reducer; \ No newline at end of file