Skip to content

Commit 8a711b3

Browse files
committed
feat: 목표 작성 상태에 따른 분기 처리
1 parent 1def14c commit 8a711b3

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

src/common/hook/useGoogleAuth.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ import getGoogleAuthCode from '@/api/auth/googleLogin/util/getGoogleAuthCode';
44
import getAccessToken from '@/api/auth/googleLogin/util/getAccessToken';
55

66
interface UserData {
7-
email: string;
8-
name: string;
9-
profileImageUrl: string;
10-
socialProvider: string;
11-
socialToken: string;
127
exists: boolean;
8+
userId?: number;
139
accessToken?: string;
14-
onboardingCompleted?: boolean;
10+
onboardingPage: string;
1511
}
1612

1713
export const useGoogleAuth = (): UserData | null => {

src/page/callback/GoogleCallback.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ const GoogleCallback = () => {
1313
return;
1414
}
1515

16-
const isExistingUser = userData.exists;
16+
const { exists, onboardingPage } = userData;
1717

18-
if (isExistingUser) {
19-
navigate(PATH.INTRO, {
20-
state: { isWritten: userData.onboardingCompleted },
21-
});
22-
} else {
18+
if (!exists) {
2319
navigate(PATH.SIGNUP, {
2420
state: { userData },
2521
});
22+
return;
23+
}
24+
25+
if (onboardingPage === 'ONBOARDING_COMPLETED') {
26+
navigate(PATH.MANDAL);
27+
} else {
28+
navigate(PATH.INTRO, { state: { pageState: onboardingPage } });
2629
}
2730
}, [userData, navigate]);
2831

src/page/intro/Intro.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import { useLocation, useNavigate } from 'react-router-dom';
22
import * as styles from '@/page/intro/Intro.css';
3+
import { PATH } from '@/route';
4+
5+
type PageStateType = 'MANDALART' | 'CORE_GOAL' | 'SUB_GOALS';
6+
7+
const ROUTE_BY_STATE: Record<PageStateType, string> = {
8+
MANDALART: PATH.TODO,
9+
CORE_GOAL: PATH.TODO_UPPER,
10+
SUB_GOALS: PATH.TODO_LOWER,
11+
};
312

413
const MESSAGE = {
514
START: {
@@ -15,13 +24,19 @@ const MESSAGE = {
1524
const Intro = () => {
1625
const navigate = useNavigate();
1726
const location = useLocation();
18-
const isWritten = location.state?.isWritten ?? false; // 기본값 false
1927

20-
const handleNavigateToTodo = () => {
21-
navigate('/todo');
22-
};
28+
const pageState = (location.state as { pageState?: PageStateType })?.pageState;
29+
const isStart = pageState === 'MANDALART';
30+
31+
const content = isStart ? MESSAGE.START : MESSAGE.CONTINUE;
2332

24-
const content = isWritten ? MESSAGE.CONTINUE : MESSAGE.START;
33+
const handleGoTodo = () => {
34+
if (!pageState) {
35+
navigate(PATH.TODO);
36+
return;
37+
}
38+
navigate(ROUTE_BY_STATE[pageState]);
39+
};
2540

2641
const renderTitle = content.title.split('<br/>').map((line, index) => (
2742
<span key={index}>
@@ -33,7 +48,7 @@ const Intro = () => {
3348
return (
3449
<main className={styles.introContainer}>
3550
<h1 className={styles.introText}>{renderTitle}</h1>
36-
<button className={styles.buttonContainer} onClick={handleNavigateToTodo}>
51+
<button className={styles.buttonContainer} onClick={handleGoTodo}>
3752
{content.button}
3853
</button>
3954
</main>

0 commit comments

Comments
 (0)