The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
onPaste shouldDirty, validatePartnerLinkUrl only if not default link
Steven Teyb515d37c3b6b
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/[linkId]/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/[linkId]/route.tsindex d2a52de9f4..f8274e4ac8 100644--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/[linkId]/route.ts+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/[linkId]/route.ts@@ -8,6 +8,7 @@ import { withPartnerProfile } from "@/lib/auth/partner";import { NewLinkProps } from "@/lib/types";import { createPartnerLinkSchema } from "@/lib/zod/schemas/partners";import { prisma } from "@dub/prisma";+import { getPrettyUrl } from "@dub/utils";import { NextResponse } from "next/server";// PATCH /api/partner-profile/[programId]/links/[linkId] - update a link for a partner@@ -60,7 +61,7 @@ export const PATCH = withPartnerProfile(}if (link.partnerGroupDefaultLinkId) {- const linkUrlChanged = link.url !== url;+ const linkUrlChanged = getPrettyUrl(link.url) !== getPrettyUrl(url);if (linkUrlChanged) {throw new DubApiError({@@ -69,10 +70,10 @@ export const PATCH = withPartnerProfile("You cannot update the destination URL of your default link.",});}+ } else {+ validatePartnerLinkUrl({ group, url });}- validatePartnerLinkUrl({ group, url });-// check if the group has a UTM templateconst groupUtmTemplate = group.utmTemplateId? await prisma.utmTemplate.findUnique({diff --git a/apps/web/ui/modals/partner-link-modal.tsx b/apps/web/ui/modals/partner-link-modal.tsxindex e7e69f441b..f6a0ab5efa 100644--- a/apps/web/ui/modals/partner-link-modal.tsx+++ b/apps/web/ui/modals/partner-link-modal.tsx@@ -209,6 +209,7 @@ function PartnerLinkModalContent({register,watch,handleSubmit,+ setValue,formState: { isDirty },} = useForm<PartnerLinkFormData>({defaultValues: link@@ -408,14 +409,18 @@ function PartnerLinkModalContent({if (isExactMode) return;e.preventDefault();- // if pasting in a URL, extract the pathname+ // if pasting in a URL, extract the pathname + query paramsconst text = e.clipboardData.getData("text/plain");+ let newValue: string;try {const url = new URL(text);- e.currentTarget.value = url.pathname.slice(1);+ newValue = url.pathname.slice(1) + url.search;} catch (err) {- e.currentTarget.value = text;+ newValue = text;}++ // Use setValue to properly dirty the form+ setValue("pathname", newValue, { shouldDirty: true });}}className={cn("z-0 block w-full rounded-r-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:z-[1] focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",