Skip to content

Commit

Permalink
chore: small fixes to admin dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
DonKoko committed Jan 31, 2025
1 parent 8849d33 commit 99c69e5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 26 deletions.
66 changes: 45 additions & 21 deletions app/routes/_layout+/admin-dashboard+/$userId.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import type { ReactNode } from "react";
import {
TierId,
type Asset,
type Qr,
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";

Expand Down Expand Up @@ -211,10 +216,47 @@ export const action = async ({
};

export default function Area51UserPage() {
const { user, organizations } = useLoaderData<typeof loader>();
// Get the loader data type
type LoaderData = SerializeFrom<typeof loader>;

const { user, organizations } = useLoaderData<LoaderData>();

const hasCustomTier =
user?.tierId === "custom" && user?.customTierLimit !== null;
// Extract user type from loader data
type User = NonNullable<LoaderData["user"]>;

const renderValue = (key: keyof User, value: User[keyof User]): ReactNode => {
switch (key) {
case "tierId":
return <TierUpdateForm tierId={user.tierId} />;
case "customerId":
return !value ? (
<Form className="inline-block" method="POST">
<input type="hidden" name="intent" value="createCustomerId" />
<Button type="submit" variant="link" size="sm">
Create customer ID
</Button>
</Form>
) : (
<>
<Button
to={`https://dashboard.stripe.com/customers/${value}`}
target="_blank"
variant={"block-link"}
>
{value}
</Button>
</>
);
default:
return typeof value === "string"
? value
: typeof value === "boolean"
? String(value)
: null;
}
};

return user ? (
<div>
Expand All @@ -234,25 +276,7 @@ export default function Area51UserPage() {
.map(([key, value]) => (
<li key={key}>
<span className="font-semibold">{key}</span>:{" "}
{key === "tierId" ? (
<TierUpdateForm tierId={user.tierId} />
) : key === "customerId" && !value ? (
<Form className="inline-block" method="POST">
<input
type="hidden"
name="intent"
value="createCustomerId"
/>
<Button type="submit" variant="link" size="sm">
Create customer ID
</Button>
</Form>
) : (
<>
{typeof value === "string" ? value : null}
{typeof value === "boolean" ? String(value) : null}
</>
)}
{renderValue(key as keyof User, value)}
</li>
))
: null}
Expand Down
6 changes: 1 addition & 5 deletions app/routes/_layout+/admin-dashboard+/users.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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`,
};
Expand Down

0 comments on commit 99c69e5

Please sign in to comment.