From c26265df545f9c231e98280648ac38a0bc27b6e3 Mon Sep 17 00:00:00 2001 From: Sam Piper Date: Mon, 18 Nov 2024 04:03:03 +0000 Subject: [PATCH] feat: Refactor user role handling and data fetching - refactor: Replace `useUser` with `useUserRoles` for role checking - fix: Correct user ID handling in data loader function - clean: Remove unused `useUser` import --- .../src/routes/_authenticated/_reponly/users/$id.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/forge/src/routes/_authenticated/_reponly/users/$id.tsx b/apps/forge/src/routes/_authenticated/_reponly/users/$id.tsx index 88299d99..f7252098 100644 --- a/apps/forge/src/routes/_authenticated/_reponly/users/$id.tsx +++ b/apps/forge/src/routes/_authenticated/_reponly/users/$id.tsx @@ -1,6 +1,7 @@ import { UserAvatar } from "@/components/avatar"; import { LocationIcon } from "@/components/icons/Locations"; import Title from "@/components/title"; +import { useUserRoles } from "@/hooks/useUserRoles.ts"; import SignInChart from "@/routes/_authenticated/_reponly/sign-in/dashboard/-components/SignInChart.tsx"; import { getUser } from "@/services/users/getUser.ts"; import getUserSignIns from "@/services/users/getUserSignIns.ts"; @@ -10,12 +11,11 @@ import { createFileRoute } from "@tanstack/react-router"; import { Badge } from "@ui/components/ui/badge.tsx"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@ui/components/ui/table.tsx"; import { Check, X } from "lucide-react"; -import {useUser} from "@/lib/utils.ts"; export default function Component() { const data = Route.useLoaderData(); const { user, trainings, signIns } = data!; - const rep = user.roles.some((role) => role.name === "Rep"); + const rep = useUserRoles().includes("Rep"); const locationIcon = (training: Training) => { return training.locations.map((location) => ); }; @@ -142,7 +142,7 @@ export default function Component() { export const Route = createFileRoute("/_authenticated/_reponly/users/$id")({ loader: async ({ params }) => { - const userId = useUser()?.id + const userId = params.id; if (userId === undefined) { return { user: null, @@ -151,9 +151,9 @@ export const Route = createFileRoute("/_authenticated/_reponly/users/$id")({ }; } const [user, trainings, signIns] = await Promise.all([ - getUser(params.id), - getUserTraining(params.id), - getUserSignIns(params.id), + getUser(userId), + getUserTraining(userId), + getUserSignIns(userId), ]); return { user,