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.

Update add-edit-link.tsx

Kiran K5da573ef65b9
diff --git a/apps/web/app/app.dub.co/embed/referrals/add-edit-link.tsx b/apps/web/app/app.dub.co/embed/referrals/add-edit-link.tsx
index f46f909b42..11b52f3206 100644
--- a/apps/web/app/app.dub.co/embed/referrals/add-edit-link.tsx
+++ b/apps/web/app/app.dub.co/embed/referrals/add-edit-link.tsx
@@ -1,4 +1,5 @@
import { mutateSuffix } from "@/lib/swr/mutate";
+import { Lock } from "@/ui/shared/icons";
import { Link } from "@dub/prisma/client";
import {
Button,
@@ -7,7 +8,7 @@ import {
useCopyToClipboard,
useMediaQuery,
} from "@dub/ui";
-import { linkConstructor, TAB_ITEM_ANIMATION_SETTINGS } from "@dub/utils";
+import { cn, linkConstructor, TAB_ITEM_ANIMATION_SETTINGS } from "@dub/utils";
import { motion } from "framer-motion";
import { useMemo, useState } from "react";
import { useForm } from "react-hook-form";
@@ -32,6 +33,7 @@ export function ReferralsEmbedCreateUpdateLink({
}: Props) {
const { isMobile } = useMediaQuery();
const [, copyToClipboard] = useCopyToClipboard();
+ const [lockKey, setLockKey] = useState(Boolean(link));
const [isSubmitting, setIsSubmitting] = useState(false);
const {
@@ -192,6 +194,20 @@ export function ReferralsEmbedCreateUpdateLink({
}
/>
</div>
+
+ {lockKey && (
+ <button
+ className="flex h-5 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">
@@ -200,8 +216,15 @@ export function ReferralsEmbedCreateUpdateLink({
<input
type="text"
placeholder="another-link"
- 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"
+ 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,
+ },
+ )}
{...register("key", { required: true })}
+ disabled={lockKey}
/>
</div>
</div>