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.

consolidate modals

Steven Teyfa76a8c81b59
diff --git a/app/ui/home/features.tsx b/app/ui/home/features.tsx
index bfc5f6b335..59a86ee0e1 100644
--- a/app/ui/home/features.tsx
+++ b/app/ui/home/features.tsx
@@ -12,7 +12,7 @@ import {
} from "#/ui/accordion";
import { AnimatePresence, motion } from "framer-motion";
import { useLinkQRModal } from "#/ui/modals/link-qr-modal";
-import { DEFAULT_LINK_PROPS } from "#/lib/constants";
+import { APP_DOMAIN, DEFAULT_LINK_PROPS } from "#/lib/constants";
import { useAddEditLinkModal } from "#/ui/modals/add-edit-link-modal";
import { Link2, QrCode } from "lucide-react";
@@ -42,7 +42,7 @@ const featureList = [
"Dub offers free custom domains on all plans - start personalizing your links today.",
cta: (
<a
- href="https://app.dub.sh"
+ href={APP_DOMAIN}
target="_blank"
rel="noreferrer"
className="block max-w-fit rounded-full border border-black bg-black px-4 py-1.5 text-sm text-white transition-all hover:bg-white hover:text-black"
@@ -87,7 +87,7 @@ const featureList = [
"With Dub, you can invite unlimited team members to collaborate on your project for free - no more sharing logins via Google groups.",
cta: (
<a
- href="https://app.dub.sh"
+ href={APP_DOMAIN}
target="_blank"
rel="noreferrer"
className="block max-w-fit rounded-full border border-black bg-black px-4 py-1.5 text-sm text-white transition-all hover:bg-white hover:text-black"
diff --git a/app/ui/modal.tsx b/app/ui/modal.tsx
index 6d9497ac1c..3c6182e3e4 100644
--- a/app/ui/modal.tsx
+++ b/app/ui/modal.tsx
@@ -120,10 +120,7 @@ export default function Modal({
<motion.div
ref={desktopModalRef}
key="desktop-modal"
- className="fixed inset-0 z-50 hidden min-h-screen items-center justify-center md:flex"
- initial={{ scale: 0.95 }}
- animate={{ scale: 1 }}
- exit={{ scale: 0.95 }}
+ className="fixed inset-0 z-50 hidden min-h-screen animate-scale-in items-center justify-center md:flex"
onMouseDown={(e) => {
if (desktopModalRef.current === e.target) {
closeModal(closeWithX);
diff --git a/app/ui/stats/toggle.tsx b/app/ui/stats/toggle.tsx
index 320bf318e4..5f47863341 100644
--- a/app/ui/stats/toggle.tsx
+++ b/app/ui/stats/toggle.tsx
@@ -16,6 +16,7 @@ import useScroll from "#/lib/hooks/use-scroll";
import Tooltip, { TooltipContent } from "../tooltip";
import useProject from "#/lib/hooks/use-project";
import { useParams } from "next/navigation";
+import { APP_DOMAIN } from "#/lib/constants";
export default function Toggle() {
const { slug: projectSlug } = useParams() as { slug?: string };
@@ -72,7 +73,7 @@ export default function Toggle() {
cta={
projectSlug ? "Upgrade to Pro" : "Create Project"
}
- href="https://app.dub.sh"
+ href={APP_DOMAIN}
/>
}
>
diff --git a/components/app/modals/accept-invite-modal.tsx b/components/app/modals/accept-invite-modal.tsx
index a3c1d5d280..4ed9d44674 100644
--- a/components/app/modals/accept-invite-modal.tsx
+++ b/components/app/modals/accept-invite-modal.tsx
@@ -10,7 +10,7 @@ import {
import { mutate } from "swr";
import BlurImage from "#/ui/blur-image";
import { LoadingDots } from "#/ui/icons";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import useProject from "#/lib/swr/use-project";
import { toast } from "sonner";
import va from "@vercel/analytics";
diff --git a/components/app/modals/add-edit-domain-modal.tsx b/components/app/modals/add-edit-domain-modal.tsx
index d537e128b2..4b839375dc 100644
--- a/components/app/modals/add-edit-domain-modal.tsx
+++ b/components/app/modals/add-edit-domain-modal.tsx
@@ -12,7 +12,7 @@ import { mutate } from "swr";
import { useDebounce } from "use-debounce";
import BlurImage from "#/ui/blur-image";
import { AlertCircleFill, Lock } from "@/components/shared/icons";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import { DomainProps } from "#/lib/types";
import Tooltip, { TooltipContent } from "#/ui/tooltip";
import useProject from "#/lib/swr/use-project";
diff --git a/components/app/modals/add-edit-link-modal/index.tsx b/components/app/modals/add-edit-link-modal/index.tsx
index da10632f83..115d2e73b8 100644
--- a/components/app/modals/add-edit-link-modal/index.tsx
+++ b/components/app/modals/add-edit-link-modal/index.tsx
@@ -14,7 +14,7 @@ import { useDebounce } from "use-debounce";
import BlurImage from "#/ui/blur-image";
import { AlertCircleFill, Lock, Random, X } from "@/components/shared/icons";
import { LoadingCircle } from "#/ui/icons";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import Tooltip, { TooltipContent } from "#/ui/tooltip";
import useProject from "#/lib/swr/use-project";
import { LinkProps } from "#/lib/types";
diff --git a/components/app/modals/add-project-modal.tsx b/components/app/modals/add-project-modal.tsx
index f064a7c8e6..ec14c346d3 100644
--- a/components/app/modals/add-project-modal.tsx
+++ b/components/app/modals/add-project-modal.tsx
@@ -12,7 +12,7 @@ import { mutate } from "swr";
import { useDebounce } from "use-debounce";
import BlurImage from "#/ui/blur-image";
import { AlertCircleFill } from "@/components/shared/icons";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import { generateDomainFromName } from "#/lib/utils";
import slugify from "@sindresorhus/slugify";
import va from "@vercel/analytics";
diff --git a/components/app/modals/archive-link-modal.tsx b/components/app/modals/archive-link-modal.tsx
index a761cce85c..faebb32b12 100644
--- a/components/app/modals/archive-link-modal.tsx
+++ b/components/app/modals/archive-link-modal.tsx
@@ -8,7 +8,7 @@ import {
} from "react";
import { mutate } from "swr";
import BlurImage from "#/ui/blur-image";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import { LinkProps } from "#/lib/types";
import { getApexDomain, getQueryString, linkConstructor } from "#/lib/utils";
import { GOOGLE_FAVICON_URL } from "#/lib/constants";
diff --git a/components/app/modals/complete-setup-modal.tsx b/components/app/modals/complete-setup-modal.tsx
index 519222b753..d7269829db 100644
--- a/components/app/modals/complete-setup-modal.tsx
+++ b/components/app/modals/complete-setup-modal.tsx
@@ -8,7 +8,7 @@ import {
useState,
} from "react";
import BlurImage from "#/ui/blur-image";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import { CheckCircleFill } from "@/components/shared/icons";
import { ExpandingArrow } from "#/ui/icons";
import useDomains from "#/lib/swr/use-domains";
diff --git a/components/app/modals/delete-account-modal.tsx b/components/app/modals/delete-account-modal.tsx
index ae7f80de31..021af5a8dd 100644
--- a/components/app/modals/delete-account-modal.tsx
+++ b/components/app/modals/delete-account-modal.tsx
@@ -8,7 +8,7 @@ import {
} from "react";
import { toast } from "sonner";
import BlurImage from "#/ui/blur-image";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import Button from "#/ui/button";
import { useSession } from "next-auth/react";
diff --git a/components/app/modals/delete-link-modal.tsx b/components/app/modals/delete-link-modal.tsx
index 12a9172be4..b93c668382 100644
--- a/components/app/modals/delete-link-modal.tsx
+++ b/components/app/modals/delete-link-modal.tsx
@@ -8,7 +8,7 @@ import {
} from "react";
import { mutate } from "swr";
import BlurImage from "#/ui/blur-image";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import { LinkProps } from "#/lib/types";
import { getApexDomain, getQueryString, linkConstructor } from "#/lib/utils";
import { toast } from "sonner";
diff --git a/components/app/modals/delete-project-modal.tsx b/components/app/modals/delete-project-modal.tsx
index 9240a0fa71..7e0d0c39e6 100644
--- a/components/app/modals/delete-project-modal.tsx
+++ b/components/app/modals/delete-project-modal.tsx
@@ -9,7 +9,7 @@ import {
import { toast } from "sonner";
import { mutate } from "swr";
import BlurImage from "#/ui/blur-image";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import useProject from "#/lib/swr/use-project";
import Button from "#/ui/button";
diff --git a/components/app/modals/google-oauth-modal.tsx b/components/app/modals/google-oauth-modal.tsx
index 9b5aa8e319..e2743414f8 100644
--- a/components/app/modals/google-oauth-modal.tsx
+++ b/components/app/modals/google-oauth-modal.tsx
@@ -7,7 +7,7 @@ import {
useState,
} from "react";
import BlurImage from "#/ui/blur-image";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import Button from "#/ui/button";
import { Google } from "@/components/shared/icons";
import Cookies from "js-cookie";
diff --git a/components/app/modals/import-bitly-modal.tsx b/components/app/modals/import-bitly-modal.tsx
index 18c17313f3..1cb9480dbe 100644
--- a/components/app/modals/import-bitly-modal.tsx
+++ b/components/app/modals/import-bitly-modal.tsx
@@ -9,7 +9,7 @@ import {
useState,
} from "react";
import BlurImage from "#/ui/blur-image";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import useProject from "#/lib/swr/use-project";
import Switch from "#/ui/switch";
import Button from "#/ui/button";
diff --git a/components/app/modals/invite-teammate-modal.tsx b/components/app/modals/invite-teammate-modal.tsx
index b2a3899ac4..e072a8ecf4 100644
--- a/components/app/modals/invite-teammate-modal.tsx
+++ b/components/app/modals/invite-teammate-modal.tsx
@@ -9,7 +9,7 @@ import {
import { mutate } from "swr";
import BlurImage from "#/ui/blur-image";
import va from "@vercel/analytics";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import useProject from "#/lib/swr/use-project";
import { toast } from "sonner";
import Button from "#/ui/button";
diff --git a/components/app/modals/link-filters-modal.tsx b/components/app/modals/link-filters-modal.tsx
index bba103f463..ddca38a321 100644
--- a/components/app/modals/link-filters-modal.tsx
+++ b/components/app/modals/link-filters-modal.tsx
@@ -5,7 +5,7 @@ import {
useMemo,
useState,
} from "react";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import LinkFilters from "../links/link-filters";
import IconMenu from "@/components/shared/icon-menu";
import { ChevronDown, Filter } from "lucide-react";
diff --git a/components/app/modals/link-qr-modal.tsx b/components/app/modals/link-qr-modal.tsx
index 941386939d..017e366844 100644
--- a/components/app/modals/link-qr-modal.tsx
+++ b/components/app/modals/link-qr-modal.tsx
@@ -10,7 +10,7 @@ import { HexColorInput, HexColorPicker } from "react-colorful";
import BlurImage from "#/ui/blur-image";
import { Clipboard } from "@/components/shared/icons";
import { ChevronRight } from "lucide-react";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import Switch from "#/ui/switch";
import Tooltip, { TooltipContent } from "#/ui/tooltip";
import { QRCodeSVG, getQRAsCanvas, getQRAsSVGDataUri } from "#/lib/qr";
diff --git a/components/app/modals/remove-teammate-modal.tsx b/components/app/modals/remove-teammate-modal.tsx
index 31e2106bc6..5753cdcbe1 100644
--- a/components/app/modals/remove-teammate-modal.tsx
+++ b/components/app/modals/remove-teammate-modal.tsx
@@ -8,7 +8,7 @@ import {
} from "react";
import { mutate } from "swr";
import BlurImage from "#/ui/blur-image";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import useProject from "#/lib/swr/use-project";
import { toast } from "sonner";
import Button from "#/ui/button";
diff --git a/components/app/modals/upgrade-plan-modal.tsx b/components/app/modals/upgrade-plan-modal.tsx
index 06ce42b43b..a430299839 100644
--- a/components/app/modals/upgrade-plan-modal.tsx
+++ b/components/app/modals/upgrade-plan-modal.tsx
@@ -5,7 +5,7 @@ import {
useMemo,
useState,
} from "react";
-import Modal from "@/components/shared/modal";
+import Modal from "#/ui/modal";
import Button from "#/ui/button";
import { useRouter } from "next/router";
import Link from "next/link";
diff --git a/components/shared/modal.tsx b/components/shared/modal.tsx
deleted file mode 100644
index ec86f9b96b..0000000000
--- a/components/shared/modal.tsx
+++ /dev/null
@@ -1,150 +0,0 @@
-import { useRouter } from "next/router";
-import {
- Dispatch,
- SetStateAction,
- useCallback,
- useEffect,
- useRef,
-} from "react";
-import FocusTrap from "focus-trap-react";
-import { AnimatePresence, motion, useAnimation } from "framer-motion";
-
-export default function Modal({
- children,
- showModal,
- setShowModal,
- bgColor = "bg-white",
- closeWithX,
- onClose,
- hideBackdrop,
- mobileOnly,
-}: {
- children: React.ReactNode;
- showModal: boolean;
- setShowModal: Dispatch<SetStateAction<boolean>>;
- bgColor?: string;
- closeWithX?: boolean;
- onClose?: () => void;
- hideBackdrop?: boolean;
- mobileOnly?: boolean;
-}) {
- const router = useRouter();
- const { key } = router.query;
- const mobileModalRef = useRef<HTMLDivElement | null>(null);
- const desktopModalRef = useRef<HTMLDivElement | null>(null);
-
- const closeModal = useCallback(
- (closeWithX?: boolean) => {
- if (closeWithX) {
- return;
- } else if (onClose) {
- onClose();
- }
- setShowModal(false);
- },
- [key, router, setShowModal],
- );
-
- const onKeyDown = useCallback((e: KeyboardEvent) => {
- if (e.key === "Escape" && !closeWithX) {
- setShowModal(false);
- }
- }, []);
-
- useEffect(() => {
- document.addEventListener("keydown", onKeyDown);
- return () => document.removeEventListener("keydown", onKeyDown);
- }, [onKeyDown]);
-
- const controls = useAnimation();
- const transitionProps = { type: "spring", stiffness: 500, damping: 30 };
- useEffect(() => {
- controls.start({
- y: 0,
- transition: transitionProps,
- });
- }, []);
-
- async function handleDragEnd(_, info) {
- const offset = info.offset.y;
- const velocity = info.velocity.y;
- const height = mobileModalRef.current?.getBoundingClientRect().height || 0;
- if (offset > height / 2 || velocity > 800) {
- await controls.start({ y: "100%", transition: transitionProps });
- closeModal();
- } else {
- controls.start({ y: 0, transition: transitionProps });
- }
- }
-
- return (
- <AnimatePresence>
- {showModal && (
- <FocusTrap
- focusTrapOptions={{
- initialFocus: false,
- clickOutsideDeactivates: true,
- onActivate: () => {
- // prevent scroll outside of modal when modal is open
- document.body.style.overflow = "hidden";
- },
- onDeactivate: () => {
- // allow scroll outside of modal when modal is closed
- document.body.style.overflow = "auto";
- },
- }}
- >
- <div className="absolute">
- <motion.div
- ref={mobileModalRef}
- key="mobile-modal"
- className="group fixed inset-x-0 bottom-0 z-40 w-screen cursor-grab active:cursor-grabbing sm:hidden"
- initial={{ y: "100%" }}
- animate={controls}
- exit={{ y: "100%" }}
- transition={transitionProps}
- drag="y"
- dragDirectionLock
- onDragEnd={handleDragEnd}
- dragElastic={{ top: 0, bottom: 1 }}
- dragConstraints={{ top: 0, bottom: 0 }}
- >
- <div
- className={`h-7 ${bgColor} rounded-t-4xl -mb-1 flex w-full items-center justify-center border-t border-gray-200`}
- >
- <div className="-mr-1 h-1 w-6 rounded-full bg-gray-300 transition-all group-active:rotate-12" />
- <div className="h-1 w-6 rounded-full bg-gray-300 transition-all group-active:-rotate-12" />
- </div>
- {children}
- </motion.div>
- {!mobileOnly && (
- <div
- ref={desktopModalRef}
- key="desktop-modal"
- className="fixed inset-0 z-40 hidden min-h-screen animate-scale-in items-center justify-center sm:flex"
- onMouseDown={(e) => {
- if (desktopModalRef.current === e.target) {
- closeModal(closeWithX);
- }
- }}
- >
- {children}
- </div>
- )}
- {!hideBackdrop && (
- <motion.div
- id="modal-backdrop"
- key="backdrop"
- className="fixed inset-0 z-30 bg-gray-100 bg-opacity-10 backdrop-blur"
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- exit={{ opacity: 0 }}
- onClick={() => closeModal(closeWithX)}
- />
- )}
- </div>
- </FocusTrap>
- )}
- </AnimatePresence>
- );
-}