fix: stage save errors and add milestone progress field
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -49,7 +49,9 @@ function sortByIsoDesc<T>(items: T[], pick: (item: T) => string) {
|
||||
}
|
||||
|
||||
function milestoneProgress(m: Milestone) {
|
||||
return m.completedAt ? 100 : 0;
|
||||
if (m.completedAt) return 100;
|
||||
const p = m.progress ?? 0;
|
||||
return Math.min(100, Math.max(0, p));
|
||||
}
|
||||
|
||||
function parseContentLines(text: string | null | undefined) {
|
||||
@@ -274,7 +276,6 @@ function DetailView({ task }: { task: TaskWithRelations }) {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
form.append('milestoneId', milestoneId);
|
||||
form.append('uploadedBy', task.creatorId);
|
||||
await apiClient.post(`/files/upload/${task.id}`, form, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
});
|
||||
@@ -289,21 +290,41 @@ function DetailView({ task }: { task: TaskWithRelations }) {
|
||||
description: data.description.trim() || undefined,
|
||||
startDate: data.startDate || undefined,
|
||||
dueDate: data.dueDate || undefined,
|
||||
progress: data.progress,
|
||||
feedback: data.feedback.trim() || undefined,
|
||||
links: JSON.stringify(data.links),
|
||||
links: data.links.length > 0 ? JSON.stringify(data.links) : undefined,
|
||||
};
|
||||
|
||||
let milestoneId: string;
|
||||
|
||||
if (stageModal?.mode === 'add') {
|
||||
const { data: created } = await apiClient.post<Milestone>(`/milestones/${task.id}`, payload);
|
||||
if (fileList.length) await uploadFiles(created.id, fileList);
|
||||
milestoneId = created.id;
|
||||
setSelectedId(created.id);
|
||||
} else if (stageModal?.milestone) {
|
||||
await apiClient.patch(`/milestones/item/${stageModal.milestone.id}`, payload);
|
||||
if (fileList.length) await uploadFiles(stageModal.milestone.id, fileList);
|
||||
const { data: updated } = await apiClient.patch<Milestone>(
|
||||
`/milestones/item/${stageModal.milestone.id}`,
|
||||
payload,
|
||||
);
|
||||
milestoneId = updated.id;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fileList.length > 0) {
|
||||
try {
|
||||
await uploadFiles(milestoneId, fileList);
|
||||
} catch {
|
||||
alert('단계는 저장됐지만 파일 업로드에 실패했습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
await qc.invalidateQueries({ queryKey: ['task', task.id] });
|
||||
setStageModal(null);
|
||||
} catch (err: unknown) {
|
||||
const ax = err as { response?: { data?: { message?: string } }; message?: string };
|
||||
const msg = ax.response?.data?.message || ax.message || '단계 저장에 실패했습니다.';
|
||||
alert(msg);
|
||||
} finally {
|
||||
setStageSaving(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user