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.

handleBanLink

Steven Tey1a0dcdbc894e
diff --git a/apps/web/ui/links/link-controls.tsx b/apps/web/ui/links/link-controls.tsx
index 301ecb5695..a65bc33459 100644
--- a/apps/web/ui/links/link-controls.tsx
+++ b/apps/web/ui/links/link-controls.tsx
@@ -78,8 +78,32 @@ export function LinkControls({ link }: { link: ResponseLink }) {
},
});
+ const handleBanLink = () => {
+ window.confirm(
+ "Are you sure you want to ban this link? It will blacklist the domain and prevent any links from that domain from being created.",
+ ) &&
+ (setOpenPopover(false),
+ toast.promise(
+ fetch(`/api/admin/links/ban?key=${link.key}`, {
+ method: "DELETE",
+ }).then(async () => {
+ await mutate(
+ (key) =>
+ typeof key === "string" && key.startsWith("/api/admin/links/ban"),
+ undefined,
+ { revalidate: true },
+ );
+ }),
+ {
+ loading: "Banning link...",
+ success: "Link banned!",
+ error: "Error banning link.",
+ },
+ ));
+ };
+
useKeyboardShortcut(
- ["e", "d", "q", "a", "t", "i", "x"],
+ ["e", "d", "q", "a", "t", "i", "x", "b"],
(e) => {
setOpenPopover(false);
switch (e.key) {
@@ -104,6 +128,9 @@ export function LinkControls({ link }: { link: ResponseLink }) {
case "x":
if (link.key !== "_root") setShowDeleteLinkModal(true);
break;
+ case "b":
+ if (!slug) handleBanLink();
+ break;
}
},
{
@@ -219,30 +246,7 @@ export function LinkControls({ link }: { link: ResponseLink }) {
)}
{!slug && ( // this is only shown in admin mode (where there's no slug)
<button
- onClick={() => {
- window.confirm(
- "Are you sure you want to ban this link? It will blacklist the domain and prevent any links from that domain from being created.",
- ) &&
- (setOpenPopover(false),
- toast.promise(
- fetch(`/api/admin/links/ban?key=${link.key}`, {
- method: "DELETE",
- }).then(async () => {
- await mutate(
- (key) =>
- typeof key === "string" &&
- key.startsWith("/api/admin/links/ban"),
- undefined,
- { revalidate: true },
- );
- }),
- {
- loading: "Banning link...",
- success: "Link banned!",
- error: "Error banning link.",
- },
- ));
- }}
+ onClick={() => handleBanLink()}
className="group flex w-full items-center justify-between rounded-md p-2 text-left text-sm font-medium text-red-600 transition-all duration-75 hover:bg-red-600 hover:text-white"
>
<IconMenu text="Ban" icon={<Delete className="h-4 w-4" />} />