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.

confirm change program domain

Steven Tey0547f5fd4105
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-default-link-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-default-link-sheet.tsx
index c0def1781f..70cfd034e4 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-default-link-sheet.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/add-edit-group-default-link-sheet.tsx
@@ -9,10 +9,10 @@ import useProgram from "@/lib/swr/use-program";
import { PartnerGroupDefaultLink } from "@/lib/types";
import { createOrUpdateDefaultLinkSchema } from "@/lib/zod/schemas/groups";
import { DomainSelector } from "@/ui/domains/domain-selector";
-import { useConfirmModal } from "@/ui/modals/confirm-modal";
+import { SimpleLinkCard } from "@/ui/links/simple-link-card";
import { RewardIconSquare } from "@/ui/partners/rewards/reward-icon-square";
import { X } from "@/ui/shared/icons";
-import { Button, Input, Sheet } from "@dub/ui";
+import { Button, Input, Modal, Sheet, useMediaQuery } from "@dub/ui";
import { Eye, Hyperlink } from "@dub/ui/icons";
import { normalizeUrl } from "@dub/utils";
import {
@@ -20,6 +20,8 @@ import {
PropsWithChildren,
ReactNode,
SetStateAction,
+ useCallback,
+ useMemo,
useState,
} from "react";
import { useForm } from "react-hook-form";
@@ -53,42 +55,16 @@ function DefaultPartnerLinkSheetContent({
const [domain, url] = watch(["domain", "url"]);
- const { setShowConfirmModal, confirmModal } = useConfirmModal({
- title: "Switching to a different program domain",
- description: (
- <div className="mt-2 space-y-3">
- <p>
- You've selected <strong className="text-black">{domain}</strong>,
- which is different from your program's current domain{" "}
- <strong className="text-black">{program?.domain}</strong>.
- </p>
- <p>By making this change, you will:</p>
- <ul className="list-disc space-y-1.5 pl-5 text-sm">
- <li>
- Change the program's primary domain to{" "}
- <strong className="text-black">{domain}</strong>.
- </li>
- <li>
- Update all default links across all partner groups to use the{" "}
- <strong className="text-black">{domain}</strong> domain.
- </li>
- <li>
- Automatically update all partner links to use{" "}
- <strong className="text-black">{domain}</strong>, potentially
- breaking them.
- </li>
- </ul>
- <p className="text-sm font-medium">
- Are you sure you want to continue?
- </p>
- </div>
- ),
- confirmText: "Continue",
- onConfirm: async () => {
- const data = watch();
- await createOrUpdateDefaultLink(data);
- },
- });
+ const { setShowChangeDomainModal, ChangeDomainModal } =
+ useChangeProgramDomainModal({
+ newDomain: domain,
+ currentDomain: program?.domain || "",
+ url: url || "",
+ onConfirm: async () => {
+ const data = watch();
+ await createOrUpdateDefaultLink(data);
+ },
+ });
const createOrUpdateDefaultLink = async (data: FormData) => {
if (!group) return;
@@ -129,7 +105,7 @@ function DefaultPartnerLinkSheetContent({
// Check if domain is different from program domain
if (program?.domain && data.domain !== program.domain) {
- setShowConfirmModal(true);
+ setShowChangeDomainModal(true);
return;
}
@@ -145,7 +121,7 @@ function DefaultPartnerLinkSheetContent({
return (
<>
- {confirmModal}
+ <ChangeDomainModal />
<form onSubmit={handleSubmit(onSubmit)} className="flex h-full flex-col">
<div className="flex h-16 items-center justify-between border-b border-neutral-200 px-6 py-4">
<Sheet.Title className="text-lg font-semibold">
@@ -297,6 +273,187 @@ function DefaultPartnerLinkSheet({
);
}
+type ChangeProgramDomainModalProps = {
+ showChangeDomainModal: boolean;
+ setShowChangeDomainModal: Dispatch<SetStateAction<boolean>>;
+ newDomain: string;
+ currentDomain: string;
+ url: string;
+ onConfirm: () => Promise<void>;
+};
+
+function ChangeProgramDomainModal(props: ChangeProgramDomainModalProps) {
+ return (
+ <Modal
+ showModal={props.showChangeDomainModal}
+ setShowModal={props.setShowChangeDomainModal}
+ >
+ <ChangeProgramDomainModalInner {...props} />
+ </Modal>
+ );
+}
+
+function ChangeProgramDomainModalInner({
+ setShowChangeDomainModal,
+ newDomain,
+ currentDomain,
+ url,
+ onConfirm,
+}: ChangeProgramDomainModalProps) {
+ const [confirming, setConfirming] = useState(false);
+ const [verificationText, setVerificationText] = useState("");
+ const { isMobile } = useMediaQuery();
+
+ const handleConfirm = async () => {
+ setConfirming(true);
+ try {
+ await onConfirm();
+ setShowChangeDomainModal(false);
+ } finally {
+ setConfirming(false);
+ }
+ };
+
+ return (
+ <>
+ <div className="space-y-2 border-b border-neutral-200 p-4 sm:p-6">
+ <h3 className="text-lg font-medium leading-none">
+ Switching to a different program domain
+ </h3>
+ </div>
+
+ <div className="bg-neutral-50 p-4 sm:p-6">
+ <div className="scrollbar-hide mb-4 flex max-h-[190px] flex-col gap-2 overflow-y-auto rounded-2xl border border-neutral-200 p-2">
+ <SimpleLinkCard
+ link={{
+ shortLink: `https://${newDomain}`,
+ url: url,
+ }}
+ />
+ </div>
+
+ <div className="space-y-3">
+ <p className="text-sm text-neutral-800">
+ You've selected <strong className="text-black">{newDomain}</strong>,
+ which is different from your program's current domain{" "}
+ <strong className="text-black">{currentDomain}</strong>.
+ </p>
+ <p className="text-sm text-neutral-800">
+ By making this change, you will:
+ </p>
+ <ul className="list-disc space-y-1.5 pl-5 text-sm text-neutral-800">
+ <li>
+ Change the program's primary domain to{" "}
+ <strong className="text-black">{newDomain}</strong>.
+ </li>
+ <li>
+ Update all default links across all partner groups to use the{" "}
+ <strong className="text-black">{newDomain}</strong> domain.
+ </li>
+ <li>
+ Automatically update all partner links to use{" "}
+ <strong className="text-black">{newDomain}</strong>, potentially
+ breaking them.
+ </li>
+ </ul>
+ </div>
+ </div>
+
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ if (verificationText === "confirm change program domain") {
+ await handleConfirm();
+ }
+ }}
+ className="flex flex-col bg-neutral-50 text-left"
+ >
+ <div className="px-4 sm:px-6">
+ <label
+ htmlFor="verification"
+ className="block text-sm text-neutral-700"
+ >
+ To verify, type{" "}
+ <span className="font-semibold">confirm change program domain</span>{" "}
+ below
+ </label>
+ <div className="relative mt-1.5 rounded-md shadow-sm">
+ <input
+ type="text"
+ name="verification"
+ id="verification"
+ pattern="confirm change program domain"
+ required
+ autoFocus={!isMobile}
+ autoComplete="off"
+ value={verificationText}
+ onChange={(e) => setVerificationText(e.target.value)}
+ className="block w-full rounded-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 className="mt-8 flex items-center justify-end gap-2 border-t border-neutral-200 bg-neutral-50 px-4 py-5 sm:px-6">
+ <Button
+ onClick={() => setShowChangeDomainModal(false)}
+ variant="secondary"
+ text="Cancel"
+ className="h-8 w-fit px-3"
+ />
+ <Button
+ disabled={verificationText !== "confirm change program domain"}
+ loading={confirming}
+ text="Continue"
+ className="h-8 w-fit px-3"
+ />
+ </div>
+ </form>
+ </>
+ );
+}
+
+export function useChangeProgramDomainModal({
+ newDomain,
+ currentDomain,
+ url,
+ onConfirm,
+}: {
+ newDomain: string;
+ currentDomain: string;
+ url: string;
+ onConfirm: () => Promise<void>;
+}) {
+ const [showChangeDomainModal, setShowChangeDomainModal] = useState(false);
+
+ const ChangeDomainModalCallback = useCallback(() => {
+ return (
+ <ChangeProgramDomainModal
+ showChangeDomainModal={showChangeDomainModal}
+ setShowChangeDomainModal={setShowChangeDomainModal}
+ newDomain={newDomain}
+ currentDomain={currentDomain}
+ url={url}
+ onConfirm={onConfirm}
+ />
+ );
+ }, [
+ showChangeDomainModal,
+ setShowChangeDomainModal,
+ newDomain,
+ currentDomain,
+ url,
+ onConfirm,
+ ]);
+
+ return useMemo(
+ () => ({
+ setShowChangeDomainModal,
+ ChangeDomainModal: ChangeDomainModalCallback,
+ }),
+ [setShowChangeDomainModal, ChangeDomainModalCallback],
+ );
+}
+
export function useDefaultPartnerLinkSheet(props: {
link?: PartnerGroupDefaultLink;
}) {