The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix
Steven Tey0a52e984ed9c
diff --git a/apps/web/ui/modals/add-edit-link-modal/android-section.tsx b/apps/web/ui/modals/add-edit-link-modal/android-section.tsxdeleted file mode 100644index 51484517de..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/android-section.tsx+++ /dev/null@@ -1,71 +0,0 @@-import { LinkProps } from "@/lib/types";-import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";-import { SimpleTooltipContent, Switch } from "@dub/ui";-import { FADE_IN_ANIMATION_SETTINGS } from "@dub/utils";-import { motion } from "framer-motion";-import { Dispatch, SetStateAction, useEffect, useState } from "react";--export default function AndroidSection({- props,- data,- setData,-}: {- props?: LinkProps;- data: LinkProps;- setData: Dispatch<SetStateAction<LinkProps>>;-}) {- const { android } = data;- const [enabled, setEnabled] = useState(!!android);- useEffect(() => {- if (enabled) {- // if enabling, add previous android link if exists- setData({- ...data,- android: props?.android || android,- });- } else {- // if disabling, remove android link- setData({ ...data, android: null });- }- }, [enabled]);-- return (- <div className="relative border-b border-gray-200 pb-5">- <div className="flex items-center justify-between">- <div className="flex items-center justify-between space-x-2">- <h2 className="text-sm font-medium text-gray-900">- Android Targeting- </h2>- <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>- <Switch fn={() => setEnabled(!enabled)} checked={enabled} />- </div>- {enabled && (- <motion.div- className="mt-3 flex rounded-md shadow-sm"- {...FADE_IN_ANIMATION_SETTINGS}- >- <input- name="android-url"- id="android-url"- placeholder="https://play.google.com/store/apps/details?id=com.disney.disneyplus"- value={android || ""}- onChange={(e) => {- setData({ ...data, android: e.target.value });- }}- 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"- aria-invalid="true"- />- </motion.div>- )}- </div>- );-}diff --git a/apps/web/ui/modals/add-edit-link-modal/cloaking-section.tsx b/apps/web/ui/modals/add-edit-link-modal/cloaking-section.tsxdeleted file mode 100644index 251e0986b3..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/cloaking-section.tsx+++ /dev/null@@ -1,135 +0,0 @@-import { LinkProps } from "@/lib/types";-import { AlertCircleFill, CheckCircleFill } from "@/ui/shared/icons";-import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";-import { LoadingSpinner, SimpleTooltipContent, Switch } from "@dub/ui";-import {- FADE_IN_ANIMATION_SETTINGS,- fetcher,- getUrlFromString,-} from "@dub/utils";-import { motion } from "framer-motion";-import { Dispatch, SetStateAction, useEffect, useState } from "react";-import useSWR from "swr";-import { useDebounce } from "use-debounce";--export default function CloakingSection({- data,- setData,-}: {- data: LinkProps;- setData: Dispatch<SetStateAction<LinkProps>>;-}) {- const { rewrite } = data;- const [enabled, setEnabled] = useState(rewrite);- useEffect(() => {- if (enabled) {- // if enabling, set rewrite to true or props.rewrite- setData({- ...data,- rewrite: true,- });- } else {- // if disabling, set rewrite to false- setData({ ...data, rewrite: false });- }- }, [enabled]);-- return (- <div className="relative border-b border-gray-200 pb-5">- <div className="flex items-center justify-between">- <div className="flex items-center justify-between space-x-2">- <h2 className="text-sm font-medium text-gray-900">Link Cloaking</h2>- <ProBadgeTooltip- content={- <SimpleTooltipContent- title="Mask your destination URL so your users only see the short link in the browser address bar."- cta="Learn more."- href="https://dub.co/help/article/link-cloaking"- />- }- />- </div>- <Switch fn={() => setEnabled(!enabled)} checked={enabled} />- </div>-- {enabled && (- <motion.div className="mt-3 grid gap-2" {...FADE_IN_ANIMATION_SETTINGS}>- <div className="relative mt-1 flex aspect-[1200/630] w-full cursor-pointer items-center justify-center overflow-hidden rounded-md border border-gray-300 bg-white shadow-sm transition-all hover:bg-gray-50">- <iframe- src={getUrlFromString(data.url)}- className="absolute z-10 h-full w-full"- />- <LoadingSpinner />- </div>- <IframeIndicator- url={getUrlFromString(data.url)}- domain={data.domain}- />- </motion.div>- )}- </div>- );-}--function IframeIndicator({ url, domain }: { url: string; domain: string }) {- const [debouncedUrl] = useDebounce(url, 500);- const { data, isLoading } = useSWR<{ iframeable: boolean }>(- `/api/links/iframeable?url=${debouncedUrl}&domain=${domain}`,- fetcher,- );-- return (- <div className="flex items-start space-x-2 rounded-md border border-gray-300 bg-white p-3">- <div className="flex-none">- {isLoading ? (- <LoadingSpinner className="h-5 w-5" />- ) : data?.iframeable ? (- <CheckCircleFill className="h-5 w-5 text-green-500" />- ) : (- <AlertCircleFill className="h-5 w-5 text-yellow-500" />- )}- </div>- <div className="flex flex-col space-y-0.5">- <p className="text-sm font-semibold text-gray-700">- {!data || isLoading- ? "Checking if URL is iFrameable..."- : data.iframeable- ? "URL is iFrameable"- : "URL is not iFrameable"}- </p>- {data &&- (data.iframeable ? (- <p className="text-sm text-gray-600">- It will be cloaked successfully.{" "}- <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>- </p>- ) : (- <p className="text-sm text-gray-600">- 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>- </p>- ))}- </div>- </div>- );-}diff --git a/apps/web/ui/modals/add-edit-link-modal/comments-section.tsx b/apps/web/ui/modals/add-edit-link-modal/comments-section.tsxdeleted file mode 100644index 3e42dc1aaf..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/comments-section.tsx+++ /dev/null@@ -1,65 +0,0 @@-import { LinkProps } from "@/lib/types";-import { InfoTooltip, SimpleTooltipContent, Switch } from "@dub/ui";-import { FADE_IN_ANIMATION_SETTINGS } from "@dub/utils";-import { motion } from "framer-motion";-import { Dispatch, SetStateAction, useEffect, useState } from "react";-import TextareaAutosize from "react-textarea-autosize";--export default function CommentsSection({- props,- data,- setData,-}: {- props?: LinkProps;- data: LinkProps;- setData: Dispatch<SetStateAction<LinkProps>>;-}) {- const { comments } = data;- const [enabled, setEnabled] = useState(!!comments);- useEffect(() => {- if (enabled) {- // if enabling, add previous comments if exists- setData({- ...data,- comments: props?.comments || comments,- });- } else {- // if disabling, remove comments- setData({ ...data, comments: null });- }- }, [enabled]);-- return (- <div className="relative border-b border-gray-200 pb-5">- <div className="flex items-center justify-between">- <div className="flex items-center justify-between space-x-2">- <h2 className="text-sm font-medium text-gray-900">Comments</h2>- <InfoTooltip- content={- <SimpleTooltipContent- title="Use comments to add context to your short links – for you and your team."- cta="Learn more."- href="https://dub.co/help/article/link-comments"- />- }- />- </div>- <Switch fn={() => setEnabled(!enabled)} checked={enabled} />- </div>- {enabled && (- <motion.div className="mt-3" {...FADE_IN_ANIMATION_SETTINGS}>- <TextareaAutosize- name="comments"- minRows={3}- 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"- placeholder="Add comments"- value={comments || ""}- onChange={(e) => {- setData({ ...data, comments: e.target.value });- }}- />- </motion.div>- )}- </div>- );-}diff --git a/apps/web/ui/modals/add-edit-link-modal/conversion-section.tsx b/apps/web/ui/modals/add-edit-link-modal/conversion-section.tsxdeleted file mode 100644index 24ac41e1d8..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/conversion-section.tsx+++ /dev/null@@ -1,126 +0,0 @@-import { LinkProps } from "@/lib/types";-import { AlertCircleFill, CheckCircleFill } from "@/ui/shared/icons";-import { LoadingSpinner, SimpleTooltipContent, Switch } from "@dub/ui";-import { BadgeTooltip } from "@dub/ui/src/tooltip";-import { fetcher } from "@dub/utils";-import { FlaskConical } from "lucide-react";-import { Dispatch, SetStateAction, useEffect, useState } from "react";-import useSWR from "swr";--export default function ConversionSection({- data,- setData,-}: {- data: LinkProps;- setData: Dispatch<SetStateAction<LinkProps>>;-}) {- const { trackConversion } = data;- const [enabled, setEnabled] = useState(trackConversion);- useEffect(() => {- if (enabled) {- // if enabling, set trackConversion to true- setData({- ...data,- trackConversion: true,- });- } else {- // if disabling, set trackConversion to false- setData({ ...data, trackConversion: false });- }- }, [enabled]);-- return (- <div className="relative border-b border-gray-200 pb-5">- <div className="flex items-center justify-between">- <div className="flex items-center justify-between space-x-2">- <h2 className="text-sm font-medium text-gray-900">- Conversion Tracking- </h2>- <BadgeTooltip- content={- <SimpleTooltipContent- title="Track conversions on your short link to measure the effectiveness of your marketing campaigns."- cta="Learn more."- href="https://dub.co/help/article/conversion-tracking"- />- }- >- <div className="flex items-center space-x-1">- <FlaskConical size={12} />- <p className="uppercase">Beta</p>- </div>- </BadgeTooltip>- </div>- <Switch fn={() => setEnabled(!enabled)} checked={enabled} />- </div>-- {/* {enabled && (- <motion.div className="mt-3" {...FADE_IN_ANIMATION_SETTINGS}>- <CheckConversionScript url={getUrlFromString(data.url)} />- </motion.div>- )} */}- </div>- );-}--function CheckConversionScript({ url }: { url: string }) {- const { data, isLoading } = useSWR<{ installed: boolean }>(- url && `/api/links/check-conversion-script?url=${url}`,- fetcher,- );-- return (- <div className="flex items-start space-x-2 rounded-md border border-gray-300 bg-white p-3">- <div className="flex-none">- {!data || isLoading ? (- <LoadingSpinner className="h-5 w-5" />- ) : data.installed ? (- <CheckCircleFill className="h-5 w-5 text-green-500" />- ) : (- <AlertCircleFill className="h-5 w-5 text-yellow-500" />- )}- </div>- <div className="flex flex-col space-y-1">- <p className="text-sm font-medium text-gray-700">- {!data || isLoading- ? "Checking if conversion script is installed..."- : data.installed- ? "Conversion Script is installed"- : "Conversion Script not detected"}- </p>- {data &&- (data.installed ? (- <p className="text-xs text-gray-600">- We will track conversions on this link.{" "}- <a- href="https://dub.co/help/article/conversion-tracking"- target="_blank"- className="text-gray-500 underline underline-offset-2 hover:text-gray-700"- >- Learn more.- </a>- </p>- ) : (- <p className="text-sm text-gray-600">- We recommend adding the{" "}- <a- href="https://github.com/dubinc/analytics"- target="_blank"- className="font-mono text-gray-500 underline underline-offset-2 hover:text-gray-700"- >- @dub/analytics- </a>{" "}- script for reliable conversion tracking.{" "}- <a- href="https://dub.co/help/article/conversion-tracking"- target="_blank"- className="text-gray-500 underline underline-offset-2 hover:text-gray-700"- >- Learn more.- </a>- </p>- ))}- </div>- </div>- );-}diff --git a/apps/web/ui/modals/add-edit-link-modal/doindex-section.tsx b/apps/web/ui/modals/add-edit-link-modal/doindex-section.tsxdeleted file mode 100644index fd87ef6bee..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/doindex-section.tsx+++ /dev/null@@ -1,49 +0,0 @@-import { LinkProps } from "@/lib/types";-import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";-import { SimpleTooltipContent, Switch } from "@dub/ui";-import { Dispatch, SetStateAction, useEffect, useState } from "react";--export default function DoIndexSection({- data,- setData,-}: {- data: LinkProps;- setData: Dispatch<SetStateAction<LinkProps>>;-}) {- const { doIndex } = data;- const [enabled, setEnabled] = useState(doIndex);- useEffect(() => {- if (enabled) {- // if enabling, set doIndex to true- setData({- ...data,- doIndex: true,- });- } else {- // if disabling, set doIndex to false- setData({ ...data, doIndex: false });- }- }, [enabled]);-- return (- <div className="relative border-b border-gray-200 pb-5">- <div className="flex items-center justify-between">- <div className="flex items-center justify-between space-x-2">- <h2 className="text-sm font-medium text-gray-900">- Search Engine Indexing- </h2>- <ProBadgeTooltip- content={- <SimpleTooltipContent- title="Allow search engines to index your short link. Disabled by default."- cta="Learn more."- href="https://dub.co/help/article/how-noindex-works"- />- }- />- </div>- <Switch fn={() => setEnabled(!enabled)} checked={enabled} />- </div>- </div>- );-}diff --git a/apps/web/ui/modals/add-edit-link-modal/expiration-section.tsx b/apps/web/ui/modals/add-edit-link-modal/expiration-section.tsxdeleted file mode 100644index 9e52b70977..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/expiration-section.tsx+++ /dev/null@@ -1,144 +0,0 @@-import { LinkProps } from "@/lib/types";-import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";-import {- ExpandingArrow,- InfoTooltip,- SimpleTooltipContent,- Switch,-} from "@dub/ui";-import {- FADE_IN_ANIMATION_SETTINGS,- formatDateTime,- getDateTimeLocal,- parseDateTime,-} from "@dub/utils";-import { motion } from "framer-motion";-import { Dispatch, SetStateAction, useEffect, useRef, useState } from "react";--export default function ExpirationSection({- props,- data,- setData,-}: {- props?: LinkProps;- data: LinkProps;- setData: Dispatch<SetStateAction<LinkProps>>;-}) {- const inputRef = useRef<HTMLInputElement>(null);-- const { expiresAt, expiredUrl } = data;- const [enabled, setEnabled] = useState(!!expiresAt);- useEffect(() => {- if (enabled) {- // if enabling, add previous expiration date if exists- setData({- ...data,- expiresAt: props?.expiresAt || expiresAt,- expiredUrl: props?.expiredUrl || null,- });- } else {- // if disabling, remove expiration date and expired URL- setData({ ...data, expiresAt: null, expiredUrl: null });- }- }, [enabled]);-- return (- <div className="relative border-b border-gray-200 pb-5">- <div className="flex items-center justify-between">- <div className="flex items-center justify-between space-x-2">- <h2 className="text-sm font-medium text-gray-900">Link Expiration</h2>- <ProBadgeTooltip- content={- <SimpleTooltipContent- title="Set an expiration date for your links – after which it won't be accessible."- cta="Learn more."- href="https://dub.co/help/article/link-expiration"- />- }- />- </div>- <Switch fn={() => setEnabled(!enabled)} checked={enabled} />- </div>- {enabled && (- <motion.div className="mt-3" {...FADE_IN_ANIMATION_SETTINGS}>- <div className="flex w-full items-center justify-between rounded-md border border-gray-300 bg-white shadow-sm transition-all focus-within:border-gray-800 focus-within:outline-none focus-within:ring-1 focus-within:ring-gray-500">- <input- ref={inputRef}- type="text"- placeholder='E.g. "tomorrow at 5pm" or "in 2 hours"'- defaultValue={expiresAt ? formatDateTime(expiresAt) : ""}- onBlur={(e) => {- if (e.target.value.length > 0) {- const parsedDateTime = parseDateTime(e.target.value);- if (parsedDateTime) {- setData({ ...data, expiresAt: parsedDateTime });- e.target.value = formatDateTime(parsedDateTime);- }- }- }}- className="flex-1 border-none bg-transparent text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-0 sm:text-sm"- />- <input- type="datetime-local"- id="expiresAt"- name="expiresAt"- value={expiresAt ? getDateTimeLocal(expiresAt) : ""}- onChange={(e) => {- const expiryDate = new Date(e.target.value);- setData({ ...data, expiresAt: expiryDate });- if (inputRef.current) {- inputRef.current.value = formatDateTime(expiryDate);- }- }}- className="w-[40px] border-none bg-transparent text-gray-500 focus:outline-none focus:ring-0 sm:text-sm"- />- </div>- <div className="mt-4">- <div className="flex items-center justify-between">- <label- htmlFor="expiredUrl"- className="flex items-center space-x-2"- >- <p className="text-sm font-medium text-gray-700">- Expiration URL- </p>- <InfoTooltip- content={- <SimpleTooltipContent- title="Redirect users to a specific URL when the link has expired."- cta="Learn more."- href="https://dub.co/help/article/link-expiration#setting-a-custom-expiration-url"- />- }- />- </label>- </div>- <div className="mt-3 flex rounded-md shadow-sm">- <input- name="expiredUrl"- id="expiredUrl"- tabIndex={0}- placeholder="https://yourwebsite.com"- value={expiredUrl || ""}- autoComplete="off"- onChange={(e) => {- setData({ ...data, expiredUrl: e.target.value });- }}- 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"- aria-invalid="true"- />- </div>- <a- href="https://dub.co/help/article/link-expiration#setting-a-default-expiration-url-for-all-links-under-a-domain"- target="_blank"- className="group mt-3 flex items-center text-sm text-gray-500 hover:text-gray-700"- >- <p>Or set a default expiration URL for your domain</p>- <ExpandingArrow />- </a>- </div>- </motion.div>- )}- </div>- );-}diff --git a/apps/web/ui/modals/add-edit-link-modal/geo-section.tsx b/apps/web/ui/modals/add-edit-link-modal/geo-section.tsxdeleted file mode 100644index 14e4b72862..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/geo-section.tsx+++ /dev/null@@ -1,159 +0,0 @@-import { LinkProps } from "@/lib/types";-import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";-import { SimpleTooltipContent, Switch } from "@dub/ui";-import { COUNTRIES, FADE_IN_ANIMATION_SETTINGS } from "@dub/utils";-import { motion } from "framer-motion";-import { Trash } from "lucide-react";-import { Dispatch, SetStateAction, useEffect, useState } from "react";--export default function GeoSection({- props,- data,- setData,-}: {- props?: LinkProps;- data: LinkProps;- setData: Dispatch<SetStateAction<LinkProps>>;-}) {- const { geo } = data;- const [enabled, setEnabled] = useState(!!geo);-- useEffect(() => {- if (enabled) {- // if enabling, add previous geo data if exists- setData({- ...data,- geo: props?.geo || {- "": "",- },- });- } else {- // if disabling, remove geo data- setData({ ...data, geo: null });- }- }, [enabled]);-- const addGeoSelector = () => {- setData((prev) => ({- ...prev,- geo: { ...((prev.geo as object) || {}), "": "" }, // Add an empty entry- }));- };-- return (- <div className="relative border-b border-gray-200 pb-5">- <div className="flex items-center justify-between">- <div className="flex items-center justify-between space-x-2">- <h2 className="text-sm font-medium text-gray-900">Geo Targeting</h2>- <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>- <Switch fn={() => setEnabled(!enabled)} checked={enabled} />- </div>- {enabled && (- <motion.div className="mt-3 grid gap-2" {...FADE_IN_ANIMATION_SETTINGS}>- {geo &&- Object.entries(geo).map(([country, url]) => (- <GeoSelector- key={country}- country={country}- url={url}- setData={setData}- />- ))}- <button- type="button"- onClick={addGeoSelector}- className="mt-2 rounded-md border border-gray-200 bg-white p-1 text-sm text-gray-400 transition-all duration-75 hover:border-gray-400 hover:text-gray-500 active:bg-gray-50"- >- Add location- </button>- </motion.div>- )}- </div>- );-}--const GeoSelector = ({- country,- url,- setData,-}: {- country: string;- url: string;- setData: Dispatch<SetStateAction<LinkProps>>;-}) => {- const removeGeoSelector = (countryToRemove: string) => {- setData((prev) => {- const { [countryToRemove]: _, ...rest } = prev.geo as {- [key: string]: string;- };- return {- ...prev,- geo: Object.keys(rest).length ? rest : null,- };- });- };-- return (- <div className="flex justify-between space-x-2">- <div className="relative flex flex-1 rounded-md shadow-sm">- <select- id={`geo-selector-${country}`}- value={country}- onChange={(e) => {- removeGeoSelector(country);- setData((prev) => ({- ...prev,- geo: {- ...((prev.geo as object) || {}),- [e.target.value]: url,- },- }));- }}- className="flex w-28 items-center justify-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 pl-3 pr-7 text-center text-sm text-gray-500 focus:border-gray-300 focus:outline-none focus:ring-0"- >- <option value="" disabled selected={!country}>- Country- </option>- {Object.entries(COUNTRIES).map(([key, value]) => (- <option key={key} value={key}>- {value}- </option>- ))}- </select>- <input- name="geo-url"- required- autoComplete="off"- className="block w-full rounded-r-md border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"- value={url}- placeholder="URL"- onChange={(e) => {- setData((prev) => ({- ...prev,- geo: {- ...((prev.geo as object) || {}),- [country]: e.target.value,- },- }));- }}- />- </div>- <button- type="button"- onClick={() => removeGeoSelector(country)}- className="flex h-10 w-10 items-center justify-center rounded-md border border-gray-200 bg-white text-sm text-gray-400 transition-all duration-75 hover:border-gray-400 hover:text-gray-500 active:bg-gray-50"- >- <Trash size={16} className="text-gray-400" />- </button>- </div>- );-};diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsxdeleted file mode 100644index 4c4710e328..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx+++ /dev/null@@ -1,562 +0,0 @@-"use client";--import useWorkspace from "@/lib/swr/use-workspace";-import { LinkWithTagsProps } 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";-import { X } from "@/ui/shared/icons";-import { UpgradeRequiredToast } from "@/ui/shared/upgrade-required-toast";-import {- Button,- LinkLogo,- Modal,- TooltipContent,- useRouterStuff,-} from "@dub/ui";-import {- DEFAULT_LINK_PROPS,- deepEqual,- getApexDomain,- getUrlWithoutUTMParams,- isValidUrl,- linkConstructor,- truncate,-} from "@dub/utils";-import { useParams, useSearchParams } from "next/navigation";-import posthog from "posthog-js";-import {- Dispatch,- SetStateAction,- UIEvent,- useCallback,- useEffect,- useMemo,- useRef,- useState,-} from "react";-import { toast } from "sonner";-import { mutate } from "swr";-import { useDebounce } from "use-debounce";-import AndroidSection from "./android-section";-import CloakingSection from "./cloaking-section";-import CommentsSection from "./comments-section";-import ConversionSection from "./conversion-section";-import DoIndexSection from "./doindex-section";-import ExpirationSection from "./expiration-section";-import GeoSection from "./geo-section";-import IOSSection from "./ios-section";-import OGSection from "./og-section";-import PasswordSection from "./password-section";-import Preview from "./preview";-import TagsSection from "./tags-section";-import UTMSection from "./utm-section";--function AddEditLinkModal({- showAddEditLinkModal,- setShowAddEditLinkModal,- props,- duplicateProps,- homepageDemo,-}: {- showAddEditLinkModal: boolean;- setShowAddEditLinkModal: Dispatch<SetStateAction<boolean>>;- props?: LinkWithTagsProps;- duplicateProps?: LinkWithTagsProps;- homepageDemo?: boolean;-}) {- const params = useParams() as { slug?: string };- const { slug } = params;- const { id: workspaceId, nextPlan, conversionEnabled } = useWorkspace();-- const [keyError, setKeyError] = useState<string | null>(null);- const [urlError, setUrlError] = useState<string | null>(null);- const [saving, setSaving] = useState(false);-- const [data, setData] = useState<LinkWithTagsProps>(- props || duplicateProps || DEFAULT_LINK_PROPS,- );-- const { domain, key, url, password, proxy } = data;-- const [generatingMetatags, setGeneratingMetatags] = useState(- props ? true : false,- );- const [debouncedUrl] = useDebounce(getUrlWithoutUTMParams(url), 500);- useEffect(() => {- // if there's a password, no need to generate metatags- if (password) {- setGeneratingMetatags(false);- setData((prev) => ({- ...prev,- title: "Password Required",- description:- "This link is password protected. Please enter the password to view it.",- image: "https://assets.dub.co/misc/password-protected.png",- }));- return;- }- /**- * Only generate metatags if:- * - modal is open- * - custom OG proxy is not enabled- * - url is not empty- **/- if (showAddEditLinkModal && !proxy && debouncedUrl.length > 0) {- setData((prev) => ({- ...prev,- title: null,- description: null,- image: null,- }));- try {- // if url is valid, continue to generate metatags, else return null- new URL(debouncedUrl);- setGeneratingMetatags(true);- fetch(`/api/metatags?url=${debouncedUrl}`).then(async (res) => {- if (res.status === 200) {- const results = await res.json();- setData((prev) => ({- ...prev,- ...{- title: truncate(results.title, 120),- description: truncate(results.description, 240),- image: results.image,- },- }));- }- // set timeout to prevent flickering- setTimeout(() => setGeneratingMetatags(false), 200);- });- } catch (_) {}- } else {- setGeneratingMetatags(false);- }- }, [debouncedUrl, password, showAddEditLinkModal]);-- const endpoint = useMemo(() => {- if (props?.id) {- return {- method: "PATCH",- url: `/api/links/${props.id}?workspaceId=${workspaceId}`,- };- } else {- return {- method: "POST",- url: `/api/links?workspaceId=${workspaceId}`,- };- }- }, [props, slug, domain, workspaceId]);-- const [atBottom, setAtBottom] = useState(false);- const handleScroll = useCallback((event: UIEvent<HTMLDivElement>) => {- const { scrollTop, scrollHeight, clientHeight } = event.currentTarget;- if (Math.abs(scrollHeight - scrollTop - clientHeight) < 5) {- setAtBottom(true);- } else {- setAtBottom(false);- }- }, []);-- const saveDisabled = useMemo(() => {- /*- Disable save if:- - modal is not open- - saving is in progress- - key is invalid- - url is invalid- - for an existing link, there's no changes- */- if (- !showAddEditLinkModal ||- saving ||- keyError ||- urlError ||- (props &&- Object.entries(props).every(([key, value]) => {- // If the key is "title" or "description" and proxy is not enabled, return true (skip the check)- if (- (key === "title" || key === "description" || key === "image") &&- !proxy- ) {- return true;- } else if (key === "geo") {- const equalGeo = deepEqual(props.geo as object, data.geo as object);- return equalGeo;- }- // Otherwise, check for discrepancy in the current key-value pair- return data[key] === value;- }))- ) {- return true;- } else {- return false;- }- }, [showAddEditLinkModal, saving, keyError, urlError, props, data]);-- const keyRef = useRef<HTMLInputElement>(null);- useEffect(() => {- if (key?.endsWith("-copy")) {- keyRef.current?.select();- }- }, []);-- const { domains, loading, primaryDomain } = useAvailableDomains({- currentDomain: domain,- });-- useEffect(() => {- // for a new link (no props or duplicateProps), set the domain to the primary domain- if (!loading && primaryDomain && !props && !duplicateProps) {- setData((prev) => ({- ...prev,- domain: primaryDomain,- }));- }- }, [loading, primaryDomain, props, duplicateProps]);-- const searchParams = useSearchParams();- const { queryParams } = useRouterStuff();-- const shortLink = useMemo(() => {- return linkConstructor({- key: data.key,- domain: data.domain,- pretty: true,- });- }, [data.key, data.domain]);-- return (- <Modal- showModal={showAddEditLinkModal}- setShowModal={setShowAddEditLinkModal}- className="max-w-screen-lg"- preventDefaultClose={homepageDemo ? false : true}- onClose={() => {- if (searchParams.has("newLink")) {- queryParams({- del: ["newLink", "newLinkDomain"],- });- }- }}- >- <div className="scrollbar-hide grid max-h-[95dvh] w-full divide-x divide-gray-100 overflow-auto md:grid-cols-2 md:overflow-hidden">- {!homepageDemo && (- <button- onClick={() => {- setShowAddEditLinkModal(false);- if (searchParams.has("newLink")) {- queryParams({- del: ["newLink"],- });- }- }}- className="group absolute right-0 top-0 z-20 m-3 hidden rounded-full p-2 text-gray-500 transition-all duration-75 hover:bg-gray-100 focus:outline-none active:bg-gray-200 md:block"- >- <X className="h-5 w-5" />- </button>- )}-- <div- className="scrollbar-hide rounded-l-2xl md:max-h-[95vh] md:overflow-auto"- onScroll={handleScroll}- >- <div className="sticky top-0 z-20 flex h-14 items-center justify-center gap-4 space-y-3 border-b border-gray-200 bg-white px-4 transition-all sm:h-24 md:px-16">- <LinkLogo apexDomain={getApexDomain(debouncedUrl)} />- <h3 className="!mt-0 max-w-sm truncate text-lg font-medium">- {props ? `Edit ${shortLink}` : "Create a new link"}- </h3>- </div>-- <form- onSubmit={async (e) => {- e.preventDefault();- setSaving(true);- // @ts-ignore – exclude extra attributes from `data` object before sending to API- const { user, tags, tagId, ...rest } = data;- const bodyData = {- ...rest,- // Map tags to tagIds- tagIds: tags.map(({ id }) => id),- };- fetch(endpoint.url, {- method: endpoint.method,- headers: {- "Content-Type": "application/json",- },- body: JSON.stringify(bodyData),- }).then(async (res) => {- if (res.status === 200) {- await mutate(- (key) =>- typeof key === "string" && key.startsWith("/api/links"),- undefined,- { revalidate: true },- );- const data = await res.json();- posthog.capture(- props ? "link_updated" : "link_created",- data,- );- // copy shortlink to clipboard when adding a new link- if (!props) {- try {- await navigator.clipboard.writeText(data.shortLink);- toast.success("Copied shortlink to clipboard!");- } catch (e) {- console.error(- "Failed to automatically copy shortlink to clipboard.",- e,- );- toast.success("Successfully created link!");- }- } else {- toast.success("Successfully updated shortlink!");- }- setShowAddEditLinkModal(false);- } else {- const { error } = await res.json();- if (error) {- if (error.message.includes("Upgrade to")) {- toast.custom(() => (- <UpgradeRequiredToast- title={`You've discovered a ${nextPlan.name} feature!`}- message={error.message}- />- ));- } else {- toast.error(error.message);- }- const message = error.message.toLowerCase();-- if (message.includes("key")) {- setKeyError(error.message);- } else if (message.includes("url")) {- setUrlError(error.message);- }- }- }- setSaving(false);- });- }}- className="grid gap-6 bg-gray-50 pt-8"- >- <div className="grid gap-6 px-4 md:px-16">- <DestinationUrlInput- domain={domain}- _key={key}- value={url}- domains={domains}- onChange={(e: React.ChangeEvent<HTMLInputElement>) => {- setUrlError(null);- setData({ ...data, url: e.target.value });- }}- required={key !== "_root"}- error={urlError || undefined}- />-- {key !== "_root" && (- <ShortLinkInput- ref={keyRef}- domain={domain}- _key={key}- existingLinkProps={props}- error={keyError || undefined}- onChange={(d) => {- setKeyError(null);- setData((data) => ({ ...data, ...d }));- }}- data={data}- saving={saving}- loading={loading}- domains={domains}- />- )}- </div>-- {/* Divider */}- <div className="relative pb-3 pt-5">- <div- className="absolute inset-0 flex items-center px-4 md:px-16"- aria-hidden="true"- >- <div className="w-full border-t border-gray-300" />- </div>- <div className="relative flex justify-center">- <span className="-translate-y-1 bg-gray-50 px-2 text-sm text-gray-500">- Optional- </span>- </div>- </div>-- <div className="grid gap-5 px-4 md:px-16">- <TagsSection {...{ props, data, setData }} />- <CommentsSection {...{ props, data, setData }} />- {conversionEnabled && (- <ConversionSection {...{ data, setData }} />- )}- <OGSection- {...{ props, data, setData }}- generatingMetatags={generatingMetatags}- />- <UTMSection {...{ props, data, setData }} />- <CloakingSection {...{ data, setData }} />- <PasswordSection {...{ props, data, setData }} />- <ExpirationSection {...{ props, data, setData }} />- <IOSSection {...{ props, data, setData }} />- <AndroidSection {...{ props, data, setData }} />- <GeoSection {...{ props, data, setData }} />- <DoIndexSection {...{ data, setData }} />- </div>-- <div- className={`${- atBottom ? "" : "md:shadow-[0_-20px_30px_-10px_rgba(0,0,0,0.1)]"- } z-10 bg-gray-50 px-4 py-8 transition-all md:sticky md:bottom-0 md:px-16`}- >- {homepageDemo ? (- <Button- disabledTooltip="This is a demo link. You can't edit it."- text="Save changes"- />- ) : (- <Button- disabled={saveDisabled}- loading={saving}- text={props ? "Save changes" : "Create link"}- />- )}- </div>- </form>- </div>- <div className="scrollbar-hide rounded-r-2xl md:max-h-[95vh] md:overflow-auto">- <Preview- data={data}- setData={setData}- generatingMetatags={generatingMetatags}- />- </div>- </div>- </Modal>- );-}--function AddEditLinkButton({- setShowAddEditLinkModal,-}: {- setShowAddEditLinkModal: Dispatch<SetStateAction<boolean>>;-}) {- const { slug, nextPlan, exceededLinks } = useWorkspace();-- const onKeyDown = useCallback((e: KeyboardEvent) => {- const target = e.target as HTMLElement;- const existingModalBackdrop = document.getElementById("modal-backdrop");- // only open modal with keyboard shortcut if:- // - c is pressed- // - user is not pressing cmd/ctrl + c- // - user is not typing in an input or textarea- // - there is no existing modal backdrop (i.e. no other modal is open)- // - workspace has not exceeded links limit- if (- e.key.toLowerCase() === "c" &&- !e.metaKey &&- !e.ctrlKey &&- target.tagName !== "INPUT" &&- target.tagName !== "TEXTAREA" &&- !existingModalBackdrop &&- !exceededLinks- ) {- e.preventDefault(); // or else it'll show up in the input field since that's getting auto-selected- setShowAddEditLinkModal(true);- }- }, []);-- // listen to paste event, and if it's a URL, open the modal and input the URL- const handlePaste = (e: ClipboardEvent) => {- const pastedContent = e.clipboardData?.getData("text");- const target = e.target as HTMLElement;- const existingModalBackdrop = document.getElementById("modal-backdrop");-- // make sure:- // - pasted content is a valid URL- // - user is not typing in an input or textarea- // - there is no existing modal backdrop (i.e. no other modal is open)- // - workspace has not exceeded links limit- if (- pastedContent &&- isValidUrl(pastedContent) &&- target.tagName !== "INPUT" &&- target.tagName !== "TEXTAREA" &&- !existingModalBackdrop &&- !exceededLinks- ) {- setShowAddEditLinkModal(true);- }- };-- useEffect(() => {- document.addEventListener("keydown", onKeyDown);- document.addEventListener("paste", handlePaste);- return () => {- document.removeEventListener("keydown", onKeyDown),- document.removeEventListener("paste", handlePaste);- };- }, [onKeyDown]);-- return (- <Button- text="Create link"- shortcut="C"- disabledTooltip={- exceededLinks ? (- <TooltipContent- title="Your workspace has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to add more links."- cta={`Upgrade to ${nextPlan.name}`}- href={`/${slug}/upgrade`}- />- ) : undefined- }- onClick={() => setShowAddEditLinkModal(true)}- />- );-}--export function useAddEditLinkModal({- props,- duplicateProps,- homepageDemo,-}: {- props?: LinkWithTagsProps;- duplicateProps?: LinkWithTagsProps;- homepageDemo?: boolean;-} = {}) {- const [showAddEditLinkModal, setShowAddEditLinkModal] = useState(false);-- const AddEditLinkModalCallback = useCallback(() => {- return (- <AddEditLinkModal- showAddEditLinkModal={showAddEditLinkModal}- setShowAddEditLinkModal={setShowAddEditLinkModal}- props={props}- duplicateProps={duplicateProps}- homepageDemo={homepageDemo}- />- );- }, [showAddEditLinkModal]);-- const AddEditLinkButtonCallback = useCallback(() => {- return (- <AddEditLinkButton setShowAddEditLinkModal={setShowAddEditLinkModal} />- );- }, []);-- return useMemo(- () => ({- showAddEditLinkModal,- setShowAddEditLinkModal,- AddEditLinkModal: AddEditLinkModalCallback,- AddEditLinkButton: AddEditLinkButtonCallback,- }),- [showAddEditLinkModal, AddEditLinkModalCallback, AddEditLinkButtonCallback],- );-}diff --git a/apps/web/ui/modals/add-edit-link-modal/ios-section.tsx b/apps/web/ui/modals/add-edit-link-modal/ios-section.tsxdeleted file mode 100644index 8e034e4269..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/ios-section.tsx+++ /dev/null@@ -1,69 +0,0 @@-import { LinkProps } from "@/lib/types";-import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";-import { SimpleTooltipContent, Switch } from "@dub/ui";-import { FADE_IN_ANIMATION_SETTINGS } from "@dub/utils";-import { motion } from "framer-motion";-import { Dispatch, SetStateAction, useEffect, useState } from "react";--export default function IOSSection({- props,- data,- setData,-}: {- props?: LinkProps;- data: LinkProps;- setData: Dispatch<SetStateAction<LinkProps>>;-}) {- const { ios } = data;- const [enabled, setEnabled] = useState(!!ios);- useEffect(() => {- if (enabled) {- // if enabling, add previous ios link if exists- setData({- ...data,- ios: props?.ios || ios,- });- } else {- // if disabling, remove ios link- setData({ ...data, ios: null });- }- }, [enabled]);-- return (- <div className="relative border-b border-gray-200 pb-5">- <div className="flex items-center justify-between">- <div className="flex items-center justify-between space-x-2">- <h2 className="text-sm font-medium text-gray-900">iOS Targeting</h2>- <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>- <Switch fn={() => setEnabled(!enabled)} checked={enabled} />- </div>- {enabled && (- <motion.div- className="mt-3 flex rounded-md shadow-sm"- {...FADE_IN_ANIMATION_SETTINGS}- >- <input- name="ios-url"- id="ios-url"- placeholder="https://apps.apple.com/app/1611158928"- value={ios || ""}- onChange={(e) => {- setData({ ...data, ios: e.target.value });- }}- 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"- aria-invalid="true"- />- </motion.div>- )}- </div>- );-}diff --git a/apps/web/ui/modals/add-edit-link-modal/og-section.tsx b/apps/web/ui/modals/add-edit-link-modal/og-section.tsxdeleted file mode 100644index a15ee06a10..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/og-section.tsx+++ /dev/null@@ -1,366 +0,0 @@-import useWorkspace from "@/lib/swr/use-workspace";-import { LinkProps } from "@/lib/types";-import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";-import { UpgradeRequiredToast } from "@/ui/shared/upgrade-required-toast";-import {- ButtonTooltip,- FileUpload,- LoadingCircle,- Magic,- Popover,- SimpleTooltipContent,- Switch,- Unsplash,-} from "@dub/ui";-import { FADE_IN_ANIMATION_SETTINGS, resizeImage } from "@dub/utils";-import { useCompletion } from "ai/react";-import { motion } from "framer-motion";-import { Link2, X } from "lucide-react";-import posthog from "posthog-js";-import { Dispatch, SetStateAction, useEffect, useState } from "react";-import TextareaAutosize from "react-textarea-autosize";-import { toast } from "sonner";-import { usePromptModal } from "../prompt-modal";-import UnsplashSearch from "./unsplash-search";--export default function OGSection({- data,- setData,- generatingMetatags,-}: {- data: LinkProps;- setData: Dispatch<SetStateAction<LinkProps>>;- generatingMetatags: boolean;-}) {- const { id: workspaceId, exceededAI, mutate } = useWorkspace();-- const { setShowPromptModal, PromptModal } = usePromptModal({- title: "Use image from URL",- description:- "Paste an image URL to use for your link's social media cards.",- label: "Image URL",- inputProps: {- type: "url",- placeholder: "https://example.com/og.png",- },- onSubmit: (image) => {- if (image) setData((prev) => ({ ...prev, image }));- },- });-- const { title, description, image, proxy } = data;-- const {- completion: completionTitle,- isLoading: generatingTitle,- complete: completeTitle,- } = useCompletion({- api: `/api/ai/completion?workspaceId=${workspaceId}`,- id: "metatags-title-ai",- onError: (error) => {- if (error.message.includes("Upgrade to Pro")) {- toast.custom(() => (- <UpgradeRequiredToast- title="You've exceeded your AI usage limit"- message={error.message}- />- ));- } else {- toast.error(error.message);- }- },- onFinish: (_, completion) => {- mutate();- posthog.capture("ai_meta_title_generated", {- title: completion,- url: data.url,- });- },- });-- const generateTitle = async () => {- completeTitle(- `You are an SEO expert. Generate an SEO-optimized meta title (max 120 characters) for the following URL:-- - URL: ${data.url}- - Meta title: ${data.title}- - Meta description: ${data.description}.-- Only respond with the title without quotation marks or special characters.- `,- );- };-- useEffect(() => {- if (completionTitle) {- setData((prev) => ({ ...prev, title: completionTitle }));- }- }, [completionTitle]);-- const {- completion: completionDescription,- isLoading: generatingDescription,- complete: completeDescription,- } = useCompletion({- api: `/api/ai/completion?workspaceId=${workspaceId}`,- id: "metatags-description-ai",- onError: (error) => {- if (error.message.includes("Upgrade to Pro")) {- toast.custom(() => (- <UpgradeRequiredToast- title="You've exceeded your AI usage limit"- message={error.message}- />- ));- } else {- toast.error(error.message);- }- },- onFinish: (_, completion) => {- mutate();- posthog.capture("ai_meta_description_generated", {- description: completion,- url: data.url,- });- },- });-- const generateDescription = async () => {- completeDescription(- `You are an SEO expert. Generate an SEO-optimized meta description (max 240 characters) for the following URL:-- - URL: ${data.url}- - Meta title: ${data.title}- - Meta description: ${data.description}.-- Only respond with the description without quotation marks or special characters.`,- );- };-- useEffect(() => {- if (completionDescription) {- setData((prev) => ({ ...prev, description: completionDescription }));- }- }, [completionDescription]);-- const [resizingImage, setResizingImage] = useState(false);-- const [cooldown, setCooldown] = useState(false);- const [openPopover, setOpenPopover] = useState(false);-- // hacky workaround to fix bug with Radix Popover: https://github.com/radix-ui/primitives/issues/2348#issuecomment-1778941310- function handleSet() {- if (cooldown) return;- setOpenPopover(!openPopover);- setCooldown(true);- setTimeout(() => {- setCooldown(false);- }, 200);- }-- return (- <div className="relative grid gap-5 border-b border-gray-200 pb-5">- <div className="flex items-center justify-between">- <div className="flex items-center justify-between space-x-2">- <h2 className="text-sm font-medium text-gray-900">- Custom Social Media Cards- </h2>- <ProBadgeTooltip- content={- <SimpleTooltipContent- title="Customize how your links look when shared on social media."- cta="Learn more."- href="https://dub.co/help/article/custom-social-media-cards"- />- }- />- </div>- <Switch- fn={() => setData((prev) => ({ ...prev, proxy: !proxy }))}- checked={proxy}- />- </div>- {proxy && (- <motion.div- key="og-options"- {...FADE_IN_ANIMATION_SETTINGS}- className="grid gap-5"- >- <div>- <div className="flex items-center justify-between">- <p className="block text-sm font-medium text-gray-700">Image</p>- <div className="flex items-center justify-between">- <ButtonTooltip- tooltipProps={{- content: "Paste a URL to an image.",- }}- onClick={() => setShowPromptModal(true)}- >- <Link2 className="h-4 w-4 text-gray-500" />- </ButtonTooltip>- <Popover- content={- <UnsplashSearch- onImageSelected={(image) =>- setData((prev) => ({ ...prev, image }))- }- setOpenPopover={handleSet}- />- }- openPopover={openPopover}- setOpenPopover={handleSet}- >- <button- onClick={handleSet}- className="flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed"- >- <Unsplash className="h-3 w-3 text-gray-500" />- </button>- </Popover>- </div>- </div>- <div className="relative mt-1">- {image && (- <button- type="button"- className="absolute right-2 top-2 z-[5] rounded-full bg-gray-100 p-1 transition-all hover:bg-gray-200"- onClick={() => {- setData((prev) => ({ ...prev, image: null }));- }}- >- <X className="size-3.5" />- </button>- )}- <FileUpload- accept="images"- imageSrc={image}- onChange={async ({ file }) => {- setResizingImage(true);-- const image = await resizeImage(file);- setData((prev) => ({- ...prev,- image,- }));-- // Delay to prevent flickering- setTimeout(() => setResizingImage(false), 500);- }}- loading={generatingMetatags || resizingImage}- accessibilityLabel="OG image upload"- content={- <>- <p>Drag and drop or click to upload.</p>- <p className="mt-2">Recommended: 1200 x 630 pixels</p>- </>- }- />- </div>- </div>-- <div>- <div className="flex items-center justify-between">- <p className="block text-sm font-medium text-gray-700">Title</p>- <div className="flex items-center gap-2">- <p className="text-sm text-gray-500">- {title?.length || 0}/120- </p>- <ButtonTooltip- tooltipProps={{- content: exceededAI- ? "You've exceeded your AI usage limit"- : !title- ? "Enter a title to generate a preview"- : "Generate an optimized title using AI.",- }}- onClick={generateTitle}- disabled={generatingTitle || exceededAI || !title}- >- {generatingTitle ? (- <LoadingCircle />- ) : (- <Magic className="h-4 w-4" />- )}- </ButtonTooltip>- </div>- </div>- <div className="relative mt-1 flex rounded-md shadow-sm">- {generatingMetatags && (- <div className="absolute flex h-full w-full items-center justify-center rounded-md border border-gray-300 bg-white">- <LoadingCircle />- </div>- )}- <TextareaAutosize- name="title"- id="title"- minRows={3}- maxLength={120}- 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"- placeholder={`${process.env.NEXT_PUBLIC_APP_NAME} - open-source link management infrastructure.`}- value={title || ""}- onChange={(e) => {- setData({ ...data, title: e.target.value });- }}- aria-invalid="true"- />- </div>- </div>-- <div>- <div className="flex items-center justify-between">- <p className="block text-sm font-medium text-gray-700">- Description- </p>- <div className="flex items-center gap-2">- <p className="text-sm text-gray-500">- {description?.length || 0}/240- </p>- <ButtonTooltip- tooltipProps={{- content: exceededAI- ? "You've exceeded your AI usage limit"- : !description- ? "Enter a description to generate a preview"- : "Generate an optimized description using AI.",- }}- onClick={generateDescription}- disabled={generatingDescription || exceededAI || !description}- >- {generatingDescription ? (- <LoadingCircle />- ) : (- <Magic className="h-4 w-4" />- )}- </ButtonTooltip>- </div>- </div>- <div className="relative mt-1 flex rounded-md shadow-sm">- {generatingMetatags && (- <div className="absolute flex h-full w-full items-center justify-center rounded-md border border-gray-300 bg-white">- <LoadingCircle />- </div>- )}- <TextareaAutosize- name="description"- id="description"- minRows={3}- maxLength={240}- 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"- placeholder={`${process.env.NEXT_PUBLIC_APP_NAME} is open-source link management infrastructure for modern marketing teams.`}- value={description || ""}- onChange={(e) => {- setData({- ...data,- description: e.target.value,- });- }}- aria-invalid="true"- />- </div>- </div>- </motion.div>- )}- <PromptModal />- </div>- );-}diff --git a/apps/web/ui/modals/add-edit-link-modal/password-section.tsx b/apps/web/ui/modals/add-edit-link-modal/password-section.tsxdeleted file mode 100644index 90d9caef4f..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/password-section.tsx+++ /dev/null@@ -1,102 +0,0 @@-import { LinkProps } from "@/lib/types";-import { Eye, EyeOff, Random } from "@/ui/shared/icons";-import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";-import { SimpleTooltipContent, Switch } from "@dub/ui";-import { ButtonTooltip } from "@dub/ui/src/tooltip";-import { FADE_IN_ANIMATION_SETTINGS, nanoid } from "@dub/utils";-import { motion } from "framer-motion";-import { Dispatch, SetStateAction, useEffect, useState } from "react";--export default function PasswordSection({- props,- data,- setData,-}: {- props?: LinkProps;- data: LinkProps;- setData: Dispatch<SetStateAction<LinkProps>>;-}) {- const { password } = data;- const [enabled, setEnabled] = useState(!!password);- useEffect(() => {- if (enabled) {- // if enabling, add previous password if exists- setData({- ...data,- password: props?.password || password,- });- } else {- // if disabling, remove password- setData({ ...data, password: null });- }- }, [enabled]);-- const [showPassword, setShowPassword] = useState(false);-- return (- <div className="relative border-b border-gray-200 pb-5">- <div className="flex items-center justify-between">- <div className="flex items-center justify-between gap-2">- <h2 className="text-sm font-medium text-gray-900">- Password Protection- </h2>- <ProBadgeTooltip- content={- <SimpleTooltipContent- title="Restrict access to your short links by encrypting it with a password."- cta="Learn more."- href="https://dub.co/help/article/password-protected-links"- />- }- />- </div>- <div className="flex items-center gap-2">- {enabled && (- <ButtonTooltip- tooltipProps={{- content: "Generate a random password",- }}- onClick={() => {- setData({ ...data, password: nanoid(24) });- }}- className="flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed"- >- <Random className="h-3 w-3" />- </ButtonTooltip>- )}- <Switch fn={() => setEnabled(!enabled)} checked={enabled} />- </div>- </div>- {enabled && (- <motion.div- className="relative mt-3 rounded-md shadow-sm"- {...FADE_IN_ANIMATION_SETTINGS}- >- <input- name="password"- id="password"- type={showPassword ? "text" : "password"}- 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"- value={password || ""}- placeholder="Enter password"- onChange={(e) => {- setData({ ...data, password: e.target.value });- }}- aria-invalid="true"- />- <button- type="button"- onClick={() => setShowPassword(!showPassword)}- className="absolute inset-y-0 right-0 flex items-center pr-3"- >- {showPassword ? (- <Eye className="h-4 w-4 text-gray-400" aria-hidden="true" />- ) : (- <EyeOff className="h-4 w-4 text-gray-400" aria-hidden="true" />- )}- </button>- </motion.div>- )}- </div>- );-}diff --git a/apps/web/ui/modals/add-edit-link-modal/preview.tsx b/apps/web/ui/modals/add-edit-link-modal/preview.tsxdeleted file mode 100644index 76f4c19ef2..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/preview.tsx+++ /dev/null@@ -1,390 +0,0 @@-import { LinkProps } from "@/lib/types";-import {- AnimatedSizeContainer,- Facebook,- FileUpload,- LinkedIn,- LoadingCircle,- Photo,- Popover,- Twitter,- Unsplash,- useMediaQuery,-} from "@dub/ui";-import { Button } from "@dub/ui/src/button";-import { getDomainWithoutWWW, resizeImage } from "@dub/utils";-import { Edit2, Link2, Upload } from "lucide-react";-import {- ChangeEvent,- Dispatch,- RefObject,- SetStateAction,- useCallback,- useMemo,- useRef,- useState,-} from "react";-import ReactTextareaAutosize from "react-textarea-autosize";-import { toast } from "sonner";-import { useDebounce } from "use-debounce";-import { usePromptModal } from "../prompt-modal";-import UnsplashSearch from "./unsplash-search";--export default function Preview({- data,- setData,- generatingMetatags,-}: {- data: LinkProps;- setData: Dispatch<SetStateAction<LinkProps>>;- generatingMetatags: boolean;-}) {- const { title, description, image, url, password } = data;- const [debouncedUrl] = useDebounce(url, 500);- const hostname = useMemo(() => {- if (password) return "dub.co";- return getDomainWithoutWWW(debouncedUrl);- }, [password, debouncedUrl]);-- const onImageChange = (image: string) =>- setData((prev) => ({ ...prev, image, proxy: true }));-- return (- <div>- <div className="sticky top-0 z-10 flex h-14 items-center justify-center border-b border-gray-200 bg-white px-5 sm:h-24">- <h2 className="text-lg font-medium">Social Previews</h2>- </div>- <div className="grid gap-5 p-5">- {/* Twitter */}- <div>- <div className="relative mb-2">- <div- className="absolute inset-0 flex items-center"- aria-hidden="true"- >- <div className="w-full border-t border-gray-200" />- </div>- <div className="relative flex justify-center">- <div className="flex items-center space-x-2 bg-white px-3">- <Twitter className="h-3 w-3" />- <p className="text-sm text-gray-400">Twitter</p>- </div>- </div>- </div>- <div className="group relative overflow-hidden rounded-2xl border border-gray-300">- <ImagePreview- image={image}- onImageChange={onImageChange}- generatingMetatags={generatingMetatags}- />- {(title || title === "") && (- <div className="absolute bottom-2 left-2 rounded-md bg-[#414142] px-1.5 py-px">- <h3 className="max-w-sm truncate text-sm text-white">- {title}- </h3>- </div>- )}- </div>- {hostname && (- <p className="mt-2 text-[0.8rem] text-[#606770]">{hostname}</p>- )}- </div>-- {/* Facebook */}- <div>- <div className="relative mb-2">- <div- className="absolute inset-0 flex items-center"- aria-hidden="true"- >- <div className="w-full border-t border-gray-200" />- </div>- <div className="relative flex justify-center">- <div className="flex items-center space-x-2 bg-white px-3">- <Facebook className="h-4 w-4" />- <p className="text-sm text-gray-400">Facebook</p>- </div>- </div>- </div>- <div className="relative border border-gray-300">- <ImagePreview- image={image}- onImageChange={onImageChange}- generatingMetatags={generatingMetatags}- />- <div className="grid gap-1 border-t border-gray-300 bg-[#f2f3f5] p-3">- {hostname ? (- <p className="text-[0.8rem] uppercase text-[#606770]">- {hostname}- </p>- ) : (- <div className="mb-1 h-4 w-24 rounded-md bg-gray-200" />- )}- {title || title === "" ? (- <input- className="truncate border-none bg-transparent p-0 font-semibold text-[#1d2129] outline-none focus:ring-0"- value={title}- onChange={(e) => {- setData((prev) => ({- ...prev,- title: e.currentTarget.value,- proxy: true,- }));- }}- />- ) : (- <div className="mb-1 h-5 w-full rounded-md bg-gray-200" />- )}- {description || description === "" ? (- <ReactTextareaAutosize- className="mb-1 line-clamp-2 w-full resize-none rounded-md border-none bg-gray-200 bg-transparent p-0 text-sm text-[#606770] outline-none focus:ring-0"- value={description}- maxRows={2}- onChange={(e) => {- setData((prev) => ({- ...prev,- description: e.currentTarget.value,- proxy: true,- }));- }}- />- ) : (- <div className="grid gap-2">- <div className="h-4 w-full rounded-md bg-gray-200" />- <div className="h-4 w-48 rounded-md bg-gray-200" />- </div>- )}- </div>- </div>- </div>-- {/* LinkedIn */}- <div>- <div className="relative mb-2">- <div- className="absolute inset-0 flex items-center"- aria-hidden="true"- >- <div className="w-full border-t border-gray-200" />- </div>- <div className="relative flex justify-center">- <div className="flex items-center space-x-2 bg-white px-3">- <LinkedIn className="h-4 w-4 text-[#0077b5]" />- <p className="text-sm text-gray-400">LinkedIn</p>- </div>- </div>- </div>- <div className="relative overflow-hidden rounded-[2px] shadow-[0_0_0_1px_rgba(0,0,0,0.15),0_2px_3px_rgba(0,0,0,0.2)]">- <ImagePreview- image={image}- onImageChange={onImageChange}- generatingMetatags={generatingMetatags}- />- <div className="grid gap-1 border-t border-gray-300 bg-white p-3">- {title || title === "" ? (- <input- className="truncate border-none bg-transparent p-0 font-semibold text-[#000000E6] outline-none focus:ring-0"- value={title}- onChange={(e) => {- setData((prev) => ({- ...prev,- title: e.currentTarget.value,- proxy: true,- }));- }}- />- ) : (- <div className="mb-1 h-5 w-full rounded-md bg-gray-200" />- )}- {hostname ? (- <p className="text-xs text-[#00000099]">{hostname}</p>- ) : (- <div className="mb-1 h-4 w-24 rounded-md bg-gray-200" />- )}- </div>- </div>- </div>- </div>- </div>- );-}--const ImagePreview = ({- image,- onImageChange,- generatingMetatags,-}: {- image: string | null;- onImageChange: (image: string) => void;- generatingMetatags?: boolean;-}) => {- const inputFileRef = useRef<HTMLInputElement>(null);-- const [openPopover, setOpenPopover] = useState(false);- const [resizing, setResizing] = useState(false);-- const { setShowPromptModal, PromptModal } = usePromptModal({- title: "Use image from URL",- description:- "Paste an image URL to use for your link's social media cards.",- label: "Image URL",- inputProps: {- placeholder: "https://example.com/og.png",- },- onSubmit: (image) => {- if (image) onImageChange(image);- },- });-- const onInputFileChange = useCallback(- async (e: ChangeEvent<HTMLInputElement>) => {- const file = e.target.files && e.target.files[0];- if (!file) return;-- if (file.size / 1024 / 1024 > 2) {- toast.error(`File size too big (max 2 MB)`);- return;- }-- setResizing(true);-- const src = await resizeImage(file);- onImageChange(src);-- // Delay to prevent flickering- setTimeout(() => setResizing(false), 500);- },- [],- );-- const previewImage = useMemo(() => {- if (generatingMetatags || resizing) {- return (- <div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 bg-gray-100">- <LoadingCircle />- </div>- );- }- if (image) {- return (- <FileUpload- accept="images"- variant="plain"- imageSrc={image}- onChange={async ({ file }) => {- setResizing(true);-- onImageChange(await resizeImage(file));-- // Delay to prevent flickering- setTimeout(() => setResizing(false), 500);- }}- loading={generatingMetatags || resizing}- clickToUpload={false}- showHoverOverlay={false}- accessibilityLabel="OG image upload"- />- );- } else {- return (- <div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 bg-gray-100">- <Photo className="h-8 w-8 text-gray-400" />- <p className="text-sm text-gray-400">- Enter a link to generate a preview.- </p>- </div>- );- }- }, [image, generatingMetatags, resizing]);-- return (- <>- {previewImage}- <Popover- align="end"- content={- <ImagePreviewPopoverContent- onImageChange={onImageChange}- inputFileRef={inputFileRef}- setOpenPopover={setOpenPopover}- setShowPromptModal={setShowPromptModal}- />- }- openPopover={openPopover}- setOpenPopover={setOpenPopover}- >- <Button- variant="secondary"- onClick={() => setOpenPopover(!openPopover)}- icon={<Edit2 className="h-3 w-3" />}- className="absolute right-2 top-2 h-8 w-8 rounded-md p-0 transition-all hover:bg-gray-100"- />- </Popover>- <input- key={image}- ref={inputFileRef}- onChange={onInputFileChange}- type="file"- accept="image/png,image/jpeg"- className="hidden"- />- <PromptModal />- </>- );-};--const ImagePreviewPopoverContent = ({- onImageChange,- inputFileRef,- setOpenPopover,- setShowPromptModal,-}: {- onImageChange: (image: string) => void;- inputFileRef: RefObject<HTMLInputElement>;- setOpenPopover: Dispatch<SetStateAction<boolean>>;- setShowPromptModal: Dispatch<SetStateAction<boolean>>;-}) => {- const { isMobile } = useMediaQuery();-- const [state, setState] = useState<"default" | "unsplash">("default");-- return (- <AnimatedSizeContainer width={!isMobile} height>- {state === "unsplash" && (- <UnsplashSearch- onImageSelected={onImageChange}- setOpenPopover={setOpenPopover}- />- )}-- {state === "default" && (- <div className="grid gap-px p-2">- <Button- text="Upload image"- variant="outline"- icon={<Upload className="h-4 w-4" />}- className="h-9 justify-start px-2 font-medium disabled:border-none disabled:bg-transparent"- onClick={() => {- inputFileRef.current?.click();- setOpenPopover(false);- }}- />- <Button- text="Use image from URL"- variant="outline"- icon={<Link2 className="h-4 w-4" />}- className="h-9 justify-start px-2 font-medium"- onClick={() => setShowPromptModal(true)}- />- <Button- text="Use image from Unsplash"- variant="outline"- icon={<Unsplash className="h-4 w-4 p-0.5" />}- className="h-9 justify-start px-2 font-medium"- onClick={() => setState("unsplash")}- />- </div>- )}- </AnimatedSizeContainer>- );-};diff --git a/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx b/apps/web/ui/modals/add-edit-link-modal/tags-section.tsxdeleted file mode 100644index 878769557c..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx+++ /dev/null@@ -1,326 +0,0 @@-import useTags from "@/lib/swr/use-tags";-import useWorkspace from "@/lib/swr/use-workspace";-import { LinkWithTagsProps, TagProps } from "@/lib/types";-import TagBadge from "@/ui/links/tag-badge";-import {- Badge,- LoadingCircle,- Magic,- SimpleTooltipContent,- Tooltip,-} from "@dub/ui";-import { useCompletion } from "ai/react";-import { Command, useCommandState } from "cmdk";-import { Check, ChevronDown, Tag, X } from "lucide-react";-import posthog from "posthog-js";-import { Dispatch, SetStateAction, useEffect, useRef, useState } from "react";-import { toast } from "sonner";-import { mutate } from "swr";-import { useDebounce } from "use-debounce";--export default function TagsSection({- data,- setData,-}: {- data: LinkWithTagsProps;- setData: Dispatch<SetStateAction<LinkWithTagsProps>>;-}) {- const { tags: availableTags } = useTags();- const { id: linkId, url, title, description, tags } = data;-- const [inputValue, setInputValue] = useState("");-- const {- id: workspaceId,- exceededAI,- mutate: mutateWorkspace,- } = useWorkspace();-- const [suggestedTags, setSuggestedTags] = useState<TagProps[]>([]);- const tagMatch = availableTags- ?.map(({ name }) => name)- .includes(inputValue.trim());-- const { complete } = useCompletion({- api: `/api/ai/completion?workspaceId=${workspaceId}`,- body: {- model: "claude-3-haiku-20240307",- },- onError: (error) => {- toast.error(error.message);- },- onFinish: (_, completion) => {- mutateWorkspace();- if (completion) {- const completionArr = completion.split(", ");- const suggestedTags = completionArr- .map((tag: string) => {- return availableTags?.find(({ name }) => name === tag) || null;- })- .filter(Boolean);- setSuggestedTags(suggestedTags as TagProps[]);- }- },- });-- const [debouncedUrl] = useDebounce(url, 500);-- useEffect(() => {- if (- !linkId &&- debouncedUrl &&- title &&- description &&- !exceededAI &&- tags.length === 0 &&- suggestedTags.length === 0 &&- availableTags &&- availableTags.length > 0- ) {- complete(- `From the list of avaialble tags below, suggest relevant tags for this link:-- - URL: ${debouncedUrl}- - Meta title: ${title}- - Meta description: ${description}.-- Only return the tag names in comma-separated format, and nothing else. If there are no relevant tags, return an empty string.-- Available tags: ${availableTags.map(({ name }) => name).join(", ")}`,- );- }- }, [debouncedUrl, title, description]);-- const [creatingTag, setCreatingTag] = useState(false);-- const createTag = async (tag: string) => {- setCreatingTag(true);- setInputValue("");- fetch(`/api/tags?workspaceId=${workspaceId}`, {- method: "POST",- headers: {- "Content-Type": "application/json",- },- body: JSON.stringify({ tag }),- }).then(async (res) => {- if (res.ok) {- await mutate(`/api/tags?workspaceId=${workspaceId}`);- const newTag = await res.json();- setData({ ...data, tags: [...tags, newTag] });- toast.success(`Successfully created tag!`);- setCreatingTag(false);- } else {- const { error } = await res.json();- toast.error(error.message);- }- });- };-- const commandRef = useRef<HTMLDivElement | null>(null);- const [openCommandList, setOpenCommandList] = useState(false);-- useEffect(() => {- const handleClickOutside = (e) => {- if (commandRef.current && !commandRef.current.contains(e.target)) {- setOpenCommandList(false);- }- };- if (openCommandList) {- document.addEventListener("click", handleClickOutside);- return () => document.removeEventListener("click", handleClickOutside);- }- }, [commandRef, openCommandList]);-- const CommandInput = () => {- const isEmpty = useCommandState((state) => state.filtered.count === 0);- return (- <Command.Input- placeholder="Select tags..."- // hack to focus on the input when the dropdown opens- autoFocus={openCommandList}- // when focus on the input. only show the dropdown if there are tags and the tagValue is not empty- onFocus={() => setOpenCommandList(true)}- value={inputValue}- onValueChange={setInputValue}- onKeyDown={(e) => {- if (e.key === "Escape") {- setOpenCommandList(false);-- // listen for cases where empty results and enter is pressed- } else if (e.key === "Enter" && isEmpty) {- setOpenCommandList(false);- createTag(inputValue);-- // remove the last tag if backspaced- } else if (- ["Backspace", "Delete"].includes(e.key) &&- inputValue === ""- ) {- setData((data) => {- const popped = [...data.tags];- popped.pop();- return { ...data, tags: popped };- });-- // if it's a letter or a number and there's no meta key pressed, openCommandList dropdown- } else if (e.key.match(/^[a-z0-9]$/i) && !e.metaKey) {- setOpenCommandList(true);- }- }}- className="block grow rounded-md border-none px-0 py-1 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-0 sm:text-sm"- />- );- };-- return (- <div className="border-b border-gray-200 pb-2">- <Command- ref={commandRef}- className="relative"- loop- filter={(value, search) => (value.includes(search.trim()) ? 1 : 0)}- >- <div className="group rounded-md border border-gray-300 bg-white p-1 focus-within:border-gray-500 focus-within:ring-1 focus-within:ring-gray-500">- <div className="absolute inset-y-0 left-0 flex items-center justify-center pl-3 text-gray-400">- {creatingTag ? (- <LoadingCircle />- ) : (- <Tooltip- content={- <SimpleTooltipContent- title={`Tags are used to organize your links in your ${process.env.NEXT_PUBLIC_APP_NAME} dashboard.`}- cta="Learn more about tags."- href="https://dub.co/help/article/how-to-use-tags"- />- }- >- <Tag className="h-4 w-4" />- </Tooltip>- )}- </div>- <div className="flex flex-wrap space-x-1.5 px-8">- {tags.map((tag) => (- <TagBadge key={tag.id} {...tag} />- ))}- <CommandInput />- {tags.length ? (- <button- type="button"- onClick={() => {- setData({ ...data, tags: [] });- setInputValue("");- }}- className="absolute inset-y-0 right-0 my-auto text-gray-400 hover:text-gray-500"- >- <X className="h-7 w-7 pr-3" />- </button>- ) : (- <ChevronDown className="absolute inset-y-0 right-0 my-auto h-7 w-7 pr-3 text-gray-400 transition-all" />- )}- </div>- </div>- {openCommandList && (- <Command.List className="absolute z-20 mt-2 h-[calc(var(--cmdk-list-height)+17px)] max-h-[300px] w-full overflow-auto rounded-md border border-gray-200 bg-white p-2 shadow-md transition-all">- {availableTags?.length === 0 && inputValue.length === 0 && (- <p className="px-4 py-2.5 text-sm text-gray-900">- Start typing to create tag...- </p>- )}- <Command.Empty>- {inputValue.length > 0 && (- <button- type="button"- onClick={() => createTag(inputValue)}- className="flex w-full cursor-pointer items-center rounded-md bg-gray-100 px-4 py-2 text-sm text-gray-900 hover:text-gray-900 aria-selected:bg-gray-100 aria-selected:text-gray-900"- >- Create tag{" "}- <span className="ml-1.5 rounded-md bg-gray-200 px-2 py-0.5 text-gray-800">- {inputValue}- </span>- </button>- )}- </Command.Empty>- {availableTags?.map((tag) => (- <Command.Item- key={tag.id}- value={tag.name}- onSelect={() => {- const isRemoving = data.tags- .map(({ id }) => id)- .includes(tag.id);- setData({- ...data,- tags: isRemoving- ? data.tags.filter(({ id }) => id !== tag.id)- : [...data.tags, tag],- });- setInputValue("");- }}- className="group flex cursor-pointer items-center justify-between rounded-md px-4 py-2 text-sm text-gray-900 hover:bg-gray-100 hover:text-gray-900 active:bg-gray-200 aria-selected:bg-gray-100 aria-selected:text-gray-900"- >- <TagBadge {...tag} />- {tags.map(({ id }) => id).includes(tag.id) && (- <Check className="h-5 w-5 text-gray-500" />- )}- </Command.Item>- ))}-- {inputValue.length > 0 && !tagMatch && (- <Command.Item- key="create-tag"- value={inputValue}- onSelect={(tag) => createTag(tag)}- className="group flex cursor-pointer items-center justify-between rounded-md px-4 py-2 text-sm text-gray-900 hover:bg-gray-100 hover:text-gray-900 active:bg-gray-200 aria-selected:bg-gray-100 aria-selected:text-gray-900"- >- <div className="flex items-center">- Create tag{" "}- <span className="ml-1.5 rounded-md bg-gray-200 px-2 py-0.5 text-gray-800">- {inputValue}- </span>- </div>- </Command.Item>- )}- </Command.List>- )}- </Command>- <div className="flex min-h-[40px] flex-wrap items-center gap-x-2 gap-y-1 py-2">- {suggestedTags.length > 0 && (- <>- <Tooltip content="AI-suggested tags based on the content of the link. Click to add.">- <div className="group">- <Magic className="h-4 w-4 transition-colors group-hover:text-gray-500" />- </div>- </Tooltip>- {suggestedTags.map((tag) => (- <button- type="button"- key={tag.id}- onClick={() => {- setData({- ...data,- tags: [...tags, tag],- });- setSuggestedTags((tags) =>- tags.filter(({ id }) => id !== tag.id),- );- posthog.capture("ai_suggested_tag_selected", {- tag: tag.name,- url: url,- });- }}- className="group flex items-center transition-all active:scale-95"- >- <Badge- variant="neutral"- className="transition-colors group-hover:border-gray-700 group-hover:text-gray-700"- >- {tag.name}- </Badge>- </button>- ))}- </>- )}- </div>- </div>- );-}diff --git a/apps/web/ui/modals/add-edit-link-modal/unsplash-search.tsx b/apps/web/ui/modals/add-edit-link-modal/unsplash-search.tsxdeleted file mode 100644index 9543041e8e..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/unsplash-search.tsx+++ /dev/null@@ -1,105 +0,0 @@-import { LoadingSpinner, useMediaQuery } from "@dub/ui";-import { fetcher } from "@dub/utils";-import { Dispatch, SetStateAction, useState } from "react";-import { toast } from "sonner";-import useSWR from "swr";-import { Basic } from "unsplash-js/dist/methods/photos/types";-import { useDebounce } from "use-debounce";--export default function UnsplashSearch({- onImageSelected,- setOpenPopover,-}: {- onImageSelected: (image: string) => void;- setOpenPopover: Dispatch<SetStateAction<boolean>>;-}) {- const [search, setSearch] = useState("");- const [debouncedQuery] = useDebounce(search, 500);- const { data } = useSWR<Basic[]>(- `/api/unsplash/search?query=${- debouncedQuery.length > 0 ? debouncedQuery : "beautiful landscape photos"- }`,- fetcher,- {- onError: (err) => {- toast.error(err.message);- },- },- );- const { isMobile } = useMediaQuery();-- return (- <div- className="h-[24rem] w-full overflow-auto p-3 md:w-[24rem]"- // Fixes a Webkit issue where elements outside of the visible area are still interactable- style={{ WebkitClipPath: "inset(0 0 0 0)" }}- >- <div className="relative mt-1 rounded-md shadow-sm">- <input- type="text"- name="search"- id="search"- placeholder="Search for an image..."- autoFocus={!isMobile}- autoComplete="off"- value={search}- onChange={(e) => setSearch(e.target.value)}- className="block w-full rounded-md border-gray-300 py-1 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"- />- </div>- {data ? (- data.length > 0 ? (- <div className="mt-3 grid grid-cols-2 gap-3">- {data.map((photo) => (- <button- key={photo.id}- type="button"- onClick={() => {- onImageSelected(photo.urls.regular);- setOpenPopover(false);- fetch("/api/unsplash/download", {- method: "POST",- headers: {- "Content-Type": "application/json",- },- body: JSON.stringify({- url: photo.links.download_location,- }),- });- }}- className="relative flex h-24 w-full items-center justify-center overflow-hidden rounded-md bg-gray-100 transition-all hover:brightness-75"- >- <img- src={photo.urls.small}- alt={photo.alt_description || "Unsplash image"}- className="absolute h-full w-full object-cover"- />- <p className="absolute bottom-0 left-0 right-0 line-clamp-1 w-full bg-black bg-opacity-10 p-1 text-xs text-white">- by{" "}- <a- className="underline underline-offset-2"- target="_blank"- rel="noopener noreferrer"- href={`${photo.user.links.html}?utm_source=dub.co&utm_medium=referral`}- >- {photo.user.name}- </a>- </p>- </button>- ))}- </div>- ) : (- <div className="flex h-[90%] items-center justify-center">- <p className="text-center text-sm text-gray-500">- No results found. <br /> Maybe try tweaking your search query?- </p>- </div>- )- ) : (- <div className="flex h-[90%] items-center justify-center">- <LoadingSpinner />- </div>- )}- </div>- );-}diff --git a/apps/web/ui/modals/add-edit-link-modal/utm-section.tsx b/apps/web/ui/modals/add-edit-link-modal/utm-section.tsxdeleted file mode 100644index ff01e745e2..0000000000--- a/apps/web/ui/modals/add-edit-link-modal/utm-section.tsx+++ /dev/null@@ -1,117 +0,0 @@-import { LinkProps } from "@/lib/types";-import { InfoTooltip, SimpleTooltipContent, Switch } from "@dub/ui";-import {- FADE_IN_ANIMATION_SETTINGS,- UTMTags,- constructURLFromUTMParams,- getParamsFromURL,- getUrlWithoutUTMParams,- paramsMetadata,-} from "@dub/utils";-import { motion } from "framer-motion";-import { Dispatch, SetStateAction, useEffect, useMemo, useState } from "react";--export default function UTMSection({- props,- data,- setData,-}: {- props?: LinkProps;- data: LinkProps;- setData: Dispatch<SetStateAction<LinkProps>>;-}) {- const { url } = data;- const isValidUrl = useMemo(() => {- try {- new URL(url);- return true;- } catch (e) {- return false;- }- }, [url]);-- const params = useMemo(() => {- return getParamsFromURL(url);- }, [url]);-- const [enabled, setEnabled] = useState(- paramsMetadata.some((param) => params[param.key]),- );-- useEffect(() => {- if (enabled) {- // if enabling, add all params from props if exists && it's still the same URL- setData({- ...data,- url:- props?.url &&- getUrlWithoutUTMParams(props?.url) === getUrlWithoutUTMParams(url)- ? props?.url- : url,- });- } else {- // if disabling, remove all UTM params- setData({- ...data,- ...UTMTags.reduce((acc, tag) => {- acc[tag] = null;- return acc;- }, {}),- url: getUrlWithoutUTMParams(url),- });- }- }, [enabled]);-- return (- <div className="relative border-b border-gray-200 pb-5">- <div className="flex items-center justify-between">- <div className="flex items-center justify-between space-x-2">- <h2 className="text-sm font-medium text-gray-900">UTM Builder</h2>- <InfoTooltip- content={- <SimpleTooltipContent- title="Add UTM parameters to your short links for conversion tracking."- cta="Learn more."- href="https://dub.co/help/article/utm-builder"- />- }- />- </div>- <Switch fn={() => setEnabled(!enabled)} checked={enabled} />- </div>- {enabled && (- <motion.div className="mt-3 grid gap-2" {...FADE_IN_ANIMATION_SETTINGS}>- {paramsMetadata.map(({ display, key, examples }) => (- <div key={key} className="relative mt-1 flex rounded-md shadow-sm">- <span className="flex w-60 items-center justify-center whitespace-nowrap rounded-l-md border border-r-0 border-gray-300 bg-gray-50 text-gray-500 sm:text-sm">- {display}- </span>- <input- type="text"- name={key}- id={key}- disabled={!isValidUrl}- className={`${- isValidUrl ? "" : "cursor-not-allowed bg-gray-100"- } block w-full rounded-r-md border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm`}- placeholder={examples}- value={params[key] || ""}- autoCapitalize="none"- onChange={(e) => {- setData({- ...data,- [key]: e.target.value,- url: constructURLFromUTMParams(url, {- ...params,- [key]: e.target.value,- }),- });- }}- />- </div>- ))}- </motion.div>- )}- </div>- );-}diff --git a/apps/web/ui/modals/link-builder/link-preview.tsx b/apps/web/ui/modals/link-builder/link-preview.tsxindex 7c9df3b2c7..64f90beaef 100644--- a/apps/web/ui/modals/link-builder/link-preview.tsx+++ b/apps/web/ui/modals/link-builder/link-preview.tsx@@ -1,8 +1,8 @@+import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";import {Button,FileUpload,Icon,- InfoTooltip,ShimmerDots,SimpleTooltipContent,useKeyboardShortcut,@@ -96,7 +96,7 @@ export function LinkPreview() {<div className="flex items-center justify-between"><div className="flex items-center gap-2"><h2 className="text-sm font-medium text-gray-700">Link Preview</h2>- <InfoTooltip+ <ProBadgeTooltipcontent={<SimpleTooltipContenttitle="Customize how your links look when shared on social media to improve click-through rates."