Skip to content

Commit

Permalink
fix(configuration-steps routing): fixes
Browse files Browse the repository at this point in the history
- Fixed the routing of configuration step in adding and editing a scorecard
  • Loading branch information
tibendadavis committed Jul 25, 2024
1 parent e435bf0 commit b4faa93
Show file tree
Hide file tree
Showing 7 changed files with 352 additions and 335 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default function useScorecardManage() {
setIsNew({ nextStepIndex: activeStepIndex + 1 });

const nextStep = steps[activeStepIndex + 1].id;
navigate(`/edit/${nextStep}/${id}?new=true`, {
navigate(`/edit/${id}/${nextStep}?new=true`, {
replace: true,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export default function useScorecardManagerNavigate({
onSave,
onNavigate,
}: any) {
const { step = "general", id } = useParams();
const { id } = useParams();
const navigate = useNavigate();
const [helpStepIndex, setHelpStepIndex] = useRecoilState(HelpIndex);
const [activeStep, setActiveStep] = useRecoilState(ActiveStepState);
const { search } = useLocation();
const { search, pathname } = useLocation();
const resetNewState = useResetRecoilState(IsNewScorecardState);
const Component = activeStep.component;
const { show } = useAlert(
Expand All @@ -30,26 +30,31 @@ export default function useScorecardManagerNavigate({

useEffect(() => {
const searchParams = new URLSearchParams(search);
const currentStep = find(steps, { id: step });

if (!isEmpty(currentStep)) {
setActiveStep(() => {
return currentStep;
});
const step = pathname.substring(pathname.lastIndexOf("/") + 1);

if (!isEmpty(step)) {
const currentStep = find(steps, { id: step });

if (!isEmpty(currentStep)) {
setActiveStep(() => {
return currentStep;
});
}
}

const isNew = searchParams.get("new");
if (isNew) {
setActiveStep((prevStep) => {
const currentIndex = findIndex(steps, ["id", prevStep.id]);
if (currentIndex === 0) {
return steps[1];
return steps[0];
} else {
return prevStep;
}
});
}
}, [resetNewState, search, setActiveStep, step]);
}, [resetNewState, search, setActiveStep, pathname, id]);

const hasNextStep = useMemo(
() => findIndex(steps, ["id", activeStep.id]) !== steps.length - 1,
Expand All @@ -70,18 +75,9 @@ export default function useScorecardManagerNavigate({
return;
}

// if (!(await form.trigger())) {
// show({
// message: i18n.t("Please fill in all required fields"),
// type: { info: true },
// });
// return;
// }

const index = findIndex(steps, ["id", activeStep.id]);
if (index !== steps.length - 1) {
onStepChange(steps[index + 1]);
// setActiveStep(steps[index + 1]);
setHelpStepIndex(0);
}
};
Expand All @@ -99,20 +95,19 @@ export default function useScorecardManagerNavigate({
if (isEmpty(id)) {
navigate(`/add/${step.id}`);
} else {
const index = findIndex(steps, ["id", step.id]);
if (index !== 0) {
navigate(`/edit/${step.id}/${id}?new=true`);
}
const searchParams = new URLSearchParams(search);
const isNew = searchParams.get("new");
const newQuery = isNew ? "?new=true" : "";
navigate(`/edit/${id}/${step.id}${newQuery}`);
}
},
[activeStep, form, navigate],
);

const onPreviousStep = () => {
const index = findIndex(steps, ["id", activeStep.id]);
//Why does it not allow to go back to the "General" step??

if (index !== 0) {
// setActiveStep(steps[index - 1]);
onStepChange(steps[index - 1]);
setHelpStepIndex(0);
}
Expand Down
Loading

0 comments on commit b4faa93

Please sign in to comment.