From 9551202370ed410fdb50b66210659070ce5f1842 Mon Sep 17 00:00:00 2001
From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com>
Date: Wed, 26 Mar 2025 00:12:22 -0700
Subject: [PATCH] keyword admin page
---
.../(dispatch)/_components/map/BaseMaps.tsx | 1 +
.../hub/app/(app)/admin/keyword/[id]/page.tsx | 13 +
.../(app)/admin/keyword/_components/Form.tsx | 245 ++++++++++++++++++
apps/hub/app/(app)/admin/keyword/action.ts | 20 ++
apps/hub/app/(app)/admin/keyword/layout.tsx | 20 ++
apps/hub/app/(app)/admin/keyword/new/page.tsx | 5 +
apps/hub/app/(app)/admin/keyword/page.tsx | 47 ++++
grafana/grafana.db | Bin 1122304 -> 1122304 bytes
.../database/prisma/schema/keyword.prisma | 10 +
9 files changed, 361 insertions(+)
create mode 100644 apps/hub/app/(app)/admin/keyword/[id]/page.tsx
create mode 100644 apps/hub/app/(app)/admin/keyword/_components/Form.tsx
create mode 100644 apps/hub/app/(app)/admin/keyword/action.ts
create mode 100644 apps/hub/app/(app)/admin/keyword/layout.tsx
create mode 100644 apps/hub/app/(app)/admin/keyword/new/page.tsx
create mode 100644 apps/hub/app/(app)/admin/keyword/page.tsx
create mode 100644 packages/database/prisma/schema/keyword.prisma
diff --git a/apps/dispatch/app/(dispatch)/_components/map/BaseMaps.tsx b/apps/dispatch/app/(dispatch)/_components/map/BaseMaps.tsx
index 6f04e0dc..938e95d0 100644
--- a/apps/dispatch/app/(dispatch)/_components/map/BaseMaps.tsx
+++ b/apps/dispatch/app/(dispatch)/_components/map/BaseMaps.tsx
@@ -7,6 +7,7 @@ export const BaseMaps = () => {
>
);
diff --git a/apps/hub/app/(app)/admin/keyword/[id]/page.tsx b/apps/hub/app/(app)/admin/keyword/[id]/page.tsx
new file mode 100644
index 00000000..399adf90
--- /dev/null
+++ b/apps/hub/app/(app)/admin/keyword/[id]/page.tsx
@@ -0,0 +1,13 @@
+import { prisma } from '@repo/db';
+import { StationForm } from '../_components/Form';
+
+export default async ({ params }: { params: Promise<{ id: string }> }) => {
+ const { id } = await params;
+ const station = await prisma.station.findUnique({
+ where: {
+ id: parseInt(id),
+ },
+ });
+ if (!station) return
Station not found
;
+ return ;
+};
diff --git a/apps/hub/app/(app)/admin/keyword/_components/Form.tsx b/apps/hub/app/(app)/admin/keyword/_components/Form.tsx
new file mode 100644
index 00000000..c604dfa9
--- /dev/null
+++ b/apps/hub/app/(app)/admin/keyword/_components/Form.tsx
@@ -0,0 +1,245 @@
+"use client";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { StationOptionalDefaultsSchema } from "@repo/db/zod";
+import { set, useForm } from "react-hook-form";
+import { z } from "zod";
+import { BosUse, Country, Station } from "@repo/db";
+import { FileText, LocateIcon, PlaneIcon } from "lucide-react";
+import { Input } from "../../../../_components/ui/Input";
+import { useState } from "react";
+import { deleteStation, upsertStation } from "../action";
+import { Button } from "../../../../_components/ui/Button";
+import { redirect } from "next/navigation";
+
+export const StationForm = ({ station }: { station?: Station }) => {
+ const form = useForm>({
+ resolver: zodResolver(StationOptionalDefaultsSchema),
+ defaultValues: station,
+ });
+ const [loading, setLoading] = useState(false);
+ const [deleteLoading, setDeleteLoading] = useState(false);
+ return (
+ <>
+
+ >
+ );
+};
diff --git a/apps/hub/app/(app)/admin/keyword/action.ts b/apps/hub/app/(app)/admin/keyword/action.ts
new file mode 100644
index 00000000..819995ad
--- /dev/null
+++ b/apps/hub/app/(app)/admin/keyword/action.ts
@@ -0,0 +1,20 @@
+"use server";
+
+import { prisma, Prisma, Station } from "@repo/db";
+
+export const upsertKeyword = async (
+ station: Prisma.StationCreateInput,
+ id?: Station["id"],
+) => {
+ const newStation = id
+ ? await prisma.station.update({
+ where: { id: id },
+ data: station,
+ })
+ : await prisma.station.create({ data: station });
+ return newStation;
+};
+
+export const deleteStation = async (id: Station["id"]) => {
+ await prisma.station.delete({ where: { id: id } });
+};
diff --git a/apps/hub/app/(app)/admin/keyword/layout.tsx b/apps/hub/app/(app)/admin/keyword/layout.tsx
new file mode 100644
index 00000000..4b82ebd3
--- /dev/null
+++ b/apps/hub/app/(app)/admin/keyword/layout.tsx
@@ -0,0 +1,20 @@
+import { prisma } from "@repo/db";
+import { Error } from "_components/Error";
+import { getServerSession } from "api/auth/[...nextauth]/auth";
+
+export default async ({ children }: { children: React.ReactNode }) => {
+ const session = await getServerSession();
+
+ if (!session) return ;
+
+ const user = await prisma.user.findUnique({
+ where: {
+ id: session.user.id,
+ },
+ });
+
+ if (!user?.permissions.includes("ADMIN_STATION"))
+ return ;
+
+ return <>{children}>;
+};
diff --git a/apps/hub/app/(app)/admin/keyword/new/page.tsx b/apps/hub/app/(app)/admin/keyword/new/page.tsx
new file mode 100644
index 00000000..a7d5f4de
--- /dev/null
+++ b/apps/hub/app/(app)/admin/keyword/new/page.tsx
@@ -0,0 +1,5 @@
+import { StationForm } from '../_components/Form';
+
+export default () => {
+ return ;
+};
diff --git a/apps/hub/app/(app)/admin/keyword/page.tsx b/apps/hub/app/(app)/admin/keyword/page.tsx
new file mode 100644
index 00000000..39a98b33
--- /dev/null
+++ b/apps/hub/app/(app)/admin/keyword/page.tsx
@@ -0,0 +1,47 @@
+import { DatabaseBackupIcon } from 'lucide-react';
+import { PaginatedTable } from '../../../_components/PaginatedTable';
+import Link from 'next/link';
+
+export default () => {
+ return (
+ <>
+
+ Stationen
+
+ }
+ rightOfSearch={
+
+
+
+
+
+ }
+ />
+ >
+ );
+};
diff --git a/grafana/grafana.db b/grafana/grafana.db
index 131eabd6527ee8aa148b1159cbecd4610b218a80..8474221c1d08eb1c9765d35a29d2536fef886464 100644
GIT binary patch
delta 157
zcmZoT;L>owWr8%L+C&*=MzxIz-*nkHowWr8%L(nJ|&Mx~7j-*nm7<;0ksIj1*n<`kYTV8zAJT&~w%uEz+(OhC*G
z#4JF}3dC$c%)Y%`kHd