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.

Industry interest filtering

Tim Wilson9dd59573bd38
diff --git a/apps/web/app/(ee)/api/network/partners/route.ts b/apps/web/app/(ee)/api/network/partners/route.ts
index cb8170bfb7..32dea73e81 100644
--- a/apps/web/app/(ee)/api/network/partners/route.ts
+++ b/apps/web/app/(ee)/api/network/partners/route.ts
@@ -14,7 +14,7 @@ import { z } from "zod";
export const GET = withWorkspace(
async ({ workspace, searchParams }) => {
const programId = getDefaultProgramIdOrThrow(workspace);
- const { status, page, pageSize, country, starred } =
+ const { status, page, pageSize, country, starred, industryInterests } =
getPartnerNetworkPartnersQuerySchema.parse(searchParams);
const partners = (await prisma.$queryRaw`
@@ -73,6 +73,7 @@ export const GET = withWorkspace(
}
${starred === true ? Prisma.sql`AND dp.starredAt IS NOT NULL` : Prisma.sql``}
${starred === false ? Prisma.sql`AND dp.starredAt IS NULL` : Prisma.sql``}
+ ${industryInterests && industryInterests.length > 0 ? Prisma.sql`AND EXISTS (SELECT 1 FROM PartnerIndustryInterest WHERE partnerId = p.id AND industryInterest IN (${Prisma.join(industryInterests)}))` : Prisma.sql``}
-- Ordering
${starred === true ? Prisma.sql`ORDER BY dp.starredAt DESC` : Prisma.sql``}
LIMIT ${pageSize} OFFSET ${(page - 1) * pageSize}`) satisfies Array<any>;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/directory/use-partner-network-filters.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/directory/use-partner-network-filters.tsx
index e30448d7e8..9fddeabc6f 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/directory/use-partner-network-filters.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/directory/use-partner-network-filters.tsx
@@ -97,10 +97,28 @@ export function usePartnerNetworkFilters({
del: "page",
});
- const onRemove = (key: string, value: any) =>
- queryParams({
- del: [key, "page"],
- });
+ const onRemove = (key: string, value: any) => {
+ if (
+ key === "industryInterests" &&
+ !(
+ selectedIndustryInterests.length === 1 &&
+ selectedIndustryInterests[0] === value
+ )
+ ) {
+ queryParams({
+ set: {
+ industryInterests: selectedIndustryInterests
+ .filter((id) => id !== value)
+ .join(","),
+ },
+ del: "page",
+ });
+ } else {
+ queryParams({
+ del: [key, "page"],
+ });
+ }
+ };
const onRemoveAll = () =>
queryParams({
diff --git a/apps/web/lib/zod/schemas/partner-network.ts b/apps/web/lib/zod/schemas/partner-network.ts
index 0ea184d404..98b738017d 100644
--- a/apps/web/lib/zod/schemas/partner-network.ts
+++ b/apps/web/lib/zod/schemas/partner-network.ts
@@ -37,7 +37,16 @@ export const getPartnerNetworkPartnersQuerySchema = z
status: partnerNetworkPartnersStatusSchema.default("discover"),
country: z.string().optional(),
starred: booleanQuerySchema.nullish(),
- industryInterests: z.array(z.nativeEnum(IndustryInterest)).optional(),
+ industryInterests: z
+ .preprocess(
+ (v) => (typeof v === "string" ? v.split(",") : v),
+ z.array(z.nativeEnum(IndustryInterest)),
+ )
+ .optional(),
+ tagIds: z
+ .union([z.string(), z.array(z.string())])
+ .transform((v) => (Array.isArray(v) ? v : v.split(",")))
+ .optional(),
})
.merge(
getPaginationQuerySchema({