Skip to content

Commit

Permalink
fix: move to the last step when editing data
Browse files Browse the repository at this point in the history
  • Loading branch information
barttom committed Jan 11, 2024
1 parent 4cdc1b6 commit 6680af4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/hooks/useSubStep/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@ export default function useSubStep<T>({bodyContent, onFinished, startFrom = 0}:
setScreenIndex(0);
}, []);

return {componentToRender: bodyContent[screenIndex], isEditing: isEditing.current, screenIndex, prevScreen, nextScreen, moveTo, resetScreenIndex};
const goToTheLastStep = useCallback(() => {
isEditing.current = false;
setScreenIndex(bodyContent.length - 1);
}, [bodyContent]);

return {componentToRender: bodyContent[screenIndex], isEditing: isEditing.current, screenIndex, prevScreen, nextScreen, moveTo, resetScreenIndex, goToTheLastStep};
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function BeneficialOwnerInfo({reimbursementAccount, reimbursementAccountDraft, o
prevScreen,
moveTo,
resetScreenIndex,
goToTheLastStep,
} = useSubStep<{beneficialOwnerBeingModifiedID: string; setBeneficialOwnerBeingModifiedID?: (id: string) => void}>({
bodyContent: BODY_CONTENT,
startFrom: 0,
Expand Down Expand Up @@ -192,6 +193,11 @@ function BeneficialOwnerInfo({reimbursementAccount, reimbursementAccountDraft, o
};

const handleBackButtonPress = () => {
if (isEditing) {
goToTheLastStep();
return;
}

// User goes back to previous step
if (currentUBOSubstep === SUBSTEP.IS_USER_UBO) {
onBackButtonPress();
Expand Down
7 changes: 6 additions & 1 deletion src/pages/ReimbursementAccount/BusinessInfo/BusinessInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,14 @@ function BusinessInfo({reimbursementAccount, reimbursementAccountDraft, policyID

const startFrom = useMemo(() => getInitialSubstepForBusinessInfo(values), [values]);

const {componentToRender: SubStep, isEditing, screenIndex, nextScreen, prevScreen, moveTo} = useSubStep({bodyContent, startFrom, onFinished: submit});
const {componentToRender: SubStep, isEditing, screenIndex, nextScreen, prevScreen, moveTo, goToTheLastStep} = useSubStep({bodyContent, startFrom, onFinished: submit});

const handleBackButtonPress = () => {
if (isEditing) {
goToTheLastStep();
return;
}

if (screenIndex === 0) {
onBackButtonPress();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ function CompleteVerification({reimbursementAccount, reimbursementAccountDraft,
});
}, [reimbursementAccount, reimbursementAccountDraft, values]);

const {componentToRender: SubStep, isEditing, screenIndex, nextScreen, prevScreen, moveTo} = useSubStep({bodyContent: BODY_CONTENT, startFrom: 0, onFinished: submit});
const {componentToRender: SubStep, isEditing, screenIndex, nextScreen, prevScreen, moveTo, goToTheLastStep} = useSubStep({bodyContent: BODY_CONTENT, startFrom: 0, onFinished: submit});

const handleBackButtonPress = () => {
if (isEditing) {
goToTheLastStep();
return;
}

if (screenIndex === 0) {
onBackButtonPress();
} else {
Expand Down
7 changes: 6 additions & 1 deletion src/pages/ReimbursementAccount/PersonalInfo/PersonalInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ function PersonalInfo({reimbursementAccount, reimbursementAccountDraft, onBackBu
}, [values]);
const startFrom = useMemo(() => getInitialSubstepForPersonalInfo(values), [values]);

const {componentToRender: SubStep, isEditing, screenIndex, nextScreen, prevScreen, moveTo} = useSubStep({bodyContent, startFrom, onFinished: submit});
const {componentToRender: SubStep, isEditing, screenIndex, nextScreen, prevScreen, moveTo, goToTheLastStep} = useSubStep({bodyContent, startFrom, onFinished: submit});

const handleBackButtonPress = () => {
if (isEditing) {
goToTheLastStep();
return;
}

if (screenIndex === 0) {
onBackButtonPress();
} else {
Expand Down

0 comments on commit 6680af4

Please sign in to comment.