-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIntro.tsx
More file actions
59 lines (48 loc) · 1.52 KB
/
Intro.tsx
File metadata and controls
59 lines (48 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { useLocation, useNavigate } from 'react-router-dom';
import * as styles from '@/page/intro/Intro.css';
import { PATH } from '@/route';
type PageStateType = 'MANDALART' | 'CORE_GOAL' | 'SUB_GOALS';
const ROUTE_BY_STATE: Record<PageStateType, string> = {
MANDALART: PATH.TODO,
CORE_GOAL: PATH.TODO_UPPER,
SUB_GOALS: PATH.TODO_LOWER,
};
const MESSAGE = {
START: {
title: '목표를 이루는 66일의 여정 <br/> 함께 시작해볼까요?',
button: '만다라트 만들기',
},
CONTINUE: {
title: '작성하던 만다라트가 있어요 <br/> 마저 목표를 세워볼까요?',
button: '이어서 작성하기',
},
};
const Intro = () => {
const navigate = useNavigate();
const location = useLocation();
const pageState = (location.state as { pageState?: PageStateType })?.pageState;
const isStart = pageState === 'MANDALART';
const content = isStart ? MESSAGE.START : MESSAGE.CONTINUE;
const handleGoTodo = () => {
if (!pageState) {
navigate(PATH.TODO);
return;
}
navigate(ROUTE_BY_STATE[pageState]);
};
const renderTitle = content.title.split('<br/>').map((line, index) => (
<span key={index}>
{line}
{index !== content.title.split('<br/>').length - 1 && <br />}
</span>
));
return (
<main className={styles.introContainer}>
<h1 className={styles.introText}>{renderTitle}</h1>
<button className={styles.buttonContainer} onClick={handleGoTodo}>
{content.button}
</button>
</main>
);
};
export default Intro;