The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
WIP end test modal
Tim Wilsond7026c6eb1a9
diff --git a/apps/web/ui/modals/link-builder/ab-testing-modal.tsx b/apps/web/ui/modals/link-builder/ab-testing-modal.tsxindex ba7a5df8cf..0c766e4bc2 100644--- a/apps/web/ui/modals/link-builder/ab-testing-modal.tsx+++ b/apps/web/ui/modals/link-builder/ab-testing-modal.tsx@@ -4,6 +4,7 @@ import {MIN_TEST_PERCENTAGE,} from "@/lib/zod/schemas/links";import { useAvailableDomains } from "@/ui/links/use-available-domains";+import { useEndABTestingModal } from "@/ui/modals/link-builder/end-ab-testing-modal";import { BusinessBadgeTooltip } from "@/ui/shared/business-badge-tooltip";import { X } from "@/ui/shared/icons";import {@@ -65,6 +66,9 @@ function ABTestingModal({currentDomain: domain,});+ const { EndABTestingModal, setShowEndABTestingModal } =+ useEndABTestingModal();+const {watch,register,@@ -189,6 +193,7 @@ function ABTestingModal({setShowModal={setShowABTestingModal}className="sm:max-w-md">+ <EndABTestingModal /><formclassName="px-5 py-4"onSubmit={(e) => {@@ -448,10 +453,14 @@ function ABTestingModal({type="button"className="text-xs font-medium text-neutral-700 transition-colors hover:text-neutral-950"onClick={() => {- (["tests", "testsCompleteAt"] as const).forEach((key) =>- setValueParent(key, null, { shouldDirty: true }),- );- setShowABTestingModal(false);+ if (idParent) {+ setShowEndABTestingModal(true);+ } else {+ (["tests", "testsCompleteAt"] as const).forEach((key) =>+ setValueParent(key, null, { shouldDirty: true }),+ );+ setShowABTestingModal(false);+ }}}>{idParent ? "End" : "Remove"} A/B test@@ -543,10 +552,12 @@ export function useABTestingModal() {const ABTestingModalCallback = useCallback(() => {return (- <ABTestingModal- showABTestingModal={showABTestingModal}- setShowABTestingModal={setShowABTestingModal}- />+ <>+ <ABTestingModal+ showABTestingModal={showABTestingModal}+ setShowABTestingModal={setShowABTestingModal}+ />+ </>);}, [showABTestingModal, setShowABTestingModal]);diff --git a/apps/web/ui/modals/link-builder/end-ab-testing-modal.tsx b/apps/web/ui/modals/link-builder/end-ab-testing-modal.tsxnew file mode 100644index 0000000000..cb37ea449f--- /dev/null+++ b/apps/web/ui/modals/link-builder/end-ab-testing-modal.tsx@@ -0,0 +1,101 @@+import { Button, Modal } from "@dub/ui";+import {+ Dispatch,+ SetStateAction,+ useCallback,+ useMemo,+ useState,+} from "react";+import { useFormContext } from "react-hook-form";+import { LinkFormData } from ".";++function EndABTestingModal({+ showEndABTestingModal,+ setShowEndABTestingModal,+}: {+ showEndABTestingModal: boolean;+ setShowEndABTestingModal: Dispatch<SetStateAction<boolean>>;+}) {+ const { watch: watchParent, setValue: setValueParent } =+ useFormContext<LinkFormData>();++ const tests = watchParent("tests") as Array<{+ url: string;+ percentage: number;+ }> | null;++ return (+ <Modal+ showModal={showEndABTestingModal}+ setShowModal={setShowEndABTestingModal}+ className="sm:max-w-md"+ >+ <div className="p-4">+ <h3 className="text-lg font-medium">End A/B test</h3>++ <div className="mt-4">+ <p className="text-sm text-neutral-700">+ Select which destination URL to use as the current destination URL,+ and end the test. Save your changes on the link editor to confirm+ the change.+ </p>+ <div className="mt-4 flex flex-col gap-2">+ {tests?.map((test, index) => (+ <button+ key={index}+ onClick={() => {+ setValueParent("url", test.url, { shouldDirty: true });+ setValueParent("tests", null, { shouldDirty: true });+ setValueParent("testsCompleteAt", null, {+ shouldDirty: true,+ });+ setShowEndABTestingModal(false);+ }}+ className="flex w-full items-center justify-between rounded-md border border-neutral-200 p-3 text-left hover:border-neutral-700"+ >+ <div className="flex items-center space-x-3">+ <span className="flex h-6 w-6 items-center justify-center rounded-full bg-neutral-100 text-sm font-medium">+ {index + 1}+ </span>+ <span className="text-sm font-medium">{test.url}</span>+ </div>+ <span className="text-sm text-neutral-500">+ {test.percentage}%+ </span>+ </button>+ ))}+ </div>+ </div>++ <div className="mt-4 flex justify-end">+ <Button+ text="Cancel"+ variant="secondary"+ onClick={() => setShowEndABTestingModal(false)}+ />+ </div>+ </div>+ </Modal>+ );+}++export function useEndABTestingModal() {+ const [showEndABTestingModal, setShowEndABTestingModal] = useState(false);++ const EndABTestingModalCallback = useCallback(() => {+ return (+ <EndABTestingModal+ showEndABTestingModal={showEndABTestingModal}+ setShowEndABTestingModal={setShowEndABTestingModal}+ />+ );+ }, [showEndABTestingModal, setShowEndABTestingModal]);++ return useMemo(+ () => ({+ setShowEndABTestingModal,+ EndABTestingModal: EndABTestingModalCallback,+ }),+ [setShowEndABTestingModal, EndABTestingModalCallback],+ );+}