From 8f9fb91c6b66a39b344a8adce1897ca0715cf090 Mon Sep 17 00:00:00 2001 From: Nishit Suwal <81785002+NSUWAL123@users.noreply.github.com> Date: Sun, 26 Nov 2023 21:40:00 +0545 Subject: [PATCH] fix (createNewProject): redirect user to projectDetails step when page is reloaded (#1009) --- 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':