1626
frontend/package-lock.json
generated
1626
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,9 @@
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
"lint": "next lint",
|
||||
"test": "vitest",
|
||||
"coverage": "vitest run --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nextui-org/react": "^2.2.9",
|
||||
@@ -34,5 +36,9 @@
|
||||
"tailwind-variants": "^0.1.18",
|
||||
"tailwindcss": "3.3.5",
|
||||
"typescript": "5.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitest/coverage-v8": "^1.6.0",
|
||||
"vitest": "^1.6.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Image, Button, Tooltip, Card, CardBody } from "@nextui-org/react";
|
||||
import { AttachmentType, CaseMessages } from "@/types/case";
|
||||
import { Trash, ArrowDownToLine } from "lucide-react";
|
||||
import { isImage } from "./isImage";
|
||||
|
||||
type Props = {
|
||||
attachments: AttachmentType[];
|
||||
@@ -22,16 +23,7 @@ export default function CaseAttachmentsEditor({
|
||||
let others = [];
|
||||
|
||||
attachments.forEach((attachment) => {
|
||||
let path = attachment.path;
|
||||
let extension = path.substring(path.lastIndexOf(".") + 1).toLowerCase();
|
||||
if (
|
||||
extension === "png" ||
|
||||
extension === "jpg" ||
|
||||
extension === "jpeg" ||
|
||||
extension === "gif" ||
|
||||
extension === "bmp" ||
|
||||
extension === "svg"
|
||||
) {
|
||||
if (isImage(attachment)) {
|
||||
images.push(attachment);
|
||||
} else {
|
||||
others.push(attachment);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { isImage } from "./isImage";
|
||||
import { AttachmentType } from "@/types/case";
|
||||
|
||||
test("isImage", () => {
|
||||
type CaseAttachmentType = {
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
CaseId: number;
|
||||
AttachmentId: number;
|
||||
};
|
||||
|
||||
const sampleCaseAttachment: CaseAttachmentType = {
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
CaseId: 1,
|
||||
AttachmentId: 1,
|
||||
};
|
||||
|
||||
const sampleAttachment: AttachmentType = {
|
||||
id: 1,
|
||||
title: "",
|
||||
detail: "",
|
||||
path: "",
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
caseAttachments: sampleCaseAttachment,
|
||||
};
|
||||
|
||||
sampleAttachment.path = "public/uploads/abc.png";
|
||||
expect(isImage(sampleAttachment)).toBe(true);
|
||||
|
||||
sampleAttachment.path = "public/uploads/abc.mp3";
|
||||
expect(isImage(sampleAttachment)).toBe(false);
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import { AttachmentType } from "@/types/case";
|
||||
|
||||
function isImage(attachmentFile: AttachmentType) {
|
||||
let path = attachmentFile.path;
|
||||
let extension = path.substring(path.lastIndexOf(".") + 1).toLowerCase();
|
||||
if (
|
||||
extension === "png" ||
|
||||
extension === "jpg" ||
|
||||
extension === "jpeg" ||
|
||||
extension === "gif" ||
|
||||
extension === "bmp" ||
|
||||
extension === "svg"
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export { isImage };
|
||||
Reference in New Issue
Block a user