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.

improved upgrade plan modal, fixed onboarding checklist

Steven Tey79acdd62f68d
diff --git a/app/ui/badge.tsx b/app/ui/badge.tsx
index f087dacf75..533751a124 100644
--- a/app/ui/badge.tsx
+++ b/app/ui/badge.tsx
@@ -6,7 +6,7 @@ export default function Badge({
className,
}: {
text: string;
- variant?: "purple" | "blue" | "black" | "gray";
+ variant?: "purple" | "blue" | "black" | "gray" | "neutral";
className?: string;
}) {
return (
@@ -18,6 +18,7 @@ export default function Badge({
"border-blue-500 bg-blue-500 text-white": variant === "blue",
"border-black bg-black text-white": variant === "black",
"border-gray-400 bg-gray-400 text-white": variant === "gray",
+ "border-gray-400 text-gray-500": variant === "neutral",
},
className,
)}
diff --git a/app/ui/modal-provider.tsx b/app/ui/modal-provider.tsx
index 1b8e5fa261..f9420475bc 100644
--- a/app/ui/modal-provider.tsx
+++ b/app/ui/modal-provider.tsx
@@ -22,9 +22,11 @@ import { mutate } from "swr";
import { useRouter } from "next/router";
import { getQueryString } from "#/lib/utils";
import { useUpgradePlanModal } from "@/components/app/modals/upgrade-plan-modal";
+import { useCompleteSetupModal } from "@/components/app/modals/complete-setup-modal";
export const ModalContext = createContext<{
setShowAddProjectModal: Dispatch<SetStateAction<boolean>>;
+ setShowCompleteSetupModal: Dispatch<SetStateAction<boolean>>;
setShowAddEditDomainModal: Dispatch<SetStateAction<boolean>>;
setShowAddEditLinkModal: Dispatch<SetStateAction<boolean>>;
setShowUpgradePlanModal: Dispatch<SetStateAction<boolean>>;
@@ -32,6 +34,7 @@ export const ModalContext = createContext<{
setPollLinks: Dispatch<SetStateAction<boolean>>;
}>({
setShowAddProjectModal: () => {},
+ setShowCompleteSetupModal: () => {},
setShowAddEditDomainModal: () => {},
setShowAddEditLinkModal: () => {},
setShowUpgradePlanModal: () => {},
@@ -42,6 +45,8 @@ export const ModalContext = createContext<{
export default function ModalProvider({ children }: { children: ReactNode }) {
const { GoogleOauthModal, setShowGoogleOauthModal } = useGoogleOauthModal();
const { AddProjectModal, setShowAddProjectModal } = useAddProjectModal();
+ const { CompleteSetupModal, setShowCompleteSetupModal } =
+ useCompleteSetupModal();
const { AcceptInviteModal, setShowAcceptInviteModal } =
useAcceptInviteModal();
const { setShowAddEditDomainModal, AddEditDomainModal } =
@@ -100,6 +105,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
<ModalContext.Provider
value={{
setShowAddProjectModal,
+ setShowCompleteSetupModal,
setShowAddEditDomainModal,
setShowAddEditLinkModal,
setShowUpgradePlanModal,
@@ -109,6 +115,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
>
<GoogleOauthModal />
<AddProjectModal />
+ <CompleteSetupModal />
{error && (error.status === 409 || error.status === 410) && (
<AcceptInviteModal />
)}
diff --git a/components/app/modals/complete-setup-modal.tsx b/components/app/modals/complete-setup-modal.tsx
index 9a0beb581a..519222b753 100644
--- a/components/app/modals/complete-setup-modal.tsx
+++ b/components/app/modals/complete-setup-modal.tsx
@@ -14,6 +14,8 @@ import { ExpandingArrow } from "#/ui/icons";
import useDomains from "#/lib/swr/use-domains";
import useLinksCount from "#/lib/swr/use-links-count";
import { ModalContext } from "#/ui/modal-provider";
+import Link from "next/link";
+import useUsers from "#/lib/swr/use-users";
function CompleteSetupModal({
showCompleteSetupModal,
@@ -26,7 +28,9 @@ function CompleteSetupModal({
const { slug } = router.query as { slug: string };
const { verified } = useDomains();
- const { data: count } = useLinksCount() as unknown as { data: number };
+ const { data: count } = useLinksCount();
+ const { users } = useUsers();
+ const { users: invites } = useUsers({ invites: true });
const { setShowAddEditLinkModal } = useContext(ModalContext);
const tasks = useMemo(() => {
@@ -36,16 +40,16 @@ function CompleteSetupModal({
cta: `/${slug}/domains`,
checked: verified,
},
- {
- display: "Invite your teammates",
- cta: `/${slug}/settings/people`,
- checked: false,
- },
{
display: "Create or import your links",
- cta: "create-link",
+ cta: `/${slug}`,
checked: count > 0,
},
+ {
+ display: "Invite your teammates",
+ cta: `/${slug}/settings/people`,
+ checked: (users && users.length > 1) || (invites && invites.length > 0),
+ },
];
}, [slug, verified, count]);
@@ -87,23 +91,18 @@ function CompleteSetupModal({
</div>
</div>
);
- if (cta === "create-link") {
- return (
- <button
- key={display}
- onClick={() => {
- setShowCompleteSetupModal(false);
- setShowAddEditLinkModal(true);
- }}
- >
- {contents}
- </button>
- );
- }
return (
- <a key={display} target="_blank" rel="noreferrer" href={cta}>
+ <Link
+ key={display}
+ href={cta}
+ onClick={() => {
+ setShowCompleteSetupModal(false);
+ display === "Create or import your links" &&
+ setShowAddEditLinkModal(true);
+ }}
+ >
{contents}
- </a>
+ </Link>
);
})}
</div>
diff --git a/components/app/modals/upgrade-plan-modal.tsx b/components/app/modals/upgrade-plan-modal.tsx
index 72244beb7e..06ce42b43b 100644
--- a/components/app/modals/upgrade-plan-modal.tsx
+++ b/components/app/modals/upgrade-plan-modal.tsx
@@ -15,6 +15,8 @@ import { CheckCircleFill } from "@/components/shared/icons";
import { capitalize } from "#/lib/utils";
import { PLANS } from "#/lib/stripe/utils";
import { getStripe } from "#/lib/stripe/client";
+import Badge from "#/ui/badge";
+import Confetti from "react-dom-confetti";
function UpgradePlanModal({
showUpgradePlanModal,
@@ -27,15 +29,21 @@ function UpgradePlanModal({
}) {
const router = useRouter();
const { slug } = router.query;
- const features = [
- "Unlimited custom domains",
- "Unlimited team members",
- "Unlimited link history",
- "Track 50x more link clicks per month",
- "Redirect your root domain",
- "Custom QR Code logo",
- ];
+ const [plan, setPlan] = useState<"Pro" | "Enterprise">("Pro");
const [period, setPeriod] = useState<"monthly" | "yearly">("yearly");
+ const features = useMemo(() => {
+ return [
+ `Track ${
+ plan === "Enterprise" ? "unlimited" : "50x more"
+ } link clicks per month`,
+ "Unlimited custom domains",
+ "Unlimited team members",
+ "Unlimited link history",
+ "Redirect your root domain",
+ "Custom QR Code logo",
+ ...(plan === "Enterprise" ? ["SSO/SAML", "Priority support"] : []),
+ ];
+ }, [plan]);
const [clicked, setClicked] = useState(false);
return (
<Modal
@@ -43,7 +51,7 @@ function UpgradePlanModal({
setShowModal={setShowUpgradePlanModal}
closeWithX={welcomeFlow}
>
- <div className="inline-block w-full transform overflow-hidden bg-white align-middle shadow-xl transition-all sm:max-w-md sm:rounded-2xl sm:border sm:border-gray-200">
+ <div className="inline-block w-full transform overflow-hidden bg-white align-middle shadow-xl transition-all sm:max-w-lg sm:rounded-2xl sm:border sm:border-gray-200">
<motion.div
variants={{
show: {
@@ -68,13 +76,13 @@ function UpgradePlanModal({
className="text-lg font-medium"
variants={STAGGER_CHILD_VARIANTS}
>
- Upgrade to Pro
+ Upgrade to {plan}
</motion.h3>
<motion.p
className="text-center text-sm text-gray-500"
variants={STAGGER_CHILD_VARIANTS}
>
- Enjoy higher limits and more powerful features with our Pro plan.
+ Enjoy higher limits and extra features with our {plan} plan.
</motion.p>
</motion.div>
<div className="bg-gray-50 px-4 py-8 text-left sm:px-16">
@@ -85,29 +93,39 @@ function UpgradePlanModal({
animate="show"
>
<div className="mb-4">
- <div className="mb-2 flex items-center justify-between">
+ <div className="mb-4 flex items-center justify-between">
<div className="flex items-center space-x-2">
<h4 className="font-medium text-gray-900">
- Pro {capitalize(period)}
+ {plan} {capitalize(period)}
</h4>
- <span className="rounded-full border border-gray-400 px-2 py-px text-sm text-gray-500">
- {period === "monthly" ? "$9/month" : "$90/year"}
- </span>
+ <Badge
+ text={`$${
+ PLANS.find((p) => p.name === plan)!.price[period].amount
+ }/${period.replace("ly", "")}`}
+ variant="neutral"
+ className="text-sm font-normal normal-case"
+ />
</div>
+ <Confetti
+ active={period === "yearly"}
+ config={{ elementCount: 200, spread: 90 }}
+ />
<button
onClick={() => {
setPeriod(period === "monthly" ? "yearly" : "monthly");
}}
- className="text-xs text-gray-500 underline"
+ className="text-xs text-gray-500 underline underline-offset-4 transition-colors hover:text-gray-800"
>
- Switch to {period === "monthly" ? "yearly" : "monthly"}
+ {period === "monthly"
+ ? "Get 2 months free 🎁"
+ : "Switch to monthly"}
</button>
</div>
<motion.div
variants={{
show: {
transition: {
- staggerChildren: 0.05,
+ staggerChildren: 0.08,
},
},
}}
@@ -128,13 +146,13 @@ function UpgradePlanModal({
</motion.div>
</div>
<Button
- text={`Upgrade to Pro ${capitalize(period)}`}
+ text={`Upgrade to ${plan} ${capitalize(period)}`}
loading={clicked}
onClick={() => {
setClicked(true);
fetch(
`/api/projects/${slug}/billing/upgrade?priceId=${
- PLANS.find((p) => p.slug === "pro")!.price[period].priceIds[
+ PLANS.find((p) => p.name === plan)!.price[period].priceIds[
process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
? "production"
: "test"
@@ -156,13 +174,33 @@ function UpgradePlanModal({
});
}}
/>
- {welcomeFlow && (
+ {welcomeFlow ? (
<Link
href={`/${slug}`}
className="text-center text-xs text-gray-500 underline underline-offset-4 transition-colors hover:text-gray-800"
>
Skip for now
</Link>
+ ) : (
+ <div className="flex items-center justify-center space-x-2">
+ <button
+ onClick={() => {
+ setPlan(plan === "Pro" ? "Enterprise" : "Pro");
+ }}
+ className="text-center text-xs text-gray-500 underline-offset-4 transition-all hover:text-gray-800 hover:underline"
+ >
+ Dub {plan === "Pro" ? "Enterprise" : "Pro"}
+ </button>
+ <p className="text-gray-500">•</p>
+ <a
+ href="https://dub.sh/pricing"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-center text-xs text-gray-500 underline-offset-4 transition-all hover:text-gray-800 hover:underline"
+ >
+ Compare plans
+ </a>
+ </div>
)}
</motion.div>
</div>
diff --git a/components/app/projects/project-card.tsx b/components/app/projects/project-card.tsx
index 3db2a8c149..e69717a75d 100644
--- a/components/app/projects/project-card.tsx
+++ b/components/app/projects/project-card.tsx
@@ -2,7 +2,7 @@ import Link from "next/link";
import useSWR from "swr";
import BlurImage from "#/ui/blur-image";
import { CheckCircleFill, XCircleFill } from "@/components/shared/icons";
-import Tooltip, { DomainsTooltip, TooltipContent } from "#/ui/tooltip";
+import Tooltip, { DomainsTooltip } from "#/ui/tooltip";
import { ProjectWithDomainProps } from "#/lib/types";
import { fetcher, nFormatter } from "#/lib/utils";
import { BarChart2, Globe, Link2 } from "lucide-react";
diff --git a/components/layout/app/index.tsx b/components/layout/app/index.tsx
index a38db4aefe..af06e3f1f2 100644
--- a/components/layout/app/index.tsx
+++ b/components/layout/app/index.tsx
@@ -116,7 +116,7 @@ export default function AppLayout({
{plan === "free" && showProBanner === false && (
<button
onClick={() => setShowUpgradePlanModal(true)}
- className="ml-3"
+ className="mb-1 ml-3 hidden sm:block"
>
<Badge
text="Upgrade to Pro"
diff --git a/components/layout/app/nav-tabs.tsx b/components/layout/app/nav-tabs.tsx
index 35c64529b3..33e93d7fba 100644
--- a/components/layout/app/nav-tabs.tsx
+++ b/components/layout/app/nav-tabs.tsx
@@ -1,6 +1,11 @@
+import { ModalContext } from "#/ui/modal-provider";
import Link from "next/link";
import { NextRouter, useRouter } from "next/router";
-import { useMemo } from "react";
+import { useContext, useMemo } from "react";
+import useDomains from "#/lib/swr/use-domains";
+import useLinksCount from "#/lib/swr/use-links-count";
+import useUsers from "#/lib/swr/use-users";
+import Badge from "#/ui/badge";
const TabsHelper = (router: NextRouter): { name: string; href: string }[] => {
const { slug, key } = router.query as {
@@ -29,6 +34,7 @@ const TabsHelper = (router: NextRouter): { name: string; href: string }[] => {
export default function NavTabs() {
const router = useRouter();
+ const { slug } = router.query as { slug?: string };
const tabs = useMemo(() => {
if (!router.isReady) {
return [];
@@ -37,8 +43,11 @@ export default function NavTabs() {
}
}, [router.query]);
+ const { verified, loading } = useDomains();
+ const { data: count } = useLinksCount();
+
return (
- <div className="-mb-0.5 flex h-12 items-center justify-start space-x-2">
+ <div className="-mb-0.5 flex h-12 items-center justify-start space-x-2 overflow-x-scroll">
{tabs.map(({ name, href }) => (
<Link
key={href}
@@ -56,6 +65,37 @@ export default function NavTabs() {
</div>
</Link>
))}
+ {slug && !loading && (!verified || count === 0) && (
+ <OnboardingChecklist />
+ )}
</div>
);
}
+
+const OnboardingChecklist = () => {
+ const { setShowCompleteSetupModal } = useContext(ModalContext);
+ const { verified } = useDomains();
+ const { data: count } = useLinksCount();
+ const { users } = useUsers();
+ const { users: invites } = useUsers({ invites: true });
+
+ const remainder = useMemo(() => {
+ return (
+ (verified ? 0 : 1) +
+ (count > 0 ? 0 : 1) +
+ ((users && users.length > 1) || (invites && invites.length > 0) ? 0 : 1)
+ );
+ }, [count, invites, users, verified]);
+
+ return (
+ <button
+ onClick={() => setShowCompleteSetupModal(true)}
+ className="flex items-center space-x-2 rounded-md border-b-2 border-transparent p-1 px-3 py-2 transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"
+ >
+ <p className="whitespace-nowrap text-sm text-gray-600">
+ Onboarding Checklist
+ </p>
+ <Badge text={remainder.toString()} variant="blue" />
+ </button>
+ );
+};
diff --git a/lib/api/domains.ts b/lib/api/domains.ts
index 5692b0565e..dfe12b8923 100644
--- a/lib/api/domains.ts
+++ b/lib/api/domains.ts
@@ -230,18 +230,18 @@ export async function changeDomainForImages(domain: string, newDomain: string) {
/* Delete a domain and all links & images associated with with */
export async function deleteDomainAndLinks(domain: string) {
- const links = await prisma.link.findMany({
- where: {
- domain,
- },
- });
- const pipeline = redis.pipeline();
- links.forEach(({ key }) => {
- pipeline.del(`${domain}:${key}`);
- });
- pipeline.del(`root:${domain}`);
+ // const links = await prisma.link.findMany({
+ // where: {
+ // domain,
+ // },
+ // });
+ // const pipeline = redis.pipeline();
+ // links.forEach(({ key }) => {
+ // pipeline.del(`${domain}:${key}`);
+ // });
+ // pipeline.del(`root:${domain}`);
return await Promise.allSettled([
- pipeline.exec(), // delete all links from redis
+ // pipeline.exec(), // delete all links from redis
// remove all images from cloudinary
cloudinary.v2.api.delete_resources_by_prefix(domain),
// remove the domain from Vercel
diff --git a/lib/swr/use-links-count.ts b/lib/swr/use-links-count.ts
index 3d6711128b..d2e922978d 100644
--- a/lib/swr/use-links-count.ts
+++ b/lib/swr/use-links-count.ts
@@ -9,7 +9,7 @@ export default function useLinksCount({
} = {}) {
const router = useRouter();
- const { data, error } = useSWR<any[]>(
+ const { data, error } = useSWR<any>(
router.isReady &&
`/api/links/_count${getQueryString(
router,
diff --git a/lib/swr/use-users.ts b/lib/swr/use-users.ts
new file mode 100644
index 0000000000..5a873531de
--- /dev/null
+++ b/lib/swr/use-users.ts
@@ -0,0 +1,23 @@
+import { useRouter } from "next/router";
+import useSWR from "swr";
+import { UserProps } from "#/lib/types";
+import { fetcher } from "#/lib/utils";
+
+export default function useUsers({ invites }: { invites?: boolean } = {}) {
+ const router = useRouter();
+ const { slug } = router.query as {
+ slug: string;
+ };
+
+ const { data: users } = useSWR<UserProps[]>(
+ slug &&
+ (invites
+ ? `/api/projects/${slug}/invites`
+ : `/api/projects/${slug}/users`),
+ fetcher,
+ );
+
+ return {
+ users,
+ };
+}
diff --git a/pages/app/[slug]/index.tsx b/pages/app/[slug]/index.tsx
index ccd04da867..6461369771 100644
--- a/pages/app/[slug]/index.tsx
+++ b/pages/app/[slug]/index.tsx
@@ -3,9 +3,7 @@ import { useAddEditLinkModal } from "@/components/app/modals/add-edit-link-modal
import MaxWidthWrapper from "@/components/shared/max-width-wrapper";
import AppLayout from "components/layout/app";
import useProject from "#/lib/swr/use-project";
-import { useContext, useEffect, useState } from "react";
-import { useCompleteSetupModal } from "@/components/app/modals/complete-setup-modal";
-import useDomains from "#/lib/swr/use-domains";
+import { useState } from "react";
import Popover from "@/components/shared/popover";
import IconMenu from "@/components/shared/icon-menu";
import { ChevronDown, FilePlus2, Import } from "lucide-react";
@@ -13,33 +11,15 @@ import { useRouter } from "next/router";
export default function ProjectLinks() {
const router = useRouter();
- const { slug, error, loading: loadingProject } = useProject();
+ const { slug } = useProject();
const { AddEditLinkModal, AddEditLinkButton } = useAddEditLinkModal();
- const { CompleteSetupModal, setShowCompleteSetupModal } =
- useCompleteSetupModal();
-
- const { verified, loading: loadingDomains } = useDomains();
-
- useEffect(() => {
- if (
- !verified &&
- !loadingProject &&
- !loadingDomains &&
- !error &&
- !document.getElementById("modal-backdrop")
- ) {
- setShowCompleteSetupModal(true);
- }
- }, [verified, loadingProject, loadingDomains, error]);
-
const [openPopover, setOpenPopover] = useState(false);
return (
<AppLayout>
{slug && <AddEditLinkModal />}
- {!verified && <CompleteSetupModal />}
<div className="flex h-36 items-center border-b border-gray-200 bg-white">
<MaxWidthWrapper>
<div className="flex items-center justify-between">
diff --git a/pages/app/[slug]/settings/people.tsx b/pages/app/[slug]/settings/people.tsx
index cd321da8e8..03ec8489a3 100644
--- a/pages/app/[slug]/settings/people.tsx
+++ b/pages/app/[slug]/settings/people.tsx
@@ -1,17 +1,16 @@
import SettingsLayout from "@/components/layout/app/settings-layout";
import { useInviteTeammateModal } from "components/app/modals/invite-teammate-modal";
import { useState } from "react";
-import { useRouter } from "next/router";
-import useSWR from "swr";
import BlurImage from "#/ui/blur-image";
import { UserProps } from "#/lib/types";
-import { fetcher, timeAgo } from "#/lib/utils";
+import { timeAgo } from "#/lib/utils";
import Popover from "@/components/shared/popover";
import IconMenu from "@/components/shared/icon-menu";
import { UserMinus } from "lucide-react";
import { ThreeDots } from "@/components/shared/icons";
import { useRemoveTeammateModal } from "@/components/app/modals/remove-teammate-modal";
import Badge from "#/ui/badge";
+import useUsers from "#/lib/swr/use-users";
const tabs: Array<"Members" | "Invitations"> = ["Members", "Invitations"];
@@ -19,19 +18,11 @@ export default function ProjectSettingsPeople() {
const { setShowInviteTeammateModal, InviteTeammateModal } =
useInviteTeammateModal();
- const router = useRouter();
- const { slug } = router.query as { slug?: string };
const [currentTab, setCurrentTab] = useState<"Members" | "Invitations">(
"Members",
);
- const { data: users } = useSWR<UserProps[]>(
- slug &&
- (currentTab === "Members"
- ? `/api/projects/${slug}/users`
- : `/api/projects/${slug}/invites`),
- fetcher,
- );
+ const { users } = useUsers({ invites: currentTab === "Invitations" });
return (
<SettingsLayout>