Skip to content

Commit

Permalink
Hidden Ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Nov 25, 2023
1 parent bf33254 commit ca61342
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 40 deletions.
35 changes: 32 additions & 3 deletions apps/api/src/controllers/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -254,6 +254,7 @@ export function ticketRoutes(fastify: FastifyInstance) {
where: {
isComplete: false,
assignedTo: null,
hidden: false,
},
});

Expand Down Expand Up @@ -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,
});
}
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Ticket" ADD COLUMN "hidden" BOOLEAN NOT NULL DEFAULT false;
1 change: 1 addition & 0 deletions apps/api/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
1 change: 1 addition & 0 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
57 changes: 41 additions & 16 deletions apps/client/pages/tickets/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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(" ");
Expand All @@ -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(
Expand Down Expand Up @@ -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}`,
Expand All @@ -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",
Expand Down Expand Up @@ -303,16 +327,23 @@ export default function Ticket() {
</p>
</div>
<div className="mt-4 flex space-x-3 md:mt-0">
{user.isAdmin && (
<button
type="button"
onClick={() => hide(!data.ticket.hidden)}
className="inline-flex justify-center items-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"
>
{data.ticket.hidden
? "Show Global"
: "Hide Ticket"}
</button>
)}
{!edit ? (
<button
type="button"
onClick={() => setEdit(true)}
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 items-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"
>
<PencilIcon
className="-ml-0.5 h-5 w-5 text-gray-400"
aria-hidden="true"
/>
Edit
</button>
) : (
Expand All @@ -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"
>
<CheckIcon
className="-ml-0.5 h-5 w-5 text-gray-400"
aria-hidden="true"
/>
Save
</button>
)}
Expand Down Expand Up @@ -766,9 +793,7 @@ export default function Ticket() {
className="-ml-0.5 h-5 w-5 text-red-500"
aria-hidden="true"
/>
<span className="pt-1">
Re-Open issue
</span>
<span className="">Re-Open issue</span>
</button>
) : (
<button
Expand Down
44 changes: 24 additions & 20 deletions apps/client/store/session.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
// UserContext.js
import { getCookie } from 'cookies-next';
import { useRouter } from 'next/router';
import { createContext, useContext, useEffect, useState } from 'react';
import { getCookie } from "cookies-next";
import { useRouter } from "next/router";
import posthog from "posthog-js";
import { PostHogProvider } from "posthog-js/react";
import { createContext, useContext, useEffect, useState } from "react";

const UserContext = createContext();

posthog.init(process.env.NEXT_PUBLIC_POSTHOG);

export const SessionProvider = ({ children }) => {
const router = useRouter();
const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true);

const fetchUserProfile = async () => {
const token = getCookie('session');
const token = getCookie("session");
try {
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/auth/profile`, {
method: 'GET',
method: "GET",
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
}
}).then(res => res.json())
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
})
.then((res) => res.json())
.then((res) => {
if(res.user){
setUser(res.user)
if (res.user) {
setUser(res.user);
setLoading(false);
} else {
console.error('Failed to fetch user profile');
router.push('/auth/login');
console.error("Failed to fetch user profile");
router.push("/auth/login");
}
})
});
} catch (error) {
// Handle fetch errors if necessary
console.error('Error fetching user profile:', error);
router.push('/auth/login');

console.error("Error fetching user profile:", error);
router.push("/auth/login");
} finally {
setLoading(false);
}
};

useEffect(() => {
console.log('fetching user profile');
console.log("fetching user profile");
fetchUserProfile();
}, []);

return (
<UserContext.Provider value={{ user, setUser, loading }}>
{children}
<PostHogProvider client={posthog}>{children}</PostHogProvider>
</UserContext.Provider>
);
};

export const useUser = () => {
const context = useContext(UserContext);
if (!context) {
throw new Error('useUser must be used within a UserProvider');
throw new Error("useUser must be used within a UserProvider");
}
return context;
};
1 change: 0 additions & 1 deletion ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module.exports = {
restart_delay: 3000,
env: {
NODE_ENV: "production",
PORT: process.env.API_PORT,
DB_USERNAME: process.env.DB_USERNAME,
DB_PASSWORD: process.env.DB_PASSWORD,
DB_HOST: process.env.DB_HOST,
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3210,6 +3210,11 @@ fastq@^1.6.0, fastq@^1.6.1:
dependencies:
reusify "^1.0.4"

fflate@^0.4.1:
version "0.4.8"
resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.4.8.tgz#f90b82aefbd8ac174213abb338bd7ef848f0f5ae"
integrity sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==

filesac@^13.0.0:
version "13.0.0"
resolved "https://registry.yarnpkg.com/filesac/-/filesac-13.0.0.tgz#fdee2f7c477320ae99f2a5fde8f47ce7ba94b0aa"
Expand Down Expand Up @@ -5222,6 +5227,13 @@ postcss@8.4.31, postcss@^8.4.23, postcss@^8.4.5:
picocolors "^1.0.0"
source-map-js "^1.0.2"

posthog-js@^1.93.2:
version "1.93.2"
resolved "https://registry.yarnpkg.com/posthog-js/-/posthog-js-1.93.2.tgz#f3ab11983c558ad36966b552bb4ad98526cdcff6"
integrity sha512-0e2kqlb4kB1/Q9poLFlMF+SUrW+DCzNBHTJuUKl177euE4LChkJipSjy2vpq98qtJ2K3Hxw7ylHf2C+dZCx4RA==
dependencies:
fflate "^0.4.1"

posthog-node@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/posthog-node/-/posthog-node-3.1.3.tgz#9c5c3dbe3360a5983a81fea2e093e5a7cdde6219"
Expand Down

0 comments on commit ca61342

Please sign in to comment.