Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create new project stepper validation #994

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/frontend/src/components/common/StepSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CommonActions } from '../../store/slices/CommonSlice';
import CoreModules from '../../shared/CoreModules.js';
import { useNavigate } from 'react-router-dom';

const StepSwitcher = ({ data, flag }) => {
const StepSwitcher = ({ data, flag, switchSteps }) => {
interface IIndividualStep {
url: string;
step: number;
Expand Down Expand Up @@ -39,7 +39,11 @@ const StepSwitcher = ({ data, flag }) => {
} lg:fmtm-w-7 lg:fmtm-h-7 xl:fmtm-w-9 xl:fmtm-h-9 fmtm-rounded-full fmtm-flex fmtm-justify-center fmtm-items-center fmtm-border-[0.15rem] fmtm-border-primaryRed hover:fmtm-cursor-pointer ${
currentStep.step >= index ? 'fmtm-bg-primaryRed' : 'fmtm-bg-transparent'
}`}
onClick={() => toggleStep(step)}
onClick={() => {
if (switchSteps) {
toggleStep(step);
}
}}
>
<AssetModules.DoneIcon
className={`${
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/components/createnewproject/SplitTasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const SplitTasks = ({ flag, geojsonFile, setGeojsonFile, customLineUpload, custo
),
);
dispatch(CreateProjectActions.SetIndividualProjectDetailsData({ ...projectDetails, ...formValues }));
dispatch(CreateProjectActions.SetCanSwitchCreateProjectSteps(true));
};

useEffect(() => {
Expand Down Expand Up @@ -197,6 +198,7 @@ const SplitTasks = ({ flag, geojsonFile, setGeojsonFile, customLineUpload, custo
dispatch(CreateProjectActions.SetGenerateProjectQRSuccess(null));
navigate(`/project_details/${encodedProjectId}`);
dispatch(CreateProjectActions.ClearCreateProjectFormData());
dispatch(CreateProjectActions.SetCanSwitchCreateProjectSteps(false));
}
if (generateQrSuccess && generateProjectLog?.status === 'PENDING') {
if (generateProjectLogIntervalCb === null) {
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/store/slices/CreateProjectSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const initialState: CreateProjectStateTypes = {
lineGeojson: null,
createProjectValidations: {},
isUnsavedChanges: false,
canSwitchCreateProjectSteps: false,
};

const CreateProject = createSlice({
Expand Down Expand Up @@ -206,6 +207,9 @@ const CreateProject = createSlice({
SetIsUnsavedChanges(state, action) {
state.isUnsavedChanges = action.payload;
},
SetCanSwitchCreateProjectSteps(state, action) {
state.canSwitchCreateProjectSteps = action.payload;
},
},
});

Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/store/types/ICreateProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type CreateProjectStateTypes = {
lineGeojson: null;
createProjectValidations: {};
isUnsavedChanges: boolean;
canSwitchCreateProjectSteps: boolean;
};
export type ValidateCustomFormResponse = {
detail: { message: string; possible_reason: string };
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/views/CreateNewProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const CreateNewProject = () => {
const dispatch = useDispatch();

const isUnsavedChanges = useAppSelector((state) => state.createproject.isUnsavedChanges);
const canSwitchCreateProjectSteps = useAppSelector((state) => state.createproject.canSwitchCreateProjectSteps);
const [geojsonFile, setGeojsonFile] = useState(null);
const [customLineUpload, setCustomLineUpload] = useState(null);
const [customPolygonUpload, setCustomPolygonUpload] = useState(null);
Expand Down Expand Up @@ -92,7 +93,7 @@ const CreateNewProject = () => {
<div className="fmtm-min-h-[72vh] fmtm-bg-gray-100 fmtm-box-border fmtm-border-[1px] fmtm-border-t-white fmtm-border-t-[0px]">
<div className=" fmtm-w-full">
<div>
<StepSwitcher data={createProjectSteps} flag={'create_project'} />
<StepSwitcher data={createProjectSteps} flag={'create_project'} switchSteps={canSwitchCreateProjectSteps} />
</div>
</div>
<div className="fmtm-mx-5 fmtm-mb-5">{(() => getCreateProjectContent())()}</div>
Expand Down