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 (createNewProject): splitTasks - validation for submit button dis… #1018

Merged
merged 1 commit into from
Dec 1, 2023
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
4 changes: 4 additions & 0 deletions src/frontend/src/api/CreateProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ const GetDividedTaskFromGeojson: Function = (url: string, payload: any) => {
dividedTaskFormData.append('dimension', payload.dimension);
const getGetDividedTaskFromGeojsonResponse = await axios.post(url, dividedTaskFormData);
const resp: OrganisationListModel = getGetDividedTaskFromGeojsonResponse.data;
dispatch(CreateProjectActions.SetIsTasksGenerated({ key: 'divide_on_square', value: true }));
dispatch(CreateProjectActions.SetIsTasksGenerated({ key: 'task_splitting_algorithm', value: false }));
dispatch(CreateProjectActions.SetDividedTaskGeojson(resp));
dispatch(CreateProjectActions.SetDividedTaskFromGeojsonLoading(false));
} catch (error) {
Expand Down Expand Up @@ -346,6 +348,8 @@ const TaskSplittingPreviewService: Function = (
// TODO display error to user, perhaps there is not osm data here?
return;
}
dispatch(CreateProjectActions.SetIsTasksGenerated({ key: 'divide_on_square', value: false }));
dispatch(CreateProjectActions.SetIsTasksGenerated({ key: 'task_splitting_algorithm', value: true }));
dispatch(CreateProjectActions.GetTaskSplittingPreview(resp));
} catch (error) {
dispatch(CreateProjectActions.GetTaskSplittingPreviewLoading(false));
Expand Down
26 changes: 26 additions & 0 deletions src/frontend/src/components/createnewproject/SplitTasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const SplitTasks = ({ flag, geojsonFile, setGeojsonFile, customLineUpload, custo
const navigate = useNavigate();

const [toggleStatus, setToggleStatus] = useState(false);
const [taskGenerationStatus, setTaskGenerationStatus] = useState(false);

const divRef = useRef(null);
const splitTasksSelection = CoreModules.useAppSelector((state) => state.createproject.splitTasksSelection);
Expand All @@ -60,12 +61,30 @@ const SplitTasks = ({ flag, geojsonFile, setGeojsonFile, customLineUpload, custo
const taskSplittingGeojsonLoading = CoreModules.useAppSelector(
(state) => state.createproject.taskSplittingGeojsonLoading,
);
const isTasksGenerated = CoreModules.useAppSelector((state) => state.createproject.isTasksGenerated);

const toggleStep = (step, url) => {
dispatch(CommonActions.SetCurrentStepFormStep({ flag: flag, step: step }));
navigate(url);
};

const checkTasksGeneration = () => {
if (!isTasksGenerated.divide_on_square && splitTasksSelection === task_split_type['divide_on_square']) {
setTaskGenerationStatus(false);
} else if (
!isTasksGenerated.task_splitting_algorithm &&
splitTasksSelection === task_split_type['task_splitting_algorithm']
) {
setTaskGenerationStatus(false);
} else {
setTaskGenerationStatus(true);
}
};

useEffect(() => {
checkTasksGeneration();
}, [splitTasksSelection, isTasksGenerated]);

const submission = () => {
dispatch(CreateProjectActions.SetIsUnsavedChanges(false));

Expand Down Expand Up @@ -300,6 +319,12 @@ const SplitTasks = ({ flag, geojsonFile, setGeojsonFile, customLineUpload, custo
onChangeData={(value) => {
handleCustomChange('task_split_type', parseInt(value));
dispatch(CreateProjectActions.SetSplitTasksSelection(parseInt(value)));
if (task_split_type['choose_area_as_task'] === parseInt(value)) {
dispatch(CreateProjectActions.SetIsTasksGenerated({ key: 'divide_on_square', value: false }));
dispatch(
CreateProjectActions.SetIsTasksGenerated({ key: 'task_splitting_algorithm', value: false }),
);
}
}}
errorMsg={errors.task_split_type}
/>
Expand Down Expand Up @@ -382,6 +407,7 @@ const SplitTasks = ({ flag, geojsonFile, setGeojsonFile, customLineUpload, custo
btnType="primary"
type="submit"
className="fmtm-font-bold"
disabled={taskGenerationStatus ? false : true}
/>
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions src/frontend/src/store/slices/CreateProjectSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const initialState: CreateProjectStateTypes = {
createProjectValidations: {},
isUnsavedChanges: false,
canSwitchCreateProjectSteps: false,
isTasksGenerated: { divide_on_square: false, task_splitting_algorithm: false },
};

const CreateProject = createSlice({
Expand Down Expand Up @@ -213,6 +214,12 @@ const CreateProject = createSlice({
SetCanSwitchCreateProjectSteps(state, action) {
state.canSwitchCreateProjectSteps = action.payload;
},
SetIsTasksGenerated(state, action) {
state.isTasksGenerated = {
...state.isTasksGenerated,
[action.payload.key]: action.payload.value,
};
},
},
});

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 @@ -34,6 +34,7 @@ export type CreateProjectStateTypes = {
createProjectValidations: {};
isUnsavedChanges: boolean;
canSwitchCreateProjectSteps: boolean;
isTasksGenerated: {};
};
export type ValidateCustomFormResponse = {
detail: { message: string; possible_reason: string };
Expand Down
Loading