Skip to content

Commit

Permalink
fix: block editor error
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Jun 21, 2024
1 parent d04bce5 commit b2496b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 156 deletions.
23 changes: 14 additions & 9 deletions apps/client/components/TicketDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -320,26 +327,24 @@ 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);
}

// Loads the previously stored editor contents.
useEffect(() => {
if (status === "success") {
loadFromStorage().then((content) => {
console.log(content);
setInitialContent(content);
});
}
Expand Down
80 changes: 0 additions & 80 deletions apps/client/pages/portal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,6 @@ export default function Home() {
const [loading, setLoading] = useState(true);
const [tickets, setTickets] = useState<any>();

// 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",
Expand All @@ -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);
}

Expand All @@ -108,26 +48,6 @@ export default function Home() {
<div className="w-full xl:w-[70%] max-w-5xl">
{!loading && (
<>
{/* <div>
<dl className="grid grid-cols-1 gap-5 sm:grid-cols-3">
{stats.map((item) => (
<Link href={item.href}>
<div
key={item.name}
className="px-4 py-5 bg-gray-900 shadow rounded-lg overflow-hidden sm:p-6"
>
<dt className="text-sm font-medium text-white truncate">
{item.name}
</dt>
<dd className="mt-1 text-3xl font-semibold text-white">
{item.stat}
</dd>
</div>
</Link>
))}
</dl>
</div> */}

<div className="flex w-full flex-col mt-4 px-1 mb-4">
{tickets !== undefined && tickets.length === 0 ? (
<>
Expand Down
69 changes: 2 additions & 67 deletions apps/client/pages/portal/ticket/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -62,22 +52,6 @@ export default function Ticket() {
const [publicComment, setPublicComment] = useState<any>(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;
Expand Down Expand Up @@ -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 (
<div>
{status === "loading" && (
Expand Down

0 comments on commit b2496b7

Please sign in to comment.