View update when upload attachment files
This commit is contained in:
@@ -15,7 +15,7 @@ import { Save, Plus, ArrowLeft, ArrowUpFromLine } from "lucide-react";
|
|||||||
import { priorities, testTypes, templates } from "@/config/selection";
|
import { priorities, testTypes, templates } from "@/config/selection";
|
||||||
import CaseStepsEditor from "./case-steps-editor";
|
import CaseStepsEditor from "./case-steps-editor";
|
||||||
import CaseAttachmentsEditor from "./case-attachments-editor";
|
import CaseAttachmentsEditor from "./case-attachments-editor";
|
||||||
import { CaseType } from "./caseTypes";
|
import { CaseType, AttachmentType } from "./caseTypes";
|
||||||
import {
|
import {
|
||||||
fetchCase,
|
fetchCase,
|
||||||
fetchCreateStep,
|
fetchCreateStep,
|
||||||
@@ -105,17 +105,48 @@ export default function CaseEditor({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDrop = (event) => {
|
const handleDrop = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
fetchCreateAttachments(params.caseId, event.dataTransfer.files);
|
handleFetchCreateAttachments(params.caseId, event.dataTransfer.files);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleInput = (event) => {
|
const handleInput = (event) => {
|
||||||
fetchCreateAttachments(params.caseId, event.target.files);
|
handleFetchCreateAttachments(params.caseId, event.target.files);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFetchCreateAttachments = async (
|
||||||
|
caseId: number,
|
||||||
|
files: File[]
|
||||||
|
) => {
|
||||||
|
const newAttachments = await fetchCreateAttachments(caseId, files);
|
||||||
|
|
||||||
|
if (newAttachments) {
|
||||||
|
const newAttachmentsWithJoinTable = [];
|
||||||
|
newAttachments.forEach((attachment: AttachmentType) => {
|
||||||
|
attachment.caseAttachments = { AttachmentId: attachment.id };
|
||||||
|
newAttachmentsWithJoinTable.push(attachment);
|
||||||
|
});
|
||||||
|
const updatedAttachments = testCase.Attachments;
|
||||||
|
updatedAttachments.push(...newAttachments);
|
||||||
|
|
||||||
|
setTestCase({
|
||||||
|
...testCase,
|
||||||
|
Attachments: updatedAttachments,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onAttachmentDelete = async (attachmentId: number) => {
|
const onAttachmentDelete = async (attachmentId: number) => {
|
||||||
await fetchDeleteAttachment(attachmentId);
|
await fetchDeleteAttachment(attachmentId);
|
||||||
|
|
||||||
|
const filteredAttachments = testCase.Attachments.filter(
|
||||||
|
(attachment) => attachment.id !== attachmentId
|
||||||
|
);
|
||||||
|
|
||||||
|
setTestCase({
|
||||||
|
...testCase,
|
||||||
|
Attachments: filteredAttachments,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ type AttachmentType = {
|
|||||||
path: string;
|
path: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
caseSteps: CaseAttachmentType;
|
caseAttachments: CaseAttachmentType;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { CaseType, StepType, AttachmentType };
|
export { CaseType, StepType, AttachmentType };
|
||||||
|
|||||||
Reference in New Issue
Block a user