diff --git a/apps/hub/app/(app)/admin/message/_components/messageForm.tsx b/apps/hub/app/(app)/admin/message/_components/messageForm.tsx index 9e614f4d..4ddac1bb 100644 --- a/apps/hub/app/(app)/admin/message/_components/messageForm.tsx +++ b/apps/hub/app/(app)/admin/message/_components/messageForm.tsx @@ -2,25 +2,24 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { Notam } from "@repo/db"; -import { - NotamOptionalDefaults, - NotamOptionalDefaultsSchema, -} from "@repo/db/zod"; +import { NotamOptionalDefaults, NotamOptionalDefaultsSchema } from "@repo/db/zod"; import { useForm } from "react-hook-form"; import { addMessage, disableMessage } from "../action"; import { useState } from "react"; +import { DateInput } from "_components/ui/DateInput"; +import "react-datepicker/dist/react-datepicker.css"; // <-- Add this line at the top if using react-datepicker export const MessageForm = ({ message }: { message?: Notam }) => { const [isSubmitting, setIsSubmitting] = useState(false); const getDefaultShowUntilDate = () => { const date = new Date(); - date.setDate(date.getDate() + 5); return date; }; const disableMessageClient = async () => { - disableMessage(); + await disableMessage(); + window.location.reload(); }; const form = useForm({ @@ -28,8 +27,9 @@ export const MessageForm = ({ message }: { message?: Notam }) => { defaultValues: { message: message?.message, color: message?.color, - isMainMsg: true, active: true, + wartungsmodus: message?.wartungsmodus, + disableHPG: message?.disableHPG, showUntil: getDefaultShowUntilDate(), }, }); @@ -39,7 +39,8 @@ export const MessageForm = ({ message }: { message?: Notam }) => { onSubmit={form.handleSubmit(async (values) => { setIsSubmitting(true); try { - const msg = await addMessage(values); + await addMessage(values); + window.location.reload(); } catch (error) { setIsSubmitting(false); console.error("Failed to add message", error); @@ -57,51 +58,76 @@ export const MessageForm = ({ message }: { message?: Notam }) => { />
-
- - Info - - Success - - Warning - - Error +
+
+ + Info + + Success + + Warning + + Error +
+
+ + +
+
+ + +
-
- - +
+
+ + +
diff --git a/apps/hub/app/(app)/admin/message/action.tsx b/apps/hub/app/(app)/admin/message/action.tsx index 646973d6..64d7b798 100644 --- a/apps/hub/app/(app)/admin/message/action.tsx +++ b/apps/hub/app/(app)/admin/message/action.tsx @@ -3,19 +3,23 @@ import { prisma, Prisma } from "@repo/db"; export const addMessage = async (message: Prisma.NotamCreateInput) => { try { - // Set all current messages with isMainMsg=true to active=false await prisma.notam.updateMany({ - where: { isMainMsg: true }, + where: { active: true }, data: { active: false }, }); + const showUntil = new Date(message.showUntil); + const showUntilActive = showUntil > new Date(); + await prisma.notam.create({ data: { message: message.message, color: message.color, - isMainMsg: true, active: true, - showUntil: new Date().toISOString(), + wartungsmodus: message.wartungsmodus, + disableHPG: message.disableHPG, + showUntilActive, + showUntil, }, }); } catch (error) { @@ -25,9 +29,8 @@ export const addMessage = async (message: Prisma.NotamCreateInput) => { export const disableMessage = async () => { try { - // Set all current messages with isMainMsg=true to active=false await prisma.notam.updateMany({ - where: { isMainMsg: true }, + where: { active: true }, data: { active: false }, }); } catch (error) { diff --git a/apps/hub/app/(app)/admin/message/page.tsx b/apps/hub/app/(app)/admin/message/page.tsx index 612dc784..4402c117 100644 --- a/apps/hub/app/(app)/admin/message/page.tsx +++ b/apps/hub/app/(app)/admin/message/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { MessageSquareWarning } from "lucide-react"; +import { Check, MessageSquareWarning } from "lucide-react"; import { MessageForm } from "./_components/messageForm"; import { PaginatedTable } from "_components/PaginatedTable"; import { ColumnDef } from "@tanstack/react-table"; @@ -23,6 +23,7 @@ export default function MessagePage() {
{ const color = row.getValue("color"); return color; }, }, + { + accessorKey: "wartungsmodus", + header: "Wartungsmodus", + cell: ({ row }) => { + const wartungsmodus = row.getValue("wartungsmodus"); + return wartungsmodus ? : ""; + }, + }, + { + accessorKey: "disableHPG", + header: "HPG deaktiviert", + cell: ({ row }) => { + const disableHPG = row.getValue("disableHPG"); + return disableHPG ? : ""; + }, + }, + { + accessorKey: "showUntil", + header: "Zeitlimit", + cell: ({ row, cell }) => { + const showUntil = new Date(cell.getValue() as string); + const createdAt = new Date(row.getValue("createdAt") as string); + if (showUntil > createdAt) { + return showUntil.toLocaleDateString("de-DE", { + year: "numeric", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + }); + } + return ""; + }, + }, { accessorKey: "createdAt", header: "Erstellt am", - sortDescFirst: false, cell: ({ cell }) => { const date = new Date(cell.getValue() as string); - return date.toLocaleDateString(); + return date.toLocaleDateString("de-DE", { + year: "numeric", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + }); }, }, ] as ColumnDef[] diff --git a/apps/hub/app/(app)/events/_components/Modal.tsx b/apps/hub/app/(app)/events/_components/Modal.tsx index 4a5f9e1d..79c4145e 100644 --- a/apps/hub/app/(app)/events/_components/Modal.tsx +++ b/apps/hub/app/(app)/events/_components/Modal.tsx @@ -23,9 +23,7 @@ import { useRouter } from "next/navigation"; import { handleParticipantEnrolled } from "../../../../helper/events"; import { eventCompleted } from "@repo/shared-components"; import MDEditor from "@uiw/react-md-editor"; -import { DayPicker } from "react-day-picker"; import toast from "react-hot-toast"; -import { se } from "date-fns/locale"; interface ModalBtnProps { title: string; diff --git a/apps/hub/app/_components/ui/PageAlert.tsx b/apps/hub/app/_components/ui/PageAlert.tsx index 827449e1..14d30d8c 100644 --- a/apps/hub/app/_components/ui/PageAlert.tsx +++ b/apps/hub/app/_components/ui/PageAlert.tsx @@ -4,7 +4,6 @@ const fetchMainMessage = async () => { return await prisma.notam.findFirst({ where: { active: true, - isMainMsg: true, }, }); }; @@ -15,19 +14,19 @@ export const WarningAlert = async () => { let msgColor; switch (mainMessage?.color) { case "WARNING": - msgColor = "alert alert-soft alert-warning ml-3 py-2"; + msgColor = "alert alert-soft alert-warning ml-3 py-2 flex items-center gap-2"; break; case "INFO": - msgColor = "alert alert-soft alert-info ml-3 py-2"; + msgColor = "alert alert-soft alert-info ml-3 py-2 flex items-center gap-2"; break; case "SUCCESS": - msgColor = "alert alert-soft alert-success ml-3 py-2"; + msgColor = "alert alert-soft alert-success ml-3 py-2 flex items-center gap-2"; break; case "ERROR": - msgColor = "alert alert-error ml-3 py-2"; + msgColor = "alert alert-error ml-3 py-2 flex items-center gap-2"; break; default: - msgColor = "alert alert-soft ml-3 py-2"; + msgColor = "alert alert-soft ml-3 py-2 flex items-center gap-2"; } if (mainMessage?.message == "" || !mainMessage) { diff --git a/packages/database/prisma/schema/migrations/20250703161512_/migration.sql b/packages/database/prisma/schema/migrations/20250703161512_/migration.sql new file mode 100644 index 00000000..4c2c6b5f --- /dev/null +++ b/packages/database/prisma/schema/migrations/20250703161512_/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - You are about to drop the column `isMainMsg` on the `Notam` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "Notam" DROP COLUMN "isMainMsg"; diff --git a/packages/database/prisma/schema/migrations/20250703161710_/migration.sql b/packages/database/prisma/schema/migrations/20250703161710_/migration.sql new file mode 100644 index 00000000..865c913a --- /dev/null +++ b/packages/database/prisma/schema/migrations/20250703161710_/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "Notam" ADD COLUMN "disableHPG" BOOLEAN NOT NULL DEFAULT false, +ADD COLUMN "wartungsmodus" BOOLEAN NOT NULL DEFAULT false; diff --git a/packages/database/prisma/schema/migrations/20250703170113_/migration.sql b/packages/database/prisma/schema/migrations/20250703170113_/migration.sql new file mode 100644 index 00000000..82c74344 --- /dev/null +++ b/packages/database/prisma/schema/migrations/20250703170113_/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Notam" ADD COLUMN "showUntilActive" BOOLEAN NOT NULL DEFAULT false; diff --git a/packages/database/prisma/schema/notam.prisma b/packages/database/prisma/schema/notam.prisma index 7f12c4ce..a875d037 100644 --- a/packages/database/prisma/schema/notam.prisma +++ b/packages/database/prisma/schema/notam.prisma @@ -8,12 +8,14 @@ enum GlobalColor { } model Notam { - id Int @id @default(autoincrement()) - color GlobalColor - message String - showUntil DateTime - isMainMsg Boolean - active Boolean - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id Int @id @default(autoincrement()) + color GlobalColor + message String + showUntil DateTime + showUntilActive Boolean @default(false) + wartungsmodus Boolean @default(false) + disableHPG Boolean @default(false) + active Boolean + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt }