From f801f8f422954b884a6541321dba0669ee9d6173 Mon Sep 17 00:00:00 2001 From: Factiven Date: Sun, 22 Oct 2023 19:43:17 +0700 Subject: Update v4.2.0 (#93) --- components/admin/dashboard/index.js | 220 ++++++++++++++++++++++++++++++------ 1 file changed, 183 insertions(+), 37 deletions(-) (limited to 'components/admin/dashboard/index.js') diff --git a/components/admin/dashboard/index.js b/components/admin/dashboard/index.js index 64a1d6f..d0c9963 100644 --- a/components/admin/dashboard/index.js +++ b/components/admin/dashboard/index.js @@ -1,4 +1,6 @@ -import React, { useState } from "react"; +import Link from "next/link"; +import React, { useEffect, useState } from "react"; +import { toast } from "sonner"; export default function AdminDashboard({ animeCount, @@ -10,13 +12,90 @@ export default function AdminDashboard({ const [selectedTime, setSelectedTime] = useState(""); const [unixTimestamp, setUnixTimestamp] = useState(null); - const handleSubmit = (e) => { + const [broadcast, setBroadcast] = useState(); + const [reportId, setReportId] = useState(); + + useEffect(() => { + async function getBroadcast() { + const res = await fetch("/api/v2/admin/broadcast", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-Broadcast-Key": "get-broadcast", + }, + }); + const data = await res.json(); + if (data) { + setBroadcast(data); + } + } + getBroadcast(); + }, []); + + const handleSubmit = async (e) => { e.preventDefault(); + let unixTime; + if (selectedTime) { - const unixTime = Math.floor(new Date(selectedTime).getTime() / 1000); + unixTime = Math.floor(new Date(selectedTime).getTime() / 1000); setUnixTimestamp(unixTime); } + + const res = await fetch("/api/v2/admin/broadcast", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-Broadcast-Key": "get-broadcast", + }, + body: JSON.stringify({ + message, + startAt: unixTime, + show: true, + }), + }); + + const data = await res.json(); + + console.log({ message, unixTime, data }); + }; + + const handleRemove = async () => { + try { + const res = await fetch("/api/v2/admin/broadcast", { + method: "DELETE", + headers: { + "Content-Type": "application/json", + "X-Broadcast-Key": "get-broadcast", + }, + }); + const data = await res.json(); + console.log(data); + } catch (error) { + console.log(error); + } + }; + + const handleResolved = async () => { + try { + console.log(reportId); + if (!reportId) return toast.error("reportId is required"); + const res = await fetch("/api/v2/admin/bug-report", { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + reportId, + }), + }); + const data = await res.json(); + if (res.status === 200) { + toast.success(data.message); + } + } catch (error) { + console.log(`error while resolving ${error}`); + } }; return (
@@ -39,7 +118,21 @@ export default function AdminDashboard({
-

Broadcast

+

+ Broadcast + + + + +

@@ -70,16 +163,24 @@ export default function AdminDashboard({ id="selectedTime" value={selectedTime} onChange={(e) => setSelectedTime(e.target.value)} - required className="w-full px-3 py-2 border rounded-md focus:outline-none text-black" />
- +
+ + +
{unixTimestamp && (

@@ -95,40 +196,85 @@ export default function AdminDashboard({ {report?.map((i, index) => (

- {i.desc}{" "} - {i.severity === "Low" && ( - - {/* */} - - - )} - {i.severity === "Medium" && ( - - {/* */} - - - )} - {i.severity === "High" && ( - - {/* */} - - - )} - {i.severity === "Critical" && ( - - - + + {i.desc}{" "} + + - )} + +
+ {i.severity === "Low" && ( + + {/* */} + + + )} + {i.severity === "Medium" && ( + + {/* */} + + + )} + {i.severity === "High" && ( + + {/* */} + + + )} + {i.severity === "Critical" && ( + + + + + )} + +
))}
-
a
); } -- cgit v1.2.3