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.

add archive and delete domain modals

Steven Tey8c88248111e3
diff --git a/apps/web/app/api/domains/[domain]/archive/route.ts b/apps/web/app/api/domains/[domain]/archive/route.ts
new file mode 100644
index 0000000000..2b44773cbb
--- /dev/null
+++ b/apps/web/app/api/domains/[domain]/archive/route.ts
@@ -0,0 +1,17 @@
+import { archiveDomain } from "@/lib/api/domains";
+import { withAuth } from "@/lib/auth";
+import { NextResponse } from "next/server";
+
+// POST /api/domains/[domain]/archive – archive a domain
+export const POST = withAuth(async ({ headers, domain }) => {
+ console.log("archiving domain", domain);
+ const response = await archiveDomain({ domain, archived: true });
+ return NextResponse.json(response, { headers });
+});
+
+// DELETE /api/domains/[domain]/archive – unarchive a domain
+export const DELETE = withAuth(async ({ headers, domain }) => {
+ console.log("unarchiving domain", domain);
+ const response = await archiveDomain({ domain, archived: false });
+ return NextResponse.json(response, { headers });
+});
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.ts
index 3b6856b6ce..cbb138b173 100644
--- a/apps/web/app/api/domains/[domain]/route.ts
+++ b/apps/web/app/api/domains/[domain]/route.ts
@@ -50,6 +50,7 @@ export const PUT = withAuth(async ({ req, workspace, domain }) => {
placeholder,
primary,
archived,
+ expiredUrl,
} = await req.json();
if (isDubDomain(domain) && workspace.id !== DUB_WORKSPACE_ID) {
@@ -79,15 +80,11 @@ export const PUT = withAuth(async ({ req, workspace, domain }) => {
...(newDomain !== domain && {
slug: newDomain,
}),
- // same logic as the redis part above
- ...(workspace.plan !== "free" &&
- (target
- ? {
- target,
- }
- : {
- target: null,
- })),
+ // only set target and expiredUrl if the workspace is not free
+ ...(workspace.plan !== "free" && {
+ target: target || null,
+ expiredUrl: expiredUrl || null,
+ }),
type,
placeholder,
primary,
diff --git a/apps/web/lib/api/domains.ts b/apps/web/lib/api/domains.ts
index 841d9d40a5..2c34388e0a 100644
--- a/apps/web/lib/api/domains.ts
+++ b/apps/web/lib/api/domains.ts
@@ -205,6 +205,23 @@ export async function setRootDomain({
]);
}
+export async function archiveDomain({
+ domain,
+ archived,
+}: {
+ domain: string;
+ archived: boolean;
+}) {
+ return await prisma.domain.update({
+ where: {
+ slug: domain,
+ },
+ data: {
+ archived,
+ },
+ });
+}
+
/* Delete a domain and all links & images associated with it */
export async function deleteDomainAndLinks(
domain: string,
diff --git a/apps/web/ui/domains/domain-card.tsx b/apps/web/ui/domains/domain-card.tsx
index e3f250cc0a..9af9deb332 100644
--- a/apps/web/ui/domains/domain-card.tsx
+++ b/apps/web/ui/domains/domain-card.tsx
@@ -4,7 +4,9 @@ import {
AlertCircleFill,
Chart,
CheckCircleFill,
+ Delete,
ExternalLink,
+ ThreeDots,
XCircleFill,
} from "@/ui/shared/icons";
import {
@@ -12,22 +14,25 @@ import {
LoadingCircle,
LoadingDots,
NumberTooltip,
+ Popover,
useIntersectionObserver,
} from "@dub/ui";
import { capitalize, fetcher, nFormatter, truncate } from "@dub/utils";
-import { QrCode } from "lucide-react";
+import { Archive, Edit3, QrCode } from "lucide-react";
import Link from "next/link";
import punycode from "punycode/";
import useSWR, { mutate } from "swr";
import { useAddEditDomainModal } from "../modals/add-edit-domain-modal";
import { useLinkQRModal } from "../modals/link-qr-modal";
import DomainConfiguration from "./domain-configuration";
-import { useRef } from "react";
+import { useRef, useState } from "react";
+import { useDeleteDomainModal } from "../modals/delete-domain-modal";
+import { useArchiveDomainModal } from "../modals/archive-domain-modal";
export default function DomainCard({ props }: { props: DomainProps }) {
const { id, slug } = useWorkspace();
- const { slug: domain, primary, target, type, verified } = props || {};
+ const { slug: domain, primary, target, type, archived } = props || {};
const { showLinkQRModal, setShowLinkQRModal, LinkQRModal } = useLinkQRModal({
props: {
@@ -68,15 +73,28 @@ export default function DomainCard({ props }: { props: DomainProps }) {
},
);
+ const [openPopover, setOpenPopover] = useState(false);
+
const { setShowAddEditDomainModal, AddEditDomainModal } =
useAddEditDomainModal({
props,
});
+ const { setShowArchiveDomainModal, ArchiveDomainModal } =
+ useArchiveDomainModal({
+ props,
+ });
+
+ const { setShowDeleteDomainModal, DeleteDomainModal } = useDeleteDomainModal({
+ props,
+ });
+
return (
<>
<AddEditDomainModal />
<LinkQRModal />
+ <ArchiveDomainModal />
+ <DeleteDomainModal />
<div
ref={domainRef}
className="flex flex-col space-y-3 rounded-lg border border-gray-200 bg-white px-5 py-8 sm:px-10"
@@ -94,13 +112,6 @@ export default function DomainCard({ props }: { props: DomainProps }) {
</p>
<ExternalLink className="h-5 w-5" />
</a>
- <button
- onClick={() => setShowLinkQRModal(true)}
- className="group rounded-full bg-gray-100 p-1.5 transition-all duration-75 hover:scale-105 hover:bg-blue-100 active:scale-95"
- >
- <span className="sr-only">QR Code</span>
- <QrCode className="h-4 w-4 text-gray-700 transition-all group-hover:text-blue-800" />
- </button>
<NumberTooltip value={clicks}>
<Link
href={`/${slug}/analytics?domain=${domain}&key=_root`}
@@ -132,11 +143,70 @@ export default function DomainCard({ props }: { props: DomainProps }) {
mutate(`/api/domains/${domain}/verify?workspaceId=${id}`);
}}
/>
- <Button
- text="Edit"
- variant="secondary"
- onClick={() => setShowAddEditDomainModal(true)}
- />
+ <Popover
+ content={
+ <div className="grid w-full gap-px p-2 sm:w-48">
+ <Button
+ text="Edit"
+ variant="outline"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowAddEditDomainModal(true);
+ }}
+ icon={<Edit3 className="h-4 w-4" />}
+ shortcut="E"
+ className="h-9 px-2 font-medium"
+ />
+ <Button
+ text="QR Code"
+ variant="outline"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowLinkQRModal(true);
+ }}
+ icon={<QrCode className="h-4 w-4" />}
+ shortcut="Q"
+ className="h-9 px-2 font-medium"
+ />
+ <Button
+ text={archived ? "Unarchive" : "Archive"}
+ variant="outline"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowArchiveDomainModal(true);
+ }}
+ icon={<Archive className="h-4 w-4" />}
+ shortcut="A"
+ className="h-9 px-2 font-medium"
+ />
+ <Button
+ text="Delete"
+ variant="danger-outline"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowDeleteDomainModal(true);
+ }}
+ icon={<Delete className="h-4 w-4" />}
+ shortcut="X"
+ className="h-9 px-2 font-medium"
+ />
+ </div>
+ }
+ align="end"
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ >
+ <div>
+ <Button
+ variant="secondary"
+ className="px-2"
+ icon={<ThreeDots className="h-5 w-5" />}
+ onClick={() => {
+ setOpenPopover(!openPopover);
+ }}
+ />
+ </div>
+ </Popover>
</div>
</div>
<div className="flex h-10 flex-col space-y-2 sm:flex-row sm:items-center sm:space-x-5 sm:space-y-0">
diff --git a/apps/web/ui/links/link-card.tsx b/apps/web/ui/links/link-card.tsx
index 6e339eedd1..292ec824c2 100644
--- a/apps/web/ui/links/link-card.tsx
+++ b/apps/web/ui/links/link-card.tsx
@@ -160,7 +160,6 @@ export default function LinkCard({
const { setShowArchiveLinkModal, ArchiveLinkModal } = useArchiveLinkModal({
props,
- archived: !archived,
});
const { setShowTransferLinkModal, TransferLinkModal } = useTransferLinkModal({
props,
@@ -605,7 +604,7 @@ export default function LinkCard({
}}
className="rounded-md px-1 py-2 transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"
>
- <span className="sr-only">Edit</span>
+ <span className="sr-only">More options</span>
<ThreeDots className="h-5 w-5 text-gray-500" />
</button>
</Popover>
diff --git a/apps/web/ui/modals/add-edit-domain-modal/index.tsx b/apps/web/ui/modals/add-edit-domain-modal/index.tsx
index e30643c086..7b5ac2d81b 100644
--- a/apps/web/ui/modals/add-edit-domain-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-domain-modal/index.tsx
@@ -54,10 +54,11 @@ function AddEditDomainModal({
type: "redirect",
clicks: 0,
projectId: id || "",
+ expiredUrl: "",
},
);
- const { slug: domain, primary, archived, target, type, placeholder } = data;
+ const { slug: domain, primary, target, type, placeholder, expiredUrl } = data;
const [lockDomain, setLockDomain] = useState(true);
const [saving, setSaving] = useState(false);
@@ -103,22 +104,6 @@ function AddEditDomainModal({
}
}, [props]);
- async function deleteDomain() {
- setDeleting(true);
- fetch(`/api/domains/${domain}?workspaceId=${id}`, {
- method: "DELETE",
- }).then(async (res) => {
- if (res.status === 200) {
- await mutate(`/api/domains?workspaceId=${id}`);
- setShowAddEditDomainModal(false);
- toast.success("Successfully deleted domain!");
- } else {
- setDomainError("Something went wrong. Please try again.");
- }
- setDeleting(false);
- });
- }
-
const [expanded, setExpanded] = useState(false);
return (
@@ -302,17 +287,6 @@ function AddEditDomainModal({
/>
</div>
- <div className="flex items-center justify-between bg-gray-50">
- <div className="flex items-center space-x-2">
- <h2 className="text-sm font-medium text-gray-900">Archived</h2>
- <InfoTooltip content="Archived domains will still work, but they won't show up in the link creation modal." />
- </div>
- <Switch
- fn={() => setData((prev) => ({ ...prev, archived: !archived }))}
- checked={archived}
- />
- </div>
-
<div>
<label
htmlFor="placeholder"
@@ -337,28 +311,64 @@ function AddEditDomainModal({
/>
</div>
</div>
+
+ <div>
+ <label
+ htmlFor="expiredUrl"
+ className="flex items-center space-x-2"
+ >
+ <h2 className="text-sm font-medium text-gray-900">
+ Expired URL
+ </h2>
+ <InfoTooltip content="URL to redirect your users to to when a link with this domain has expired." />
+ </label>
+ <div className="relative mt-2 rounded-md shadow-sm">
+ {plan !== "free" ? (
+ <div className="relative mt-2 rounded-md shadow-sm">
+ <input
+ type="url"
+ name="expiredUrl"
+ id="expiredUrl"
+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"
+ placeholder="https://yourwebsite.com"
+ value={expiredUrl}
+ onChange={(e) =>
+ setData({ ...data, expiredUrl: e.target.value })
+ }
+ />
+ </div>
+ ) : (
+ <Tooltip
+ content={
+ <TooltipContent
+ title="You can't configure a custom expired URL on a free plan. Upgrade to a Pro plan to proceed."
+ cta="Upgrade to Pro"
+ onClick={() => {
+ setShowAddEditDomainModal(false);
+ queryParams({
+ set: {
+ upgrade: "pro",
+ },
+ });
+ }}
+ />
+ }
+ >
+ <div className="mt-2 w-full cursor-not-allowed rounded-md border border-gray-300 px-3 py-2 text-left text-sm text-gray-300 sm:max-w-md">
+ https://yourwebsite.com
+ </div>
+ </Tooltip>
+ )}
+ </div>
+ </div>
</motion.div>
)}
- <div className="grid gap-2">
- <Button
- text={props ? "Save changes" : "Add domain"}
- disabled={saveDisabled}
- loading={saving}
- />
- {props && (
- <Button
- variant="danger"
- text="Delete domain"
- onClick={() => {
- window.confirm(
- "Warning: Deleting your workspace's domain will delete all existing short links using the domain. Are you sure you want to continue?",
- ) && deleteDomain();
- }}
- loading={deleting}
- />
- )}
- </div>
+ <Button
+ text={props ? "Save changes" : "Add domain"}
+ disabled={saveDisabled}
+ loading={saving}
+ />
</form>
</Modal>
);
diff --git a/apps/web/ui/modals/archive-domain-modal.tsx b/apps/web/ui/modals/archive-domain-modal.tsx
new file mode 100644
index 0000000000..89e68477e5
--- /dev/null
+++ b/apps/web/ui/modals/archive-domain-modal.tsx
@@ -0,0 +1,153 @@
+import useWorkspace from "@/lib/swr/use-workspace";
+import { DomainProps } from "@/lib/types";
+import { Button, Modal, useToastWithUndo } from "@dub/ui";
+import { getApexDomain } from "@dub/utils";
+import {
+ Dispatch,
+ MouseEvent,
+ SetStateAction,
+ useCallback,
+ useMemo,
+ useState,
+} from "react";
+import { toast } from "sonner";
+import { mutate } from "swr";
+import LinkLogo from "../links/link-logo";
+
+const sendArchiveRequest = ({
+ domain,
+ archive,
+ workspaceId,
+}: {
+ domain: string;
+ archive: boolean;
+ workspaceId?: string;
+}) => {
+ const baseUrl = `/api/domains/${domain}/archive`;
+ return fetch(`${baseUrl}?workspaceId=${workspaceId}`, {
+ method: archive ? "POST" : "DELETE",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+};
+
+const revalidateDomains = () => {
+ return mutate(
+ (key) => typeof key === "string" && key.startsWith("/api/domains"),
+ undefined,
+ { revalidate: true },
+ );
+};
+
+function ArchiveDomainModal({
+ showArchiveDomainModal,
+ setShowArchiveDomainModal,
+ props,
+}: {
+ showArchiveDomainModal: boolean;
+ setShowArchiveDomainModal: Dispatch<SetStateAction<boolean>>;
+ props: DomainProps;
+}) {
+ const toastWithUndo = useToastWithUndo();
+
+ const { id: workspaceId } = useWorkspace();
+ const [archiving, setArchiving] = useState(false);
+ const domain = props.slug;
+ const apexDomain = getApexDomain(domain);
+
+ const handleArchiveRequest = async (event: MouseEvent<HTMLButtonElement>) => {
+ event.preventDefault();
+
+ setArchiving(true);
+ const res = await sendArchiveRequest({
+ domain,
+ archive: !props.archived,
+ workspaceId,
+ });
+ setArchiving(false);
+
+ if (!res.ok) {
+ const { error } = await res.json();
+ toast.error(error.message);
+ return;
+ }
+
+ revalidateDomains();
+ setShowArchiveDomainModal(false);
+ toastWithUndo({
+ id: "domain-archive-undo-toast",
+ message: `Successfully ${props.archived ? "unarchived" : "archived"} domain!`,
+ undo: undoAction,
+ duration: 5000,
+ });
+ };
+
+ const undoAction = () => {
+ toast.promise(
+ sendArchiveRequest({
+ domain,
+ archive: props.archived,
+ workspaceId,
+ }),
+ {
+ loading: "Undo in progress...",
+ error: "Failed to roll back changes. An error occurred.",
+ success: () => {
+ revalidateDomains();
+ return "Undo successful! Changes reverted.";
+ },
+ },
+ );
+ };
+
+ return (
+ <Modal
+ showModal={showArchiveDomainModal}
+ setShowModal={setShowArchiveDomainModal}
+ >
+ <div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 text-center sm:px-16">
+ <LinkLogo apexDomain={apexDomain} />
+ <h3 className="text-lg font-medium">
+ {props.archived ? "Unarchive" : "Archive"} {domain}
+ </h3>
+ <p className="text-sm text-gray-500">
+ {props.archived
+ ? "By unarchiving this domain, it will show up in the link creation modal again."
+ : "Archived domains will still work, but they won't show up in the link creation modal."}
+ </p>
+ </div>
+
+ <div className="flex flex-col space-y-6 bg-gray-50 px-4 py-8 text-left sm:px-16">
+ <Button
+ onClick={handleArchiveRequest}
+ autoFocus
+ loading={archiving}
+ text={`Confirm ${props.archived ? "unarchive" : "archive"}`}
+ />
+ </div>
+ </Modal>
+ );
+}
+
+export function useArchiveDomainModal({ props }: { props: DomainProps }) {
+ const [showArchiveDomainModal, setShowArchiveDomainModal] = useState(false);
+
+ const ArchiveDomainModalCallback = useCallback(() => {
+ return props ? (
+ <ArchiveDomainModal
+ showArchiveDomainModal={showArchiveDomainModal}
+ setShowArchiveDomainModal={setShowArchiveDomainModal}
+ props={props}
+ />
+ ) : null;
+ }, [showArchiveDomainModal, setShowArchiveDomainModal]);
+
+ return useMemo(
+ () => ({
+ setShowArchiveDomainModal,
+ ArchiveDomainModal: ArchiveDomainModalCallback,
+ }),
+ [setShowArchiveDomainModal, ArchiveDomainModalCallback],
+ );
+}
diff --git a/apps/web/ui/modals/archive-link-modal.tsx b/apps/web/ui/modals/archive-link-modal.tsx
index da9c1a1ad5..28515622d9 100644
--- a/apps/web/ui/modals/archive-link-modal.tsx
+++ b/apps/web/ui/modals/archive-link-modal.tsx
@@ -14,14 +14,18 @@ import { toast } from "sonner";
import { mutate } from "swr";
import LinkLogo from "../links/link-logo";
-const sendArchiveRequest = (
- archived: boolean,
- id: string,
- workspaceId?: string,
-) => {
- const baseUrl = `/api/links/${id}/archive`;
+const sendArchiveRequest = ({
+ linkId,
+ archive,
+ workspaceId,
+}: {
+ linkId: string;
+ archive: boolean;
+ workspaceId?: string;
+}) => {
+ const baseUrl = `/api/links/${linkId}/archive`;
return fetch(`${baseUrl}?workspaceId=${workspaceId}`, {
- method: archived ? "POST" : "DELETE",
+ method: archive ? "POST" : "DELETE",
headers: {
"Content-Type": "application/json",
},
@@ -40,12 +44,10 @@ function ArchiveLinkModal({
showArchiveLinkModal,
setShowArchiveLinkModal,
props,
- archived,
}: {
showArchiveLinkModal: boolean;
setShowArchiveLinkModal: Dispatch<SetStateAction<boolean>>;
props: LinkProps;
- archived: boolean;
}) {
const toastWithUndo = useToastWithUndo();
@@ -67,7 +69,11 @@ function ArchiveLinkModal({
event.preventDefault();
setArchiving(true);
- const res = await sendArchiveRequest(archived, props.id, workspaceId);
+ const res = await sendArchiveRequest({
+ linkId: props.id,
+ archive: !props.archived,
+ workspaceId,
+ });
setArchiving(false);
if (!res.ok) {
@@ -80,21 +86,28 @@ function ArchiveLinkModal({
setShowArchiveLinkModal(false);
toastWithUndo({
id: "link-archive-undo-toast",
- message: `Successfully ${archived ? "archived" : "unarchived"} link!`,
+ message: `Successfully ${props.archived ? "unarchived" : "archived"} link!`,
undo: undoAction,
duration: 5000,
});
};
const undoAction = () => {
- toast.promise(sendArchiveRequest(!archived, props.id, workspaceId), {
- loading: "Undo in progress...",
- error: "Failed to roll back changes. An error occurred.",
- success: () => {
- revalidateLinks();
- return "Undo successful! Changes reverted.";
+ toast.promise(
+ sendArchiveRequest({
+ linkId: props.id,
+ archive: props.archived,
+ workspaceId,
+ }),
+ {
+ loading: "Undo in progress...",
+ error: "Failed to roll back changes. An error occurred.",
+ success: () => {
+ revalidateLinks();
+ return "Undo successful! Changes reverted.";
+ },
},
- });
+ );
};
return (
@@ -105,12 +118,12 @@ function ArchiveLinkModal({
<div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 text-center sm:px-16">
<LinkLogo apexDomain={apexDomain} />
<h3 className="text-lg font-medium">
- {archived ? "Archive" : "Unarchive"} {shortlink}
+ {props.archived ? "Unarchive" : "Archive"} {shortlink}
</h3>
<p className="text-sm text-gray-500">
- {archived
- ? "Archived links will still work - they just won't show up on your main dashboard."
- : "By unarchiving this link, it will show up on your main dashboard again."}
+ {props.archived
+ ? "By unarchiving this link, it will show up on your main dashboard again."
+ : "Archived links will still work - they just won't show up on your main dashboard."}
</p>
</div>
@@ -119,20 +132,14 @@ function ArchiveLinkModal({
onClick={handleArchiveRequest}
autoFocus
loading={archiving}
- text={`Confirm ${archived ? "archive" : "unarchive"}`}
+ text={`Confirm ${props.archived ? "unarchive" : "archive"}`}
/>
</div>
</Modal>
);
}
-export function useArchiveLinkModal({
- props,
- archived = true,
-}: {
- props: LinkProps;
- archived: boolean;
-}) {
+export function useArchiveLinkModal({ props }: { props: LinkProps }) {
const [showArchiveLinkModal, setShowArchiveLinkModal] = useState(false);
const ArchiveLinkModalCallback = useCallback(() => {
@@ -141,7 +148,6 @@ export function useArchiveLinkModal({
showArchiveLinkModal={showArchiveLinkModal}
setShowArchiveLinkModal={setShowArchiveLinkModal}
props={props}
- archived={archived}
/>
) : null;
}, [showArchiveLinkModal, setShowArchiveLinkModal]);
diff --git a/apps/web/ui/modals/delete-domain-modal.tsx b/apps/web/ui/modals/delete-domain-modal.tsx
new file mode 100644
index 0000000000..abcc87381d
--- /dev/null
+++ b/apps/web/ui/modals/delete-domain-modal.tsx
@@ -0,0 +1,111 @@
+import useWorkspace from "@/lib/swr/use-workspace";
+import { DomainProps } from "@/lib/types";
+import { Button, Modal, useMediaQuery } from "@dub/ui";
+import { getApexDomain } from "@dub/utils";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useMemo,
+ useState,
+} from "react";
+import { toast } from "sonner";
+import { mutate } from "swr";
+import LinkLogo from "../links/link-logo";
+
+function DeleteDomainModal({
+ showDeleteDomainModal,
+ setShowDeleteDomainModal,
+ props,
+}: {
+ showDeleteDomainModal: boolean;
+ setShowDeleteDomainModal: Dispatch<SetStateAction<boolean>>;
+ props: DomainProps;
+}) {
+ const { id } = useWorkspace();
+ const [deleting, setDeleting] = useState(false);
+ const domain = props.slug;
+ const apexDomain = getApexDomain(domain);
+
+ const { isMobile } = useMediaQuery();
+
+ return (
+ <Modal
+ showModal={showDeleteDomainModal}
+ setShowModal={setShowDeleteDomainModal}
+ >
+ <div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 text-center sm:px-16">
+ <LinkLogo apexDomain={apexDomain} />
+ <h3 className="text-lg font-medium">Delete {domain}</h3>
+ <p className="text-sm text-gray-500">
+ Warning: Deleting this domain will delete all associated links as well
+ as their anaytics, permanently. This action cannot be undone – proceed
+ with caution.
+ </p>
+ </div>
+
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ setDeleting(true);
+ fetch(`/api/domains/${domain}?workspaceId=${id}`, {
+ method: "DELETE",
+ }).then(async (res) => {
+ if (res.status === 200) {
+ await mutate(`/api/domains?workspaceId=${id}`);
+ setShowDeleteDomainModal(false);
+ toast.success("Successfully deleted domain!");
+ } else {
+ toast.error("Something went wrong. Please try again.");
+ }
+ setDeleting(false);
+ });
+ }}
+ className="flex flex-col space-y-3 bg-gray-50 px-4 py-8 text-left sm:px-16"
+ >
+ <div>
+ <label htmlFor="verification" className="block text-sm text-gray-700">
+ To verify, type{" "}
+ <span className="font-semibold">confirm delete {domain}</span> below
+ </label>
+ <div className="relative mt-1 rounded-md shadow-sm">
+ <input
+ type="text"
+ name="verification"
+ id="verification"
+ pattern={`confirm delete ${domain}`}
+ required
+ autoFocus={!isMobile}
+ autoComplete="off"
+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"
+ />
+ </div>
+ </div>
+
+ <Button variant="danger" text="Confirm delete" loading={deleting} />
+ </form>
+ </Modal>
+ );
+}
+
+export function useDeleteDomainModal({ props }: { props?: DomainProps }) {
+ const [showDeleteDomainModal, setShowDeleteDomainModal] = useState(false);
+
+ const DeleteDomainModalCallback = useCallback(() => {
+ return props ? (
+ <DeleteDomainModal
+ showDeleteDomainModal={showDeleteDomainModal}
+ setShowDeleteDomainModal={setShowDeleteDomainModal}
+ props={props}
+ />
+ ) : null;
+ }, [showDeleteDomainModal, setShowDeleteDomainModal]);
+
+ return useMemo(
+ () => ({
+ setShowDeleteDomainModal,
+ DeleteDomainModal: DeleteDomainModalCallback,
+ }),
+ [setShowDeleteDomainModal, DeleteDomainModalCallback],
+ );
+}
diff --git a/apps/web/ui/modals/delete-link-modal.tsx b/apps/web/ui/modals/delete-link-modal.tsx
index 3b1f8f1b90..12698c3892 100644
--- a/apps/web/ui/modals/delete-link-modal.tsx
+++ b/apps/web/ui/modals/delete-link-modal.tsx
@@ -47,8 +47,8 @@ function DeleteLinkModal({
<LinkLogo apexDomain={apexDomain} />
<h3 className="text-lg font-medium">Delete {shortlink}</h3>
<p className="text-sm text-gray-500">
- Warning: Deleting this link will remove all of its stats. This action
- cannot be undone.
+ Warning: Deleting this link will remove all of its analytics. This
+ action cannot be undone – proceed with caution.
</p>
</div>