Skip to content

Commit

Permalink
Merge pull request #1755 from dubinc/fix/link-duplication
Browse files Browse the repository at this point in the history
Fix duplicate link URL not being updated
  • Loading branch information
steven-tey authored Nov 27, 2024
2 parents 51e9a94 + 3e936e9 commit 907fedf
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion apps/web/ui/links/destination-url-input.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
"use client";

import { DomainProps } from "@/lib/types";
import { InfoTooltip, SimpleTooltipContent, useMediaQuery } from "@dub/ui";
import {
InfoTooltip,
SimpleTooltipContent,
useMediaQuery,
UTM_PARAMETERS,
} from "@dub/ui";
import { getParamsFromURL } from "@dub/utils";
import { forwardRef, HTMLProps, ReactNode, useId } from "react";
import { useFormContext } from "react-hook-form";
import { LinkFormData } from "../modals/link-builder";
import { AlertCircleFill } from "../shared/icons";
import { ProBadgeTooltip } from "../shared/pro-badge-tooltip";

Expand Down Expand Up @@ -32,6 +40,8 @@ export const DestinationUrlInput = forwardRef<
const inputId = useId();
const { isMobile } = useMediaQuery();

const { setValue: setValueParent } = useFormContext<LinkFormData>();

return (
<div>
<div className="flex items-center justify-between">
Expand Down Expand Up @@ -84,6 +94,18 @@ export const DestinationUrlInput = forwardRef<
} block w-full rounded-md focus:outline-none sm:text-sm`}
aria-invalid="true"
{...inputProps}
onChange={(e) => {
const url = e.target.value;

setValueParent("url", url);
const parentParams = getParamsFromURL(url);

UTM_PARAMETERS.filter((p) => p.key !== "ref").forEach((p) =>
setValueParent(p.key as any, parentParams?.[p.key], {
shouldDirty: true,
}),
);
}}
/>
{error && (
<div className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
Expand Down

0 comments on commit 907fedf

Please sign in to comment.