-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventFunnel.tsx
More file actions
165 lines (158 loc) · 5.78 KB
/
EventFunnel.tsx
File metadata and controls
165 lines (158 loc) · 5.78 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import HostSelectionPage from '../../../pages/event/ui/host/HostSelectionPage';
import HostCreationPage from '../../../pages/event/ui/host/HostCreationPage';
import EventTitlePage from '../../../pages/event/ui/create-event/EventTitlePage';
import EventPeriodPage from '../../../pages/event/ui/create-event/EventPeriodPage';
import EventInfoPage from '../../../pages/event/ui/create-event/EventInfoPage';
import EventTypePage from '../../../pages/event/ui/create-event/EventTypePage';
import EventTagPage from '../../../pages/event/ui/create-event/EventTagPage';
import EventOrganizerInfoPage from '../../../pages/event/ui/create-event/EventOrganizerInfoPage';
import EventRegisterLayout from '../../../shared/ui/backgrounds/EventRegisterLayout';
import { useLocation, useNavigate } from 'react-router-dom';
import { EventFunnelInterface, StepNames } from '../../../shared/types/funnelType';
import { useFunnelState } from '../model/FunnelContext';
import { useEventCreation } from '../hooks/useEventHook';
import { useHostCreation } from '../../host/hook/useHostHook';
import { HostCreationRequest } from '../../host/model/host';
import { useState } from 'react';
const EventFunnel = ({ onNext, Funnel, Step, currentStep }: EventFunnelInterface) => {
const navigate = useNavigate();
const { eventState, hostState, setHostState } = useFunnelState();
const { mutate: createEvent } = useEventCreation();
const { mutate: createHost } = useHostCreation();
const location = useLocation();
const [backPath] = useState(location.state?.backPath ?? '/');
//중복 클릭 방지
const [isSubmittingEvent, setIsSubmittingEvent] = useState(false);
const [isSubmittingHost, setIsSubmittingHost] = useState(false);
const stepOrder = [
StepNames.HostSelection,
StepNames.HostCreation,
StepNames.EventTitle,
StepNames.EventPeriod,
StepNames.EventOrganizerInfo,
StepNames.EventInfo,
StepNames.EventType,
StepNames.EventTag,
] as const;
const stepNameToIndex = (name: StepNames) => stepOrder.indexOf(name);
const goTo = (stepName: StepNames) => {
const index = stepNameToIndex(stepName);
onNext(String(index));
};
const handleNext = (nextStep: string) => {
onNext(nextStep);
};
const handleCreateEvent = () => {
if (isSubmittingEvent) return;
setIsSubmittingEvent(true);
createEvent(eventState, {
onSuccess: () => {
navigate('/menu/myHost');
},
onError: error => {
console.error('API 호출 실패:', error);
},
});
}
const initialHostState: HostCreationRequest = {
profileImageUrl: '',
hostChannelName: '',
hostEmail: '',
channelDescription: '',
};
const handleHostCreation = () => {
if (isSubmittingHost) return;
setIsSubmittingHost(true);
createHost(hostState, {
onSuccess: () => {
setHostState(initialHostState);
goTo(StepNames.HostSelection);
},
onError: error => {
const message = error?.message || '호스트 생성에 실패했습니다. 다시 시도해주세요.';
alert(message);
},
});
};
return (
<Funnel>
<Step name={StepNames.HostSelection}>
<EventRegisterLayout
title="이벤트를 호스팅할 채널을 선택해주세요"
onNext={() => goTo(StepNames.EventTitle)}
onPrev={() => navigate(backPath)}
requireValidation={true}
>
<HostSelectionPage onNext={handleNext} currentStep={currentStep} />
</EventRegisterLayout>
</Step>
<Step name={StepNames.HostCreation}>
<EventRegisterLayout
title="채널을 새로 생성합니다"
onNext={() => handleHostCreation()}
onPrev={() => goTo(StepNames.HostSelection)}
requireValidation={true}
>
<HostCreationPage />
</EventRegisterLayout>
</Step>
<Step name={StepNames.EventTitle}>
<EventRegisterLayout
title="이벤트 제목을 입력해주세요"
onNext={() => goTo(StepNames.EventPeriod)}
onPrev={() => goTo(StepNames.HostSelection)}
requireValidation={true}
>
<EventTitlePage />
</EventRegisterLayout>
</Step>
<Step name={StepNames.EventPeriod}>
<EventRegisterLayout
title="이벤트 기간을 입력해주세요"
onNext={() => goTo(StepNames.EventOrganizerInfo)}
onPrev={() => goTo(StepNames.EventTitle)}
>
<EventPeriodPage />
</EventRegisterLayout>
</Step>
<Step name={StepNames.EventOrganizerInfo}>
<EventRegisterLayout
title="이벤트 주최자 정보를 입력해주세요"
onNext={() => goTo(StepNames.EventInfo)}
onPrev={() => goTo(StepNames.EventPeriod)}
requireValidation={true}
>
<EventOrganizerInfoPage />
</EventRegisterLayout>
</Step>
<Step name={StepNames.EventInfo}>
<EventRegisterLayout
title="이벤트 정보를 입력해주세요"
onNext={() => goTo(StepNames.EventType)}
onPrev={() => goTo(StepNames.EventOrganizerInfo)}
requireValidation={true}
>
<EventInfoPage />
</EventRegisterLayout>
</Step>
<Step name={StepNames.EventType}>
<EventRegisterLayout
title="이벤트 진행방식을 선택해주세요"
onNext={() => goTo(StepNames.EventTag)}
onPrev={() => goTo(StepNames.EventInfo)}
>
<EventTypePage />
</EventRegisterLayout>
</Step>
<Step name={StepNames.EventTag}>
<EventRegisterLayout
onNext={() => handleCreateEvent()}
onPrev={() => goTo(StepNames.EventType)}
>
<EventTagPage />
</EventRegisterLayout>
</Step>
</Funnel>
);
};
export default EventFunnel;