-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegram.tsx
More file actions
27 lines (23 loc) · 861 Bytes
/
telegram.tsx
File metadata and controls
27 lines (23 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"use client"
import { useQuery } from "@tanstack/react-query"
import { useSession } from "@/lib/auth"
import { useTRPC } from "@/lib/trpc/client"
export function Telegram() {
const { data: session, isPending } = useSession()
if (isPending || !session) return null
const { user } = session
if (!user.telegramUsername || !user.telegramId) return null
return <ShowTelegram username={user.telegramUsername} userId={user.telegramId} />
}
function ShowTelegram({ username, userId }: { username: string; userId: number }) {
const trpc = useTRPC()
const { data, isLoading } = useQuery(trpc.tg.permissions.getRoles.queryOptions({ userId }))
return (
<>
<span>@{username}</span>
{!isLoading && data?.roles?.length && (
<span className="text-foreground/30 text-xs">(roles: {data.roles.join(", ")})</span>
)}
</>
)
}