added reports page

This commit is contained in:
PxlLoewe
2025-05-16 22:49:44 -07:00
parent da5ec8470d
commit 40ca6b1bd9
25 changed files with 1355 additions and 1363 deletions

View File

@@ -3,11 +3,12 @@ import { ExclamationTriangleIcon, PaperPlaneIcon } from "@radix-ui/react-icons";
import { useSession } from "next-auth/react";
import { useEffect, useState } from "react";
import { cn } from "helpers/cn";
import { serverApi } from "helpers/axios";
import { toast } from "react-hot-toast";
import { useLeftMenuStore } from "_store/leftMenuStore";
import { asPublicUser } from "@repo/db";
import { useQuery } from "@tanstack/react-query";
import { getConnectedUserAPI } from "querys/connected-user";
import { sendReportAPI } from "querys/report";
export const Report = () => {
const { setChatOpen, setReportTabOpen, reportTabOpen, setOwnId } =
@@ -106,18 +107,18 @@ export const Report = () => {
e.preventDefault();
if (message.length < 1 || !selectedPlayer) return;
setSending(true);
serverApi("/report", {
method: "POST",
data: {
message,
to: selectedPlayer,
},
sendReportAPI({
text: message,
senderUserId: session.data!.user.id,
reportedUserId: selectedPlayer,
})
.then(() => {
toast.success("Report gesendet");
setMessage("");
setSending(false);
})
.catch(() => {
.catch((err) => {
toast.error(`Fehler beim Senden des Reports: ${err}`);
setSending(false);
});
}}

View File

@@ -0,0 +1,19 @@
import { Prisma, Report } from "@repo/db";
import { serverApi } from "helpers/axios";
export const sendReportAPI = async (
report:
| (Prisma.Without<
Prisma.ReportCreateInput,
Prisma.ReportUncheckedCreateInput
> &
Prisma.ReportUncheckedCreateInput)
| (Prisma.Without<
Prisma.ReportUncheckedCreateInput,
Prisma.ReportCreateInput
> &
Prisma.ReportCreateInput),
) => {
const repsonse = await serverApi.put("/report", report);
return repsonse.data as Report;
};