Discord account Linkage, penalty update
This commit is contained in:
@@ -3,7 +3,7 @@ import { User2 } from "lucide-react";
|
||||
import { PaginatedTable } from "../../../_components/PaginatedTable";
|
||||
import Link from "next/link";
|
||||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { DiscordAccount, Prisma, User } from "@repo/db";
|
||||
import { DiscordAccount, Penalty, Prisma, User } from "@repo/db";
|
||||
import { useSession } from "next-auth/react";
|
||||
|
||||
const AdminUserPage = () => {
|
||||
@@ -21,16 +21,15 @@ const AdminUserPage = () => {
|
||||
{ firstname: { contains: searchTerm, mode: "insensitive" } },
|
||||
{ lastname: { contains: searchTerm, mode: "insensitive" } },
|
||||
{ email: { contains: searchTerm, mode: "insensitive" } },
|
||||
{
|
||||
discordAccounts: {
|
||||
some: { username: { contains: searchTerm, mode: "insensitive" } },
|
||||
},
|
||||
},
|
||||
{ publicId: { contains: searchTerm, mode: "insensitive" } },
|
||||
{ DiscordAccount: { username: { contains: searchTerm, mode: "insensitive" } } },
|
||||
],
|
||||
} as Prisma.UserWhereInput;
|
||||
}}
|
||||
include={{
|
||||
discordAccounts: true,
|
||||
DiscordAccount: true,
|
||||
ReceivedReports: true,
|
||||
Penaltys: true,
|
||||
}}
|
||||
initialOrderBy={[
|
||||
{
|
||||
@@ -55,6 +54,15 @@ const AdminUserPage = () => {
|
||||
{
|
||||
header: "Berechtigungen",
|
||||
cell(props) {
|
||||
const activePenaltys = props.row.original.Penaltys.filter(
|
||||
(penalty) =>
|
||||
!penalty.suspended &&
|
||||
(penalty.type === "BAN" ||
|
||||
(penalty.type === "TIME_BAN" && penalty!.until! > new Date())),
|
||||
);
|
||||
if (activePenaltys.length > 0) {
|
||||
return <span className="font-bold text-red-600">AKTIVE STRAFE</span>;
|
||||
}
|
||||
if (props.row.original.permissions.length === 0) {
|
||||
return <span className="text-gray-700">Keine</span>;
|
||||
} else if (props.row.original.permissions.includes("ADMIN_USER_ADVANCED")) {
|
||||
@@ -69,14 +77,26 @@ const AdminUserPage = () => {
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Strafen / Reports",
|
||||
cell(props) {
|
||||
const penaltyCount = props.row.original.Penaltys.length;
|
||||
const reportCount = props.row.original.ReceivedReports.length;
|
||||
return (
|
||||
<span className="w-full text-center">
|
||||
{penaltyCount} / {reportCount}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Discord",
|
||||
cell(props) {
|
||||
const discord = props.row.original.discordAccounts;
|
||||
if (discord.length === 0) {
|
||||
const discord = props.row.original.DiscordAccount;
|
||||
if (!discord) {
|
||||
return <span className="text-gray-700">Nicht verbunden</span>;
|
||||
}
|
||||
return <span>{discord.map((d) => d.username).join(", ")}</span>;
|
||||
return <span>{discord.username}</span>;
|
||||
},
|
||||
},
|
||||
...(session?.user.permissions.includes("ADMIN_USER_ADVANCED")
|
||||
@@ -97,7 +117,13 @@ const AdminUserPage = () => {
|
||||
</div>
|
||||
),
|
||||
},
|
||||
] as ColumnDef<User & { discordAccounts: DiscordAccount[] }>[]
|
||||
] as ColumnDef<
|
||||
User & {
|
||||
DiscordAccount: DiscordAccount;
|
||||
ReceivedReports: Report[];
|
||||
Penaltys: Penalty[];
|
||||
}
|
||||
>[]
|
||||
} // Define the columns for the user table
|
||||
leftOfSearch={
|
||||
<p className="flex items-center gap-2 text-left text-2xl font-semibold">
|
||||
|
||||
Reference in New Issue
Block a user