-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 같은 플로우 안의 여러 페이지를 관리하기 위한 퍼널 추상화 및 적용 (#482)
* refactor/#473: navigate 관련 코드 훅 분리 * feat/#473: Funnel, useFunnel 구현 * feat/#473: NonEmptyArray 타입 추가 * feat/#473: ReviewFormFunnel 적용 * refactor/#473: Review페이지 경로 수정 * feat/#473: 템플릿 overflow-y auto로 변경 * feat/#473: 스크롤 디자인 안보이도록 수정 * feat/#473: useFunnel 반환값 객체로 수정 * feat/#473: PetProfile 등록 폼 Funnel 적용 * fix/#473: 믹스견인 경우에만 petSize 기본값 넣어주도록 수정 * feat/#473: 펫 등록 폼 작성 시 페이지 이동해도 상태가 유지되도록 설정 * feat/#473: 폼 작성 중 사용자의 실수를 예방하기 위한 goBackSafely 적용 * feat/#473: 리뷰 스텝 상수화 * fix/#473: 0살(1살미만)일 때 다음 버튼 활성화되도록 수정 * fix/#473: ReviewForm 테스트 깨지는 문제 해결 * refactor/#473: 코드 컨벤션 맞추기 및 불필요한 코드 삭제 * refactor/#473: 인라인 분기문 변수로 추출
- Loading branch information
1 parent
7a7d415
commit e3240ef
Showing
38 changed files
with
657 additions
and
495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Children, isValidElement, PropsWithChildren, ReactElement, useEffect } from 'react'; | ||
|
||
import { NonEmptyArray } from '@/types/common/utility'; | ||
import { RuntimeError } from '@/utils/errors'; | ||
|
||
export interface FunnelProps<Steps extends NonEmptyArray<string>> { | ||
steps: Steps; | ||
step: Steps[number]; | ||
children: Array<ReactElement<StepProps<Steps>>> | ReactElement<StepProps<Steps>>; | ||
} | ||
|
||
export interface StepProps<Steps extends NonEmptyArray<string>> extends PropsWithChildren { | ||
name: Steps[number]; | ||
onNext?: VoidFunction; | ||
} | ||
|
||
export const Funnel = <Steps extends NonEmptyArray<string>>(props: FunnelProps<Steps>) => { | ||
const { steps, step, children } = props; | ||
const validChildren = Children.toArray(children) | ||
.filter(isValidElement<StepProps<Steps>>) | ||
.filter(({ props }) => steps.includes(props.name)); | ||
|
||
const targetStep = validChildren.find(child => child.props.name === step); | ||
|
||
if (!targetStep) { | ||
throw new RuntimeError( | ||
{ code: 'WRONG_URL_FORMAT' }, | ||
`${step} 스텝 컴포넌트를 찾지 못했습니다.`, | ||
); | ||
} | ||
|
||
return targetStep; | ||
}; | ||
|
||
export const Step = <T extends NonEmptyArray<string>>({ onNext, children }: StepProps<T>) => { | ||
useEffect(() => { | ||
onNext?.(); | ||
}, [onNext]); | ||
|
||
return children; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const FORM_EXIT_CONFIRMATION_MESSAGE = | ||
'페이지를 떠나면 현재까지 입력한 정보가 사라질 수 있어요. 뒤로 가시겠어요?'; | ||
|
||
export { FORM_EXIT_CONFIRMATION_MESSAGE }; |
Oops, something went wrong.