-
Notifications
You must be signed in to change notification settings - Fork 5
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
[FE] 행사 생성 페이지에 퍼널 방식 적용 #591
Changes from all commits
34ba35e
703714d
e36c678
9f3671b
072b2d1
ec8beb5
25f93ad
4b0e1bc
888d32e
3e7e507
fe3f795
8e0a7c5
979dd73
ea487e5
8f53bdf
39b70ff
359dfcc
1f4dc28
9b20499
9f317eb
f92acbb
e4e49c4
b721f5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {useState} from 'react'; | ||
|
||
import useSetEventNameStep from './useSetEventNameStep'; | ||
|
||
// 행사 생성 페이지에서 여러 스텝에 걸쳐 사용되는 상태를 선언해 내려주는 용도의 훅입니다. | ||
const useCreateEventData = () => { | ||
const eventNameProps = useSetEventNameStep(); | ||
const [eventToken, setEventToken] = useState(''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이벤트 토큰은 행사가 생성된 후 백엔드로부터 값을 받아오는 값이니깐 마지막 퍼널에서만 필요할 것 같아요. |
||
|
||
return { | ||
eventNameProps, | ||
eventToken, | ||
setEventToken, | ||
}; | ||
}; | ||
|
||
export default useCreateEventData; |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,58 @@ | ||||||||||||
import {useState} from 'react'; | ||||||||||||
|
||||||||||||
type UseFunnel = { | ||||||||||||
defaultStep: string; | ||||||||||||
stepList: string[]; | ||||||||||||
}; | ||||||||||||
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 우리가 정의한 step과 여기의 step이 다른 의미라서 조금 헷갈릴 수 있을 것 같아요. |
||||||||||||
|
||||||||||||
type StepProps = { | ||||||||||||
children: React.ReactNode; | ||||||||||||
name: string; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
type FunnelProps = { | ||||||||||||
children: React.ReactElement<StepProps>[]; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Funnel안에 Step밖에 못 오게 한 것 넘 좋아잉 |
||||||||||||
}; | ||||||||||||
|
||||||||||||
const useFunnel = ({defaultStep, stepList}: UseFunnel) => { | ||||||||||||
const [step, setStep] = useState(defaultStep); | ||||||||||||
|
||||||||||||
const moveToNextStep = () => { | ||||||||||||
const curStepIndex = stepList.indexOf(step); | ||||||||||||
|
||||||||||||
if (curStepIndex === stepList.length - 1) return; | ||||||||||||
|
||||||||||||
setStep(stepList[curStepIndex + 1]); | ||||||||||||
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
}; | ||||||||||||
|
||||||||||||
const moveToPrevStep = () => { | ||||||||||||
const curStepIndex = stepList.indexOf(step); | ||||||||||||
|
||||||||||||
if (curStepIndex === 0) return; | ||||||||||||
|
||||||||||||
setStep(stepList[curStepIndex - 1]); | ||||||||||||
Comment on lines
+31
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
}; | ||||||||||||
|
||||||||||||
const Step = (stepProps: StepProps) => { | ||||||||||||
return <>{stepProps.children}</>; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
const Funnel = ({children}: FunnelProps) => { | ||||||||||||
const targetStep = children.find(curStep => curStep.props.name === step); | ||||||||||||
|
||||||||||||
if (!targetStep) | ||||||||||||
throw new Error(`현재 ${step} 단계에 보여줄 컴포넌트가 존재하지 않습니다. Step 컴포넌트를 호출해 사용해주세요.`); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 역시 웨디 에러까지 꼼꼼히 👍👍 |
||||||||||||
|
||||||||||||
return <>{targetStep}</>; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
return { | ||||||||||||
Step, | ||||||||||||
step, | ||||||||||||
Funnel, | ||||||||||||
moveToNextStep, | ||||||||||||
moveToPrevStep, | ||||||||||||
}; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
export default useFunnel; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {useState} from 'react'; | ||
import {useNavigate} from 'react-router-dom'; | ||
|
||
import validateEventPassword from '@utils/validate/validateEventPassword'; | ||
|
||
import RULE from '@constants/rule'; | ||
|
||
import useRequestPostEvent from './queries/event/useRequestPostEvent'; | ||
|
||
export type UseSetEventPasswordStepReturnType = ReturnType<typeof useSetEventPasswordStep>; | ||
|
||
const useSetEventPasswordStep = () => { | ||
const [password, setPassword] = useState(''); | ||
const [errorMessage, setErrorMessage] = useState(''); | ||
const [canSubmit, setCanSubmit] = useState(false); | ||
const {postEvent: requestPostEvent, isPostEventPending} = useRequestPostEvent(); | ||
|
||
const submitDataForPostEvent = async ({ | ||
event, | ||
eventName, | ||
setEventToken, | ||
}: { | ||
event: React.FormEvent<HTMLFormElement>; | ||
eventName: string; | ||
setEventToken: (eventToken: string) => void; | ||
}) => { | ||
event.preventDefault(); | ||
|
||
await postEvent(eventName, setEventToken); | ||
}; | ||
|
||
const getPasswordWithPad = () => { | ||
return String(password).padStart(4, '0'); | ||
}; | ||
|
||
const postEvent = async (eventName: string, updateEventToken: (eventToken: string) => void) => { | ||
await requestPostEvent( | ||
{eventName, password: getPasswordWithPad()}, | ||
{ | ||
onSuccess: ({eventId}) => { | ||
updateEventToken(eventId); | ||
}, | ||
}, | ||
); | ||
}; | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const newValue = event.target.value; | ||
const validation = validateEventPassword(newValue); | ||
|
||
setCanSubmit(newValue.length === RULE.maxEventPasswordLength); | ||
|
||
if (validation.isValid) { | ||
setPassword(newValue); | ||
setErrorMessage(''); | ||
} else { | ||
event.target.value = password; | ||
setErrorMessage(validation.errorMessage ?? ''); | ||
Comment on lines
+53
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ErrorMessage type이 string | null 이었던 걸로 기억합니다. 그래서 빈 문자열 대신에 null을 넣는 것이 더 좋을 것 같아요! 하지만 중요한 것은 아니라 패쑤해도 괜찮아유 |
||
} | ||
}; | ||
|
||
return { | ||
submitDataForPostEvent, | ||
errorMessage, | ||
handleChange, | ||
canSubmit, | ||
isPostEventPending, | ||
password, | ||
}; | ||
}; | ||
|
||
export default useSetEventPasswordStep; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
back onClick의 기본값을 navigate(-1)기능을 넣어준 것은 컴포넌트의 이름이 back이기 때문에 ㄷ로가기 기능을 default로 넣어준걸까요?