diff --git a/apps/client/components/TicketDetails/index.tsx b/apps/client/components/TicketDetails/index.tsx index 08b3d8c82..79961758f 100644 --- a/apps/client/components/TicketDetails/index.tsx +++ b/apps/client/components/TicketDetails/index.tsx @@ -27,6 +27,14 @@ function isHTML(str) { return false; } +function isJsonString(str) { + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; +} const ticketStatusMap = [ { id: 1, value: "needs_support", name: "Needs Support" }, @@ -259,7 +267,6 @@ export default function Ticket() { const handleUpload = async () => { if (file) { - console.log("Uploading file..."); const formData = new FormData(); formData.append("file", file); @@ -320,18 +327,17 @@ export default function Ticket() { async function loadFromStorage() { const storageString = data.ticket.detail as PartialBlock[]; - - if (isHTML(storageString)) { - return undefined; + if (storageString && isJsonString(storageString)) { + return JSON.parse(storageString) as PartialBlock[]; } else { - return storageString - ? (JSON.parse(storageString) as PartialBlock[]) - : undefined; + return undefined; } } async function convertHTML() { - const blocks = await editor.tryParseHTMLToBlocks(data.ticket.detail); + const blocks = (await editor.tryParseHTMLToBlocks( + data.ticket.detail + )) as PartialBlock[]; editor.replaceBlocks(editor.document, blocks); } @@ -339,7 +345,6 @@ export default function Ticket() { useEffect(() => { if (status === "success") { loadFromStorage().then((content) => { - console.log(content); setInitialContent(content); }); } diff --git a/apps/client/pages/portal/index.tsx b/apps/client/pages/portal/index.tsx index fb7855732..c478997e9 100644 --- a/apps/client/pages/portal/index.tsx +++ b/apps/client/pages/portal/index.tsx @@ -21,45 +21,6 @@ export default function Home() { const [loading, setLoading] = useState(true); const [tickets, setTickets] = useState(); - // async function getOpenTickets() { - // await fetch(`/api/v1/data/tickets/open`, { - // method: "GET", - // headers: { - // Authorization: `Bearer ${token}`, - // }, - // }) - // .then((res) => res.json()) - // .then((res) => { - // setOpenTickets(res.count); - // }); - // } - - // async function getCompletedTickets() { - // await fetch(`/api/v1/data/tickets/completed`, { - // method: "GET", - // headers: { - // Authorization: `Bearer ${token}`, - // }, - // }) - // .then((res) => res.json()) - // .then((res) => { - // setCompletedTickets(res.count); - // }); - // } - - // async function getUnassginedTickets() { - // await fetch(`/api/v1/data/tickets/open`, { - // method: "GET", - // headers: { - // Authorization: `Bearer ${token}`, - // }, - // }) - // .then((res) => res.json()) - // .then((res) => { - // setUnassigned(res.count); - // }); - // } - async function fetchTickets() { await fetch(`/api/v1/tickets/user/open`, { method: "GET", @@ -73,29 +34,8 @@ export default function Home() { }); } - const stats = [ - { - name: t("open_tickets"), - stat: openTickets, - href: "/portal/tickets/open", - }, - { - name: t("completed_tickets"), - stat: completedTickets, - href: "/portal/tickets/closed", - }, - { - name: t("unassigned_tickets"), - stat: unassigned, - href: "/tickets", - }, - ]; - async function datafetch() { fetchTickets(); - // getOpenTickets(); - // getCompletedTickets(); - // getUnassginedTickets(); await setLoading(false); } @@ -108,26 +48,6 @@ export default function Home() {
{!loading && ( <> - {/*
-
- {stats.map((item) => ( - -
-
- {item.name} -
-
- {item.stat} -
-
- - ))} -
-
*/} -
{tickets !== undefined && tickets.length === 0 ? ( <> diff --git a/apps/client/pages/portal/ticket/[id].tsx b/apps/client/pages/portal/ticket/[id].tsx index b8f2f1212..eaac41f6e 100644 --- a/apps/client/pages/portal/ticket/[id].tsx +++ b/apps/client/pages/portal/ticket/[id].tsx @@ -7,27 +7,17 @@ import { LockClosedIcon, LockOpenIcon, } from "@heroicons/react/20/solid"; -import { Link } from "@mantine/tiptap"; -import Highlight from "@tiptap/extension-highlight"; -import Underline from "@tiptap/extension-underline"; -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 { useQuery } from "react-query"; -// import TextAlign from '@tiptap/extension-text-align'; -import SubScript from "@tiptap/extension-subscript"; -import Superscript from "@tiptap/extension-superscript"; + import { getCookie } from "cookies-next"; import useTranslation from "next-translate/useTranslation"; import Frame from "react-frame-component"; import { useUser } from "../../../store/session"; - -function classNames(...classes: any) { - return classes.filter(Boolean).join(" "); -} +import { classNames } from "@/shadcn/lib/utils"; export default function Ticket() { const router = useRouter(); @@ -62,22 +52,6 @@ export default function Ticket() { const [publicComment, setPublicComment] = useState(false); const [timeReason, setTimeReason] = useState(""); - const IssueEditor = useEditor({ - extensions: [ - StarterKit, - Underline, - Link, - Superscript, - SubScript, - Highlight, - // TextAlign.configure({ types: ['heading', 'paragraph'] }), - ], - content: issue, - onUpdate({ editor }) { - setIssue(editor.getHTML()); - }, - }); - const history = useRouter(); const { id } = history.query; @@ -117,45 +91,6 @@ export default function Ticket() { .then(() => refetch()); } - // const propsUpload = { - // name: "file", - // showUploadList: false, - // action: `/api/v1/ticket/${id}/file/upload`, - // data: () => { - // let data = new FormData(); - // data.append("file", file); - // data.append("filename", file.name); - // data.append("ticket", ticket.id); - // }, - // onChange(info: any) { - // if (info.file.status !== "uploading") { - // console.log(info.file, info.fileList); - // } - // if (info.file.status === "done") { - // message.success(`${info.file.name} file uploaded successfully`); - // setUploaded(true); - // } else if (info.file.status === "error") { - // message.error(`${info.file.name} file upload failed.`); - // } - // }, - // progress: { - // strokeColor: { - // "0%": "#108ee9", - // "100%": "#87d068", - // }, - // strokeWidth: 3, - // format: (percent) => `${parseFloat(percent.toFixed(2))}%`, - // }, - // }; - - useEffect(() => { - if (status === "success") { - if (IssueEditor) { - IssueEditor.commands.setContent(data.ticket.detail); - } - } - }, [data, IssueEditor]); - return (
{status === "loading" && (