Skip to content

Commit d22d6b5

Browse files
feat: mainCard useFunnel hook 적용
1 parent 72fc2d9 commit d22d6b5

File tree

1 file changed

+14
-24
lines changed
  • apps/client/src/pages/onBoarding/components/funnel

1 file changed

+14
-24
lines changed

apps/client/src/pages/onBoarding/components/funnel/MainCard.tsx

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ const MacStep = lazy(() => import('./step/MacStep'));
99
const FinalStep = lazy(() => import('./step/FinalStep'));
1010
import { cva } from 'class-variance-authority';
1111
import { usePostSignUp } from '@shared/apis/queries';
12-
import { useNavigate, useLocation } from 'react-router-dom';
1312
import { firebaseConfig } from '../../../../firebase-config';
1413
import { initializeApp } from 'firebase/app';
1514
import { getMessaging, getToken } from 'firebase/messaging';
1615
import { registerServiceWorker } from '@pages/onBoarding/utils/registerServiceWorker';
1716
import { AlarmsType } from '@constants/alarms';
1817
import { normalizeTime } from '@pages/onBoarding/utils/formatRemindTime';
18+
import { useFunnel } from '@shared/hooks/useFunnel';
1919
const stepProgress = [{ progress: 33 }, { progress: 66 }, { progress: 100 }];
2020
import {
2121
Step,
@@ -50,11 +50,13 @@ const CardStyle = cva(
5050
);
5151

5252
const MainCard = () => {
53-
const navigate = useNavigate();
54-
const location = useLocation();
5553
const { mutate: postSignData } = usePostSignUp();
5654

57-
const [step, setStep] = useState<StepType>(Step.STORY_0);
55+
const { currentStep: step, currentIndex, setStep, goNext, goPrev } =
56+
useFunnel<StepType>({
57+
steps: stepOrder,
58+
initialStep: Step.STORY_0,
59+
});
5860
const [direction, setDirection] = useState(0);
5961
const [alarmSelected, setAlarmSelected] = useState<1 | 2 | 3>(1);
6062
const [isMac, setIsMac] = useState(false);
@@ -64,17 +66,11 @@ const MainCard = () => {
6466
const [jobShareAgree, setJobShareAgree] = useState(true);
6567

6668
useEffect(() => {
67-
const params = new URLSearchParams(location.search);
6869
const storedEmail = localStorage.getItem('email');
6970
if (storedEmail) {
7071
setUserEmail(storedEmail);
7172
}
72-
73-
const stepParam = params.get('step') as StepType;
74-
if (stepParam && Object.values(Step).includes(stepParam)) {
75-
setStep(stepParam);
76-
}
77-
}, [location.search]);
73+
}, []);
7874

7975
const app = initializeApp(firebaseConfig);
8076
const messaging = getMessaging(app);
@@ -154,8 +150,7 @@ const MainCard = () => {
154150
};
155151

156152
const nextStep = async () => {
157-
const idx = stepOrder.indexOf(step);
158-
const next = stepOrder[idx + 1];
153+
const next = stepOrder[currentIndex + 1];
159154
const isAlarmStep = step === Step.ALARM;
160155
const isFinalStep = step === Step.FINAL;
161156
const isMacStep = next === Step.MAC;
@@ -173,7 +168,6 @@ const MainCard = () => {
173168
if (shouldSkipMacStep) {
174169
setDirection(1);
175170
setStep(Step.FINAL);
176-
navigate(`/onboarding?step=${Step.FINAL}`);
177171
return;
178172
}
179173

@@ -192,22 +186,18 @@ const MainCard = () => {
192186
}
193187

194188
setDirection(1);
195-
setStep(next);
196-
navigate(`/onboarding?step=${next}`);
189+
goNext();
197190
sendGAEvent(
198-
`onboard-step-${idx + 1}`,
199-
`onboard-step-${idx + 1}`,
200-
`onboard-step-${idx + 1}`
191+
`onboard-step-${currentIndex + 1}`,
192+
`onboard-step-${currentIndex + 1}`,
193+
`onboard-step-${currentIndex + 1}`
201194
);
202195
};
203196

204197
const prevStep = () => {
205-
const idx = stepOrder.indexOf(step);
206-
if (idx > 0) {
207-
const previous = stepOrder[idx - 1];
198+
if (currentIndex > 0) {
208199
setDirection(-1);
209-
setStep(previous);
210-
navigate(`/onboarding?step=${previous}`);
200+
goPrev();
211201
}
212202
};
213203

0 commit comments

Comments
 (0)