Skip to content

Commit 3adf206

Browse files
authored
Merge pull request #178 from SOPT-36-NINEDOT/feat/#134/lowerGoalApi
[Feat]: 하위 목표 뷰 남은 API 연결
2 parents 7bff975 + 9d829ad commit 3adf206

File tree

10 files changed

+252
-88
lines changed

10 files changed

+252
-88
lines changed

src/api/constant/queryKey.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ export const QUERY_KEY = {
1717
STREAK: (mandalartId: number) => ['streaks', mandalartId],
1818
JOB_LIST: ['jobList'],
1919
RECOMMENDED_TODO: (mandalartId: number) => ['recommendedTodo', mandalartId],
20-
MANDAL_ALL: ['mandalAll'] as const,
20+
MANDAL_ALL: ['mandaclAll'] as const,
2121
CORE_GOALS: ['coreGoals'],
2222
PERSONA: 'persona',
23+
UPDATE_SUB_GOAL: (id: number) => ['updateSubGoal', id],
24+
DELETE_SUB_GOAL: (id: number) => ['deleteSubGoal', id],
25+
OVERALL_GOAL: ['overallGoal'],
2326
USER_INFO: ['userInfo'],
2427
} as const;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useMutation, useQueryClient } from '@tanstack/react-query';
2+
3+
import { deleteSubGoal } from '../index';
4+
5+
import { QUERY_KEY } from '@/api/constant/queryKey';
6+
7+
export const useDeleteSubGoal = () => {
8+
const queryClient = useQueryClient();
9+
10+
return useMutation({
11+
mutationFn: (subGoalId: number) => deleteSubGoal(subGoalId),
12+
onSuccess: (_, subGoalId) => {
13+
queryClient.invalidateQueries({
14+
queryKey: QUERY_KEY.SUB_GOAL_IDS(subGoalId),
15+
exact: true,
16+
});
17+
queryClient.invalidateQueries({
18+
queryKey: ['subGoals'],
19+
refetchType: 'active',
20+
});
21+
},
22+
});
23+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
3+
import { getOverallGoal } from '../index';
4+
5+
import { QUERY_KEY } from '@/api/constant/queryKey';
6+
7+
export const useOverallGoal = (mandalartId: number) => {
8+
return useQuery({
9+
queryKey: [QUERY_KEY.OVERALL_GOAL, mandalartId],
10+
queryFn: () => getOverallGoal(mandalartId),
11+
enabled: !!mandalartId,
12+
});
13+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { useMutation, useQueryClient } from '@tanstack/react-query';
2+
3+
import { updateSubGoal } from '../index';
4+
import type { UpdateSubGoalRequest } from '../type/updateSubGoal.request';
5+
6+
import { QUERY_KEY } from '@/api/constant/queryKey';
7+
8+
export const useUpdateSubGoal = (subGoalId: number) => {
9+
const queryClient = useQueryClient();
10+
11+
return useMutation({
12+
mutationFn: (payload: UpdateSubGoalRequest) => updateSubGoal(subGoalId, payload),
13+
onSuccess: () => {
14+
queryClient.invalidateQueries({
15+
queryKey: QUERY_KEY.SUB_GOAL_IDS(subGoalId),
16+
exact: true,
17+
});
18+
queryClient.invalidateQueries({
19+
queryKey: ['subGoals'],
20+
refetchType: 'active',
21+
});
22+
},
23+
});
24+
};

src/api/domain/lowerTodo/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import type {
66
AiRecommendSubGoalRequest,
77
AiRecommendSubGoalResponse,
88
} from './type/aiRecommendSubGoal';
9+
import type { UpdateSubGoalRequest } from './type/updateSubGoal.request';
910

10-
import { get, post } from '@/api';
11+
import { get, post, api } from '@/api';
1112
import { END_POINT } from '@/api/constant/endPoint';
1213
import type { BaseResponse } from '@/type/api';
14+
import axiosInstance from '@/api/axiosInstance';
1315

1416
export const getCoreGoals = async (mandalartId: number) => {
1517
const { data } = await get<BaseResponse<GetCoreGoalsResponse>>(
@@ -83,3 +85,16 @@ export const postAiRecommendSubGoals = async (
8385
const { data } = await post(`/core-goals/${coreGoalSnapshotId}/sub-goals/ai`, { goals });
8486
return data;
8587
};
88+
89+
export const updateSubGoal = async (subGoalId: number, payload: UpdateSubGoalRequest) => {
90+
return (await api.patch(`/sub-goals/${subGoalId}`, payload)).data;
91+
};
92+
93+
export const deleteSubGoal = async (subGoalId: number) => {
94+
return (await api.delete(`/sub-goals/${subGoalId}`)).data;
95+
};
96+
97+
export const getOverallGoal = async (mandalartId: number): Promise<{ title: string }> => {
98+
const response = await axiosInstance.get(`/mandalarts/${mandalartId}`);
99+
return response.data.data;
100+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface UpdateSubGoalRequest {
2+
title: string;
3+
cycle: 'DAILY' | 'WEEKLY' | 'ONCE';
4+
}

src/common/component/MandalartTextField/MandalartTextField.css.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const bigGoalBase = {
1515
fontSize: fonts.title01.fontSize,
1616
fontWeight: fonts.title01.fontWeight,
1717
lineHeight: fonts.title01.lineHeight,
18+
color: colors.grey10,
1819
};
1920
const subGoalBase = {
2021
display: 'flex',
@@ -27,6 +28,7 @@ const subGoalBase = {
2728
fontSize: fonts.subtitle03.fontSize,
2829
fontWeight: fonts.subtitle03.fontWeight,
2930
lineHeight: fonts.subtitle03.lineHeight,
31+
color: colors.grey10,
3032
};
3133
const todoBase = {
3234
display: 'flex',
@@ -39,6 +41,7 @@ const todoBase = {
3941
fontSize: fonts.subtitle03.fontSize,
4042
fontWeight: fonts.subtitle03.fontWeight,
4143
lineHeight: fonts.subtitle03.lineHeight,
44+
color: '#111111',
4245
};
4346

4447
export const bigGoalBaseClass = style(bigGoalBase);
@@ -53,7 +56,7 @@ export const inputBase = style({
5356
border: 'none',
5457
outline: 'none',
5558
padding: 0,
56-
color: 'inherit',
59+
color: colors.grey10,
5760
});
5861

5962
const makeInputStyle = (font: Record<string, string | number>) =>

src/common/component/MandalartTextField/MandalartTextField.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,7 @@ const TextField = ({
107107
const effectivePlaceholder = getPlaceholder(variant, placeholder);
108108

109109
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
110-
const newValue = e.target.value;
111-
if (effectiveMaxLength && newValue.length > effectiveMaxLength) {
112-
return;
113-
}
114-
onChange(newValue);
110+
onChange(e.target.value);
115111
};
116112

117113
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {

src/page/home/StartButton/StartButton.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { buttonHandlerType } from '@/page/home/type/buttonHandlerType';
2-
32
import { startButton } from '@/page/home/StartButton/StartButton.css';
43

54
const StartButton = ({ onClick }: buttonHandlerType) => {

0 commit comments

Comments
 (0)