From 4bfb3b4250efa735aa265e924680a36a4b8bb1a7 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sat, 21 Dec 2024 21:35:35 +0000 Subject: feature: Add an admin notice about the usage of the legacy container images --- apps/web/app/dashboard/admin/page.tsx | 15 +++-- apps/web/components/dashboard/admin/AdminCard.tsx | 3 + .../components/dashboard/admin/AdminNotices.tsx | 71 ++++++++++++++++++++++ .../components/dashboard/header/ProfileOptions.tsx | 11 +++- apps/web/components/ui/alert.tsx | 60 ++++++++++++++++++ 5 files changed, 151 insertions(+), 9 deletions(-) create mode 100644 apps/web/components/dashboard/admin/AdminCard.tsx create mode 100644 apps/web/components/dashboard/admin/AdminNotices.tsx create mode 100644 apps/web/components/ui/alert.tsx (limited to 'apps/web') diff --git a/apps/web/app/dashboard/admin/page.tsx b/apps/web/app/dashboard/admin/page.tsx index 18efc889..cf97698b 100644 --- a/apps/web/app/dashboard/admin/page.tsx +++ b/apps/web/app/dashboard/admin/page.tsx @@ -1,5 +1,7 @@ import { redirect } from "next/navigation"; import AdminActions from "@/components/dashboard/admin/AdminActions"; +import { AdminCard } from "@/components/dashboard/admin/AdminCard"; +import { AdminNotices } from "@/components/dashboard/admin/AdminNotices"; import ServerStats from "@/components/dashboard/admin/ServerStats"; import UserList from "@/components/dashboard/admin/UserList"; import { getServerAuthSession } from "@/server/auth"; @@ -10,14 +12,15 @@ export default async function AdminPage() { redirect("/"); } return ( - <> -
+
+ + -
-
+ + -
- + +
); } diff --git a/apps/web/components/dashboard/admin/AdminCard.tsx b/apps/web/components/dashboard/admin/AdminCard.tsx new file mode 100644 index 00000000..3a52b5e5 --- /dev/null +++ b/apps/web/components/dashboard/admin/AdminCard.tsx @@ -0,0 +1,3 @@ +export function AdminCard({ children }: { children: React.ReactNode }) { + return
{children}
; +} diff --git a/apps/web/components/dashboard/admin/AdminNotices.tsx b/apps/web/components/dashboard/admin/AdminNotices.tsx new file mode 100644 index 00000000..4977736f --- /dev/null +++ b/apps/web/components/dashboard/admin/AdminNotices.tsx @@ -0,0 +1,71 @@ +"use client"; + +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; +import { Badge } from "@/components/ui/badge"; +import { api } from "@/lib/trpc"; +import { AlertCircle } from "lucide-react"; + +import { AdminCard } from "./AdminCard"; + +interface AdminNotice { + level: "info" | "warning" | "error"; + message: React.ReactNode; + title: string; +} + +function useAdminNotices() { + const { data } = api.admin.getAdminNoticies.useQuery(); + if (!data) { + return []; + } + const ret: AdminNotice[] = []; + if (data.legacyContainersNotice) { + ret.push({ + level: "warning", + message: ( +

+ You're using the legacy docker container images. Those will stop + getting supported soon. Please follow{" "} + + this guide + {" "} + to upgrade. +

+ ), + title: "Legacy Container Images", + }); + } + return ret; +} + +export function AdminNotices() { + const notices = useAdminNotices(); + + if (notices.length === 0) { + return null; + } + return ( + +
+ {notices.map((n, i) => ( + + + {n.title} + {n.message} + + ))} +
+
+ ); +} + +export function AdminNoticeBadge() { + const notices = useAdminNotices(); + if (notices.length === 0) { + return null; + } + return {notices.length}; +} diff --git a/apps/web/components/dashboard/header/ProfileOptions.tsx b/apps/web/components/dashboard/header/ProfileOptions.tsx index 3dbfcf04..fc18e9d2 100644 --- a/apps/web/components/dashboard/header/ProfileOptions.tsx +++ b/apps/web/components/dashboard/header/ProfileOptions.tsx @@ -16,6 +16,8 @@ import { LogOut, Moon, Paintbrush, Settings, Shield, Sun } from "lucide-react"; import { signOut, useSession } from "next-auth/react"; import { useTheme } from "next-themes"; +import { AdminNoticeBadge } from "../admin/AdminNotices"; + function DarkModeToggle() { const { t } = useTranslation(); const { theme } = useTheme(); @@ -72,9 +74,12 @@ export default function SidebarProfileOptions() { {session.user.role == "admin" && ( - - - {t("admin.admin_settings")} + +
+ + {t("admin.admin_settings")} +
+
)} diff --git a/apps/web/components/ui/alert.tsx b/apps/web/components/ui/alert.tsx new file mode 100644 index 00000000..706b711e --- /dev/null +++ b/apps/web/components/ui/alert.tsx @@ -0,0 +1,60 @@ +import type { VariantProps } from "class-variance-authority"; +import * as React from "react"; +import { cn } from "@/lib/utils"; +import { cva } from "class-variance-authority"; + +const alertVariants = cva( + "relative w-full rounded-lg border p-4 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7", + { + variants: { + variant: { + default: "bg-background text-foreground", + destructive: + "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive", + }, + }, + defaultVariants: { + variant: "default", + }, + }, +); + +const Alert = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes & VariantProps +>(({ className, variant, ...props }, ref) => ( +
+)); +Alert.displayName = "Alert"; + +const AlertTitle = React.forwardRef< + HTMLParagraphElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( + // eslint-disable-next-line jsx-a11y/heading-has-content +
+)); +AlertTitle.displayName = "AlertTitle"; + +const AlertDescription = React.forwardRef< + HTMLParagraphElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)); +AlertDescription.displayName = "AlertDescription"; + +export { Alert, AlertTitle, AlertDescription }; -- cgit v1.2.3-70-g09d2