From ca61342d1120d4f4fd8ff26846dc8e0515bf6892 Mon Sep 17 00:00:00 2001
From: potts99
Date: Sat, 25 Nov 2023 22:58:21 +0000
Subject: [PATCH] Hidden Ticket
---
apps/api/src/controllers/ticket.ts | 35 +++++++++++-
.../20231125221631_hidden/migration.sql | 2 +
apps/api/src/prisma/schema.prisma | 1 +
apps/client/package.json | 1 +
apps/client/pages/tickets/[id].tsx | 57 +++++++++++++------
apps/client/store/session.js | 44 +++++++-------
ecosystem.config.js | 1 -
yarn.lock | 12 ++++
8 files changed, 113 insertions(+), 40 deletions(-)
create mode 100644 apps/api/src/prisma/migrations/20231125221631_hidden/migration.sql
diff --git a/apps/api/src/controllers/ticket.ts b/apps/api/src/controllers/ticket.ts
index 4cb205f92..f1aeff869 100644
--- a/apps/api/src/controllers/ticket.ts
+++ b/apps/api/src/controllers/ticket.ts
@@ -153,7 +153,7 @@ export function ticketRoutes(fastify: FastifyInstance) {
if (token) {
const tickets = await prisma.ticket.findMany({
- where: { isComplete: false },
+ where: { isComplete: false, hidden: false },
include: {
client: {
select: { id: true, name: true, number: true },
@@ -187,7 +187,7 @@ export function ticketRoutes(fastify: FastifyInstance) {
const user = await checkSession(bearer);
const tickets = await prisma.ticket.findMany({
- where: { isComplete: false, userId: user!.id },
+ where: { isComplete: false, userId: user!.id, hidden: false },
include: {
client: {
select: { id: true, name: true, number: true },
@@ -219,7 +219,7 @@ export function ticketRoutes(fastify: FastifyInstance) {
if (token) {
const tickets = await prisma.ticket.findMany({
- where: { isComplete: true },
+ where: { isComplete: true, hidden: false },
include: {
client: {
select: { id: true, name: true, number: true },
@@ -254,6 +254,7 @@ export function ticketRoutes(fastify: FastifyInstance) {
where: {
isComplete: false,
assignedTo: null,
+ hidden: false,
},
});
@@ -430,6 +431,34 @@ export function ticketRoutes(fastify: FastifyInstance) {
});
}
}
+
+ reply.send({
+ success: true,
+ });
+ }
+ );
+
+ // Hide a ticket
+ fastify.put(
+ "/api/v1/ticket/status/hide",
+
+ async (request: FastifyRequest, reply: FastifyReply) => {
+ const { hidden, id }: any = request.body;
+
+ await prisma.ticket
+ .update({
+ where: { id: id },
+ data: {
+ hidden: hidden,
+ },
+ })
+ .then(async (ticket) => {
+ // await sendTicketStatus(ticket);
+ });
+
+ reply.send({
+ success: true,
+ });
}
);
diff --git a/apps/api/src/prisma/migrations/20231125221631_hidden/migration.sql b/apps/api/src/prisma/migrations/20231125221631_hidden/migration.sql
new file mode 100644
index 000000000..e55b74cb5
--- /dev/null
+++ b/apps/api/src/prisma/migrations/20231125221631_hidden/migration.sql
@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE "Ticket" ADD COLUMN "hidden" BOOLEAN NOT NULL DEFAULT false;
diff --git a/apps/api/src/prisma/schema.prisma b/apps/api/src/prisma/schema.prisma
index dfbd68da1..fa54db79e 100644
--- a/apps/api/src/prisma/schema.prisma
+++ b/apps/api/src/prisma/schema.prisma
@@ -106,6 +106,7 @@ model Ticket {
Number Int @default(autoincrement())
status TicketStatus @default(needs_support)
type TicketType @default(support)
+ hidden Boolean @default(false)
TicketFile TicketFile[]
Comment Comment[]
diff --git a/apps/client/package.json b/apps/client/package.json
index 11ad3bb07..8a6fcddc0 100644
--- a/apps/client/package.json
+++ b/apps/client/package.json
@@ -45,6 +45,7 @@
"next-themes": "^0.0.15",
"next-translate": "^1.3.4",
"nodemailer": "^6.7.2",
+ "posthog-js": "^1.93.2",
"prosemirror-model": "^1.18.1",
"pug": "^3.0.2",
"react": "18.2.0",
diff --git a/apps/client/pages/tickets/[id].tsx b/apps/client/pages/tickets/[id].tsx
index f8f30159f..51fc33ab7 100644
--- a/apps/client/pages/tickets/[id].tsx
+++ b/apps/client/pages/tickets/[id].tsx
@@ -7,7 +7,6 @@ import {
ChevronUpDownIcon,
LockClosedIcon,
LockOpenIcon,
- PencilIcon,
} from "@heroicons/react/20/solid";
import { Link, RichTextEditor } from "@mantine/tiptap";
import Highlight from "@tiptap/extension-highlight";
@@ -23,6 +22,7 @@ import renderHTML from "react-render-html";
import SubScript from "@tiptap/extension-subscript";
import Superscript from "@tiptap/extension-superscript";
import { getCookie } from "cookies-next";
+import { useUser } from "../../store/session";
function classNames(...classes: any) {
return classes.filter(Boolean).join(" ");
@@ -33,6 +33,10 @@ export default function Ticket() {
const token = getCookie("session");
+ const { user } = useUser();
+
+ console.log(user);
+
const fetchTicketById = async () => {
const id = router.query.id;
const res = await fetch(
@@ -113,9 +117,9 @@ export default function Ticket() {
async function updateStatus() {
await fetch(
- `${process.env.NEXT_PUBLIC_API_URL}/api/v1/ticket/update-status`,
+ `${process.env.NEXT_PUBLIC_API_URL}/api/v1/ticket/status/update`,
{
- method: "POST",
+ method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
@@ -129,6 +133,26 @@ export default function Ticket() {
.then((res) => res.json())
.then(() => refetch());
}
+
+ async function hide(hidden) {
+ await fetch(
+ `${process.env.NEXT_PUBLIC_API_URL}/api/v1/ticket/status/hide`,
+ {
+ method: "PUT",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${token}`,
+ },
+ body: JSON.stringify({
+ hidden,
+ id,
+ }),
+ }
+ )
+ .then((res) => res.json())
+ .then(() => refetch());
+ }
+
async function addComment() {
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/ticket/comment`, {
method: "POST",
@@ -303,16 +327,23 @@ export default function Ticket() {
+ {user.isAdmin && (
+
+ )}
{!edit ? (
) : (
@@ -322,12 +353,8 @@ export default function Ticket() {
update();
setEdit(false);
}}
- className="inline-flex justify-center gap-x-1.5 rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
+ className="inline-flex justify-center gap-x-1.5 rounded-md bg-white px-5 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
>
-
Save
)}
@@ -766,9 +793,7 @@ export default function Ticket() {
className="-ml-0.5 h-5 w-5 text-red-500"
aria-hidden="true"
/>
-
- Re-Open issue
-
+
Re-Open issue
) : (