Skip to content
6 changes: 6 additions & 0 deletions apps/web/src/app/admin/users/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export default async function Page({ params }: { params: { slug: string } }) {
return <p className="text-center font-bold">User Not Found</p>;
}

const roles = await db.query.roles.findMany({
columns: { id: true, name: true },
});

const banInstance = await db.query.bannedUsers.findFirst({
where: eq(bannedUsers.userID, subject.clerkID),
});
Expand Down Expand Up @@ -83,6 +87,7 @@ export default async function Page({ params }: { params: { slug: string } }) {
name={`${subject.firstName} ${subject.lastName}`}
currentRoleId={subject.role_id}
userID={subject.clerkID}
roles={roles}
/>
</Restricted>

Expand Down Expand Up @@ -146,6 +151,7 @@ export default async function Page({ params }: { params: { slug: string } }) {
name={`${subject.firstName} ${subject.lastName}`}
currentRoleId={subject.role_id}
userID={subject.clerkID}
roles={roles}
/>
</div>

Expand Down
10 changes: 6 additions & 4 deletions apps/web/src/components/Restricted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ function Restricted({
if (targetRolePosition !== undefined) {
if (
position === "higher" &&
!compareUserPosition(user, targetRolePosition)
compareUserPosition(user, targetRolePosition)
) {
return <></>;
return <>{children}</>;
}
if (
position === "lower" &&
compareUserPosition(user, targetRolePosition) !== -1
) {
return <></>;
return <>{children}</>;
}
if (
position === "equal" &&
compareUserPosition(user, targetRolePosition) !== 0
) {
return <></>;
return <>{children}</>;
}

return <></>;
}
return <>{children}</>;
}
Expand Down
5 changes: 2 additions & 3 deletions apps/web/src/components/admin/users/UpdateRoleDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,24 @@ import { useAction } from "next-safe-action/hooks";
import { updateRole } from "@/actions/admin/user-actions";
import { useState } from "react";
import { Badge } from "@/components/shadcn/ui/badge";
import { db } from "db";
import { titleCase } from "@/lib/utils/shared/string";

interface UpdateRoleDialogProps {
userID: string;
name: string;
currentRoleId: number;
roles: { id: number; name: string }[];
}

export default async function UpdateRoleDialog({
userID,
currentRoleId,
name,
roles,
}: UpdateRoleDialogProps) {
const [roleToSet, setRoleToSet] = useState(currentRoleId);
const [open, setOpen] = useState(false);

const roles = await db.query.roles.findMany();

const currentRoleName = titleCase(
roles.find((r) => r.id === currentRoleId)?.name.replace("_", " ") || "",
);
Expand Down