From bc05bd1d0648ccee468347548f21c99c9fffc884 Mon Sep 17 00:00:00 2001 From: Mathias Gruber Date: Sat, 19 Oct 2024 13:15:02 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Ability=20to=20silence/ban/warn?= =?UTF-8?q?=20etc=20at=20lower=20&=20higher=20timescales?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/drizzle/constants.ts | 3 ++ app/src/app/reports/[reportid]/page.tsx | 58 +++++++++++++++++++------ app/src/server/api/routers/reports.ts | 23 ++++++---- app/src/utils/time.ts | 19 ++++++++ app/src/validators/reports.ts | 6 ++- 5 files changed, 84 insertions(+), 25 deletions(-) diff --git a/app/drizzle/constants.ts b/app/drizzle/constants.ts index 3d6b0d84..9c58b857 100644 --- a/app/drizzle/constants.ts +++ b/app/drizzle/constants.ts @@ -141,6 +141,9 @@ export const BanStates = [ "OFFICIAL_WARNING", ] as const; +export const TimeUnits = ["minutes", "hours", "days", "weeks", "months"] as const; +export type TimeUnit = (typeof TimeUnits)[number]; + export const WeaponTypes = [ "STAFF", "AXE", diff --git a/app/src/app/reports/[reportid]/page.tsx b/app/src/app/reports/[reportid]/page.tsx index 766f6c7b..18cf25ac 100644 --- a/app/src/app/reports/[reportid]/page.tsx +++ b/app/src/app/reports/[reportid]/page.tsx @@ -15,11 +15,16 @@ import SliderField from "@/layout/SliderField"; import Post from "@/layout/Post"; import ParsedReportJson from "@/layout/ReportReason"; import Loader from "@/layout/Loader"; - +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; import { Button } from "@/components/ui/button"; import { CommentOnReport } from "@/layout/Comment"; import { api } from "@/utils/api"; -import { type ReportCommentSchema } from "@/validators/reports"; import { reportCommentSchema } from "@/validators/reports"; import { useInfinitePagination } from "@/libs/pagination"; import { useRequiredUserData } from "@/utils/UserContext"; @@ -30,6 +35,9 @@ import { canPostReportComment } from "@/validators/reports"; import { canModerateReports } from "@/validators/reports"; import { canEscalateBan } from "@/validators/reports"; import { canClearReport } from "@/validators/reports"; +import { TimeUnits } from "@/drizzle/constants"; +import type { ReportCommentSchema } from "@/validators/reports"; +import type { TimeUnit } from "@/drizzle/constants"; import type { BaseServerResponse } from "@/server/api/trpc"; export default function Report({ params }: { params: { reportid: string } }) { @@ -76,11 +84,13 @@ export default function Report({ params }: { params: { reportid: string } }) { } = useForm({ defaultValues: { banTime: 0, + banTimeUnit: "days", }, resolver: zodResolver(reportCommentSchema), }); const watchedLength = watch("banTime", 0); + const watchedUnit = watch("banTimeUnit", "days"); // Get utils const utils = api.useUtils(); @@ -191,18 +201,38 @@ export default function Report({ params }: { params: { reportid: string } }) {
{canBan && ( - +
+
+ +
+ +
)} {canWrite && ( { + return input.banTime !== undefined && input.banTimeUnit !== undefined + ? new Date( + new Date().getTime() + + input.banTime * getMillisecondsFromTimeUnit(input.banTimeUnit), + ) + : null; +}; diff --git a/app/src/utils/time.ts b/app/src/utils/time.ts index 561750a9..5766d86a 100644 --- a/app/src/utils/time.ts +++ b/app/src/utils/time.ts @@ -1,3 +1,5 @@ +import type { TimeUnit } from "@/drizzle/constants"; + /** * Get game time which is the UTC HH:MM:SS timestring */ @@ -123,3 +125,20 @@ export const getCurrentSeason = () => { return "summer"; } }; + +export const getMillisecondsFromTimeUnit = (timeUnit: TimeUnit) => { + switch (timeUnit) { + case "minutes": + return 1000 * 60; + case "hours": + return 1000 * 60 * 60; + case "days": + return 1000 * 60 * 60 * 24; + case "weeks": + return 1000 * 60 * 60 * 24 * 7; + case "months": + return 1000 * 60 * 60 * 24 * 30; + default: + return 1000; + } +}; diff --git a/app/src/validators/reports.ts b/app/src/validators/reports.ts index e258c1f0..4aa13b13 100644 --- a/app/src/validators/reports.ts +++ b/app/src/validators/reports.ts @@ -1,5 +1,6 @@ import { z } from "zod"; -import type { UserData, UserReport } from "../../drizzle/schema"; +import { TimeUnits } from "@/drizzle/constants"; +import type { UserData, UserReport } from "@/drizzle/schema"; export const systems = [ "forum_comment", @@ -21,7 +22,8 @@ export type UserReportSchema = z.infer; export const reportCommentSchema = z.object({ comment: z.string().min(10).max(5000), object_id: z.string(), - banTime: z.number().min(0).max(365), + banTime: z.number().min(0).max(100), + banTimeUnit: z.enum(TimeUnits), }); export type ReportCommentSchema = z.infer;