-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: React Query 기본 환경 설정 & 상태별 프로젝트 일정 전체 조회 API 처리 추가 (#93)
* Config: #89 React Query Devtools 추가 * Feat: #89 React Query 기본 설정 추가 * Feat: #89 Mutation 기본 Error handler 추가 * Refactor: #89 Axios 에러 처리와 React Query 에러 처리 통합 * Feat: #89 Task 목록 useQuery 작성 * Chore: #89 Mock 데이터 수정 & Task, Status 타입 수정 * Chore: #89 Mock & Type 변경 * Feat: 할일 전체 목록 API MSW Handler 추가 * Chore: MSW Handler 추가로 할일 목록 Dummy 참조 삭제
- Loading branch information
Showing
16 changed files
with
333 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import axios from 'axios'; | ||
|
||
// ToDo: useAxios의 에러 처리와 react query의 에러 처리를 담당하도록 만들 것 | ||
export default function errorHandler<T extends Error>(error: T) { | ||
// ToDo: AxiosError가 아닌 경우 에러 처리 | ||
if (!axios.isAxiosError(error)) return; | ||
|
||
if (error.request) { | ||
// ToDo: 네트워크 요청을 보냈지만 응답이 없는 경우 에러 처리 | ||
} else if (error.response) { | ||
// ToDo: 요청후 응답을 받았지만 200 이외의 응답 코드인 경우 예외 처리 | ||
} else { | ||
// ToDo: request 설정 오류 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { MutationCache, QueryCache, QueryClient } from '@tanstack/react-query'; | ||
import { MINUTE } from '@constants/units'; | ||
import errorHandler from '@hooks/errorHandler'; | ||
import type { QueryClientConfig } from '@tanstack/react-query'; | ||
|
||
// ToDo: 기본 옵션 설정 대화하고 확정하기 | ||
const queryClientOptions: QueryClientConfig = { | ||
defaultOptions: { | ||
queries: { | ||
staleTime: 5 * MINUTE, | ||
gcTime: 10 * MINUTE, | ||
refetchOnMount: true, | ||
refetchOnReconnect: true, | ||
refetchOnWindowFocus: true, | ||
retry: 3, | ||
}, | ||
}, | ||
queryCache: new QueryCache({ | ||
onError: (error) => { | ||
console.error(`Query: ${error.name}:${error.message}:${error.stack}`); | ||
errorHandler(error); | ||
}, | ||
}), | ||
mutationCache: new MutationCache({ | ||
onError: (error) => { | ||
console.error(`Mutation: ${error.name}:${error.message}:${error.stack}`); | ||
errorHandler(error); | ||
}, | ||
}), | ||
}; | ||
|
||
export const queryClient = new QueryClient(queryClientOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,34 @@ | ||
import { TASK_DUMMY } from '@mocks/mockData'; | ||
import { TaskListWithStatus } from '@/types/TaskType'; | ||
import { Project } from '@/types/ProjectType'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { findTaskList } from '@services/taskService'; | ||
|
||
import type { TaskListWithStatus } from '@/types/TaskType'; | ||
import type { Project } from '@/types/ProjectType'; | ||
|
||
function getTaskNameList(taskList: TaskListWithStatus[]) { | ||
return taskList | ||
.map((statusTask) => statusTask.tasks) | ||
.flat() | ||
.map((task) => task.name); | ||
return taskList.length > 0 | ||
? taskList | ||
.map((statusTask) => statusTask.tasks) | ||
.flat() | ||
.map((task) => task.name) | ||
: []; | ||
} | ||
|
||
// Todo: Task Query CRUD로직 작성하기 | ||
// QueryKey: project, projectId, tasks | ||
export default function useTaskQuery(projectId: Project['projectId']) { | ||
const taskList = TASK_DUMMY; | ||
// Todo: Task Query CUD로직 작성하기 | ||
export function useTasksQuery(projectId: Project['projectId']) { | ||
const { | ||
data: taskList = [], | ||
isLoading: isTaskLoading, | ||
isError: isTaskError, | ||
error: taskError, | ||
} = useQuery({ | ||
queryKey: ['projects', projectId, 'tasks'], | ||
queryFn: async () => { | ||
const { data } = await findTaskList(projectId); | ||
return data; | ||
}, | ||
}); | ||
|
||
const taskNameList = taskList ? getTaskNameList(taskList) : []; | ||
const taskNameList = getTaskNameList(taskList); | ||
|
||
return { taskList, taskNameList }; | ||
return { taskList, taskNameList, isTaskLoading, isTaskError, taskError }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import userServiceHandler from '@mocks/services/userServiceHandler'; | ||
import teamServiceHandler from '@mocks/services/teamServiceHandler'; | ||
import projectServiceHandler from '@mocks/services/projectServiceHandler'; | ||
import taskServiceHandler from '@mocks/services/taskServiceHandler'; | ||
|
||
const handlers = [...userServiceHandler, ...teamServiceHandler, ...projectServiceHandler]; | ||
const handlers = [...userServiceHandler, ...teamServiceHandler, ...projectServiceHandler, ...taskServiceHandler]; | ||
|
||
export default handlers; |
Oops, something went wrong.