Skip to content

Commit 083eeb4

Browse files
committed
fix:improved handling of steps data based on projectmapped state in stepper and setting empty redux values on deletion of project
1 parent 0503759 commit 083eeb4

File tree

7 files changed

+55
-45
lines changed

7 files changed

+55
-45
lines changed

ui/src/components/Common/DeleteProjectModal/index.tsx

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
import { useState } from 'react';
33
import {
44
Button,
5-
Notification,
65
ModalBody,
76
ModalHeader,
87
ModalFooter,
98
ButtonGroup
109
} from '@contentstack/venus-components';
1110

12-
// Service
13-
import { deleteProject } from '../../../services/api/project.service';
14-
1511
// Interfaces
1612
import { SettingsModalProps } from '../../../components/Modal/modal.interface';
1713

@@ -22,39 +18,11 @@ import { SettingsModalProps } from '../../../components/Modal/modal.interface';
2218
* @returns {JSX.Element} The rendered DeleteProjectModal component.
2319
*/
2420
const DeleteProjectModal = (props: SettingsModalProps) => {
25-
const { closeModal, navigate, projectId, projectName, selectedOrg } = props;
21+
const { closeModal, projectName, handleDeleteProject } = props;
2622

2723
const [isLoading, setIsLoading] = useState<boolean>(false);
2824

29-
/**
30-
* Handles the deletion of the project.
31-
*
32-
* @param {() => void} closeModal - A function to close the modal.
33-
* @returns {Promise<void>} A promise that resolves when the project is deleted.
34-
*/
35-
const handleDeleteProject = async (closeModal: () => void): Promise<void> => {
36-
setIsLoading(true);
37-
const response = await deleteProject(selectedOrg?.value || '', projectId ?? '');
38-
39-
if (response?.status === 200) {
40-
setIsLoading(false);
41-
closeModal();
42-
setTimeout(() => {
43-
navigate('/projects');
44-
}, 800);
45-
setTimeout(() => {
46-
Notification({
47-
notificationContent: { text: response?.data?.data?.message },
48-
notificationProps: {
49-
position: 'bottom-center',
50-
hideProgressBar: true
51-
},
52-
type: 'success'
53-
});
54-
}, 1200);
55-
}
56-
};
57-
25+
5826
return (
5927
<>
6028
<ModalHeader
@@ -83,7 +51,7 @@ const DeleteProjectModal = (props: SettingsModalProps) => {
8351
icon="v2-Delete"
8452
tabindex={0}
8553
isLoading={isLoading}
86-
onClick={() => handleDeleteProject(closeModal)}
54+
onClick={() => handleDeleteProject()}
8755
>
8856
Delete
8957
</Button>

ui/src/components/Common/Settings/index.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Setting } from './setting.interface';
2323
import { ModalObj } from '../../../components/Modal/modal.interface';
2424

2525
// Service
26-
import { getProject, updateProject } from '../../../services/api/project.service';
26+
import { deleteProject, getProject, updateProject } from '../../../services/api/project.service';
2727
import { CS_ENTRIES } from '../../../utilities/constants';
2828
import { getCMSDataFromFile } from '../../../cmsData/cmsSelector';
2929

@@ -32,6 +32,9 @@ import DeleteProjectModal from '../DeleteProjectModal';
3232

3333
//stylesheet
3434
import './Settings.scss';
35+
import { useDispatch } from 'react-redux';
36+
import { updateNewMigrationData } from '../../../store/slice/migrationDataSlice';
37+
import { DEFAULT_NEW_MIGRATION } from '../../../context/app/app.interface';
3538

3639
/**
3740
* Renders the Settings component.
@@ -51,6 +54,7 @@ const Settings = () => {
5154
);
5255

5356
const navigate = useNavigate();
57+
const dispatch = useDispatch()
5458

5559
useEffect(() => {
5660
const fetchData = async () => {
@@ -120,6 +124,29 @@ const Settings = () => {
120124
});
121125
}
122126
};
127+
const handleDeleteProject = async (closeModal: ()=> void): Promise<void> => {
128+
//setIsLoading(true);
129+
const response = await deleteProject(selectedOrganisation?.value, params?.projectId ?? '');
130+
131+
if (response?.status === 200) {
132+
//setIsLoading(false);
133+
closeModal();
134+
dispatch(updateNewMigrationData(DEFAULT_NEW_MIGRATION));
135+
setTimeout(() => {
136+
navigate('/projects');
137+
}, 800);
138+
setTimeout(() => {
139+
Notification({
140+
notificationContent: { text: response?.data?.data?.message },
141+
notificationProps: {
142+
position: 'bottom-center',
143+
hideProgressBar: true
144+
},
145+
type: 'success'
146+
});
147+
}, 1200);
148+
}
149+
};
123150

124151
const handleClick = () => {
125152
cbModal({
@@ -129,6 +156,7 @@ const Settings = () => {
129156
projectId={params?.projectId ?? ''}
130157
projectName={projectName}
131158
navigate={navigate}
159+
handleDeleteProject={() => handleDeleteProject(props?.closeModal)}
132160
{...props}
133161
/>
134162
),

ui/src/components/Common/router.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const AppRouter = () => {
3333

3434
{/* ALL PROTECTED ROUTES HERE */}
3535
<Route element={<PrivateRoute redirectTo="/" />}>
36-
<Route path="/migrations" element={<MigrationLazyLoad />} />
3736
<Route path="/projects" element={<ProjectsLazyLoad />} />
3837

3938
<Route

ui/src/components/DestinationStack/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
33
import AutoVerticalStepper from '../Stepper/VerticalStepper/AutoVerticalStepper';
44
import { getDestinationStackSteps } from './StepperSteps';
5-
import { CircularLoader, HelpText, Icon, Info, Tooltip } from '@contentstack/venus-components';
5+
import { CircularLoader } from '@contentstack/venus-components';
66
import { CS_ENTRIES } from '../../utilities/constants';
77
import {
88
DEFAULT_DESTINATION_STACK_DATA,
@@ -39,8 +39,8 @@ const DestinationStackComponent = ({
3939
const migrationData = useSelector((state: RootState) => state?.migration?.migrationData);
4040
const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData);
4141
const dispatch = useDispatch();
42-
const [isLoading, setIsLoading] = useState<boolean>(newMigrationData?.isprojectMapped);
43-
42+
const [isLoading, setIsLoading] = useState<boolean>(true);
43+
const [isProjectMapped, setisProjectMapped] = useState<boolean>(newMigrationData?.isprojectMapped);
4444
const handleAllStepsComplete = (flag = false) => {
4545
handleOnAllStepsComplete(flag);
4646
};
@@ -94,9 +94,14 @@ const DestinationStackComponent = ({
9494
}
9595
}
9696
}, [internalActiveStepIndex]);
97+
98+
useEffect(()=>{
99+
setisProjectMapped(newMigrationData?.isprojectMapped);
100+
},[newMigrationData?.isprojectMapped]);
101+
97102
return (
98103
<>
99-
{isLoading || newMigrationData?.isprojectMapped ? (
104+
{isLoading || isProjectMapped ? (
100105
<div className="loader-container">
101106
<CircularLoader />
102107
</div>

ui/src/components/Modal/modal.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface SettingsModalProps {
1717
projectName?: string;
1818
closeModal: () => void;
1919
navigate: (url: string) => void;
20+
handleDeleteProject: () => void;
2021
}
2122

2223
export interface FormData {

ui/src/components/Stepper/HorizontalStepper/HorizontalStepper.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import React, { useState, useImperativeHandle, forwardRef, useEffect } from 'react';
2+
import React, { useState, useImperativeHandle, forwardRef, useEffect, useRef } from 'react';
33
import { useNavigate, useParams } from 'react-router-dom';
44
import './HorizontalStepper.scss';
55
import { cbModal, Notification, Button, CircularLoader } from '@contentstack/venus-components';
@@ -46,6 +46,7 @@ export type stepperProps = {
4646
handleSaveCT?: () => void;
4747
changeDropdownState: () => void;
4848
projectData: MigrationResponse;
49+
isProjectMapped: boolean;
4950
};
5051

5152
export type HorizontalStepperHandles = {
@@ -88,16 +89,21 @@ const HorizontalStepper = forwardRef(
8889

8990
const navigate = useNavigate();
9091
const { projectId = '' } = useParams();
92+
const newMigrationDataRef = useRef(newMigrationData);
9193

9294
const handleSaveCT = props?.handleSaveCT;
9395
const handleDropdownChange = props?.changeDropdownState;
9496
useBlockNavigation(isModalOpen);
9597

98+
useEffect(() => {
99+
newMigrationDataRef.current = newMigrationData;
100+
}, [newMigrationData]);
101+
96102
useEffect(() => {
97103
const stepIndex = parseInt(stepId || '', 10) - 1;
98104

99105
if (!Number.isNaN(stepIndex) && stepIndex >= 0 && stepIndex < steps?.length) {
100-
!newMigrationData?.isprojectMapped && setShowStep(stepIndex);
106+
!newMigrationDataRef?.current?.isprojectMapped && setShowStep(stepIndex);
101107
setStepsCompleted((prev) => {
102108
const updatedStepsCompleted = [...prev];
103109
if (
@@ -266,7 +272,7 @@ const HorizontalStepper = forwardRef(
266272
<>
267273
{!hideTabView && <StepsTitleCreator />}
268274
<div className={`stepContent ${props.stepContentClassName}`}>
269-
{newMigrationData?.isprojectMapped ? (
275+
{(newMigrationDataRef?.current?.isprojectMapped || props?.isProjectMapped)? (
270276
<div className={`stepper-loader `}>
271277
<CircularLoader />
272278
</div>

ui/src/pages/Migration/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,14 @@ const Migration = () => {
329329
currentStep: -1
330330
},
331331
destination_stack: {
332+
...newMigrationData?.destination_stack,
332333
selectedOrg: selectedOrganisationData,
333334
selectedStack: selectedStackData,
334335
stackArray: [],
335336
migratedStacks: migratedstacks?.data?.destinationStacks,
336337
sourceLocale: projectData?.source_locales,
337-
localeMapping: locales
338+
localeMapping: locales,
339+
csLocale: newMigrationDataRef?.current?.destination_stack?.csLocale
338340
},
339341
content_mapping: {
340342
isDropDownChanged: false,
@@ -721,6 +723,7 @@ const Migration = () => {
721723
handleSaveCT={saveRef?.current?.handleSaveContentType}
722724
changeDropdownState={changeDropdownState}
723725
projectData={projectData || defaultMigrationResponse}
726+
isProjectMapped={isProjectMapper}
724727
/>
725728
</div>
726729
</div>

0 commit comments

Comments
 (0)