-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUpperTodo.tsx
More file actions
102 lines (85 loc) · 2.95 KB
/
UpperTodo.tsx
File metadata and controls
102 lines (85 loc) · 2.95 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import Mandalart from '@common/component/Mandalart/Mandalart';
import * as styles from './UpperTodo.css';
import { SubGoalFields, UpperTodoHeader, MandalCompleteButton } from './component';
import { useUpperTodoState, useUpperTodoAI } from './hook';
import { toMainSubGoals } from './utils/goal';
import { DEFAULT_TEXT, ALERT, GOAL_COUNT } from './constants';
import GradientBackground from '@/common/component/Background/GradientBackground';
import { PATH } from '@/route';
import { useGetUser } from '@/api/domain/signup/hook/useGetUser';
import { useMandalartId } from '@/common/hook/useMandalartId';
const UpperTodo = () => {
const mandalartId = useMandalartId();
const navigate = useNavigate();
const { data: user } = useGetUser();
const {
data,
subGoals,
setSubGoals,
isTooltipOpen,
setIsTooltipOpen,
coreGoalIds,
handleSubGoalEnter,
refetch,
refetchCoreGoalIds,
} = useUpperTodoState(mandalartId);
const mainGoal = data?.title || DEFAULT_TEXT.mainGoal;
const displayUserName = user?.name ?? '김도트';
const handleNavigateLower = () => {
if (!mandalartId) {
alert(ALERT.noMandalartId);
return;
}
navigate(PATH.TODO_LOWER);
};
const [hasAiRecommendUsed, setHasAiRecommendUsed] = useState(false);
const { isLoading: isUpperAiLoading, handleOpenAiModal } = useUpperTodoAI({
mandalartId,
mainGoal,
subGoals,
setSubGoals,
refetch,
refetchCoreGoalIds,
setIsTooltipOpen,
hasAiBeenUsed: hasAiRecommendUsed,
markAiUsed: () => setHasAiRecommendUsed(true),
});
const filledSubGoalCount = subGoals.filter((v) => v.trim() !== '').length;
const hasFilledSubGoals = filledSubGoalCount > 0;
const isAllSubGoalsFilled = filledSubGoalCount >= GOAL_COUNT;
const isAiUsed = hasAiRecommendUsed || isUpperAiLoading || isAllSubGoalsFilled;
const handleEnter = (index: number, value: string) => {
handleSubGoalEnter(index, value);
};
return (
<main className={styles.upperTodoContainer}>
<GradientBackground />
<section className={styles.upperTodoBoxWrapper}>
<UpperTodoHeader
userName={displayUserName}
mainGoal={mainGoal}
isTooltipOpen={isTooltipOpen}
setIsTooltipOpen={setIsTooltipOpen}
isAiUsed={isAiUsed}
handleOpenAiModal={handleOpenAiModal}
/>
<div className={styles.upperTodoBox}>
<Mandalart type="TODO_MAIN" mainGoal={mainGoal} subGoals={toMainSubGoals(subGoals)} />
<SubGoalFields
values={subGoals}
onChange={setSubGoals}
idPositions={coreGoalIds?.coreGoalIds || []}
onEnter={handleEnter}
/>
</div>
<MandalCompleteButton
hasFilledSubGoals={hasFilledSubGoals}
handleNavigateLower={handleNavigateLower}
/>
</section>
</main>
);
};
export default UpperTodo;