Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next #300

Merged
merged 5 commits into from
Apr 10, 2024
Merged

next #300

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions apps/api/src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,57 @@ export function authRoutes(fastify: FastifyInstance) {
}
);

// Reset password by admin
fastify.post(
"/api/v1/auth/admin/reset-password",
async (request: FastifyRequest, reply: FastifyReply) => {
let { password, user } = request.body as {
password: string;
user: string;
};

console.log(user);

const bearer = request.headers.authorization!.split(" ")[1];
const token = checkToken(bearer);

if (token) {
let session = await prisma.session.findUnique({
where: {
sessionToken: bearer,
},
});

const check = await prisma.user.findUnique({
where: { id: session?.userId },
});

if (check?.isAdmin === false) {
reply.code(401).send({
message: "Unauthorized",
});
}

const hashedPass = await bcrypt.hash(password, 10);

await prisma.user.update({
where: { id: user },
data: {
password: hashedPass,
},
});

reply.send({
success: true,
});
} else {
reply.send({
success: false,
});
}
}
);

// Update a users profile/config
fastify.put(
"/api/v1/auth/profile",
Expand Down
3 changes: 3 additions & 0 deletions apps/api/src/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export function userRoutes(fastify: FastifyInstance) {
const token = checkToken(bearer);
if (token) {
const users = await prisma.user.findMany({
where: {
external_user: false,
},
select: {
id: true,
name: true,
Expand Down
7 changes: 4 additions & 3 deletions apps/client/components/ResetPassword/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@ import { notifications } from "@mantine/notifications";
import { getCookie } from "cookies-next";
import React, { Fragment, useState } from "react";

export default function ResetPassword() {
export default function ResetPassword({ user }) {
const [open, setOpen] = useState(false);
const [password, setPassword] = useState("");
const [check, setCheck] = useState("");

const postData = async () => {
if (check === password && password.length > 3) {
await fetch(`/api/v1/auth/reset-password`, {
await fetch(`/api/v1/auth/admin/reset-password`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + getCookie("session"),
},
body: JSON.stringify({
password,
user: user.id,
}),
})
.then((res) => res.json())
.then((res) => {
if (res.success) {
notifications.show({
title: "Success",
message: `Password updated :)`,
message: `Password updated`,
color: "green",
autoClose: 5000,
});
Expand Down
16 changes: 8 additions & 8 deletions apps/client/layouts/newLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,11 @@ export default function NewLayout({ children }: any) {
item.current
? "bg-[#F0F3F9] dark:bg-gray-800 dark:text-green-600"
: " hover:bg-[#F0F3F9] dark:hover:bg-gray-800 dark:hover:text-gray-900 ",
"group -mx-2 flex gap-x-3 p-1 text-xs font-semibold leading-6"
"group -mx-2 flex gap-x-3 p-1 text-xs rounded-md font-semibold leading-6"
)}
>
<item.icon
className="h-4 w-4 shrink-0 mt-1"
className="h-4 w-4 ml-1 shrink-0 mt-1"
aria-hidden="true"
/>
<span className="whitespace-nowrap">{item.name}</span>
Expand All @@ -794,10 +794,10 @@ export default function NewLayout({ children }: any) {
location.pathname === "/tickets"
? "bg-[#F0F3F9] dark:bg-gray-800 dark:text-green-600"
: " hover:bg-[#F0F3F9] dark:hover:bg-white dark:hover:text-gray-900 ",
"group -mx-2 flex gap-x-3 p-1 text-xs font-semibold leading-6"
"group -mx-2 flex gap-x-3 p-1 rounded-md text-xs font-semibold leading-6"
)}
>
<TicketIcon className="h-4 w-4 shrink-0 mt-1" />
<TicketIcon className="h-4 w-4 ml-1 shrink-0 mt-1" />
<span className="whitespace-nowrap">Tickets</span>
<div className="flex w-full justify-end float-right">
<span className="flex h-6 w-6 shrink-0 items-center bg-transparent border-none justify-center text-md font-medium">
Expand All @@ -813,7 +813,7 @@ export default function NewLayout({ children }: any) {
location.pathname === "/tickets/open"
? "bg-[#F0F3F9] dark:bg-gray-800 dark:text-green-600"
: " hover:bg-[#F0F3F9] dark:hover:bg-white dark:hover:text-gray-900 ",
"group -mx-2 flex gap-x-3 p-1 mll-2 text-xs font-semibold leading-6"
"group -mx-2 flex gap-x-3 p-1 pl-3 rounded-md text-xs font-semibold leading-6"
)}
>
<span className="whitespace-nowrap">
Expand All @@ -834,7 +834,7 @@ export default function NewLayout({ children }: any) {
location.pathname === "/tickets/closed"
? "bg-[#F0F3F9] dark:bg-gray-800 dark:text-green-600"
: " hover:bg-[#F0F3F9] dark:hover:bg-white dark:hover:text-gray-900 ",
"group -mx-2 flex gap-x-3 p-1 text-xs font-semibold leading-6"
"group -mx-2 flex gap-x-3 p-1 pl-3 rounded-md text-xs font-semibold leading-6"
)}
>
<span className="whitespace-nowrap">
Expand All @@ -856,14 +856,14 @@ export default function NewLayout({ children }: any) {
location.pathname.includes("/admin")
? "bg-[#F0F3F9] dark:bg-gray-800 dark:text-green-600"
: " hover:bg-[#F0F3F9] dark:hover:bg-white dark:hover:text-gray-900 ",
"group -mx-2 flex gap-x-3 p-1 text-xs font-semibold leading-6"
"group -mx-2 flex gap-x-3 p-1 rounded-md text-xs font-semibold leading-6"
)}
>
<ContextMenu.Root>
<ContextMenu.Trigger>
<>
<Cog6ToothIcon
className="h-4 w-4 shrink-0 mt-1"
className="h-4 w-4 ml-1 shrink-0 mt-1"
aria-hidden="true"
/>
<span className="whitespace-nowrap">
Expand Down
86 changes: 36 additions & 50 deletions apps/client/pages/ticket/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//@ts-nocheck
import { Listbox, Switch, Transition } from "@headlessui/react";
import {
CheckCircleIcon,
CheckIcon,
ChevronUpDownIcon,
LockClosedIcon,
LockOpenIcon,
} from "@heroicons/react/20/solid";
import { Link, RichTextEditor } from "@mantine/tiptap";
import Highlight from "@tiptap/extension-highlight";
Expand Down Expand Up @@ -310,16 +309,15 @@ export default function Ticket() {
{status === "error" && (
<div className="min-h-screen flex flex-col justify-center items-center py-12 sm:px-6 lg:px-8">
<h2 className="text-2xl font-bold"> Error fetching data ... </h2>
{/* <img src={server} className="h-96 w-96" alt="error" /> */}
</div>
)}

{status === "success" && (
<main className="flex-1 min-h-[90vh] py-8">
<div className="mx-auto max-w-6xl w-full px-4 sm:px-6 lg:px-8 flex flex-col xl:flex-row justify-center">
<div className="mx-auto max-w-7xl w-full px-4 flex flex-col xl:flex-row justify-center">
<div className="xl:border-r xl:border-gray-200 xl:pr-8 xl:w-2/3">
<div className="">
<div className="md:flex md:items-center md:justify-between md:space-x-4 xl:border-b xl:pb-6">
<div className="md:flex md:justify-between md:space-x-4 xl:border-b xl:pb-4">
<div className="w-4/5">
{edit ? (
<div className="">
Expand All @@ -341,41 +339,17 @@ export default function Ticket() {
<div className="mt-2 text-xs flex flex-row items-center space-x-1 text-gray-500 dark:text-white">
{!data.ticket.isComplete ? (
<div className="flex items-center space-x-2">
<LockOpenIcon
className="h-3 w-3 text-green-500"
aria-hidden="true"
/>
<span className="text-xs font-medium text-green-700 dark:text-white">
<span className="inline-flex items-center rounded-md bg-green-50 px-2 py-1 text-xs font-medium text-green-700 ring-1 ring-inset ring-green-600/20">
{t("open_issue")}
</span>
</div>
) : (
<div className="flex items-center space-x-2">
<LockClosedIcon
className="h-4 w-4 text-red-500"
aria-hidden="true"
/>
<span className="text-xs font-medium text-red-700 dark:text-white">
<span className="inline-flex items-center rounded-md bg-red-50 px-2 py-1 text-xs font-medium text-red-700 ring-1 ring-inset ring-red-600/10">
{t("closed_issue")}
</span>
</div>
)}
<span className="font-medium text-xs text-gray-900 dark:text-white">
{data.ticket.email}
</span>
<span className="text-xs text-gray-900 dark:text-whit">
via
</span>
<span className="font-medium text-xs text-gray-900 dark:text-white">
{data.ticket.fromImap === true
? " Email - "
: " Agent - "}
</span>

<span className="text-xs font-medium text-gray-900 dark:text-white">
{t("created_at")}{" "}
{moment(data.ticket.createdAt).format("DD/MM/YYYY")}
</span>
</div>
</div>
<div className="mt-4 flex space-x-3 md:mt-0">
Expand Down Expand Up @@ -407,7 +381,7 @@ export default function Ticket() {
) : (
<Button
variant="outline"
className="hover:cursor-pointer"
className="hover:cursor-pointer align-top"
onClick={() => update()}
>
Save
Expand Down Expand Up @@ -503,8 +477,25 @@ export default function Ticket() {
</div>
</aside>
<div className="py-3 xl:pb-0 xl:pt-2">
<span className="text-sm font-bold">{t("description")}</span>
<div className="prose max-w-none">
<div className="flex flex-row items-center text-sm space-x-1">
{data.ticket.fromImap ? (
<>
<span className="font-bold">{data.ticket.email}</span>
<span>created via email at </span>
<span className="font-bold">
{moment(data.ticket.createdAt).format("DD/MM/YYYY")}
</span>
</>
) : (
<>
<span>Created by at </span>
<span className="">
{moment(data.ticket.createdAt).format("DD/MM/YYYY")}
</span>
</>
)}
</div>
<div className="prose max-w-none mt-2">
{edit && !data.ticket.fromImap ? (
<RichTextEditor
editor={IssueEditor}
Expand Down Expand Up @@ -555,14 +546,11 @@ export default function Ticket() {
) : (
<div className="">
{data.ticket.fromImap ? (
<div className="break-words bg-white rounded-md p-4 text-black">
{/* {renderHTML(data.ticket.detail)} */}
<div className="break-words bg-white rounded-md text-black">
<Frame
className="min-h-[60vh] h-full w-full"
initialContent={data.ticket.detail}
>
{" "}
</Frame>
/>
</div>
) : (
<div className="">
Expand Down Expand Up @@ -756,28 +744,26 @@ export default function Ticket() {
</button>
) : (
<button
onClick={() => {
transferTicket();
}}
className="text-sm font-medium text-gray-500 hover:underline dark:text-white"
onClick={() => setAssignedEdit(false)}
className="text-sm align-top font-medium text-gray-500 hover:underline dark:text-white"
>
{t("save")}
cancel
</button>
)}
</div>
{!assignedEdit ? (
<ul role="list" className="mt-3 space-y-3">
<li className="flex justify-star items-center space-x-2">
<ul role="list" className="mt-1 space-y-3">
<li className="flex justify-start items-center space-x-2">
<div className="flex-shrink-0">
<span className="inline-flex h-6 w-6 items-center justify-center rounded-full bg-gray-500">
<span className="inline-flex h-5 w-5 items-center justify-center rounded-full bg-gray-500">
<span className="text-xs font-medium leading-none text-white uppercase ">
{data.ticket.assignedTo
? data.ticket.assignedTo.name[0]
: "-"}
</span>
</span>
</div>
<div className="text-sm font-medium text-gray-900 dark:text-white">
<div className="text-sm font-medium mt-[4px] text-gray-900 dark:text-white">
{data.ticket.assignedTo
? data.ticket.assignedTo.name
: ""}
Expand Down Expand Up @@ -1385,7 +1371,7 @@ export default function Ticket() {
</div>
)}
</div>
<div className="border-t border-gray-200">
{/* <div className="border-t border-gray-200">
<div className="flex flex-row items-center justify-between mt-2">
<span className="text-sm font-medium text-gray-500 dark:text-white">
Attachments
Expand Down Expand Up @@ -1418,7 +1404,7 @@ export default function Ticket() {
</div>
)}
</>
</div>
</div> */}
</div>
</div>
</div>
Expand Down
Loading