Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

disable editing default link

Steven Teye93ed8c170d4
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/links/partner-link-card.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/links/partner-link-card.tsx
index b175347be7..ee3752ce07 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/links/partner-link-card.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/links/partner-link-card.tsx
@@ -63,6 +63,7 @@ export function PartnerLinkCard({
const { programEnrollment } = useProgramEnrollment();
const { setShowPartnerLinkModal, PartnerLinkModal } = usePartnerLinkModal({
link,
+ isDefaultLink,
});
const ref = useRef<HTMLDivElement>(null);
diff --git a/apps/web/ui/modals/partner-link-modal.tsx b/apps/web/ui/modals/partner-link-modal.tsx
index 72e74bd27b..200950228c 100644
--- a/apps/web/ui/modals/partner-link-modal.tsx
+++ b/apps/web/ui/modals/partner-link-modal.tsx
@@ -3,7 +3,7 @@
import { mutateSuffix } from "@/lib/swr/mutate";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
import { PartnerProfileLinkProps } from "@/lib/types";
-import { X } from "@/ui/shared/icons";
+import { Lock, X } from "@/ui/shared/icons";
import { QRCode } from "@/ui/shared/qr-code";
import {
Button,
@@ -11,13 +11,19 @@ import {
Modal,
ShimmerDots,
SimpleTooltipContent,
+ Tooltip,
useCopyToClipboard,
useEnterSubmit,
useLocalStorage,
useMediaQuery,
} from "@dub/ui";
import { ArrowTurnLeft, Pen2, QRCode as QRCodeIcon } from "@dub/ui/icons";
-import { getDomainWithoutWWW, linkConstructor } from "@dub/utils";
+import {
+ cn,
+ getDomainWithoutWWW,
+ getPrettyUrl,
+ linkConstructor,
+} from "@dub/utils";
import { AnimatePresence, motion } from "framer-motion";
import {
Dispatch,
@@ -41,12 +47,14 @@ interface PartnerLinkFormData {
interface PartnerLinkModalProps {
link?: PartnerProfileLinkProps;
+ isDefaultLink?: boolean;
showPartnerLinkModal: boolean;
setShowPartnerLinkModal: Dispatch<SetStateAction<boolean>>;
}
export function PartnerLinkModal({
link,
+ isDefaultLink,
showPartnerLinkModal,
setShowPartnerLinkModal,
}: PartnerLinkModalProps) {
@@ -58,6 +66,7 @@ export function PartnerLinkModal({
>
<PartnerLinkModalContent
link={link}
+ isDefaultLink={isDefaultLink}
setShowPartnerLinkModal={setShowPartnerLinkModal}
/>
</Modal>
@@ -151,16 +160,20 @@ function QRCodePreview({
function PartnerLinkModalContent({
link,
+ isDefaultLink,
setShowPartnerLinkModal,
}: {
link?: PartnerProfileLinkProps;
+ isDefaultLink?: boolean;
setShowPartnerLinkModal: Dispatch<SetStateAction<boolean>>;
}) {
const { programEnrollment } = useProgramEnrollment();
const destinationDomain =
getDomainWithoutWWW(programEnrollment?.program?.url || "https://dub.co") ??
"dub.co";
- const shortLinkDomain = programEnrollment?.program?.domain || "dub.sh";
+ const shortLinkDomain = programEnrollment?.program?.domain ?? "dub.sh";
+
+ const [lockKey, setLockKey] = useState(Boolean(link));
const form = useForm<PartnerLinkFormData>({
defaultValues: link
@@ -278,49 +291,72 @@ function PartnerLinkModalContent({
}
/>
</div>
- <div className="mt-2 flex rounded-md">
- <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
- {destinationDomain}
- </span>
- <input
- {...register("url", { required: false })}
- type="text"
- id="url"
- placeholder="(optional)"
- autoFocus={!isMobile}
- onPaste={(e: React.ClipboardEvent<HTMLInputElement>) => {
- e.preventDefault();
- // if pasting in a URL, extract the pathname
- const text = e.clipboardData.getData("text/plain");
- try {
- const url = new URL(text);
- e.currentTarget.value = url.pathname.slice(1);
- } catch (err) {
- e.currentTarget.value = text;
- }
- }}
- className="block w-full rounded-r-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
- />
- </div>
+ {isDefaultLink ? (
+ <Tooltip content="You cannot edit the default link destination">
+ <div className="mt-2 block w-full rounded-md border border-neutral-300 bg-neutral-50 px-3 py-2 text-neutral-500 sm:text-sm">
+ {getPrettyUrl(link?.url)}
+ </div>
+ </Tooltip>
+ ) : (
+ <div className="mt-2 flex rounded-md">
+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
+ {destinationDomain}
+ </span>
+ <input
+ {...register("url", { required: false })}
+ type="text"
+ id="url"
+ placeholder="(optional)"
+ autoFocus={!isMobile}
+ onPaste={(e: React.ClipboardEvent<HTMLInputElement>) => {
+ e.preventDefault();
+ // if pasting in a URL, extract the pathname
+ const text = e.clipboardData.getData("text/plain");
+ try {
+ const url = new URL(text);
+ e.currentTarget.value = url.pathname.slice(1);
+ } catch (err) {
+ e.currentTarget.value = text;
+ }
+ }}
+ className="block w-full rounded-r-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ />
+ </div>
+ )}
</div>
<div>
- <div className="flex items-center gap-2">
- <label
- htmlFor="key"
- className="block text-sm font-medium text-neutral-700"
- >
- Short Link
- </label>
- <InfoTooltip
- content={
- <SimpleTooltipContent
- title="This is the short link that will redirect to your destination URL."
- cta="Learn more."
- href="https://dub.co/help/article/how-to-create-link"
- />
- }
- />
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-2">
+ <label
+ htmlFor="key"
+ className="block text-sm font-medium text-neutral-700"
+ >
+ Short Link
+ </label>
+ <InfoTooltip
+ content={
+ <SimpleTooltipContent
+ title="This is the short link that will redirect to your destination URL."
+ cta="Learn more."
+ href="https://dub.co/help/article/how-to-create-link"
+ />
+ }
+ />
+ </div>
+ {lockKey && (
+ <button
+ className="flex h-6 items-center space-x-2 text-sm text-neutral-500 transition-all duration-75 hover:text-black active:scale-95"
+ type="button"
+ onClick={() => {
+ window.confirm(
+ "Updating your short link key could potentially break existing links. Are you sure you want to continue?",
+ ) && setLockKey(false);
+ }}
+ >
+ <Lock className="h-3 w-3" />
+ </button>
+ )}
</div>
<div className="mt-2 flex rounded-md">
<span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
@@ -330,7 +366,14 @@ function PartnerLinkModalContent({
{...register("key", { required: true })}
type="text"
id="key"
- className="block w-full rounded-r-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ disabled={lockKey}
+ className={cn(
+ "block w-full rounded-r-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
+ {
+ "cursor-not-allowed border border-neutral-300 bg-neutral-100 text-neutral-500":
+ lockKey,
+ },
+ )}
placeholder="short-link"
/>
</div>