1// @ts-ignore
2globalThis.onReply = (id: string) => {
3 location.href = `/admin/q+a/${id}?return=inbox`;
4};
5// @ts-ignore
6globalThis.onDelete = async (id: string) => {
7 const div = document.querySelector(`[data-q="${id}"]`) as HTMLDivElement;
8 if (!div) return alert("Question not found");
9
10 // Pending State
11 div.style.opacity = "0.5";
12 div.style.pointerEvents = "none";
13 div?.querySelectorAll("button").forEach((b) => {
14 b.disabled = true;
15 });
16
17 try {
18 const resp = await fetch(`/admin/q+a/${id}`, {
19 method: "DELETE",
20 headers: {
21 Accept: "application/json",
22 },
23 });
24 if (resp.status !== 200) {
25 throw new Error("Failed to delete question, status: " + resp.status);
26 }
27 } catch (e: any) {
28 div.style.opacity = "1";
29 div.style.pointerEvents = "auto";
30 div?.querySelectorAll("button").forEach((b) => {
31 b.disabled = false;
32 });
33 return alert(e.message);
34 }
35
36 div.remove();
37};
38// @ts-ignore
39globalThis.onDeleteFull = async (id: string) => {
40 const div = document.querySelector(`[data-q="${id}"]`) as HTMLDivElement;
41 if (!div) return alert("Question not found");
42
43 // Confirmation
44 if (!confirm("Are you sure you want to delete this question?")) return;
45
46 // Pending State
47 div.style.opacity = "0.5";
48 div.style.pointerEvents = "none";
49 div?.querySelectorAll("button").forEach((b) => {
50 b.disabled = true;
51 });
52
53 try {
54 const resp = await fetch(`/admin/q+a/${id}`, {
55 method: "DELETE",
56 headers: {
57 Accept: "application/json",
58 "X-Delete-Full": "true",
59 },
60 });
61 if (resp.status !== 200) {
62 throw new Error("Failed to delete question, status: " + resp.status);
63 }
64 } catch (e: any) {
65 div.style.opacity = "1";
66 div.style.pointerEvents = "auto";
67 div?.querySelectorAll("button").forEach((b) => {
68 b.disabled = false;
69 });
70 return alert(e.message);
71 }
72
73 div.remove();
74};