Skip to content

Commit

Permalink
feat: Refactor user role handling and data fetching
Browse files Browse the repository at this point in the history
- refactor: Replace `useUser` with `useUserRoles` for role checking
- fix: Correct user ID handling in data loader function
- clean: Remove unused `useUser` import
  • Loading branch information
Sampiiiii committed Nov 18, 2024
1 parent bef48a1 commit c26265d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions apps/forge/src/routes/_authenticated/_reponly/users/$id.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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) => <LocationIcon location={location} key={training.id} />);
};
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit c26265d

Please sign in to comment.