Report logic #2
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
import { PrismaClient } from "@prisma/client";
|
||||||
|
|
||||||
interface ReportStore {
|
interface ReportStore {
|
||||||
ownId: null | string;
|
ownId: null | string;
|
||||||
@@ -13,4 +14,19 @@ export const useReportStore = create<ReportStore>((set) => ({
|
|||||||
setReportOpen: (open: boolean) => set({ reportOpen: open }),
|
setReportOpen: (open: boolean) => set({ reportOpen: open }),
|
||||||
setOwnId: (id: string) => set({ ownId: id }),
|
setOwnId: (id: string) => set({ ownId: id }),
|
||||||
}));
|
}));
|
||||||
// TODO: implement logic for reports
|
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
export const sendReport = async (receiverId: string, message: string) => {
|
||||||
|
try {
|
||||||
|
await prisma.reportMessage.create({
|
||||||
|
data: {
|
||||||
|
receiverId,
|
||||||
|
message,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to send report:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { ExclamationTriangleIcon, PaperPlaneIcon } from "@radix-ui/react-icons";
|
import { ExclamationTriangleIcon, PaperPlaneIcon } from "@radix-ui/react-icons";
|
||||||
import { useReportStore } from "_store/reportStore";
|
import { useReportStore, sendReport } from "_store/reportStore";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import {
|
import {
|
||||||
@@ -107,13 +107,14 @@ export const Report = () => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (message.length < 1 || !selectedPlayer) return;
|
if (message.length < 1 || !selectedPlayer) return;
|
||||||
setSending(true);
|
setSending(true);
|
||||||
// TODO: Implement logic for reports
|
sendReport(selectedPlayer, message)
|
||||||
/* sendReport(selectedPlayer, message).then(() => {
|
.then(() => {
|
||||||
setMessage("");
|
setMessage("");
|
||||||
setSending(false);
|
setSending(false);
|
||||||
}); */
|
})
|
||||||
setMessage("");
|
.catch(() => {
|
||||||
setSending(false);
|
setSending(false);
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
disabled={sending}
|
disabled={sending}
|
||||||
>
|
>
|
||||||
|
|||||||
13
packages/database/prisma/schema/reportMessage.prisma
Normal file
13
packages/database/prisma/schema/reportMessage.prisma
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
model ReportMessage {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
text String
|
||||||
|
senderId String
|
||||||
|
reportedId String
|
||||||
|
timestamp DateTime @default(now())
|
||||||
|
reportedName String
|
||||||
|
senderName String
|
||||||
|
|
||||||
|
// relations:
|
||||||
|
sender User @relation("SentReports", fields: [senderId], references: [id])
|
||||||
|
reported User @relation("ReceivedReports", fields: [reportedId], references: [id])
|
||||||
|
}
|
||||||
@@ -43,6 +43,8 @@ model User {
|
|||||||
EventAppointment EventAppointment[]
|
EventAppointment EventAppointment[]
|
||||||
SentMessages ChatMessage[] @relation("SentMessages")
|
SentMessages ChatMessage[] @relation("SentMessages")
|
||||||
ReceivedMessages ChatMessage[] @relation("ReceivedMessages")
|
ReceivedMessages ChatMessage[] @relation("ReceivedMessages")
|
||||||
|
SentReports ReportMessage[] @relation("SentReports")
|
||||||
|
ReceivedReports ReportMessage[] @relation("ReceivedReports")
|
||||||
/**
|
/**
|
||||||
* Missions Mission[]
|
* Missions Mission[]
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user