Skip to content

Commit

Permalink
Feat: #115 파일 업로드 성공은 묶어서, 실패는 개별 메세지 노출로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Seok93 committed Sep 27, 2024
1 parent 613775b commit ae1299d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
10 changes: 1 addition & 9 deletions src/components/modal/task/CreateModalTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,7 @@ export default function CreateModalTask({ project, onClose: handleClose }: Creat
else rejectedFileList.push(result);
});

if (fulfilledFileList.length > 0) {
const fulfilledFilesName = fulfilledFileList.map((result) => result.file.name).join(', ');
toastSuccess(`${fulfilledFilesName} 파일 업로드에 성공했습니다.`);
}

if (rejectedFileList.length > 0) {
const rejectedFilesName = rejectedFileList.map((result) => result.file.name).join(', ');
toastError(`${rejectedFilesName} 파일 업로드에 실패했습니다.`);
}
if (fulfilledFileList.length > 0) toastSuccess(`${fulfilledFileList.length}개의 파일 업로드에 성공했습니다.`);
};

const handleSubmit: SubmitHandler<TaskForm> = async (taskFormData) => {
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/query/useTaskQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type { Project } from '@/types/ProjectType';
import type {
Task,
TaskCreationForm,
TaskFilesForm,
TaskListWithStatus,
TaskOrder,
TaskUpdateForm,
Expand Down Expand Up @@ -57,11 +56,13 @@ export function useCreateStatusTask(projectId: Project['projectId']) {

// 일정 단일 파일 업로드
export function useUploadTaskFile(projectId: Project['projectId']) {
const { toastError } = useToast();
const mutation = useMutation({
mutationFn: ({ taskId, file }: TaskUploadForm) =>
uploadTaskFile(projectId, taskId, file, {
headers: { 'Content-Type': 'multipart/form-data' },
}),
onError: (error, { file }) => toastError(`${file.name} 파일 업로드에 실패 했습니다.`),
});

return mutation;
Expand Down

0 comments on commit ae1299d

Please sign in to comment.