The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add expiration modal + a bunch of mobile improvements
Tim Wilsond76326519a66
diff --git a/apps/web/ui/modals/add-edit-link-modal-new/constants.ts b/apps/web/ui/modals/add-edit-link-modal-new/constants.tsnew file mode 100644index 0000000000..d7382b1e4a--- /dev/null+++ b/apps/web/ui/modals/add-edit-link-modal-new/constants.ts@@ -0,0 +1,101 @@+import { LinkWithTagsProps } from "@/lib/types";+import {+ CircleHalfDottedClock,+ Crosshairs3,+ Incognito,+ InputPassword,+ SquareChart,+ WindowSearch,+} from "@dub/ui/src/icons";+import { UseFormSetValue } from "react-hook-form";+import { LinkFormData } from ".";+import { getExpirationLabel } from "./expiration-modal";+import { getPasswordLabel } from "./password-modal";+import { getTargetingLabel } from "./targeting-modal";++export const TOGGLES = [+ {+ key: "rewrite",+ icon: Incognito,+ label: "Link Cloaking",+ description:+ "Mask your destination URL so your users only see the short link in the browser address bar.",+ learnMoreUrl: "https://dub.co/help/article/link-cloaking",+ shortcutKey: "l",+ type: "boolean",+ },+ {+ key: "trackConversion",+ icon: SquareChart,+ label: "Conversion Tracking",+ description:+ "Track conversions on your short link to measure the effectiveness of your marketing campaigns.",+ learnMoreUrl: "https://dub.co/help/article/conversion-tracking",+ shortcutKey: "c",+ conversionEnabled: true,+ type: "boolean",+ },+ {+ key: "doIndex",+ icon: WindowSearch,+ label: "Search Engine Indexing",+ description:+ "Allow search engines to index your short link. Disabled by default.",+ learnMoreUrl: "https://dub.co/help/article/how-noindex-works",+ shortcutKey: "s",+ type: "boolean",+ },+];++export const MOBILE_MORE_ITEMS = [+ {+ key: "password",+ icon: InputPassword,+ label: "Password",+ badgeLabel: getPasswordLabel,+ description:+ "Protect your links with a password so only authorized users can access them.",+ learnMoreUrl: "https://dub.co/help/article/password-protected-links",+ shortcutKey: "p",+ enabled: (data: LinkFormData) => Boolean(data.password),+ remove: (setValue: UseFormSetValue<LinkWithTagsProps>) =>+ setValue("password", null),+ type: "modal",+ },+ {+ key: "expiresAt",+ icon: CircleHalfDottedClock,+ label: "Link Expiration",+ badgeLabel: getExpirationLabel,+ description:+ "Set an expiration date for your links – after which it won't be accessible.",+ learnMoreUrl: "https://dub.co/help/article/link-expiration",+ shortcutKey: "e",+ enabled: (data: LinkFormData) => Boolean(data.expiresAt),+ remove: (setValue: UseFormSetValue<LinkWithTagsProps>) => {+ setValue("expiresAt", null);+ setValue("expiredUrl", null);+ },+ type: "modal",+ },+ {+ key: "targeting",+ icon: Crosshairs3,+ label: "Targeting",+ badgeLabel: getTargetingLabel,+ description:+ "Target your links to specific audiences based on their location, device, or browser.",+ learnMoreUrl: "https://dub.co/help/article/geo-targeting",+ shortcutKey: "T",+ enabled: (data: LinkFormData) =>+ Boolean(+ data.ios || data.android || Object.keys(data.geo || {}).length > 0,+ ),+ remove: (setValue: UseFormSetValue<LinkWithTagsProps>) => {+ setValue("ios", null);+ setValue("android", null);+ setValue("geo", null);+ },+ type: "modal",+ },+];diff --git a/apps/web/ui/modals/add-edit-link-modal-new/expiration-modal.tsx b/apps/web/ui/modals/add-edit-link-modal-new/expiration-modal.tsxindex 480b6341d9..4690b55d9d 100644--- a/apps/web/ui/modals/add-edit-link-modal-new/expiration-modal.tsx+++ b/apps/web/ui/modals/add-edit-link-modal-new/expiration-modal.tsx@@ -58,7 +58,7 @@ function ExpirationModal({},});- const [expiresAt, expiredUrl] = watch(["expiresAt", "expiredUrl"]);+ const [expiresAt] = watch(["expiresAt", "expiredUrl"]);const expiresAtParent = watchParent("expiresAt");const inputRef = useRef<HTMLInputElement>(null);@@ -68,15 +68,18 @@ function ExpirationModal({<ModalshowModal={showExpirationModal}setShowModal={setShowExpirationModal}- className="max-w-md"+ className="sm:max-w-md"><formclassName="px-5 py-4"- onSubmit={handleSubmit((data) => {- setValueParent("expiresAt", data.expiresAt);- setValueParent("expiredUrl", data.expiredUrl);- setShowExpirationModal(false);- })}+ onSubmit={(e) => {+ e.stopPropagation();+ handleSubmit((data) => {+ setValueParent("expiresAt", data.expiresAt);+ setValueParent("expiredUrl", data.expiredUrl);+ setShowExpirationModal(false);+ })(e);+ }}><div className="flex items-center justify-between"><div className="flex items-center gap-2">@@ -250,6 +253,18 @@ function ExpirationModal({);}+export function getExpirationLabel({+ expiresAt,+}: Pick<LinkFormData, "expiresAt">) {+ return expiresAt+ ? formatDate(expiresAt, {+ month: "short",+ year: undefined,+ timeZone: undefined,+ }) || "Expiration"+ : "Expiration";+}+function ExpirationButton({setShowExpirationModal,}: {@@ -265,15 +280,7 @@ function ExpirationButton({return (<Buttonvariant="secondary"- text={- expiresAt- ? formatDate(expiresAt, {- month: "short",- year: undefined,- timeZone: undefined,- }) || "Expiration"- : "Expiration"- }+ text={getExpirationLabel({ expiresAt })}icon={<CircleHalfDottedClockclassName={cn("size-4", expiresAt && "text-blue-500")}diff --git a/apps/web/ui/modals/add-edit-link-modal-new/index.tsx b/apps/web/ui/modals/add-edit-link-modal-new/index.tsxindex 48d7dbb6e6..122d0348c7 100644--- a/apps/web/ui/modals/add-edit-link-modal-new/index.tsx+++ b/apps/web/ui/modals/add-edit-link-modal-new/index.tsx@@ -49,9 +49,11 @@ import { mutate } from "swr";import { useDebounce } from "use-debounce";import { useExpirationModal } from "./expiration-modal";import { LinkPreview } from "./link-preview";+import { MoreDropdown } from "./more-dropdown";+import { OptionsList } from "./options-list";import { usePasswordModal } from "./password-modal";import { QRCodePreview } from "./qr-code-preview";-import { TogglesDropdown, TogglesList } from "./toggles";+import { useTargetingModal } from "./targeting-modal";import { useMetatags } from "./use-metatags";import { UTMBuilder } from "./utm-builder";@@ -202,11 +204,13 @@ function AddEditLinkModalInner({);const { PasswordModal, PasswordButton } = usePasswordModal();+ const { TargetingModal, TargetingButton } = useTargetingModal();const { ExpirationModal, ExpirationButton } = useExpirationModal();return (<><PasswordModal />+ <TargetingModal /><ExpirationModal /><ModalshowModal={showAddEditLinkModal}@@ -421,7 +425,7 @@ function AddEditLinkModalInner({</div><div className="flex grow flex-col justify-end">- <TogglesList />+ <OptionsList /></div></div></div>@@ -437,9 +441,12 @@ function AddEditLinkModalInner({</div><div className="flex items-center justify-between border-t border-gray-100 bg-gray-50 p-4"><div className="flex items-center gap-2">- <ExpirationButton />- <PasswordButton />- <TogglesDropdown />+ <div className="flex items-center gap-2 max-sm:hidden">+ <ExpirationButton />+ <TargetingButton />+ <PasswordButton />+ </div>+ <MoreDropdown /></div>{homepageDemo ? (<Buttondiff --git a/apps/web/ui/modals/add-edit-link-modal-new/more-dropdown.tsx b/apps/web/ui/modals/add-edit-link-modal-new/more-dropdown.tsxnew file mode 100644index 0000000000..c5552a13cc--- /dev/null+++ b/apps/web/ui/modals/add-edit-link-modal-new/more-dropdown.tsx@@ -0,0 +1,126 @@+import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";+import {+ Button,+ Popover,+ SimpleTooltipContent,+ useKeyboardShortcut,+ useMediaQuery,+} from "@dub/ui";+import { Dots } from "@dub/ui/src/icons";+import { useContext, useMemo, useState } from "react";+import { useFormContext } from "react-hook-form";+import { LinkFormData, LinkModalContext } from ".";+import { MOBILE_MORE_ITEMS, TOGGLES } from "./constants";+import { useExpirationModal } from "./expiration-modal";+import { usePasswordModal } from "./password-modal";+import { useTargetingModal } from "./targeting-modal";++export function MoreDropdown() {+ const { isMobile } = useMediaQuery();++ const { conversionEnabled } = useContext(LinkModalContext);++ const { watch, setValue } = useFormContext<LinkFormData>();+ const data = watch();++ const [openPopover, setOpenPopover] = useState(false);++ const options = useMemo(() => {+ const toggles = TOGGLES.filter((toggle) =>+ toggle.conversionEnabled ? conversionEnabled || data[toggle.key] : true,+ );++ return [...(isMobile ? MOBILE_MORE_ITEMS : []), ...toggles];+ }, [conversionEnabled, data, isMobile]);++ useKeyboardShortcut(+ options.map(({ shortcutKey }) => shortcutKey),+ (e) => {+ const option = options.find(({ shortcutKey }) => shortcutKey === e.key);+ if (!option) return;++ setOpenPopover(false);+ setValue(option.key as any, !data[option.key]);+ },+ { modal: true },+ );++ const { PasswordModal, setShowPasswordModal } = usePasswordModal();+ const { TargetingModal, setShowTargetingModal } = useTargetingModal();+ const { ExpirationModal, setShowExpirationModal } = useExpirationModal();++ return (+ <>+ <PasswordModal />+ <TargetingModal />+ <ExpirationModal />+ <Popover+ align="start"+ content={+ <div className="grid p-1 max-sm:w-full md:min-w-72">+ {options.map((option) => {+ const enabled =+ "enabled" in option ? option.enabled(data) : data[option.key];++ return (+ <Button+ type="button"+ variant="outline"+ key={option.key}+ onClick={() => {+ setOpenPopover(false);++ if (option.type === "modal") {+ ({+ password: setShowPasswordModal,+ targeting: setShowTargetingModal,+ expiresAt: setShowExpirationModal,+ })[option.key]?.(true);+ } else setValue(option.key as any, !enabled);+ }}+ className="h-9 w-full justify-start px-2 text-sm text-gray-700"+ textWrapperClassName="grow"+ text={+ <div className="flex items-center justify-between gap-2">+ <div className="flex items-center gap-1">+ <option.icon className="mr-1 size-4 text-gray-950" />+ {option.type === "modal"+ ? enabled+ ? ""+ : "Add "+ : enabled+ ? "Remove "+ : "Add "}+ {option.label}+ <ProBadgeTooltip+ content={+ <SimpleTooltipContent+ title={option.description}+ cta="Learn more."+ href={option.learnMoreUrl}+ />+ }+ />+ </div>+ <kbd className="hidden size-6 cursor-default items-center justify-center rounded-md border border-gray-200 font-sans text-xs text-gray-800 sm:flex">+ {option.shortcutKey.toUpperCase()}+ </kbd>+ </div>+ }+ />+ );+ })}+ </div>+ }+ openPopover={openPopover}+ setOpenPopover={setOpenPopover}+ >+ <Button+ variant="secondary"+ icon={<Dots className="size-4" />}+ className="h-9 px-2.5"+ />+ </Popover>+ </>+ );+}diff --git a/apps/web/ui/modals/add-edit-link-modal-new/og-modal.tsx b/apps/web/ui/modals/add-edit-link-modal-new/og-modal.tsxindex 8216c2217d..6d24e0d7f0 100644--- a/apps/web/ui/modals/add-edit-link-modal-new/og-modal.tsx+++ b/apps/web/ui/modals/add-edit-link-modal-new/og-modal.tsx@@ -58,7 +58,7 @@ function OGModalInner({setValue: setValueParent,} = useFormContext<LinkFormData>();- const { watch, setValue, getValues, reset } = useForm<+ const { watch, setValue, getValues, reset, handleSubmit } = useForm<Pick<LinkFormData, "image" | "title" | "description" | "proxy">>({defaultValues: {@@ -187,19 +187,18 @@ function OGModalInner({<ModalshowModal={showOGModal}setShowModal={setShowOGModal}- className="max-w-[500px]"+ className="sm:max-w-[500px]"><formclassName="px-5 py-4"- // For some reason using handleSubmit causes the link modal's form to submitonSubmit={(e) => {- e.preventDefault();e.stopPropagation();-- setShowOGModal(false);- (["image", "title", "description", "proxy"] as const).forEach(- (key) => setValueParent(key, getValues(key)),- );+ handleSubmit(async (data) => {+ setShowOGModal(false);+ (["image", "title", "description", "proxy"] as const).forEach(+ (key) => setValueParent(key, data[key]),+ );+ })(e);}}><div className="flex items-center justify-between">diff --git a/apps/web/ui/modals/add-edit-link-modal-new/options-list.tsx b/apps/web/ui/modals/add-edit-link-modal-new/options-list.tsxnew file mode 100644index 0000000000..1f1b28cc86--- /dev/null+++ b/apps/web/ui/modals/add-edit-link-modal-new/options-list.tsx@@ -0,0 +1,163 @@+import { AlertCircleFill, CheckCircleFill, X } from "@/ui/shared/icons";+import { Tooltip, useMediaQuery } from "@dub/ui";+import { LoadingSpinner } from "@dub/ui/src/icons";+import { fetcher, isValidUrl as isValidUrlFn } from "@dub/utils";+import { AnimatePresence, motion } from "framer-motion";+import { ReactNode, useMemo } from "react";+import { useFormContext } from "react-hook-form";+import useSWR from "swr";+import { useDebounce } from "use-debounce";+import { LinkFormData } from ".";+import { MOBILE_MORE_ITEMS, TOGGLES } from "./constants";++export function OptionsList() {+ const { isMobile } = useMediaQuery();++ const { watch, setValue } = useFormContext<LinkFormData>();+ const data = watch();++ const enabledToggles = useMemo(+ () => TOGGLES.filter(({ key }) => data[key]),+ [data],+ );++ const enabledItems = useMemo(+ () => [+ ...enabledToggles,+ ...(isMobile+ ? MOBILE_MORE_ITEMS.filter(({ enabled }) => enabled(data)).map(+ (item) => ({ ...item, label: item.badgeLabel(data) }),+ )+ : []),+ ],+ [enabledToggles, isMobile, data],+ );++ return enabledItems.length ? (+ <div className="flex flex-wrap gap-2">+ <AnimatePresence>+ {enabledItems.map((item) => {+ const Component =+ item.key === "rewrite" ? LinkCloakingToggleBadge : ToggleBadge;+ return (+ <motion.div+ key={item.key}+ initial={{ opacity: 0 }}+ animate={{ opacity: 1 }}+ transition={{ duration: 0.1 }}+ >+ <Component+ toggle={item}+ {...(item.type === "modal" &&+ "enabled" in item &&+ item.enabled(data) && {+ icon: <item.icon className="size-3.5 text-blue-500" />,+ })}+ onRemove={() =>+ "remove" in item+ ? item.remove(setValue)+ : setValue(item.key as any, false)+ }+ />+ </motion.div>+ );+ })}+ </AnimatePresence>+ </div>+ ) : null;+}++function ToggleBadge({+ toggle,+ onRemove,+ icon,+}: {+ toggle: (typeof TOGGLES)[number];+ onRemove: () => void;+ icon?: ReactNode;+}) {+ return (+ <span className="group flex cursor-default items-center gap-1.5 rounded-md border border-gray-200 bg-gray-50 pl-1.5 text-xs text-gray-600">+ {icon}+ {toggle.label}+ <button+ type="button"+ onClick={onRemove}+ className="-ml-1 p-1 text-gray-400 hover:text-gray-500"+ >+ <X className="size-3.5" />+ </button>+ </span>+ );+}++function LinkCloakingToggleBadge({+ toggle,+ onRemove,+}: {+ toggle: (typeof TOGGLES)[number];+ onRemove: () => void;+}) {+ const { watch } = useFormContext<LinkFormData>();+ const [url, domain] = watch(["url", "domain"]);+ const [debouncedUrl] = useDebounce(url, 500);+ const isValidUrl = useMemo(+ () => debouncedUrl && isValidUrlFn(debouncedUrl),+ [debouncedUrl],+ );++ const { data, isLoading } = useSWR<{ iframeable: boolean }>(+ domain && isValidUrl+ ? `/api/links/iframeable?url=${debouncedUrl}&domain=${domain}`+ : null,+ fetcher,+ );++ const badge = useMemo(+ () => (+ <ToggleBadge+ toggle={toggle}+ onRemove={onRemove}+ icon={+ isLoading ? (+ <LoadingSpinner className="size-3.5" />+ ) : !data ? null : data?.iframeable ? (+ <CheckCircleFill className="size-3.5 text-green-500" />+ ) : (+ <AlertCircleFill className="size-3.5 text-yellow-500" />+ )+ }+ />+ ),+ [data, isLoading],+ );++ return data && !data?.iframeable ? (+ <Tooltip+ content={+ <div className="block max-w-sm text-pretty px-4 py-2 text-center text-sm text-gray-700">+ We will try to cloak it with{" "}+ <a+ href="https://nextjs.org/docs/pages/api-reference/functions/next-response#rewrite"+ target="_blank"+ className="text-gray-500 underline underline-offset-2 hover:text-gray-700"+ >+ Next.js Rewrites+ </a>+ , but it might not work as expected.{" "}+ <a+ href="https://dub.co/help/article/link-cloaking"+ target="_blank"+ className="text-gray-500 underline underline-offset-2 hover:text-gray-700"+ >+ Learn more.+ </a>+ </div>+ }+ >+ <div>{badge}</div>+ </Tooltip>+ ) : (+ badge+ );+}diff --git a/apps/web/ui/modals/add-edit-link-modal-new/password-modal.tsx b/apps/web/ui/modals/add-edit-link-modal-new/password-modal.tsxindex 8af285b042..c2384f2451 100644--- a/apps/web/ui/modals/add-edit-link-modal-new/password-modal.tsx+++ b/apps/web/ui/modals/add-edit-link-modal-new/password-modal.tsx@@ -56,14 +56,17 @@ function PasswordModal({<ModalshowModal={showPasswordModal}setShowModal={setShowPasswordModal}- className="max-w-md"+ className="sm:max-w-md"><formclassName="px-5 py-4"- onSubmit={handleSubmit((data) => {- setValueParent("password", data.password);- setShowPasswordModal(false);- })}+ onSubmit={(e) => {+ e.stopPropagation();+ handleSubmit((data) => {+ setValueParent("password", data.password);+ setShowPasswordModal(false);+ })(e);+ }}><div className="flex items-center justify-between"><div className="flex items-center gap-2">@@ -183,6 +186,10 @@ function PasswordModal({);}+export function getPasswordLabel({ password }: Pick<LinkFormData, "password">) {+ return password ? "Protected" : "Password";+}+function PasswordButton({setShowPasswordModal,}: {@@ -198,7 +205,7 @@ function PasswordButton({return (<Buttonvariant="secondary"- text={password ? "Protected" : "Password"}+ text={getPasswordLabel({ password })}icon={<InputPassword className={cn("size-4", password && "text-blue-500")} />}diff --git a/apps/web/ui/modals/add-edit-link-modal-new/targeting-modal.tsx b/apps/web/ui/modals/add-edit-link-modal-new/targeting-modal.tsxnew file mode 100644index 0000000000..6258da7f58--- /dev/null+++ b/apps/web/ui/modals/add-edit-link-modal-new/targeting-modal.tsx@@ -0,0 +1,365 @@+import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";+import {+ Button,+ Modal,+ SimpleTooltipContent,+ Tooltip,+ useKeyboardShortcut,+} from "@dub/ui";+import { ArrowBoldUp, Crosshairs3 } from "@dub/ui/src/icons";+import { cn, COUNTRIES } from "@dub/utils";+import {+ Dispatch,+ Fragment,+ SetStateAction,+ useCallback,+ useId,+ useMemo,+ useState,+} from "react";+import { useForm, useFormContext } from "react-hook-form";+import { LinkFormData } from ".";++function TargetingModal({+ showTargetingModal,+ setShowTargetingModal,+}: {+ showTargetingModal: boolean;+ setShowTargetingModal: Dispatch<SetStateAction<boolean>>;+}) {+ const id = useId();++ const {+ watch: watchParent,+ getValues: getValuesParent,+ setValue: setValueParent,+ } = useFormContext<LinkFormData>();++ const { watch, register, setValue, reset, handleSubmit } = useForm<+ Pick<LinkFormData, "ios" | "android" | "geo">+ >({+ values: {+ ios: getValuesParent("ios"),+ android: getValuesParent("android"),+ geo: getValuesParent("geo"),+ },+ });++ const geo = watch("geo");++ const [iosParent, androidParent, geoParent] = watchParent([+ "ios",+ "android",+ "geo",+ ]);++ const parentEnabled = Boolean(+ iosParent || androidParent || Object.keys(geoParent || {}).length > 0,+ );++ return (+ <>+ <Modal+ showModal={showTargetingModal}+ setShowModal={setShowTargetingModal}+ className="sm:max-w-md"+ >+ <form+ className="px-5 py-4"+ onSubmit={(e) => {+ e.stopPropagation();+ handleSubmit((data) => {+ setValueParent("ios", data.ios);+ setValueParent("android", data.android);++ // Filter out empty geo values+ const geo = Object.fromEntries(+ Object.entries(data.geo || {}).filter(+ ([key, value]) => key?.trim() && value?.trim(),+ ),+ );+ setValueParent("geo", Object.keys(geo).length > 0 ? geo : null);++ setShowTargetingModal(false);+ })(e);+ }}+ >+ <div className="flex items-center justify-between">+ <h3 className="text-lg font-medium">Targeting</h3>+ <div className="max-md:hidden">+ <Tooltip+ content={+ <div className="px-2 py-1 text-xs text-gray-700">+ Press{" "}+ <strong className="font-medium text-gray-950">+ Shift+T+ </strong>{" "}+ to open this quickly+ </div>+ }+ side="right"+ >+ <kbd className="flex h-6 cursor-default items-center justify-center gap-1 rounded-md border border-gray-200 px-1.5 font-sans text-xs text-gray-950">+ <ArrowBoldUp className="size-3 shrink-0" />T+ </kbd>+ </Tooltip>+ </div>+ </div>++ <div className="scrollbar-hide -m-1 mt-6 flex max-h-[calc(100dvh-250px)] flex-col gap-6 overflow-y-auto p-1">+ {/* Geo */}+ <div>+ <div className="flex items-center gap-2">+ <span className="block text-sm font-medium text-gray-700">+ Geo Targeting+ </span>+ <ProBadgeTooltip+ content={+ <SimpleTooltipContent+ title="Redirect your users to different links based on their location."+ cta="Learn more about geo targeting."+ href="https://dub.co/help/article/geo-targeting"+ />+ }+ />+ </div>+ <div className="mt-2">+ {geo && (+ <div className="mb-2 grid grid-cols-[min-content_1fr] gap-y-2">+ {Object.entries(geo).map(([key, value]) => (+ <Fragment key={key}>+ <select+ id={`geo-selector-${key}`}+ value={key}+ onChange={(e) => {+ const newGeo = {};+ delete Object.assign(newGeo, geo, {+ [e.target.value]: value,+ })[key];+ setValue("geo", newGeo);+ }}+ className="flex w-32 items-center justify-center rounded-l-md border border-r-0 border-gray-300 bg-white pl-3 pr-7 text-left text-sm text-gray-500 focus:border-gray-300 focus:outline-none focus:ring-0"+ >+ <option value="" disabled selected={!key}>+ Country+ </option>+ {Object.entries(COUNTRIES).map(([key, value]) => (+ <option key={key} value={key}>+ {value}+ </option>+ ))}+ </select>+ <input+ type="text"+ id={`${id}-${key}`}+ placeholder="https://example.com"+ className="h-full grow rounded-r-md border border-gray-300 text-sm placeholder-gray-400 focus:border-gray-500 focus:ring-gray-500"+ value={value}+ onChange={(e) => {+ setValue(`geo`, {+ ...((geo as object) || {}),+ [key]: e.target.value,+ });+ }}+ />+ </Fragment>+ ))}+ </div>+ )}+ <Button+ type="button"+ variant="secondary"+ text="Add location"+ className="h-9"+ onClick={() => {+ setValue("geo", { ...((geo as object) || {}), "": "" });+ }}+ disabled={Object.keys(geo || {}).includes("")}+ />+ </div>+ </div>++ {/* iOS */}+ <div>+ <div className="flex items-center gap-2">+ <label+ htmlFor={`${id}-ios-url`}+ className="block text-sm font-medium text-gray-700"+ >+ iOS Targeting+ </label>+ <ProBadgeTooltip+ content={+ <SimpleTooltipContent+ title="Redirect your iOS users to a different link."+ cta="Learn more about device targeting."+ href="https://dub.co/help/article/device-targeting"+ />+ }+ />+ </div>+ <div className="mt-2 rounded-md shadow-sm">+ <input+ id={`${id}-ios-url`}+ placeholder="https://apps.apple.com/app/1611158928"+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ {...register("ios")}+ />+ </div>+ </div>++ {/* Android */}+ <div>+ <div className="flex items-center gap-2">+ <label+ htmlFor={`${id}-android-url`}+ className="block text-sm font-medium text-gray-700"+ >+ Android Targeting+ </label>+ <ProBadgeTooltip+ content={+ <SimpleTooltipContent+ title="Redirect your Android users to a different link."+ cta="Learn more about device targeting."+ href="https://dub.co/help/article/device-targeting"+ />+ }+ />+ </div>+ <div className="mt-2 rounded-md shadow-sm">+ <input+ id={`${id}-android-url`}+ placeholder="https://play.google.com/store/apps/details?id=com.disney.disneyplus"+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ {...register("android")}+ />+ </div>+ </div>+ </div>++ <div className="mt-6 flex items-center justify-between">+ <div>+ {parentEnabled && (+ <button+ type="button"+ className="text-xs font-medium text-gray-700 transition-colors hover:text-gray-950"+ onClick={() => {+ setValueParent("ios", null);+ setValueParent("android", null);+ setValueParent("geo", null);+ setShowTargetingModal(false);+ }}+ >+ Remove targeting+ </button>+ )}+ </div>+ <div className="flex items-center gap-2">+ <Button+ type="button"+ variant="secondary"+ text="Cancel"+ className="h-9 w-fit"+ onClick={() => {+ reset();+ setShowTargetingModal(false);+ }}+ />+ <Button+ type="submit"+ variant="primary"+ text={parentEnabled ? "Save" : "Add targeting"}+ className="h-9 w-fit"+ />+ </div>+ </div>+ </form>+ </Modal>+ </>+ );+}++export function getTargetingLabel({+ ios,+ android,+ geo,+}: Pick<LinkFormData, "ios" | "android" | "geo">) {+ const geoEnabled = Object.keys(geo || {}).length > 0;++ const targets = [Boolean(ios), Boolean(android), geoEnabled];+ const count = targets.filter(Boolean).length;+ const countries = Object.keys(geo || {});++ if (count === 0) return "Targeting";+ if (count === 1) {+ const index = targets.findIndex(Boolean);+ if (index <= 1) return ["iOS", "Android"][index];+ if (!geoEnabled) return "Targeting";++ // Geo+ if (countries.length === 1 && countries[0]) return countries[0];+ return `${countries.length} Target${countries.length === 1 ? "" : "s"}`;+ }++ return `${count + (countries.length > 1 ? countries.length - 1 : 0)} Targets`;+}++function TargetingButton({+ setShowTargetingModal,+}: {+ setShowTargetingModal: Dispatch<SetStateAction<boolean>>;+}) {+ const { watch } = useFormContext<LinkFormData>();+ const [ios, android, geo] = watch(["ios", "android", "geo"]);++ useKeyboardShortcut("T", () => setShowTargetingModal(true), {+ modal: true,+ });++ const geoEnabled = Object.keys(geo || {}).length > 0;+ const enabled = Boolean(ios || android || geoEnabled);++ const label = useMemo(+ () => getTargetingLabel({ ios, android, geo }),+ [ios, android, geo],+ );++ return (+ <Button+ variant="secondary"+ text={label}+ icon={+ <Crosshairs3 className={cn("size-4", enabled && "text-blue-500")} />+ }+ className="h-9 w-fit px-2.5 font-medium text-gray-700"+ onClick={() => setShowTargetingModal(true)}+ />+ );+}++export function useTargetingModal() {+ const [showTargetingModal, setShowTargetingModal] = useState(false);++ const TargetingModalCallback = useCallback(() => {+ return (+ <TargetingModal+ showTargetingModal={showTargetingModal}+ setShowTargetingModal={setShowTargetingModal}+ />+ );+ }, [showTargetingModal, setShowTargetingModal]);++ const TargetingButtonCallback = useCallback(() => {+ return <TargetingButton setShowTargetingModal={setShowTargetingModal} />;+ }, [setShowTargetingModal]);++ return useMemo(+ () => ({+ setShowTargetingModal,+ TargetingModal: TargetingModalCallback,+ TargetingButton: TargetingButtonCallback,+ }),+ [setShowTargetingModal, TargetingModalCallback, TargetingButtonCallback],+ );+}diff --git a/apps/web/ui/modals/add-edit-link-modal-new/toggles.tsx b/apps/web/ui/modals/add-edit-link-modal-new/toggles.tsxdeleted file mode 100644index 686f6e34a6..0000000000--- a/apps/web/ui/modals/add-edit-link-modal-new/toggles.tsx+++ /dev/null@@ -1,267 +0,0 @@-import { AlertCircleFill, CheckCircleFill, X } from "@/ui/shared/icons";-import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";-import {- Button,- Popover,- SimpleTooltipContent,- Tooltip,- useKeyboardShortcut,-} from "@dub/ui";-import {- Dots,- Incognito,- LoadingSpinner,- SquareChart,- WindowSearch,-} from "@dub/ui/src/icons";-import { fetcher, isValidUrl as isValidUrlFn } from "@dub/utils";-import { AnimatePresence, motion } from "framer-motion";-import { ReactNode, useContext, useMemo, useState } from "react";-import { useFormContext } from "react-hook-form";-import useSWR from "swr";-import { useDebounce } from "use-debounce";-import { LinkFormData, LinkModalContext } from ".";--const TOGGLES = [- {- key: "rewrite",- icon: Incognito,- label: "Link Cloaking",- description:- "Mask your destination URL so your users only see the short link in the browser address bar.",- learnMoreUrl: "https://dub.co/help/article/link-cloaking",- shortcutKey: "l",- badge: LinkCloakingToggleBadge,- },- {- key: "trackConversion",- icon: SquareChart,- label: "Conversion Tracking",- description:- "Track conversions on your short link to measure the effectiveness of your marketing campaigns.",- learnMoreUrl: "https://dub.co/help/article/conversion-tracking",- shortcutKey: "c",- conversionEnabled: true,- },- {- key: "doIndex",- icon: WindowSearch,- label: "Search Engine Indexing",- description:- "Allow search engines to index your short link. Disabled by default.",- learnMoreUrl: "https://dub.co/help/article/how-noindex-works",- shortcutKey: "s",- },-];--export function TogglesDropdown() {- const { conversionEnabled } = useContext(LinkModalContext);-- const { watch, setValue } = useFormContext<LinkFormData>();- const data = watch();-- const [openPopover, setOpenPopover] = useState(false);-- const toggles = useMemo(- () =>- TOGGLES.filter((toggle) =>- toggle.conversionEnabled ? conversionEnabled || data[toggle.key] : true,- ),- [conversionEnabled, data],- );-- useKeyboardShortcut(- toggles.map(({ shortcutKey }) => shortcutKey),- (e) => {- const toggle = toggles.find(({ shortcutKey }) => shortcutKey === e.key);- if (!toggle) return;-- setOpenPopover(false);- setValue(toggle.key as any, !data[toggle.key]);- },- { modal: true },- );-- return (- <Popover- align="start"- content={- <div className="grid p-1 max-sm:w-full md:min-w-72">- {toggles.map((toggle) => {- const enabled = data[toggle.key];-- return (- <Button- type="button"- variant="outline"- key={toggle.key}- onClick={() => {- setOpenPopover(false);- setValue(toggle.key as any, !enabled);- }}- className="h-9 w-full justify-start px-2 text-sm text-gray-700"- textWrapperClassName="grow"- text={- <div className="flex items-center justify-between gap-2">- <div className="flex items-center gap-1">- <toggle.icon className="mr-1 size-4 text-gray-950" />- {enabled ? "Remove" : "Add"} {toggle.label}- <ProBadgeTooltip- content={- <SimpleTooltipContent- title={toggle.description}- cta="Learn more."- href={toggle.learnMoreUrl}- />- }- />- </div>- <kbd className="flex size-6 cursor-default items-center justify-center rounded-md border border-gray-200 font-sans text-xs text-gray-800">- {toggle.shortcutKey.toUpperCase()}- </kbd>- </div>- }- />- );- })}- </div>- }- openPopover={openPopover}- setOpenPopover={setOpenPopover}- >- <Button- variant="secondary"- icon={<Dots className="size-4" />}- className="h-9 px-2.5"- />- </Popover>- );-}--export function TogglesList() {- const { watch, setValue } = useFormContext<LinkFormData>();- const data = watch();-- const enabledToggles = useMemo(- () => TOGGLES.filter(({ key }) => data[key]),- [data],- );-- return enabledToggles.length ? (- <div className="flex flex-wrap gap-2">- <AnimatePresence>- {enabledToggles.map((toggle) => {- const Component = toggle.badge || ToggleBadge;- return (- <motion.div- key={toggle.key}- initial={{ opacity: 0 }}- animate={{ opacity: 1 }}- transition={{ duration: 0.1 }}- >- <Component- toggle={toggle}- onRemove={() => setValue(toggle.key as any, false)}- />- </motion.div>- );- })}- </AnimatePresence>- </div>- ) : null;-}--function ToggleBadge({- toggle,- onRemove,- icon,-}: {- toggle: (typeof TOGGLES)[number];- onRemove: () => void;- icon?: ReactNode;-}) {- return (- <span className="group flex cursor-default items-center gap-1.5 rounded-md border border-gray-200 bg-gray-50 pl-1.5 text-xs text-gray-600">- {icon}- {toggle.label}- <button- type="button"- onClick={onRemove}- className="-ml-1 p-1 text-gray-400 hover:text-gray-500"- >- <X className="size-3.5" />- </button>- </span>- );-}--function LinkCloakingToggleBadge({- toggle,- onRemove,-}: {- toggle: (typeof TOGGLES)[number];- onRemove: () => void;-}) {- const { watch } = useFormContext<LinkFormData>();- const [url, domain] = watch(["url", "domain"]);- const [debouncedUrl] = useDebounce(url, 500);- const isValidUrl = useMemo(- () => debouncedUrl && isValidUrlFn(debouncedUrl),- [debouncedUrl],- );-- const { data, isLoading } = useSWR<{ iframeable: boolean }>(- domain && isValidUrl- ? `/api/links/iframeable?url=${debouncedUrl}&domain=${domain}`- : null,- fetcher,- );-- const badge = useMemo(- () => (- <ToggleBadge- toggle={toggle}- onRemove={onRemove}- icon={- isLoading ? (- <LoadingSpinner className="size-3.5" />- ) : !data ? null : data?.iframeable ? (- <CheckCircleFill className="size-3.5 text-green-500" />- ) : (- <AlertCircleFill className="size-3.5 text-yellow-500" />- )- }- />- ),- [data, isLoading],- );-- return data && !data?.iframeable ? (- <Tooltip- content={- <div className="block max-w-sm text-pretty px-4 py-2 text-center text-sm text-gray-700">- We will try to cloak it with{" "}- <a- href="https://nextjs.org/docs/pages/api-reference/functions/next-response#rewrite"- target="_blank"- className="text-gray-500 underline underline-offset-2 hover:text-gray-700"- >- Next.js Rewrites- </a>- , but it might not work as expected.{" "}- <a- href="https://dub.co/help/article/link-cloaking"- target="_blank"- className="text-gray-500 underline underline-offset-2 hover:text-gray-700"- >- Learn more.- </a>- </div>- }- >- <div>{badge}</div>- </Tooltip>- ) : (- badge- );-}diff --git a/packages/ui/src/icons/nucleo/arrow-bold-up.tsx b/packages/ui/src/icons/nucleo/arrow-bold-up.tsxnew file mode 100644index 0000000000..4e5eef98f4--- /dev/null+++ b/packages/ui/src/icons/nucleo/arrow-bold-up.tsx@@ -0,0 +1,24 @@+import { SVGProps } from "react";++export function ArrowBoldUp(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="M14.391,8.448L9.398,1.867c-.2-.264-.597-.264-.797,0L3.609,8.448c-.25,.329-.015,.802,.398,.802h2.743v6c0,.552,.448,1,1,1h2.5c.552,0,1-.448,1-1v-6h2.743c.413,0,.648-.473,.398-.802Z"+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ </g>+ </svg>+ );+}diff --git a/packages/ui/src/icons/nucleo/crosshairs3.tsx b/packages/ui/src/icons/nucleo/crosshairs3.tsxnew file mode 100644index 0000000000..1c4e813004--- /dev/null+++ b/packages/ui/src/icons/nucleo/crosshairs3.tsx@@ -0,0 +1,70 @@+import { SVGProps } from "react";++export function Crosshairs3(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">+ <circle+ cx="9"+ cy="9"+ fill="none"+ r="7.25"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="9"+ x2="9"+ y1="7"+ y2="4.75"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="11"+ x2="13.25"+ y1="9"+ y2="9"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="9"+ x2="9"+ y1="11"+ y2="13.25"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="7"+ x2="4.75"+ y1="9"+ y2="9"+ />+ </g>+ </svg>+ );+}diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.tsindex 5aff5b758a..dcadb1173d 100644--- a/packages/ui/src/icons/nucleo/index.ts+++ b/packages/ui/src/icons/nucleo/index.ts@@ -1,4 +1,5 @@export * from "./apple";+export * from "./arrow-bold-up";export * from "./arrow-right";export * from "./arrow-turn-left";export * from "./arrow-turn-right2";@@ -25,6 +26,7 @@ export * from "./circles3";export * from "./cloud-upload";export * from "./code";export * from "./connected-dots";+export * from "./crosshairs3";export * from "./cube";export * from "./cube-settings";export * from "./cursor-rays";