From c066e38688b7f166a630cea05ddf9f4ca65e60ce Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Fri, 24 Nov 2023 14:49:57 +0545 Subject: [PATCH] fix (createNewProject): pageReload - redirect user to projectDetails step when page is reloaded on other steps of form --- src/frontend/src/views/CreateNewProject.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/views/CreateNewProject.tsx b/src/frontend/src/views/CreateNewProject.tsx index 5d60e2b080..f57cf963c8 100644 --- a/src/frontend/src/views/CreateNewProject.tsx +++ b/src/frontend/src/views/CreateNewProject.tsx @@ -7,7 +7,7 @@ import UploadArea from '../components/createnewproject/UploadArea'; import DataExtract from '../components/createnewproject/DataExtract'; import SplitTasks from '../components/createnewproject/SplitTasks'; import SelectForm from '../components/createnewproject/SelectForm'; -import { useLocation } from 'react-router-dom'; +import { useLocation, useNavigate } from 'react-router-dom'; import { useDispatch } from 'react-redux'; import { CommonActions } from '.././store/slices/CommonSlice'; import { useAppSelector } from '../types/reduxTypes'; @@ -15,13 +15,23 @@ import Prompt from '../hooks/Prompt'; const CreateNewProject = () => { const location = useLocation(); const dispatch = useDispatch(); + const navigate = useNavigate(); const isUnsavedChanges = useAppSelector((state) => state.createproject.isUnsavedChanges); const canSwitchCreateProjectSteps = useAppSelector((state) => state.createproject.canSwitchCreateProjectSteps); + const projectDetails: any = useAppSelector((state) => state.createproject.projectDetails); const [geojsonFile, setGeojsonFile] = useState(null); const [customLineUpload, setCustomLineUpload] = useState(null); const [customPolygonUpload, setCustomPolygonUpload] = useState(null); const [customFormFile, setCustomFormFile] = useState(null); + + useEffect(() => { + if (location.pathname !== '/create-project' && !projectDetails.name && !projectDetails.odk_central_url) { + dispatch(CommonActions.SetCurrentStepFormStep({ flag: 'create_project', step: 1 })); + navigate('/create-project'); + } + }, [location.pathname]); + useEffect(() => { switch (location.pathname) { case '/create-project':