diff --git a/src/app/(dashboard)/[guildUrlName]/leaderboard/[rewardId]/components/Leaderboard.tsx b/src/app/(dashboard)/[guildUrlName]/leaderboard/[rewardId]/components/Leaderboard.tsx
index 28c707fea0..e25fa1c19f 100644
--- a/src/app/(dashboard)/[guildUrlName]/leaderboard/[rewardId]/components/Leaderboard.tsx
+++ b/src/app/(dashboard)/[guildUrlName]/leaderboard/[rewardId]/components/Leaderboard.tsx
@@ -1,6 +1,8 @@
"use client";
+import { userOptions } from "@/lib/options";
import {
+ useQuery,
useSuspenseInfiniteQuery,
useSuspenseQuery,
} from "@tanstack/react-query";
@@ -8,8 +10,9 @@ import { leaderboardOptions, pointsRewardOptions } from "../options";
import { LeaderboardUserCard } from "./LeaderboardUserCard";
export const Leaderboard = ({ rewardId }: { rewardId: string }) => {
+ const { data: user } = useQuery(userOptions());
const { data: rawData } = useSuspenseInfiniteQuery(
- leaderboardOptions({ rewardId }),
+ leaderboardOptions({ rewardId, userId: user?.id }),
);
const { data: pointReward } = useSuspenseQuery(
@@ -20,10 +23,12 @@ export const Leaderboard = ({ rewardId }: { rewardId: string }) => {
return (
- {/*
*/}
+ {!!data.user && (
+
+ )}
{`${pointReward.data.name} leaderboard`}
diff --git a/src/app/(dashboard)/[guildUrlName]/leaderboard/[rewardId]/components/LeaderboardUserCard.tsx b/src/app/(dashboard)/[guildUrlName]/leaderboard/[rewardId]/components/LeaderboardUserCard.tsx
index 4b6babc857..4f2944aace 100644
--- a/src/app/(dashboard)/[guildUrlName]/leaderboard/[rewardId]/components/LeaderboardUserCard.tsx
+++ b/src/app/(dashboard)/[guildUrlName]/leaderboard/[rewardId]/components/LeaderboardUserCard.tsx
@@ -7,7 +7,7 @@ import { pointsRewardOptions } from "../options";
export const LeaderboardUserCard = ({
user,
-}: { user: Leaderboard["user"] }) => {
+}: { user: NonNullable }) => {
const { rewardId } = useParams<{ rewardId: string }>();
const { data: pointReward } = useSuspenseQuery(
pointsRewardOptions({ rewardId }),
@@ -24,7 +24,9 @@ export const LeaderboardUserCard = ({
- {user.userId}
+
+ {user.primaryIdentity.foreignId}
+
{`${user.amount} `}
diff --git a/src/app/(dashboard)/[guildUrlName]/leaderboard/[rewardId]/options.ts b/src/app/(dashboard)/[guildUrlName]/leaderboard/[rewardId]/options.ts
index 1f2ac9ad5a..6461427b3e 100644
--- a/src/app/(dashboard)/[guildUrlName]/leaderboard/[rewardId]/options.ts
+++ b/src/app/(dashboard)/[guildUrlName]/leaderboard/[rewardId]/options.ts
@@ -3,11 +3,14 @@ import { fetchGuildApiData } from "@/lib/fetchGuildApi";
import type { GuildReward } from "@/lib/schemas/guildReward";
import { infiniteQueryOptions, queryOptions } from "@tanstack/react-query";
-export const leaderboardOptions = ({ rewardId }: { rewardId: string }) => {
+export const leaderboardOptions = ({
+ rewardId,
+ userId,
+}: { rewardId: string; userId?: string }) => {
return infiniteQueryOptions({
queryKey: ["leaderboard", rewardId],
queryFn: ({ pageParam }) =>
- fetchLeaderboard({ rewardId, offset: pageParam }),
+ fetchLeaderboard({ rewardId, userId, offset: pageParam }),
initialPageParam: 1,
enabled: rewardId !== undefined,
getNextPageParam: (lastPage) =>
diff --git a/src/app/(dashboard)/explorer/fetchers.ts b/src/app/(dashboard)/explorer/fetchers.ts
index 335db2db96..af0956bd31 100644
--- a/src/app/(dashboard)/explorer/fetchers.ts
+++ b/src/app/(dashboard)/explorer/fetchers.ts
@@ -24,10 +24,11 @@ export const fetchGuildSearch = async ({
export const fetchLeaderboard = async ({
rewardId,
+ userId,
offset = 0,
-}: { rewardId: string; offset?: number }) => {
- console.log("fetching leaderboard", `reward/${rewardId}/leaderboard`);
+}: { rewardId: string; userId?: string; offset?: number }) => {
return fetchGuildApiData<
Leaderboard & { total: number; offset: number; limit: number }
- >(`reward/${rewardId}/leaderboard`); // TODO: use the offset param
+ >(`reward/${rewardId}/leaderboard?userId=${userId}
+`); // TODO: use the offset param
};
diff --git a/src/lib/schemas/leaderboard.ts b/src/lib/schemas/leaderboard.ts
index 822bc523e7..8fd35b00d1 100644
--- a/src/lib/schemas/leaderboard.ts
+++ b/src/lib/schemas/leaderboard.ts
@@ -4,11 +4,16 @@ const LeaderboardUserSchema = z.object({
userId: z.string().uuid(),
amount: z.number(),
rank: z.number(),
+ // TODO: use the user identity schema here
+ primaryIdentity: z.object({
+ identityId: z.string().uuid(),
+ foreignId: z.string(),
+ }),
});
const LeaderboardSchema = z.object({
leaderboard: z.array(LeaderboardUserSchema.omit({ rank: true })),
- user: LeaderboardUserSchema,
+ user: LeaderboardUserSchema.optional(),
});
export type Leaderboard = z.infer;