Skip to content

Commit 9a4b280

Browse files
committed
fix:[CMG-633]:prefiled values of affic and validation message on new project creation
1 parent 3f0c084 commit 9a4b280

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

ui/src/components/Modal/index.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,17 @@ const Modal = (props: ProjectModalProps) => {
3434
title
3535
},
3636
selectedOrg,
37-
isOpen
37+
isOpen,
38+
createProject
3839
} = props;
3940

4041
const [inputValue, setInputValue] = useState<boolean>(false);
4142

42-
const handleSubmit = async (values: FormData): Promise<boolean> => {
43+
const handleSubmit = async (values: FormData)=> {
4344
// const payload = {name: values?.name, description: values?.description || ''}
4445

45-
const res = await createProject(selectedOrg?.uid || '', values);
46-
if (res?.error) {
47-
return res?.error;
48-
}
49-
if (res?.status === 201) {
50-
const projectId = res?.data?.project?.id;
51-
window.location.href = `/projects/${projectId}/migration/steps/1`;
52-
}
53-
return res;
46+
const result = await createProject(values);
47+
return result;
5448
};
5549

5650
const nameValidation = (value: string) => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { ModalType } from '../../pages/Projects/projects.interface';
44
export interface ModalObj {
55
closeModal: () => void;
66
}
7-
87
export interface ProjectModalProps {
98
modalData: ModalType;
109
selectedOrg: IDropDown;
1110
closeModal: () => void;
1211
isOpen: (flag: boolean) => void;
12+
createProject: (values : FormData)=> void
1313
}
1414
export interface SettingsModalProps {
1515
selectedOrg: IDropDown;

ui/src/pages/Projects/index.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@contentstack/venus-components';
1111
import { jsonToHtml } from '@contentstack/json-rte-serializer';
1212
import HTMLReactParser from 'html-react-parser';
13-
import { useLocation } from 'react-router-dom';
13+
import { useLocation, useNavigate } from 'react-router-dom';
1414
import { useSelector } from 'react-redux';
1515

1616
// Redux
@@ -19,7 +19,7 @@ import useBlockNavigation from '../../hooks/userNavigation';
1919

2020
// Services
2121
import { getCMSDataFromFile } from '../../cmsData/cmsSelector';
22-
import { getAllProjects } from '../../services/api/project.service';
22+
import { createProject, getAllProjects } from '../../services/api/project.service';
2323

2424
// Utilities
2525
import { CS_ENTRIES } from '../../utilities/constants';
@@ -41,6 +41,9 @@ import { NO_PROJECTS, NO_PROJECTS_SEARCH } from '../../common/assets';
4141

4242
// styles
4343
import './index.scss';
44+
import { useDispatch } from 'react-redux';
45+
import { DEFAULT_NEW_MIGRATION } from '../../context/app/app.interface';
46+
import { updateNewMigrationData } from '../../store/slice/migrationDataSlice';
4447

4548
const Projects = () => {
4649
const [data, setData] = useState<ProjectsType>({});
@@ -69,6 +72,8 @@ const Projects = () => {
6972
const [isModalOpen, setIsModalOpen] = useState(false);
7073

7174
usePreventBackNavigation();
75+
const navigate = useNavigate();
76+
const dispatch = useDispatch();
7277

7378
const fetchProjects = async () => {
7479
setLoadStatus(true);
@@ -132,6 +137,20 @@ const Projects = () => {
132137
};
133138
useBlockNavigation(isModalOpen || true);
134139

140+
const createProjectCall = async(values : any) => {
141+
const res:any = await createProject(selectedOrganisation?.uid || '', values);
142+
if (res?.error) {
143+
return res?.error;
144+
}
145+
if (res?.status === 201) {
146+
const projectId = res?.data?.project?.id;
147+
dispatch(updateNewMigrationData(DEFAULT_NEW_MIGRATION))
148+
navigate(`/projects/${projectId}/migration/steps/1`);
149+
150+
}
151+
return res;
152+
153+
}
135154
// Function for open modal
136155
const openModal = () => {
137156
setIsModalOpen(true);
@@ -144,6 +163,7 @@ const Projects = () => {
144163
}
145164
selectedOrg={selectedOrganisation}
146165
isOpen={setIsModalOpen}
166+
createProject={createProjectCall}
147167
{...props}
148168
/>
149169
),

0 commit comments

Comments
 (0)