Skip to content

Commit

Permalink
feat : useStep에서 현재 단계 상태를 추가하여 다음 페이지 로직 통제 (#344)
Browse files Browse the repository at this point in the history
Co-authored-by: (hoooooony) <([email protected])>
  • Loading branch information
hoooooony and (hoooooony) authored Jun 5, 2024
1 parent 26b7cfe commit 4b79879
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Binary file added .yarn/cache/fsevents-patch-21ad2b1333-8.zip
Binary file not shown.
19 changes: 16 additions & 3 deletions src/page/Auth/hook/useStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ export const useStep = (type: Type) => {
const target = type === 'find' ? findPassword : register;
const [index, setIndex] = useState(0);
const [isComplete, setIsComplete] = useState<boolean>(false);
const [isStepComplete, setIsStepComplete] = useState<boolean>(false);
const navigate = useNavigate();

const nextStep = () => {
if (index + 1 < target.length) setIndex((prev) => prev + 1);
if (isStepComplete && index + 1 < target.length) {
setIndex((prev) => prev + 1);
setIsStepComplete(false);
} else if (isStepComplete && index + 1 === target.length) {
setIsComplete(true);
}
};

const previousStep = () => {
Expand All @@ -25,10 +31,17 @@ export const useStep = (type: Type) => {
};

const currentStep = target[index];

const totalStep = target.length;

return {
nextStep, previousStep, currentStep, index, totalStep, isComplete, setIsComplete,
nextStep,
previousStep,
currentStep,
index,
totalStep,
isComplete,
setIsComplete,
isStepComplete,
setIsStepComplete,
};
};

0 comments on commit 4b79879

Please sign in to comment.