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.

return the webhooks with links info

Kiran Kea1a2d43c3c6
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.ts
index 1bacf840d9..f750a4a17b 100644
--- a/apps/web/app/api/links/[linkId]/route.ts
+++ b/apps/web/app/api/links/[linkId]/route.ts
@@ -24,26 +24,46 @@ export const GET = withWorkspace(
linkId: params.linkId,
});
- const tags = await prisma.tag.findMany({
- where: {
- links: {
- some: {
- linkId: link.id,
+ const [tags, webhooks] = await Promise.all([
+ prisma.tag.findMany({
+ where: {
+ links: {
+ some: {
+ linkId: link.id,
+ },
},
},
- },
- select: {
- id: true,
- name: true,
- color: true,
- },
- });
+ select: {
+ id: true,
+ name: true,
+ color: true,
+ },
+ }),
+
+ prisma.webhook.findMany({
+ where: {
+ links: {
+ some: {
+ linkId: link.id,
+ },
+ },
+ },
+ select: {
+ id: true,
+ name: true,
+ url: true,
+ },
+ }),
+ ]);
const response = transformLink({
...link,
tags: tags.map((tag) => {
return { tag };
}),
+ webhooks: webhooks.map((webhook) => {
+ return { webhook };
+ }),
});
return NextResponse.json(response, { headers });
diff --git a/apps/web/lib/api/links/get-links-for-workspace.ts b/apps/web/lib/api/links/get-links-for-workspace.ts
index 726ea42561..d620df2cc4 100644
--- a/apps/web/lib/api/links/get-links-for-workspace.ts
+++ b/apps/web/lib/api/links/get-links-for-workspace.ts
@@ -76,6 +76,17 @@ export async function getLinksForWorkspace({
},
},
},
+ webhooks: {
+ select: {
+ webhook: {
+ select: {
+ id: true,
+ name: true,
+ url: true,
+ },
+ },
+ },
+ },
},
orderBy: {
[sort]: "desc",
diff --git a/apps/web/lib/api/links/utils/transform-link.ts b/apps/web/lib/api/links/utils/transform-link.ts
index 950d5819d6..530cf4f91c 100644
--- a/apps/web/lib/api/links/utils/transform-link.ts
+++ b/apps/web/lib/api/links/utils/transform-link.ts
@@ -1,17 +1,20 @@
-import { Link, Tag } from "@prisma/client";
+import { Link, Tag, Webhook } from "@prisma/client";
export type LinkWithTags = Link & {
tags?: { tag: Pick<Tag, "id" | "name" | "color"> }[];
+ webhooks?: { webhook: Pick<Webhook, "id" | "name" | "url"> }[];
};
// Transform link with additional properties
export const transformLink = (link: LinkWithTags) => {
const tags = (link.tags || []).map(({ tag }) => tag);
+ const webhooks = (link.webhooks || []).map(({ webhook }) => webhook);
return {
...link,
tagId: tags?.[0]?.id ?? null, // backwards compatibility
tags,
+ webhooks,
qrCode: `https://api.dub.co/qr?url=${link.shortLink}?qr=1`,
workspaceId: link.projectId ? `ws_${link.projectId}` : null,
};
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 75c5dc638a..fed962e147 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -20,6 +20,8 @@ export type LinkProps = Link;
export interface LinkWithTagsProps extends LinkProps {
tags: TagProps[];
+ webhooks: WebhookProps;
+ webhookIds: string[];
}
export interface SimpleLinkProps {
diff --git a/apps/web/ui/modals/link-builder/index.tsx b/apps/web/ui/modals/link-builder/index.tsx
index f2adb32909..ae0dfa3f43 100644
--- a/apps/web/ui/modals/link-builder/index.tsx
+++ b/apps/web/ui/modals/link-builder/index.tsx
@@ -70,9 +70,7 @@ export const LinkModalContext = createContext<{
generatingMetatags: boolean;
}>({ generatingMetatags: false });
-export type LinkFormData = LinkWithTagsProps & {
- webhookIds?: string[];
-};
+export type LinkFormData = LinkWithTagsProps;
type LinkBuilderProps = {
showLinkBuilder: boolean;
@@ -466,8 +464,8 @@ function LinkBuilderInner({
</div>
<div className="flex items-center justify-between gap-2 border-t border-gray-100 bg-gray-50 p-4">
<div className="flex min-w-0 items-center gap-2">
- <WebhookSelect />
<UTMButton />
+ <WebhookSelect />
<div className="flex items-center gap-2 max-sm:hidden">
<ExpirationButton />
<TargetingButton />