File tree Expand file tree Collapse file tree 4 files changed +32
-3
lines changed
Expand file tree Collapse file tree 4 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -10,10 +10,13 @@ export default function MainPage() {
1010 const { goal, isLoading } = useFetchGetGoal ( ) ;
1111 const router = useRouter ( ) ;
1212
13- // goal이 없고 로딩이 끝났으면 온보딩 페이지로 이동
13+ // goal이 없고 로딩이 끝났으며, 온보딩 기록이 없으면 온보딩 페이지로 이동
1414 useEffect ( ( ) => {
15- if ( ! isLoading && goal ) {
16- router . replace ( '/onboarding' ) ;
15+ if ( ! isLoading && ! goal ) {
16+ const onboardingVisited = typeof window !== 'undefined' && localStorage . getItem ( 'onboarding_visited_at' ) ;
17+ if ( ! onboardingVisited ) {
18+ router . replace ( '/onboarding' ) ;
19+ }
1720 }
1821 } , [ isLoading , goal , router ] ) ;
1922
Original file line number Diff line number Diff line change 33import Image from 'next/image' ;
44import Button from '@/shared/components/navigation/Button' ;
55import { useRouter } from 'next/navigation' ;
6+ import { useEffect } from 'react' ;
67
78export default function OnBoardingPage ( ) {
89 const router = useRouter ( ) ;
10+
11+ // 온보딩 페이지 진입 시 방문 날짜 저장
12+ useEffect ( ( ) => {
13+ if ( typeof window !== 'undefined' ) {
14+ localStorage . setItem ( 'onboarding_visited_at' , new Date ( ) . toISOString ( ) ) ;
15+ }
16+ } , [ ] ) ;
17+
918 return (
1019 < div className = "flex w-full h-full bg-[#1C1C1E]" >
1120 < div className = "flex flex-1 flex-col gap-14 px-4 py-8" >
Original file line number Diff line number Diff line change 1+ import { Goal } from '@/shared/type/goal' ;
2+ import { useRouter } from 'next/navigation' ;
3+ import { useEffect } from 'react' ;
4+
5+ export function useGoOnboarding ( isLoading : boolean , goal : Goal | null ) {
6+ const router = useRouter ( ) ;
7+ // goal이 없고 로딩이 끝났으며, 온보딩 기록이 없으면 온보딩 페이지로 이동
8+ useEffect ( ( ) => {
9+ if ( ! isLoading && ! goal ) {
10+ const onboardingVisited = typeof window !== 'undefined' && localStorage . getItem ( 'onboarding_visited_at' ) ;
11+ if ( ! onboardingVisited ) {
12+ router . replace ( '/onboarding' ) ;
13+ }
14+ }
15+ } , [ isLoading , goal , router ] ) ;
16+ }
Original file line number Diff line number Diff line change 1+ export { useGoOnboarding } from './hooks/useGoOnboarding' ;
You can’t perform that action at this time.
0 commit comments