The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Separate upgraded modal from welcome modal
Tim Wilsonff477cdf2cff
diff --git a/apps/web/ui/modals/modal-provider.tsx b/apps/web/ui/modals/modal-provider.tsxindex 3d9635c948..599e206137 100644--- a/apps/web/ui/modals/modal-provider.tsx+++ b/apps/web/ui/modals/modal-provider.tsx@@ -29,6 +29,7 @@ import { useImportRebrandlyModal } from "./import-rebrandly-modal";import { useImportRewardfulModal } from "./import-rewardful-modal";import { useLinkBuilder } from "./link-builder";import { useProgramWelcomeModal } from "./program-welcome-modal";+import { useUpgradedModal } from "./upgraded-modal";import { useWelcomeModal } from "./welcome-modal";export const ModalContext = createContext<{@@ -99,6 +100,7 @@ function ModalProviderClient({ children }: { children: ReactNode }) {useImportRebrandlyModal();const { setShowImportCsvModal, ImportCsvModal } = useImportCsvModal();const { setShowWelcomeModal, WelcomeModal } = useWelcomeModal();+ const { setShowUpgradedModal, UpgradedModal } = useUpgradedModal();const { setShowProgramWelcomeModal, ProgramWelcomeModal } =useProgramWelcomeModal();const { setShowImportRewardfulModal, ImportRewardfulModal } =@@ -106,9 +108,8 @@ function ModalProviderClient({ children }: { children: ReactNode }) {useEffect(() => {setShowProgramWelcomeModal(searchParams.has("onboarded-program"));- setShowWelcomeModal(- searchParams.has("onboarded") || searchParams.has("upgraded"),- );+ setShowWelcomeModal(searchParams.has("onboarded"));+ setShowUpgradedModal(searchParams.has("upgraded"));}, [searchParams]);const [hashes, setHashes] = useCookies<SimpleLinkProps[]>("hashes__dub", [], {@@ -206,6 +207,7 @@ function ModalProviderClient({ children }: { children: ReactNode }) {<ImportCsvModal /><ImportRewardfulModal /><WelcomeModal />+ <UpgradedModal /><ProgramWelcomeModal />{children}</ModalContext.Provider>diff --git a/apps/web/ui/modals/upgraded-modal.tsx b/apps/web/ui/modals/upgraded-modal.tsxnew file mode 100644index 0000000000..90ee27a24e--- /dev/null+++ b/apps/web/ui/modals/upgraded-modal.tsx@@ -0,0 +1,150 @@+import useWorkspace from "@/lib/swr/use-workspace";+import { Button, Modal, useRouterStuff, useScrollProgress } from "@dub/ui";+import { cn, getPlanDetails, PLANS, PRO_PLAN } from "@dub/utils";+import { usePlausible } from "next-plausible";+import { useSearchParams } from "next/navigation";+import posthog from "posthog-js";+import {+ Dispatch,+ SetStateAction,+ useCallback,+ useEffect,+ useMemo,+ useRef,+ useState,+} from "react";+import { ModalHero } from "../shared/modal-hero";+import { PlanFeatures } from "../workspaces/plan-features";++function UpgradedModal({+ showUpgradedModal,+ setShowUpgradedModal,+}: {+ showUpgradedModal: boolean;+ setShowUpgradedModal: Dispatch<SetStateAction<boolean>>;+}) {+ const { queryParams } = useRouterStuff();+ const searchParams = useSearchParams();++ const { dotLinkClaimed } = useWorkspace();++ const scrollRef = useRef<HTMLDivElement>(null);+ const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);++ const planId = searchParams.get("plan");+ const plausible = usePlausible();++ const handlePlanUpgrade = async () => {+ if (planId) {+ const currentPlan = getPlanDetails(planId);+ const period = searchParams.get("period");+ if (currentPlan && period) {+ plausible(`Upgraded to ${currentPlan.name}`);+ posthog.capture("plan_upgraded", {+ plan: currentPlan.name,+ period,+ revenue: currentPlan.price[period],+ });+ }+ }+ };+ useEffect(() => {+ handlePlanUpgrade();+ }, [searchParams, planId]);++ const plan = planId+ ? PLANS.find(+ (p) => p.name.toLowerCase() === planId.replace("+", " ").toLowerCase(),+ ) ?? PRO_PLAN+ : undefined;++ return (+ <Modal+ showModal={showUpgradedModal}+ setShowModal={setShowUpgradedModal}+ onClose={() =>+ queryParams({+ del: ["onboarded", "upgraded", "plan", "period"],+ })+ }+ >+ <div className="flex flex-col">+ <ModalHero />+ <div className="px-6 py-8 sm:px-12">+ <div className="relative">+ <div+ ref={scrollRef}+ onScroll={updateScrollProgress}+ className="scrollbar-hide max-h-[calc(100vh-350px)] overflow-y-auto pb-6"+ >+ <h1+ className={cn(+ "text-lg font-medium text-neutral-950",+ plan ? "text-left" : "text-center",+ )}+ >+ {plan+ ? `Dub ${plan.name} looks good on you!`+ : "Welcome to Dub!"}+ </h1>+ <p+ className={cn(+ "mt-2 text-sm text-neutral-500",+ plan ? "text-left" : "text-center",+ )}+ >+ Thank you for upgrading to the {plan?.name} plan! You now have+ access to more powerful features and higher limits.+ </p>+ {plan && (+ <>+ <h2 className="mb-2 mt-6 text-base font-medium text-neutral-950">+ Explore the benefits of your {plan.name} plan+ </h2>+ <PlanFeatures plan={plan.name} />+ </>+ )}+ </div>+ {/* Bottom scroll fade */}+ <div+ className="pointer-events-none absolute bottom-0 left-0 hidden h-16 w-full bg-gradient-to-t from-white sm:block"+ style={{ opacity: 1 - Math.pow(scrollProgress, 2) }}+ ></div>+ </div>+ <Button+ type="button"+ variant="primary"+ text="Get started"+ className="mt-2"+ onClick={() =>+ queryParams({+ del: ["onboarded", "upgraded", "plan", "period"],+ })+ }+ />+ </div>+ </div>+ </Modal>+ );+}++export function useUpgradedModal() {+ const [showUpgradedModal, setShowUpgradedModal] = useState(false);++ const UpgradedModalCallback = useCallback(() => {+ return (+ <UpgradedModal+ showUpgradedModal={showUpgradedModal}+ setShowUpgradedModal={setShowUpgradedModal}+ />+ );+ }, [showUpgradedModal, setShowUpgradedModal]);++ return useMemo(+ () => ({+ setShowUpgradedModal,+ UpgradedModal: UpgradedModalCallback,+ }),+ [setShowUpgradedModal, UpgradedModalCallback],+ );+}diff --git a/apps/web/ui/modals/welcome-modal.tsx b/apps/web/ui/modals/welcome-modal.tsxindex 53e835f761..75d4d10b27 100644--- a/apps/web/ui/modals/welcome-modal.tsx+++ b/apps/web/ui/modals/welcome-modal.tsx@@ -29,7 +29,6 @@ function WelcomeModal({const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);const planId = searchParams.get("plan");- const upgraded = searchParams.get("upgraded");const plausible = usePlausible();const handlePlanUpgrade = async () => {@@ -91,9 +90,9 @@ function WelcomeModal({plan ? "text-left" : "text-center",)}>- {upgraded- ? `Thank you for upgrading to the ${plan?.name} plan! You now have access to more powerful features and higher limits.`- : "Thanks for signing up – your account is ready to go! Now you have one central, organized place to build and manage all your short links."}+ Thanks for signing up – your account is ready to go! Now you+ have one central, organized place to build and manage all your+ short links.</p>{plan && (<>