Skip to content

Commit 5a10141

Browse files
authored
Add link to user dashboard page in profile page (#2898)
1 parent fd13fd6 commit 5a10141

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

apps/web/src/app/profil/[profileSlug]/ProfilePage.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EventList } from "@/app/arrangementer/components/EventList"
44
import { useEventAllByAttendingUserIdInfiniteQuery } from "@/app/arrangementer/components/queries"
55
import { OnlineIcon } from "@/components/atoms/OnlineIcon"
66
import { EventListItemSkeleton } from "@/components/molecules/EventListItem/EventListItem"
7+
import { env } from "@/env"
78
import { useTRPC } from "@/utils/trpc/client"
89
import { useFullPathname } from "@/utils/use-full-pathname"
910
import { useSession } from "@dotkomonline/oauth2/react"
@@ -54,6 +55,7 @@ import { notFound, useParams, useSearchParams } from "next/navigation"
5455
import { type ElementType, useMemo } from "react"
5556
import { PenaltyDialog } from "./components/PenaltyDialog"
5657
import SkeletonProfilePage from "./loading"
58+
import { useIsAdminQuery } from "./queries"
5759

5860
const UserProp = (props: { label: string; value: string | number | null; icon: ElementType }) => {
5961
const Icon = props.icon
@@ -241,6 +243,8 @@ export function ProfilePage() {
241243
[groups]
242244
)
243245

246+
const { isAdmin } = useIsAdminQuery()
247+
244248
if (user === undefined || userLoading) {
245249
return <SkeletonProfilePage />
246250
}
@@ -252,6 +256,8 @@ export function ProfilePage() {
252256
const activeMembership = findActiveMembership(user)
253257
const grade = activeMembership ? getMembershipGrade(activeMembership) : null
254258

259+
const dashboardUrl = new URL(`/brukere/${user.id}`, env.NEXT_PUBLIC_DASHBOARD_URL).toString()
260+
255261
return (
256262
<div className="flex flex-col gap-8 w-full">
257263
<div className="flex flex-row gap-4">
@@ -264,9 +270,25 @@ export function ProfilePage() {
264270

265271
<div className="flex flex-col gap-2 grow">
266272
<div className="flex flex-row w-full justify-between">
267-
<Title element="h1" className="font-semibold text-xl md:text-2xl">
268-
{user.name}
269-
</Title>
273+
<div className="flex flex-row gap-4 items-center">
274+
<Title element="h1" className="font-semibold text-xl md:text-2xl">
275+
{user.name}
276+
</Title>
277+
{isAdmin && (
278+
<Button
279+
element={Link}
280+
href={dashboardUrl}
281+
target="_blank"
282+
rel="noopener noreferrer"
283+
variant="unstyled"
284+
className="w-fit p-1.5 bg-blue-100 hover:bg-blue-50 rounded-md transition-colors dark:bg-stone-700 dark:hover:bg-stone-600 gap-1.5"
285+
title="Rediger arrangement"
286+
>
287+
<IconEdit className="size-[1.25em] md:w-6 md:h-6" />
288+
<Text className="md:hidden">Rediger</Text>
289+
</Button>
290+
)}
291+
</div>
270292
{isUser && (
271293
<Button
272294
element={Link}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { useTRPC } from "@/utils/trpc/client"
2+
import { useQuery } from "@tanstack/react-query"
3+
4+
export const useIsAdminQuery = () => {
5+
const trpc = useTRPC()
6+
const { data: isAdmin, isLoading } = useQuery(trpc.user.isAdmin.queryOptions())
7+
return { isAdmin, isLoading }
8+
}

0 commit comments

Comments
 (0)