From 637c036af5ac4a2607b8ef51d6b95611939fb527 Mon Sep 17 00:00:00 2001 From: potts99 Date: Sat, 30 Mar 2024 14:45:58 +0000 Subject: [PATCH] file uploads --- apps/api/src/controllers/storage.ts | 2 +- apps/api/src/controllers/ticket.ts | 7 +++ apps/client/pages/ticket/[id].tsx | 72 ++++++++++++++++------------- 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/apps/api/src/controllers/storage.ts b/apps/api/src/controllers/storage.ts index 07d24255b..60d492b84 100644 --- a/apps/api/src/controllers/storage.ts +++ b/apps/api/src/controllers/storage.ts @@ -17,7 +17,7 @@ export function objectStoreRoutes(fastify: FastifyInstance) { const uploadedFile = await prisma.ticketFile.create({ data: { ticketId: request.params.id, - filename: request.file.filename, + filename: request.file.originalname, path: request.file.path, mime: request.file.mimetype, size: request.file.size, diff --git a/apps/api/src/controllers/ticket.ts b/apps/api/src/controllers/ticket.ts index fee23a445..c110f868d 100644 --- a/apps/api/src/controllers/ticket.ts +++ b/apps/api/src/controllers/ticket.ts @@ -183,10 +183,17 @@ export function ticketRoutes(fastify: FastifyInstance) { }, }); + const files = await prisma.ticketFile.findMany({ + where: { + ticketId: id, + }, + }); + var t = { ...ticket, comments: [...comments], TimeTracking: [...timeTracking], + files: [...files], }; reply.send({ diff --git a/apps/client/pages/ticket/[id].tsx b/apps/client/pages/ticket/[id].tsx index 5791ec9c2..3a63906d7 100644 --- a/apps/client/pages/ticket/[id].tsx +++ b/apps/client/pages/ticket/[id].tsx @@ -15,7 +15,7 @@ import { useEditor } from "@tiptap/react"; import StarterKit from "@tiptap/starter-kit"; import moment from "moment"; import { useRouter } from "next/router"; -import { Fragment, useEffect, useState } from "react"; +import { Fragment, useEffect, useRef, useState } from "react"; import { useQuery } from "react-query"; import renderHTML from "react-render-html"; // import TextAlign from '@tiptap/extension-text-align'; @@ -262,6 +262,11 @@ export default function Ticket() { const data = await result.json(); + if (data.success) { + setFile(null); + refetch(); + } + console.log(data); } catch (error) { console.error(error); @@ -269,6 +274,13 @@ export default function Ticket() { } }; + const fileInputRef = useRef(null); + + const handleButtonClick = () => { + // Click the hidden file input element + fileInputRef.current.click(); + }; + useEffect(() => { fetchUsers(); }, []); @@ -1515,39 +1527,37 @@ export default function Ticket() { Attachments - + {!file ? ( + + ) : ( + + )} <> -
- - -
- {file && ( -
- File details: - -
- )} - - {file && ( - - )} + {data.ticket.files.length > 0 && + data.ticket.files.map((file: any) => ( +
+ {file.filename} +
+ ))}