1- import { Progress , Button , sendGAEvent } from '@pinback/design-system/ui' ;
2- import { useState , useEffect , lazy , Suspense } from 'react' ;
1+ import { Progress , Button } from '@pinback/design-system/ui' ;
2+ import { lazy , Suspense } from 'react' ;
33import { motion , AnimatePresence } from 'framer-motion' ;
44import SocialLoginStep from './step/SocialLoginStep' ;
55const StoryStep = lazy ( ( ) => import ( './step/StoryStep' ) ) ;
@@ -8,21 +8,13 @@ const AlarmStep = lazy(() => import('./step/AlarmStep'));
88const MacStep = lazy ( ( ) => import ( './step/MacStep' ) ) ;
99const FinalStep = lazy ( ( ) => import ( './step/FinalStep' ) ) ;
1010import { cva } from 'class-variance-authority' ;
11- import { usePostSignUp } from '@shared/apis/queries' ;
12- import { firebaseConfig } from '../../../../firebase-config' ;
13- import { initializeApp } from 'firebase/app' ;
14- import { getMessaging , getToken } from 'firebase/messaging' ;
15- import { registerServiceWorker } from '@pages/onBoarding/utils/registerServiceWorker' ;
16- import { AlarmsType } from '@constants/alarms' ;
17- import { normalizeTime } from '@pages/onBoarding/utils/formatRemindTime' ;
18- import { useFunnel } from '@shared/hooks/useFunnel' ;
1911const stepProgress = [ { progress : 33 } , { progress : 66 } , { progress : 100 } ] ;
2012import {
2113 Step ,
22- stepOrder ,
2314 StepType ,
2415 storySteps ,
2516} from '@pages/onBoarding/constants/onboardingSteps' ;
17+ import { useOnboardingFunnel } from '@pages/onBoarding/hooks/useOnboardingFunnel' ;
2618
2719const variants = {
2820 slideIn : ( direction : number ) => ( {
@@ -50,74 +42,16 @@ const CardStyle = cva(
5042) ;
5143
5244const MainCard = ( ) => {
53- const { mutate : postSignData } = usePostSignUp ( ) ;
54-
55- const { currentStep : step , currentIndex, setStep, goNext, goPrev } =
56- useFunnel < StepType > ( {
57- steps : stepOrder ,
58- initialStep : Step . STORY_0 ,
59- } ) ;
60- const [ direction , setDirection ] = useState ( 0 ) ;
61- const [ alarmSelected , setAlarmSelected ] = useState < 1 | 2 | 3 > ( 1 ) ;
62- const [ isMac , setIsMac ] = useState ( false ) ;
63- const [ userEmail , setUserEmail ] = useState ( '' ) ;
64- const [ remindTime , setRemindTime ] = useState ( '09:00' ) ;
65- const [ fcmToken , setFcmToken ] = useState < string | null > ( null ) ;
66- const [ jobShareAgree , setJobShareAgree ] = useState ( true ) ;
67-
68- useEffect ( ( ) => {
69- const storedEmail = localStorage . getItem ( 'email' ) ;
70- if ( storedEmail ) {
71- setUserEmail ( storedEmail ) ;
72- }
73- } , [ ] ) ;
74-
75- const app = initializeApp ( firebaseConfig ) ;
76- const messaging = getMessaging ( app ) ;
77-
78- const requestFCMToken = async ( ) : Promise < string | null > => {
79- try {
80- const permission = await Notification . requestPermission ( ) ;
81- registerServiceWorker ( ) ;
82-
83- if ( permission !== 'granted' ) {
84- alert ( '알림 권한 허용이 필요합니다!' ) ;
85- return null ;
86- }
87-
88- const forFcmtoken = await getToken ( messaging , {
89- vapidKey : import . meta. env . VITE_FIREBASE_VAPID_KEY ,
90- } ) ;
91-
92- if ( forFcmtoken ) {
93- return forFcmtoken ;
94- } else {
95- alert ( '토큰 생성 실패. 다시 시도해주세요.' ) ;
96- return null ;
97- }
98- } catch ( error ) {
99- console . error ( 'FCM 토큰 받는 도중 오류:' , error ) ;
100- alert ( '알림 설정 중 오류가 발생했습니다. 다시 시도해주세요.' ) ;
101- return null ;
102- }
103- } ;
104-
105- useEffect ( ( ) => {
106- const ua = navigator . userAgent . toLowerCase ( ) ;
107- if ( ua . includes ( 'mac os' ) || ua . includes ( 'iphone' ) || ua . includes ( 'ipad' ) ) {
108- setIsMac ( true ) ;
109- }
110-
111- ( async ( ) => {
112- const token = await requestFCMToken ( ) ;
113- if ( token ) {
114- setFcmToken ( token ) ;
115- localStorage . setItem ( 'FcmToken' , token ) ;
116- } else {
117- alert ( '푸시 알람 설정 에러' ) ;
118- }
119- } ) ( ) ;
120- } , [ ] ) ;
45+ const {
46+ step,
47+ direction,
48+ alarmSelected,
49+ jobShareAgree,
50+ setAlarmSelected,
51+ setJobShareAgree,
52+ nextStep,
53+ prevStep,
54+ } = useOnboardingFunnel ( ) ;
12155
12256 const renderStep = ( ) => {
12357 switch ( step ) {
@@ -149,58 +83,6 @@ const MainCard = () => {
14983 }
15084 } ;
15185
152- const nextStep = async ( ) => {
153- const next = stepOrder [ currentIndex + 1 ] ;
154- const isAlarmStep = step === Step . ALARM ;
155- const isFinalStep = step === Step . FINAL ;
156- const isMacStep = next === Step . MAC ;
157- const shouldSkipMacStep = isMacStep && ! isMac ;
158-
159- if ( isAlarmStep ) {
160- if ( alarmSelected === 1 ) setRemindTime ( '09:00' ) ;
161- else if ( alarmSelected === 2 ) setRemindTime ( '20:00' ) ;
162- else {
163- const raw = AlarmsType [ alarmSelected - 1 ] . time ;
164- setRemindTime ( normalizeTime ( raw ) ) ;
165- }
166- }
167-
168- if ( shouldSkipMacStep ) {
169- setDirection ( 1 ) ;
170- setStep ( Step . FINAL ) ;
171- return ;
172- }
173-
174- if ( isFinalStep ) {
175- postSignData (
176- { email : userEmail , remindDefault : remindTime , fcmToken } ,
177- {
178- onSuccess : ( ) => ( window . location . href = '/' ) ,
179- onError : ( ) => {
180- const savedEmail = localStorage . getItem ( 'email' ) ;
181- if ( savedEmail ) window . location . href = '/' ;
182- } ,
183- }
184- ) ;
185- return ;
186- }
187-
188- setDirection ( 1 ) ;
189- goNext ( ) ;
190- sendGAEvent (
191- `onboard-step-${ currentIndex + 1 } ` ,
192- `onboard-step-${ currentIndex + 1 } ` ,
193- `onboard-step-${ currentIndex + 1 } `
194- ) ;
195- } ;
196-
197- const prevStep = ( ) => {
198- if ( currentIndex > 0 ) {
199- setDirection ( - 1 ) ;
200- goPrev ( ) ;
201- }
202- } ;
203-
20486 return (
20587 < div
20688 className = { CardStyle ( {
0 commit comments