Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

update use link filters

Steven Tey407511899b29
diff --git a/apps/web/app/api/admin/links/count/route.ts b/apps/web/app/api/admin/links/count/route.ts
index 1fe6f512ac..76bc7ad6e0 100644
--- a/apps/web/app/api/admin/links/count/route.ts
+++ b/apps/web/app/api/admin/links/count/route.ts
@@ -6,7 +6,7 @@ import { NextResponse } from "next/server";
// GET /api/admin/links/count
export const GET = withAdmin(async ({ searchParams }) => {
let { groupBy, search, domain, tagId } = searchParams as {
- groupBy?: "domain" | "tagId";
+ groupBy?: "domain" | "tagId" | "userId";
search?: string;
domain?: string;
tagId?: string;
@@ -30,7 +30,7 @@ export const GET = withAdmin(async ({ searchParams }) => {
...(search && {
OR: [
{
- key: { contains: search },
+ shortLink: { contains: search },
},
{
url: { contains: search },
@@ -66,7 +66,7 @@ export const GET = withAdmin(async ({ searchParams }) => {
}),
};
- if (groupBy === "domain") {
+ if (groupBy) {
response = await prisma.link.groupBy({
by: [groupBy],
where,
@@ -76,6 +76,7 @@ export const GET = withAdmin(async ({ searchParams }) => {
[groupBy]: "desc",
},
},
+ take: 500,
});
} else {
response = await prisma.link.count({
diff --git a/apps/web/ui/links/use-link-filters.tsx b/apps/web/ui/links/use-link-filters.tsx
index a920c2d90b..4b8881092a 100644
--- a/apps/web/ui/links/use-link-filters.tsx
+++ b/apps/web/ui/links/use-link-filters.tsx
@@ -74,6 +74,7 @@ export function useLinkFilters() {
icon: User,
label: "Creator",
options:
+ // @ts-expect-error
users?.map(({ id, name, email, image, count }) => ({
value: id,
label: name || email,
@@ -260,12 +261,21 @@ function useUserFilterOptions() {
return useMemo(
() =>
users
- ?.map((user) => ({
- ...user,
- count:
- usersCount?.find(({ userId }) => userId === user.id)?._count || 0,
- }))
- .sort((a, b) => b.count - a.count) ?? null,
+ ? users
+ .map((user) => ({
+ ...user,
+ count:
+ usersCount?.find(({ userId }) => userId === user.id)?._count ||
+ 0,
+ }))
+ .sort((a, b) => b.count - a.count)
+ : usersCount
+ ? usersCount.map(({ userId, _count }) => ({
+ id: userId,
+ name: userId,
+ count: _count,
+ }))
+ : null,
[users, usersCount],
);
}