Skip to content

Commit baeafcf

Browse files
committed
[feat] : 온보딩 진입 기능 추가 및 방문 기록 저장
- goal이 없고, localStorage에 온보딩 방문 기록이 없을 때만 온보딩 페이지로 이동하는 로직을 useGoOnboarding 커스텀 훅으로 분리 - 온보딩 페이지 진입 시 localStorage에 'onboarding_visited_at' 키로 방문 날짜 저장
1 parent 368f1ca commit baeafcf

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/app/(home)/home/page.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff 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

src/app/(home)/onboarding/page.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
import Image from 'next/image';
44
import Button from '@/shared/components/navigation/Button';
55
import { useRouter } from 'next/navigation';
6+
import { useEffect } from 'react';
67

78
export 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">
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

src/feature/onBoarding/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { useGoOnboarding } from './hooks/useGoOnboarding';

0 commit comments

Comments
 (0)