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.

LinkWithTags → ExpandedLink

Steven Teyc2d9ba822249
diff --git a/apps/web/lib/api/links/bulk-create-links.ts b/apps/web/lib/api/links/bulk-create-links.ts
index 549eb88dc6..c2ad164052 100644
--- a/apps/web/lib/api/links/bulk-create-links.ts
+++ b/apps/web/lib/api/links/bulk-create-links.ts
@@ -14,7 +14,7 @@ import {
checkIfLinksHaveTags,
checkIfLinksHaveWebhooks,
combineTagIds,
- LinkWithTags,
+ ExpandedLink,
transformLink,
} from "./utils";
@@ -28,7 +28,7 @@ export async function bulkCreateLinks({
const hasTags = checkIfLinksHaveTags(links);
const hasWebhooks = checkIfLinksHaveWebhooks(links);
- let createdLinks: LinkWithTags[] = [];
+ let createdLinks: ExpandedLink[] = [];
if (hasTags || hasWebhooks) {
// create links via Promise.all (because createMany doesn't return the created links)
diff --git a/apps/web/lib/api/links/propagate-bulk-link-changes.ts b/apps/web/lib/api/links/propagate-bulk-link-changes.ts
index 4721df8d56..c5f9479bc4 100644
--- a/apps/web/lib/api/links/propagate-bulk-link-changes.ts
+++ b/apps/web/lib/api/links/propagate-bulk-link-changes.ts
@@ -1,9 +1,9 @@
import { recordLink } from "@/lib/tinybird";
import { RedisLinkProps } from "@/lib/types";
import { formatRedisLink, redis } from "@/lib/upstash";
-import { LinkWithTags } from "./utils";
+import { ExpandedLink } from "./utils";
-export async function propagateBulkLinkChanges(links: LinkWithTags[]) {
+export async function propagateBulkLinkChanges(links: ExpandedLink[]) {
const pipeline = redis.pipeline();
// split links into domains for better write effeciency in Redis
diff --git a/apps/web/lib/api/links/utils/transform-link.ts b/apps/web/lib/api/links/utils/transform-link.ts
index 3c5f6aaf2b..a7cb981a4c 100644
--- a/apps/web/lib/api/links/utils/transform-link.ts
+++ b/apps/web/lib/api/links/utils/transform-link.ts
@@ -1,13 +1,13 @@
import { Dashboard, Link, Tag } from "@prisma/client";
-export type LinkWithTags = Link & {
+export type ExpandedLink = Link & {
tags?: { tag: Pick<Tag, "id" | "name" | "color"> }[];
webhooks?: { webhookId: string }[];
dashboard?: Dashboard | null;
};
// Transform link with additional properties
-export const transformLink = (link: LinkWithTags) => {
+export const transformLink = (link: ExpandedLink) => {
const tags = (link.tags || []).map(({ tag }) => tag);
const webhookIds = link.webhooks?.map(({ webhookId }) => webhookId) ?? [];
diff --git a/apps/web/lib/swr/use-links.ts b/apps/web/lib/swr/use-links.ts
index fb5c938ac7..9a02052d7d 100644
--- a/apps/web/lib/swr/use-links.ts
+++ b/apps/web/lib/swr/use-links.ts
@@ -3,7 +3,7 @@ import { fetcher } from "@dub/utils";
import { useEffect, useState } from "react";
import useSWR, { SWRConfiguration } from "swr";
import { z } from "zod";
-import { LinkWithTagsProps, UserProps } from "../types";
+import { ExpandedLinkProps, UserProps } from "../types";
import { getLinksQuerySchemaExtended } from "../zod/schemas/links";
import useWorkspace from "./use-workspace";
@@ -24,7 +24,7 @@ export default function useLinks(
}, []);
const { data: links, isValidating } = useSWR<
- (LinkWithTagsProps & {
+ (ExpandedLinkProps & {
user: UserProps;
})[]
>(
diff --git a/apps/web/lib/tinybird/record-click.ts b/apps/web/lib/tinybird/record-click.ts
index 8562e5bbf8..bd56bfd2df 100644
--- a/apps/web/lib/tinybird/record-click.ts
+++ b/apps/web/lib/tinybird/record-click.ts
@@ -7,7 +7,7 @@ import {
import { EU_COUNTRY_CODES } from "@dub/utils/src/constants/countries";
import { geolocation, ipAddress } from "@vercel/functions";
import { userAgent } from "next/server";
-import { LinkWithTags, transformLink } from "../api/links/utils/transform-link";
+import { ExpandedLink, transformLink } from "../api/links/utils/transform-link";
import {
detectBot,
detectQr,
@@ -170,7 +170,7 @@ export async function recordClick({
// @ts-ignore – bot & qr should be boolean
data: transformClickEventData({
...clickData,
- link: transformLink(link as LinkWithTags),
+ link: transformLink(link as ExpandedLink),
}),
});
}
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index c6c66f756e..edcc38c944 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -19,7 +19,7 @@ import {
export type LinkProps = Link;
-export interface LinkWithTagsProps extends LinkProps {
+export interface ExpandedLinkProps extends LinkProps {
tags: TagProps[];
webhookIds: string[];
dashboardId: string | null;
diff --git a/apps/web/lib/webhook/transform.ts b/apps/web/lib/webhook/transform.ts
index 0713b26a17..1f97fea056 100644
--- a/apps/web/lib/webhook/transform.ts
+++ b/apps/web/lib/webhook/transform.ts
@@ -4,7 +4,7 @@ import {
} from "@/lib/webhook/schemas";
import { nanoid, toCamelCase } from "@dub/utils";
import type { Webhook } from "@prisma/client";
-import { LinkWithTags, transformLink } from "../api/links/utils/transform-link";
+import { ExpandedLink, transformLink } from "../api/links/utils/transform-link";
import { WebhookTrigger } from "../types";
import z from "../zod";
import { clickEventSchema, clickEventSchemaTB } from "../zod/schemas/clicks";
@@ -66,7 +66,7 @@ export const transformLeadEventData = (data: any) => {
id: lead.clickId,
},
// transformLink -> add shortLink, qrCode, workspaceId, etc.
- link: transformLink(lead.link as LinkWithTags),
+ link: transformLink(lead.link as ExpandedLink),
});
};
@@ -96,7 +96,7 @@ export const transformSaleEventData = (data: any) => {
bot: sale.bot === 1,
},
// transformLink -> add shortLink, qrCode, workspaceId, etc.
- link: transformLink(sale.link as LinkWithTags),
+ link: transformLink(sale.link as ExpandedLink),
});
};
diff --git a/apps/web/ui/links/links-container.tsx b/apps/web/ui/links/links-container.tsx
index 95d80c258b..29bc5b37d8 100644
--- a/apps/web/ui/links/links-container.tsx
+++ b/apps/web/ui/links/links-container.tsx
@@ -2,7 +2,7 @@
import useLinks from "@/lib/swr/use-links";
import useLinksCount from "@/lib/swr/use-links-count";
-import { LinkWithTagsProps, UserProps } from "@/lib/types";
+import { ExpandedLinkProps, UserProps } from "@/lib/types";
import { PaginationControls } from "@dub/blocks/src/pagination-controls";
import { CardList, MaxWidthWrapper, usePagination } from "@dub/ui";
import { CursorRays, Hyperlink, LoadingSpinner } from "@dub/ui/src/icons";
@@ -22,7 +22,7 @@ import LinkCardPlaceholder from "./link-card-placeholder";
import LinkNotFound from "./link-not-found";
import { LinksDisplayContext } from "./links-display-provider";
-export type ResponseLink = LinkWithTagsProps & {
+export type ResponseLink = ExpandedLinkProps & {
user: UserProps;
};
diff --git a/apps/web/ui/modals/link-builder/constants.ts b/apps/web/ui/modals/link-builder/constants.ts
index c7e8d2364f..e9bf318413 100644
--- a/apps/web/ui/modals/link-builder/constants.ts
+++ b/apps/web/ui/modals/link-builder/constants.ts
@@ -1,4 +1,4 @@
-import { LinkWithTagsProps } from "@/lib/types";
+import { ExpandedLinkProps } from "@/lib/types";
import {
CircleHalfDottedClock,
Crosshairs3,
@@ -58,7 +58,7 @@ export const MOBILE_MORE_ITEMS = [
learnMoreUrl: "https://dub.co/help/article/password-protected-links",
shortcutKey: "l",
enabled: (data: LinkFormData) => Boolean(data.password),
- remove: (setValue: UseFormSetValue<LinkWithTagsProps>) =>
+ remove: (setValue: UseFormSetValue<ExpandedLinkProps>) =>
setValue("password", null, { shouldDirty: true }),
type: "modal",
},
@@ -72,7 +72,7 @@ export const MOBILE_MORE_ITEMS = [
learnMoreUrl: "https://dub.co/help/article/link-expiration",
shortcutKey: "e",
enabled: (data: LinkFormData) => Boolean(data.expiresAt),
- remove: (setValue: UseFormSetValue<LinkWithTagsProps>) => {
+ remove: (setValue: UseFormSetValue<ExpandedLinkProps>) => {
setValue("expiresAt", null, { shouldDirty: true });
setValue("expiredUrl", null, { shouldDirty: true });
},
@@ -91,7 +91,7 @@ export const MOBILE_MORE_ITEMS = [
Boolean(
data.ios || data.android || Object.keys(data.geo || {}).length > 0,
),
- remove: (setValue: UseFormSetValue<LinkWithTagsProps>) => {
+ remove: (setValue: UseFormSetValue<ExpandedLinkProps>) => {
setValue("ios", null, { shouldDirty: true });
setValue("android", null, { shouldDirty: true });
setValue("geo", null, { shouldDirty: true });
diff --git a/apps/web/ui/modals/link-builder/draft-controls.tsx b/apps/web/ui/modals/link-builder/draft-controls.tsx
index d5f5f07c36..0d317f4c26 100644
--- a/apps/web/ui/modals/link-builder/draft-controls.tsx
+++ b/apps/web/ui/modals/link-builder/draft-controls.tsx
@@ -1,4 +1,4 @@
-import { LinkWithTagsProps } from "@/lib/types";
+import { ExpandedLinkProps } from "@/lib/types";
import { AnimatedSizeContainer, Button, Popover, useMediaQuery } from "@dub/ui";
import {
CircleCheck,
@@ -28,7 +28,7 @@ export type DraftControlsHandle = {
};
type DraftControlsProps = {
- props?: LinkWithTagsProps;
+ props?: ExpandedLinkProps;
workspaceId: string;
};
diff --git a/apps/web/ui/modals/link-builder/index.tsx b/apps/web/ui/modals/link-builder/index.tsx
index 69ff9cb528..009f5702a8 100644
--- a/apps/web/ui/modals/link-builder/index.tsx
+++ b/apps/web/ui/modals/link-builder/index.tsx
@@ -1,7 +1,7 @@
"use client";
import useWorkspace from "@/lib/swr/use-workspace";
-import { LinkWithTagsProps } from "@/lib/types";
+import { ExpandedLinkProps } from "@/lib/types";
import { DestinationUrlInput } from "@/ui/links/destination-url-input";
import { ShortLinkInput } from "@/ui/links/short-link-input";
import { useAvailableDomains } from "@/ui/links/use-available-domains";
@@ -73,13 +73,13 @@ export const LinkModalContext = createContext<{
generatingMetatags: boolean;
}>({ generatingMetatags: false });
-export type LinkFormData = LinkWithTagsProps;
+export type LinkFormData = ExpandedLinkProps;
type LinkBuilderProps = {
showLinkBuilder: boolean;
setShowLinkBuilder: Dispatch<SetStateAction<boolean>>;
- props?: LinkWithTagsProps;
- duplicateProps?: LinkWithTagsProps;
+ props?: ExpandedLinkProps;
+ duplicateProps?: ExpandedLinkProps;
homepageDemo?: boolean;
};
@@ -594,8 +594,8 @@ export function useLinkBuilder({
duplicateProps,
homepageDemo,
}: {
- props?: LinkWithTagsProps;
- duplicateProps?: LinkWithTagsProps;
+ props?: ExpandedLinkProps;
+ duplicateProps?: ExpandedLinkProps;
homepageDemo?: boolean;
} = {}) {
const [showLinkBuilder, setShowLinkBuilder] = useState(false);