The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add permanent retention toggle to UI
Tim Wilson51f585d0059b
diff --git a/apps/web/lib/swr/use-domains.ts b/apps/web/lib/swr/use-domains.tsindex 8fb68cc72e..1320aad0ce 100644--- a/apps/web/lib/swr/use-domains.ts+++ b/apps/web/lib/swr/use-domains.ts@@ -22,7 +22,9 @@ export default function useDomains({const { id: workspaceId } = useWorkspace();const { getQueryString } = useRouterStuff();- const { data, error, mutate } = useSWR<DomainProps[]>(+ const { data, error, mutate } = useSWR<+ (DomainProps & { linkRetentionDays?: number })[]+ >(workspaceId &&`/api/domains${ignoreParamsdiff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.tsindex ba9162cdba..8d94f4e0fe 100644--- a/apps/web/lib/zod/schemas/links.ts+++ b/apps/web/lib/zod/schemas/links.ts@@ -454,6 +454,12 @@ export const createLinkBodySchema = z.object({.string().nullish().describe("The date and time when the tests were or will be completed."),+ linkRetentionCleanupDisabledAt: z+ .string()+ .nullish()+ .describe(+ "For domains that have link retention settings enabled, the date and time when the retention cleanup was disabled for this link.",+ ),});export const createLinkBodySchemaAsync = createLinkBodySchema.extend({diff --git a/apps/web/scripts/delete-old-links.ts b/apps/web/scripts/delete-old-links.tsdeleted file mode 100644index a80fdee529..0000000000--- a/apps/web/scripts/delete-old-links.ts+++ /dev/null@@ -1,49 +0,0 @@-import { prisma } from "@dub/prisma";-import "dotenv-flow/config";-import { recordLinkTB, transformLinkTB } from "../lib/tinybird";--async function main() {- const domain = await prisma.domain.findUniqueOrThrow({- where: {- slug: "sms.domain.com",- },- });-- if (domain["linkRetentionDays"]) {- const links = await prisma.link.findMany({- where: {- domain: "sms.domain.com",- createdAt: {- // 90 days ago- lt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 90),- },- },- orderBy: {- createdAt: "asc",- },- take: 500,- });-- await Promise.all([- // Record the links deletion in Tinybird- // not 100% sure if we need this yet, maybe we should just delete the link completely from TB to save space?- recordLinkTB(- links.map((link) => ({- ...transformLinkTB(link),- deleted: true,- })),- ),- prisma.link.deleteMany({- where: {- id: {- in: links.map((link) => link.id),- },- },- }),- ]);-- console.table(links);- }-}--main();diff --git a/apps/web/ui/links/link-builder/constants.ts b/apps/web/ui/links/link-builder/constants.tsindex 86698f761e..e8461554a3 100644--- a/apps/web/ui/links/link-builder/constants.ts+++ b/apps/web/ui/links/link-builder/constants.ts@@ -9,10 +9,12 @@ import {Flask,Icon,Incognito,+ InfinityIcon,InputPassword,WindowSearch,} from "@dub/ui/icons";import { Settings, User2 } from "lucide-react";+import { UseFormSetValue } from "react-hook-form";type MoreItem = {key: string;@@ -24,6 +26,8 @@ type MoreItem = {type: string;badgeLabel?: (data: LinkFormData) => string;enabled?: (data: LinkFormData) => boolean;+ enable?: (setValue: UseFormSetValue<LinkFormData>) => void;+ remove?: (setValue: UseFormSetValue<LinkFormData>) => void;add?: boolean;};@@ -48,6 +52,21 @@ export const MORE_ITEMS: MoreItem[] = [shortcutKey: "s",type: "boolean",},+ {+ key: "linkRetentionCleanupDisabledAt",+ icon: InfinityIcon,+ label: "Permanent Retention",+ description: "Exclude this link from link retention settings.",+ shortcutKey: "r",+ type: "boolean",+ enabled: (data) => Boolean(data.linkRetentionCleanupDisabledAt),+ enable: (setValue) =>+ setValue("linkRetentionCleanupDisabledAt", new Date(), {+ shouldDirty: true,+ }),+ remove: (setValue) =>+ setValue("linkRetentionCleanupDisabledAt", null, { shouldDirty: true }),+ },{key: "partnerId",icon: User2,diff --git a/apps/web/ui/links/link-builder/more-dropdown.tsx b/apps/web/ui/links/link-builder/more-dropdown.tsxindex c4e8a40d21..2eb8575151 100644--- a/apps/web/ui/links/link-builder/more-dropdown.tsx+++ b/apps/web/ui/links/link-builder/more-dropdown.tsx@@ -1,3 +1,4 @@+import useDomains from "@/lib/swr/use-domains";import useWorkspace from "@/lib/swr/use-workspace";import { useABTestingModal } from "@/ui/modals/link-builder/ab-testing-modal";import { useAdvancedModal } from "@/ui/modals/link-builder/advanced-modal";@@ -23,15 +24,23 @@ export function MoreDropdown() {const data = watch();+ const { allWorkspaceDomains } = useDomains();+const options = useMemo(() => {return [...(isMobile ? MOBILE_MORE_ITEMS : []), ...MORE_ITEMS].filter((option) => {if (option.key === "testVariants") return flags?.abTesting;if (option.key === "partnerId") return Boolean(defaultProgramId);+ if (option.key === "linkRetentionCleanupDisabledAt")+ return Boolean(+ allWorkspaceDomains.find((d) => d.slug === data.domain)+ ?.linkRetentionDays,+ );+return true;},);- }, [data, isMobile, flags, defaultProgramId]);+ }, [data, isMobile, flags, defaultProgramId, allWorkspaceDomains]);const { ABTestingModal, setShowABTestingModal } = useABTestingModal();const { PasswordModal, setShowPasswordModal } = usePasswordModal();@@ -55,8 +64,15 @@ export function MoreDropdown() {const option = options.find(({ shortcutKey }) => shortcutKey === e.key);if (!option) return;+ const enabled =+ "enabled" in option && typeof option.enabled === "function"+ ? option.enabled(data)+ : data[option.key];+setOpenPopover(false);if (option.type === "modal") modalCallbacks[option.key]?.(true);+ else if (enabled && option.remove) option.remove(setValue);+ else if (enabled && option.enable) option.enable(setValue);elsesetValue(option.key as any, !data[option.key], { shouldDirty: true });},@@ -89,9 +105,11 @@ export function MoreDropdown() {onClick={() => {setOpenPopover(false);- if (option.type === "modal") {+ if (option.type === "modal")modalCallbacks[option.key]?.(true);- } else+ else if (enabled && option.remove) option.remove(setValue);+ else if (!enabled && option.enable) option.enable(setValue);+ elsesetValue(option.key as any, !enabled, {shouldDirty: true,});diff --git a/apps/web/ui/links/link-builder/options-list.tsx b/apps/web/ui/links/link-builder/options-list.tsxindex 0ba9928cfa..42b2043266 100644--- a/apps/web/ui/links/link-builder/options-list.tsx+++ b/apps/web/ui/links/link-builder/options-list.tsx@@ -22,7 +22,11 @@ export function OptionsList() {const data = useWatch({ control });const enabledToggles = useMemo(- () => TOGGLES.filter(({ key }) => data[key]),+ () =>+ TOGGLES.filter(({ key, enabled }) =>+ // @ts-ignore - useWatch returns a deep partial, should be fixed in a future react-hook-form release+ enabled ? enabled(data) : data[key],+ ),[data],);@@ -58,8 +62,7 @@ export function OptionsList() {><Componenttoggle={item}- {...(item.type === "modal" &&- "enabled" in item &&+ {...("enabled" in item &&typeof item.enabled === "function" &&// @ts-ignore - useWatch returns a deep partial, should be fixed in a future react-hook-form releaseitem.enabled(data) && {diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.tsindex fc8163acc3..fa8ec80693 100644--- a/packages/ui/src/icons/nucleo/index.ts+++ b/packages/ui/src/icons/nucleo/index.ts@@ -128,6 +128,7 @@ export * from "./history";export * from "./hyperlink";export * from "./icosahedron";export * from "./incognito";+export * from "./infinity-icon";export * from "./input-field";export * from "./input-password";export * from "./input-password-pointer";diff --git a/packages/ui/src/icons/nucleo/infinity-icon.tsx b/packages/ui/src/icons/nucleo/infinity-icon.tsxnew file mode 100644index 0000000000..f1c8138e55--- /dev/null+++ b/packages/ui/src/icons/nucleo/infinity-icon.tsx@@ -0,0 +1,24 @@+import { SVGProps } from "react";++export function InfinityIcon(props: SVGProps<SVGSVGElement>) {+ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ {...props}+ >+ <g fill="currentColor">+ <path+ d="m7.2831,7.1659c-.8935-.8252-1.8429-1.4159-2.9331-1.4159-1.7122,0-3.1,1.4549-3.1,3.25s1.3878,3.25,3.1,3.25c3.6167,0,5.6833-6.5,9.3-6.5,1.7122,0,3.1,1.4549,3.1,3.25s-1.3878,3.25-3.1,3.25c-1.0903,0-2.0397-.5907-2.9332-1.416"+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ </g>+ </svg>+ );+}