Skip to content

Commit 3565ac8

Browse files
feat: show telegram role (if it is not 'user')
1 parent 9973b51 commit 3565ac8

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

src/app/dashboard/(active)/account/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
22
import { getInitials } from "@/lib/utils";
33
import { getServerSession } from "@/server/auth";
4-
import { Telegram } from "./link-telegram";
4+
import { Telegram } from "./telegram";
55

66
export default async function Account() {
77
const { data: session } = await getServerSession();

src/app/dashboard/(active)/account/link-telegram.tsx renamed to src/app/dashboard/(active)/account/telegram.tsx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,42 @@ import { InputWithPrefix } from "@/components/input-prefix";
1717
import { Code } from "@/components/code";
1818
import { toast } from "sonner";
1919
import { ClockAlertIcon } from "lucide-react";
20-
21-
const RESET_TIMER_EVENT = "polinetwork:reset_telegram_link_timer"
20+
import { useTRPC } from "@/lib/trpc/client";
21+
import { useQuery } from "@tanstack/react-query";
2222

2323
export function Telegram() {
2424
const { data: session, isPending } = useSession();
2525
if (isPending) return <></>;
2626
const { user } = session!;
2727

28-
return user.telegramUsername ? (
29-
<span>@{user.telegramUsername}</span>
28+
return user.telegramUsername && user.telegramId ? (
29+
<ShowTelegram username={user.telegramUsername} userId={user.telegramId} />
3030
) : (
3131
<LinkTelegram />
3232
);
3333
}
3434

35+
function ShowTelegram({
36+
username,
37+
userId,
38+
}: {
39+
username: string;
40+
userId: number;
41+
}) {
42+
const trpc = useTRPC();
43+
const { data, isLoading } = useQuery(
44+
trpc.tg.permissions.getRole.queryOptions({ userId }),
45+
);
46+
return (
47+
<>
48+
<span>@{username}</span>
49+
{!isLoading && data && data.role !== "user" && (
50+
<span className="text-xs text-foreground/30">(role: {data.role})</span>
51+
)}
52+
</>
53+
);
54+
}
55+
3556
function LinkTelegram() {
3657
const [open, setOpen] = useState(false);
3758
const { refetch } = useSession();
@@ -117,11 +138,11 @@ function Form({ onComplete }: { onComplete: () => void }) {
117138
}
118139

119140
function reset() {
120-
setTTL(null)
121-
setCode(null)
122-
setExpired(false)
123-
setUsername("")
124-
localStorage.removeItem("linktg")
141+
setTTL(null);
142+
setCode(null);
143+
setExpired(false);
144+
setUsername("");
145+
localStorage.removeItem("linktg");
125146
}
126147

127148
useEffect(() => {
@@ -164,7 +185,7 @@ function Form({ onComplete }: { onComplete: () => void }) {
164185
);
165186

166187
return code && ttl ? (
167-
<div className="flex flex-col items-center gap-4 pt-8 pb-4">
188+
<div className="flex flex-col items-center gap-4 pb-4 pt-8">
168189
<p className="flex items-center justify-between gap-4 text-4xl">
169190
{code.split("").map((c, i) => (
170191
<span key={i}>{c}</span>
@@ -189,7 +210,7 @@ function Form({ onComplete }: { onComplete: () => void }) {
189210
<Code copyOnClick>/link</Code>
190211
</div>
191212

192-
<p className="text-xs text-foreground/30 pt-2">
213+
<p className="pt-2 text-xs text-foreground/30">
193214
Having troubles with this code?{" "}
194215
<button className="underline" onClick={reset}>
195216
Click to reset
@@ -228,8 +249,6 @@ function Timer({
228249
const ttlMs = ttl * 1000;
229250
const [timeLeft, setTimeLeft] = useState<number>(pTimeLeft * 1000);
230251

231-
window.addEventListener(RESET_TIMER_EVENT, () => {})
232-
233252
const percentage = (timeLeft / ttlMs) * 100;
234253
useEffect(() => {
235254
if (timeLeft === 0) return;

0 commit comments

Comments
 (0)