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.

11.5 KB
Raw Blame
"use client";

import { testIds } from "@/lib/e2e/test-ids";
import { useSyncedLocalStorage } from "@/lib/hooks/use-synced-local-storage";
import { getPlanCapabilities } from "@/lib/plan-capabilities";
import useDomains from "@/lib/swr/use-domains";
import useWorkspace from "@/lib/swr/use-workspace";
import { WorkspaceProps } from "@/lib/types";
import { MarkdownDescription } from "@/ui/shared/markdown-description";
import { SlackSupportInviteModal } from "@/ui/workspaces/slack-support-invite-modal";
import {
  BlurImage,
  Book2,
  Button,
  Check2,
  CircleQuestion,
  CursorRays,
  Globe,
  Hyperlink,
  LinesY,
  LoadingSpinner,
  Msg,
  Users,
} from "@dub/ui";
import { Slack } from "@dub/ui/icons";
import { capitalize, cn, isWorkspaceBillingTrialActive } from "@dub/utils";
import { usePlausible } from "next-plausible";
import Link from "next/link";
import { useEffect, useState } from "react";
import { useOnboardingProgress } from "../../use-onboarding-progress";

export function SuccessPageClient({
  workspace,
}: {
  workspace: Pick<WorkspaceProps, "name" | "slug" | "logo" | "plan">;
}) {
  const { plan, planPeriod, trialEndsAt } = useWorkspace();

  const showSlackInvite =
    getPlanCapabilities(workspace.plan).canRequestSlackSupportInvite &&
    !isWorkspaceBillingTrialActive(trialEndsAt);

  const [slackInviteDone, setSlackInviteDone] = useSyncedLocalStorage(
    workspace.slug ? `slack-support-dismissed:${workspace.slug}` : "__none__",
    false,
  );
  const [slackInviteModalOpen, setSlackInviteModalOpen] = useState(false);

  const { finish, isLoading, isSuccessful } = useOnboardingProgress();

  const { allWorkspaceDomains, loading: isLoadingDomains } = useDomains();
  const connectedDomain = Boolean(allWorkspaceDomains?.length);

  const plausible = usePlausible();
  useEffect(() => {
    if (plan && plan !== "free") {
      plausible(`Upgraded to ${capitalize(plan)}`);
      plausible("Upgraded Plan", {
        props: {
          product: "Links",
          plan: capitalize(plan),
          planPeriod: capitalize(planPeriod),
        },
      });
    }
  }, [plan]);

  return (
    <div className="mx-auto flex w-full max-w-sm flex-col items-center pb-10">
      <div
        className={cn(
          "flex flex-col items-center",
          "animate-slide-up-fade [--offset:10px] [animation-duration:1s] [animation-fill-mode:both]",
        )}
      >
        {workspace.logo && (
          <div className="relative mb-5">
            <BlurImage
              src={workspace.logo}
              alt="workspace logo"
              className="size-24 rounded-full"
              width={96}
              height={96}
            />
            <div className="absolute -bottom-1 -right-1 flex size-7 items-center justify-center rounded-full bg-green-400 ring-4 ring-white">
              <Check2 className="size-4 text-green-800" />
            </div>
          </div>
        )}
        <h1
          className="text-pretty text-center text-xl font-semibold"
          data-testid={testIds.onboarding.workspaceCreated}
        >
          The {workspace.name} workspace has been created
        </h1>
        <MarkdownDescription className="mt-2 text-pretty text-center text-base text-neutral-500">
          Now you have one central, organized place to create and [manage all
          your short links](https://dub.co/help/category/link-management).
        </MarkdownDescription>
        <div className="mt-4 w-full">
          <Button
            onClick={() => finish()}
            loading={isLoading || isSuccessful}
            text="Go to your dashboard"
            className="h-9 rounded-lg"
            data-testid={testIds.onboarding.goToDashboard}
          />
        </div>
      </div>

      <div
        className={cn(
          "mt-8 flex w-full max-w-[400px] flex-col gap-3",
          "animate-slide-up-fade motion-reduce:animate-fade-in [--offset:10px] [animation-delay:250ms] [animation-duration:0.5s] [animation-fill-mode:both]",
        )}
      >
        <h3
          className="text-content-emphasis font-semibold"
          data-testid={testIds.onboarding.completeSetup}
        >
          Complete setup
        </h3>

        <div className="divide-border-subtle border-border-subtle bg-bg-muted flex flex-col divide-y overflow-hidden rounded-lg border">
          {[
            {
              icon: Globe,
              title: "Connect domain",
              description: "Claim a free domain or connect your own",
              href: `/${workspace.slug}/settings/domains`,
              cta: connectedDomain ? "Manage" : "Connect",
              loading: isLoadingDomains,
              complete: Boolean(allWorkspaceDomains?.length),
            },
            {
              icon: Hyperlink,
              title: "Create a short link",
              description: "Create your first Dub short link",
              href: `/${workspace.slug}/links?newLink=true`,
              cta: "Create",
            },
            {
              icon: LinesY,
              title: "Explore analytics",
              description: "View clicks and performance data",
              href: `/${workspace.slug}/analytics`,
              cta: "View",
            },
            {
              icon: CursorRays,
              title: "Explore events",
              description: "View events for your short links",
              href: `/${workspace.slug}/events`,
              cta: "View",
            },
          ].map(
            ({
              icon: Icon,
              title,
              description,
              href,
              cta,
              loading,
              complete,
            }) => (
              <div
                key={href}
                className={cn(
                  "flex items-center justify-between gap-2 px-2.5 py-2",
                  complete && "bg-black/[0.02]",
                )}
              >
                <div className="flex min-w-0 items-center gap-2">
                  <div
                    className={cn(
                      "flex size-8 items-center justify-center rounded-md bg-black/5",
                      complete && "bg-green-400",
                    )}
                  >
                    {loading ? (
                      <LoadingSpinner className="size-4" />
                    ) : complete ? (
                      <Check2 className="size-4 text-green-800" />
                    ) : (
                      <Icon className="size-4" />
                    )}
                  </div>
                  <div
                    className={cn(
                      "min-w-0",
                      (loading || complete) && "opacity-60",
                    )}
                  >
                    <div className="text-content-default text-sm font-medium">
                      {title}
                    </div>
                    <p className="text-content-subtle truncate text-xs font-medium">
                      {description}
                    </p>
                  </div>
                </div>

                <Link
                  href={href}
                  target="_blank"
                  className="border-subtle bg-bg-default hover:bg-bg-muted flex h-7 items-center rounded-lg border px-2.5 text-sm font-medium transition-transform active:scale-[0.98]"
                >
                  {cta}
                </Link>
              </div>
            ),
          )}
        </div>
      </div>

      <div
        className={cn(
          "mt-8 flex w-full max-w-[400px] flex-col gap-3",
          "animate-slide-up-fade motion-reduce:animate-fade-in [--offset:10px] [animation-delay:250ms] [animation-duration:0.5s] [animation-fill-mode:both]",
        )}
      >
        <h3 className="text-content-emphasis font-semibold">
          Additional resources
        </h3>

        <div className="divide-border-subtle border-border-subtle bg-bg-muted flex flex-col divide-y rounded-lg border">
          {showSlackInvite && (
            <div className="flex items-center justify-between gap-2 px-2.5 py-2">
              <div className="flex min-w-0 items-center gap-2">
                <div className="flex size-8 items-center justify-center rounded-md bg-black/5">
                  <Slack className="size-4" />
                </div>
                <div className="min-w-0">
                  <div className="text-content-default text-sm font-medium">
                    Slack invite
                  </div>
                  <p className="text-content-subtle truncate text-xs font-medium">
                    Get priority support
                  </p>
                </div>
              </div>

              <button
                type="button"
                disabled={slackInviteDone}
                onClick={() => setSlackInviteModalOpen(true)}
                className={cn(
                  "border-subtle bg-bg-default hover:bg-bg-muted flex h-7 items-center rounded-lg border px-2.5 text-sm font-medium transition-transform active:scale-[0.98]",
                  "disabled:pointer-events-none disabled:opacity-50",
                )}
              >
                {slackInviteDone ? "Invite sent" : "Request invite"}
              </button>
            </div>
          )}
          {[
            {
              icon: Users,
              title: "Team members",
              description: "Invite and manage team members",
              href: `/${workspace.slug}/settings/members`,
              cta: "Invite",
            },
            {
              icon: CircleQuestion,
              title: "Help center",
              description: "Answers to your questions",
              href: "https://dub.co/help",
              cta: "Read",
            },
            {
              icon: Book2,
              title: "Docs",
              description: "Platform documentation",
              href: "https://dub.co/docs",
              cta: "Learn",
            },
            {
              icon: Msg,
              title: "Support",
              description: "Product support or help requests",
              href: "https://dub.co/contact/support",
              cta: "Chat",
            },
          ].map(({ icon: Icon, title, description, href, cta }) => (
            <div
              key={href}
              className="flex items-center justify-between gap-2 px-2.5 py-2"
            >
              <div className="flex min-w-0 items-center gap-2">
                <div className="flex size-8 items-center justify-center rounded-md bg-black/5">
                  <Icon className="size-4" />
                </div>
                <div className="min-w-0">
                  <div className="text-content-default text-sm font-medium">
                    {title}
                  </div>
                  <p className="text-content-subtle truncate text-xs font-medium">
                    {description}
                  </p>
                </div>
              </div>

              <Link
                href={href}
                target="_blank"
                className="border-subtle bg-bg-default hover:bg-bg-muted flex h-7 items-center rounded-lg border px-2.5 text-sm font-medium transition-transform active:scale-[0.98]"
              >
                {cta}
              </Link>
            </div>
          ))}
        </div>
      </div>
      {showSlackInvite && (
        <SlackSupportInviteModal
          showModal={slackInviteModalOpen}
          setShowModal={setSlackInviteModalOpen}
          workspaceSlug={workspace.slug}
          onInviteSent={() => setSlackInviteDone(true)}
          onInviteConflict={() => setSlackInviteDone(true)}
        />
      )}
    </div>
  );
}