Skip to content

Commit

Permalink
Feat: #102 상태 변경 API를 위한 React Query 처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Seok93 committed Sep 4, 2024
1 parent 96ff8a7 commit 244f1f5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/hooks/query/useStatusQuery.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { queryClient } from '@hooks/query/queryClient';
import { useMemo } from 'react';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import useToast from '@hooks/useToast';
import { PROJECT_STATUS_COLORS } from '@constants/projectStatus';
import { createStatus, getStatusList } from '@services/statusService';
import { createStatus, getStatusList, updateStatus } from '@services/statusService';

import type { Project } from '@/types/ProjectType';
import type { ProjectStatus, ProjectStatusForm, UsableColor } from '@/types/ProjectStatusType';
Expand Down Expand Up @@ -108,3 +109,20 @@ export function useCreateStatus(projectId: Project['projectId']) {

return mutation;
}

export function useUpdateStatus(projectId: Project['projectId'], statusId: ProjectStatus['statusId']) {
const { toastSuccess } = useToast();
const queryClient = useQueryClient();

const mutation = useMutation({
mutationFn: (formData: ProjectStatusForm) => updateStatus(projectId, statusId, formData),
onSuccess: () => {
toastSuccess('프로젝트 상태를 수정했습니다.');
queryClient.invalidateQueries({
queryKey: ['projects', projectId, 'statuses'],
});
},
});

return mutation;
}
20 changes: 20 additions & 0 deletions src/services/statusService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,23 @@ export async function createStatus(
) {
return authAxios.post(`/project/${projectId}/status`, formData, axiosConfig);
}

/**
* 프로젝트 상태 수정 API
*
* @export
* @async
* @param {Project['projectId']} projectId - 프로젝트 ID
* @param {ProjectStatus['statusId']} statusId - 프로젝트 상태 ID
* @param {ProjectStatusForm} formData - 상태 정보 객체
* @param {AxiosRequestConfig} [axiosConfig={}] - axios 요청 옵션 설정 객체
* @returns {Promise<AxiosResponse<void>>}
*/
export async function updateStatus(
projectId: Project['projectId'],
statusId: ProjectStatus['statusId'],
formData: ProjectStatusForm,
axiosConfig: AxiosRequestConfig = {},
) {
return authAxios.patch(`/project/${projectId}/status/${statusId}`, formData, axiosConfig);
}

0 comments on commit 244f1f5

Please sign in to comment.