From 99c69e532ffe077461abe4d1ac49bf6484119e89 Mon Sep 17 00:00:00 2001 From: Donkoko Date: Fri, 31 Jan 2025 16:01:20 +0200 Subject: [PATCH] chore: small fixes to admin dashboard --- .../_layout+/admin-dashboard+/$userId.tsx | 66 +++++++++++++------ .../_layout+/admin-dashboard+/users.tsx | 6 +- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/app/routes/_layout+/admin-dashboard+/$userId.tsx b/app/routes/_layout+/admin-dashboard+/$userId.tsx index 1856c1aa8..ffc20700d 100644 --- a/app/routes/_layout+/admin-dashboard+/$userId.tsx +++ b/app/routes/_layout+/admin-dashboard+/$userId.tsx @@ -1,3 +1,4 @@ +import type { ReactNode } from "react"; import { TierId, type Asset, @@ -5,7 +6,11 @@ import { type User, type CustomTierLimit, } from "@prisma/client"; -import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node"; +import type { + ActionFunctionArgs, + LoaderFunctionArgs, + SerializeFrom, +} from "@remix-run/node"; import { json } from "@remix-run/node"; import { useLoaderData, Link, useFetcher } from "@remix-run/react"; @@ -211,10 +216,47 @@ export const action = async ({ }; export default function Area51UserPage() { - const { user, organizations } = useLoaderData(); + // Get the loader data type + type LoaderData = SerializeFrom; + + const { user, organizations } = useLoaderData(); const hasCustomTier = user?.tierId === "custom" && user?.customTierLimit !== null; + // Extract user type from loader data + type User = NonNullable; + + const renderValue = (key: keyof User, value: User[keyof User]): ReactNode => { + switch (key) { + case "tierId": + return ; + case "customerId": + return !value ? ( +
+ + +
+ ) : ( + <> + + + ); + default: + return typeof value === "string" + ? value + : typeof value === "boolean" + ? String(value) + : null; + } + }; return user ? (
@@ -234,25 +276,7 @@ export default function Area51UserPage() { .map(([key, value]) => (
  • {key}:{" "} - {key === "tierId" ? ( - - ) : key === "customerId" && !value ? ( -
    - - -
    - ) : ( - <> - {typeof value === "string" ? value : null} - {typeof value === "boolean" ? String(value) : null} - - )} + {renderValue(key as keyof User, value)}
  • )) : null} diff --git a/app/routes/_layout+/admin-dashboard+/users.tsx b/app/routes/_layout+/admin-dashboard+/users.tsx index 4dc8a26e5..24fbdc234 100644 --- a/app/routes/_layout+/admin-dashboard+/users.tsx +++ b/app/routes/_layout+/admin-dashboard+/users.tsx @@ -1,6 +1,6 @@ import type { User } from "@prisma/client"; import type { LoaderFunctionArgs } from "@remix-run/node"; -import { redirect, json } from "@remix-run/node"; +import { json } from "@remix-run/node"; import { useNavigate } from "@remix-run/react"; import { ErrorContent } from "~/components/errors"; import type { HeaderData } from "~/components/layout/header/types"; @@ -26,10 +26,6 @@ export async function loader({ context, request }: LoaderFunctionArgs) { request, }); - if (page > totalPages) { - return redirect("/admin-dashboard"); - } - const header: HeaderData = { title: `Admin dashboard`, };