-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLowerTodo.tsx
More file actions
120 lines (102 loc) · 3.45 KB
/
LowerTodo.tsx
File metadata and controls
120 lines (102 loc) · 3.45 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { useNavigate } from 'react-router-dom';
import Mandalart from '@common/component/Mandalart/Mandalart';
import * as styles from './LowerTodo.css';
import { LowerTodoHeader, MandalCompleteButton, TodoFields } from './component';
import { useLowerTodoState, useLowerTodoAI } from './hook';
import { toMainSubGoals } from './utils/goal';
import { DEFAULT_TEXT, ALERT } from '@/common/constants/todo';
import { truncateText } from '@/common/util/format';
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 LowerTodo = () => {
const mandalartId = useMandalartId();
const navigate = useNavigate();
const { data: user } = useGetUser();
const {
data,
coreGoalsData,
selectedGoalIndex,
selectedCoreGoalId,
allTodos,
currentTodos,
isTooltipOpen,
setIsTooltipOpen,
handleTodoEnter,
handleTodoChange,
handleSubGoalClick,
isAiUsed,
setIsAiUsed,
} = useLowerTodoState(mandalartId);
const displayUserName = user?.name ?? '김도트';
const mainGoal = data?.title || DEFAULT_TEXT.overallGoal;
const selectedGoalTitle =
coreGoalsData?.coreGoals?.[selectedGoalIndex]?.title ||
coreGoalsData?.coreGoals?.sort((a: any, b: any) => a.position - b.position)[0]?.title ||
mainGoal;
const handleNavigateComplete = () => {
if (!mandalartId) {
alert(ALERT.noMandalartId);
return;
}
navigate(PATH.MANDAL);
};
const { handleOpenAiModal } = useLowerTodoAI({
selectedCoreGoalId,
selectedCoreGoalTitle: selectedGoalTitle,
selectedGoalIndex,
currentTodos,
setCurrentTodos: handleTodoChange,
setIsTooltipOpen,
isAiUsed,
setIsAiUsed,
handleTodoEnter,
});
const hasFilledSubGoals = allTodos.some((todos) =>
todos.some((todo) => todo.title.trim() !== ''),
);
const currentTodosFilled = currentTodos.every((todo) => todo.title.trim() !== '');
const isAiDisabled = isAiUsed[selectedGoalIndex] || currentTodosFilled;
const handleEnter = (index: number, todo: any) => {
handleTodoEnter(index, todo);
};
return (
<main className={styles.lowerTodoContainer}>
<GradientBackground />
<section className={styles.lowerTodoBoxWrapper}>
<LowerTodoHeader
userName={displayUserName}
title={selectedGoalTitle}
isTooltipOpen={isTooltipOpen}
setIsTooltipOpen={setIsTooltipOpen}
isAiDisabled={isAiDisabled}
handleOpenAiModal={handleOpenAiModal}
/>
<div className={styles.lowerTodoBox}>
<Mandalart
type="TODO_MAIN"
mainGoal={truncateText(mainGoal, 23)}
subGoals={toMainSubGoals(coreGoalsData?.coreGoals || []).map((goal) => ({
...goal,
title: truncateText(goal.title, 23),
}))}
onGoalClick={handleSubGoalClick}
selectedGoalIndex={selectedGoalIndex}
/>
<TodoFields
values={currentTodos}
onChange={handleTodoChange}
onEnter={handleEnter}
selectedCoreGoalTitle={selectedGoalTitle}
/>
</div>
<MandalCompleteButton
hasFilledSubGoals={hasFilledSubGoals}
handleNavigateComplete={handleNavigateComplete}
/>
</section>
</main>
);
};
export default LowerTodo;