-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunnelPage.tsx
More file actions
72 lines (64 loc) · 2.2 KB
/
FunnelPage.tsx
File metadata and controls
72 lines (64 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { useEffect, useState } from 'react';
import { useFunnel } from '../../../../features/event/hooks/useFunnelHook';
import EventFunnel from '../../../../features/event/ui/EventFunnel';
import { useLocation, useNavigate } from 'react-router-dom';
import { FunnelProvider } from '../../../../features/event/model/FunnelContext';
// import { MAIN_ROUTES } from '../../../../app/routes/routes';
const FunnelPage = () => {
const { Funnel, Step, setStep, currentStep, steps } = useFunnel(0);
const [previousStep, setPreviousStep] = useState<number[]>([]);
const navigate = useNavigate();
const location = useLocation();
const onNextClick = (targetStep: number) => {
const nextStep = targetStep !== undefined ? targetStep : currentStep + 1;
if (nextStep < steps.length) {
setPreviousStep([...previousStep, currentStep]);
setStep(nextStep);
navigate(`${location.pathname}?step=${steps[nextStep]}`);
}
};
// ${MAIN_ROUTES.eventCreation}?step=${steps[0]}`
const onPrevClick = () => {
if (currentStep === 1 || currentStep === 2) {
// HostCreation에서 뒤로가기: 브라우저 히스토리 뒤로
navigate(-1);
return;
}
const prevStep = previousStep.pop();
if (prevStep !== undefined) {
setStep(prevStep);
navigate(`${location.pathname}?step=${steps[prevStep]}`);
}
};
useEffect(() => {
const params = new URLSearchParams(location.search);
const step = params.get('step');
if (step) {
const index = steps.findIndex(s => s === step);
if (index !== -1) {
setStep(index);
}
}
}, [location.search, setStep, steps]);
// Funnel current step을 HostSelection으로 초기화
useEffect(() => {
setStep(0);
setPreviousStep([]);
if (!new URLSearchParams(location.search).get('step')) {
navigate(`${location.pathname}?step=${steps[0]}`, { replace: true });
}
}, []);
return (
<FunnelProvider>
<EventFunnel
onNext={(nextStep: string) => onNextClick(Number(nextStep))}
onPrev={onPrevClick}
Funnel={Funnel}
Step={Step}
setStep={setStep}
currentStep={currentStep}
/>
</FunnelProvider>
);
};
export default FunnelPage;