Skip to content

Commit

Permalink
ui update (Peppermint-Lab#208)
Browse files Browse the repository at this point in the history
* site

* Create site

* site

* site

* boilerplate for internal notifications

* mark as read

* add version badge

* link

* clean up config

* new ui

* temp redirect

* ui

* nicer ticket ui

* notebooks ui & themes

* notebooks

* proxy pt1

* proxy pt2

* ui things v nice much wow

* prevent layout keyboard shortcuts on ticket create

* proxy pt3

* save html

* tickets

* dark mode pt1

* dark pt2

* remove default
  • Loading branch information
potts99 authored Dec 12, 2023
1 parent 4baaaab commit 5fd53aa
Show file tree
Hide file tree
Showing 63 changed files with 3,063 additions and 4,264 deletions.
9 changes: 9 additions & 0 deletions apps/api/src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ export function authRoutes(fastify: FastifyInstance) {

const config = await prisma.config.findFirst();

const notifcations = await prisma.notifications.findMany({
where: { userId: user!.id },
orderBy: {
createdAt: "desc",
},
});

const data = {
id: user!.id,
email: user!.email,
Expand All @@ -427,6 +434,8 @@ export function authRoutes(fastify: FastifyInstance) {
ticket_comments: user!.notify_ticket_comments,
ticket_assigned: user!.notify_ticket_assigned,
sso_status: config!.sso_active,
version: config!.client_version,
notifcations,
};

reply.send({
Expand Down
6 changes: 5 additions & 1 deletion apps/api/src/controllers/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { sendAssignedEmail } from "../lib/nodemailer/ticket/assigned";
import { sendComment } from "../lib/nodemailer/ticket/comment";
import { sendTicketCreate } from "../lib/nodemailer/ticket/create";
import { sendTicketStatus } from "../lib/nodemailer/ticket/status";
import { createNotification } from "../lib/notifications";
import { checkSession } from "../lib/session";
import { prisma } from "../prisma";

Expand Down Expand Up @@ -74,6 +75,8 @@ export function ticketRoutes(fastify: FastifyInstance) {
});

await sendAssignedEmail(assgined!.email);

await createNotification("ticket_assigned", engineer.id, ticket);
}

const webhook = await prisma.webhooks.findMany({
Expand Down Expand Up @@ -232,13 +235,14 @@ export function ticketRoutes(fastify: FastifyInstance) {

// Get all tickets (admin)
fastify.get(
"/api/v1/tickets/all/admin",
"/api/v1/tickets/all",
async (request: FastifyRequest, reply: FastifyReply) => {
const bearer = request.headers.authorization!.split(" ")[1];
const token = checkToken(bearer);

if (token) {
const tickets = await prisma.ticket.findMany({
where: { hidden: false },
orderBy: [
{
createdAt: "desc",
Expand Down
25 changes: 25 additions & 0 deletions apps/api/src/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,29 @@ export function userRoutes(fastify: FastifyInstance) {
}
}
);

// Mark Notification as read
fastify.get(
"/api/v1/user/notifcation/:id",

async (request: FastifyRequest, reply: FastifyReply) => {
const bearer = request.headers.authorization!.split(" ")[1];
const token = checkToken(bearer);

const { id }: any = request.params;

if (token) {
await prisma.notifications.update({
where: { id: id },
data: {
read: true,
},
});

reply.send({
success: true,
});
}
}
);
}
2 changes: 1 addition & 1 deletion apps/api/src/lib/imap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const getEmails = async () => {
isComplete: Boolean(false),
priority: "Low",
fromImap: Boolean(true),
detail: textAsHtml,
detail: html,
},
});

Expand Down
31 changes: 31 additions & 0 deletions apps/api/src/lib/notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { prisma } from "../prisma";

export async function createNotification(
type: string,
userId: string,
ticket: any
) {
try {
let text = "";

console.log("ticket", ticket);

switch (type) {
case "ticket_assigned":
text = `Assigned Ticket #${ticket.Number}`;
break;
case "ticket_comment":
text = `New comment on #${ticket.Number}`;
break;
}

await prisma.notifications.create({
data: {
text,
userId,
},
});
} catch (error) {
console.log(error);
}
}
8 changes: 4 additions & 4 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ server.register(require("@fastify/swagger"), {
},
});

server.register(import("@fastify/rate-limit"), {
max: 20,
timeWindow: "1 minute",
});
// server.register(import("@fastify/rate-limit"), {
// max: 20,
// timeWindow: "1 minute",
// });

// register all routes
registerRoutes(server);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- CreateTable
CREATE TABLE "notifications" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"title" TEXT NOT NULL,
"read" BOOLEAN NOT NULL DEFAULT false,
"text" TEXT NOT NULL,
"userId" TEXT NOT NULL,

CONSTRAINT "notifications_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `title` on the `notifications` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "notifications" DROP COLUMN "title";
31 changes: 22 additions & 9 deletions apps/api/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ model User {
notify_ticket_assigned Boolean @default(true)
firstLogin Boolean @default(true)
todos Todos[]
tickets Ticket[]
file UserFile[]
notes Notes[]
Team Team? @relation(fields: [teamId], references: [id])
teamId String?
Comment Comment[]
Session Session[]
TimeTracking TimeTracking[]
todos Todos[]
tickets Ticket[]
file UserFile[]
notes Notes[]
Team Team? @relation(fields: [teamId], references: [id])
teamId String?
Comment Comment[]
Session Session[]
TimeTracking TimeTracking[]
notifications notifications[]
}

model Team {
Expand Down Expand Up @@ -310,6 +311,18 @@ model EmailQueue {
imap Imap_Email[]
}

model notifications {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
read Boolean @default(false)
text String
user User @relation(fields: [userId], references: [id])
userId String
}

enum Hook {
ticket_created
ticket_status_changed
Expand Down
19 changes: 8 additions & 11 deletions apps/client/components/ListTodo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import { useState } from "react";
import { useQuery } from "react-query";

async function getTodos(token) {
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/todos/all`,
{
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
}
);
const res = await fetch(`/api/v1/todos/all`, {
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
});
return res.json();
}

Expand All @@ -37,7 +34,7 @@ export default function ListTodo() {
}

async function onSubmit() {
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/todo/create`, {
await fetch(`/api/v1/todo/create`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -53,7 +50,7 @@ export default function ListTodo() {
}

async function deleteTodo(id) {
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/todo/${id}/delete`, {
await fetch(`/api/v1/todo/${id}/delete`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Expand Down
23 changes: 10 additions & 13 deletions apps/client/components/ResetPassword/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ export default function ResetPassword() {

const postData = async () => {
if (check === password && password.length > 3) {
await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/auth/reset-password`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + getCookie("session"),
},
body: JSON.stringify({
password,
}),
}
)
await fetch(`/api/v1/auth/reset-password`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + getCookie("session"),
},
body: JSON.stringify({
password,
}),
})
.then((res) => res.json())
.then((res) => {
if (res.success) {
Expand Down
15 changes: 6 additions & 9 deletions apps/client/components/TicketViews/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ import {
import TicketsMobileList from "../../components/TicketsMobileList";

const fetchALLTIckets = async () => {
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/tickets/all/admin`,
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${getCookie("session")}`,
},
}
);
const res = await fetch(`/api/v1/tickets/all/admin`, {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${getCookie("session")}`,
},
});
return res.json();
};

Expand Down
Loading

0 comments on commit 5fd53aa

Please sign in to comment.