Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

2.3 KB
Raw Blame
import { Icon } from "@editor/ui/Icon";
import { useTranslation } from "react-i18next";
import OnboardingSlideShell, {
  ShellHero,
  type ShellButton,
} from "@editor/components/onboarding/OnboardingSlideShell";
import { useSaasOnboardingState } from "@editor/components/onboarding/useSaasOnboardingState";
import {
  type SlideId,
  type ButtonAction,
  type ButtonDefinition,
} from "@editor/components/onboarding/saasOnboardingFlowConfig";

interface SaasOnboardingModalProps {
  opened: boolean;
  onClose: () => void;
  /**
   * Drop the closing "desktop-install" slide. Set by the desktop app, which
   * reuses this flow but has no reason to pitch its own download. Defaults to
   * false (slide shown) so the web (saas) flow is unchanged.
   */
  hideDesktopInstall?: boolean;
  slideIds?: SlideId[];
}

export default function SaasOnboardingModal(props: SaasOnboardingModalProps) {
  const { t } = useTranslation();
  const flow = useSaasOnboardingState(props);

  if (!flow) {
    return null;
  }

  const {
    currentStep,
    totalSteps,
    currentSlide,
    slideDefinition,
    flowState,
    handleButtonAction,
  } = flow;

  const heroType = slideDefinition.hero.type;
  const hero =
    heroType === "dual-icon" || heroType === "logo" ? (
      <ShellHero appIcon />
    ) : (
      <ShellHero>
        {heroType === "bolt" && <Icon name="zap" size={30} />}
        {heroType === "team" && <Icon name="users-plus" size={30} />}
      </ShellHero>
    );

  const resolveLabel = (button: ButtonDefinition) => {
    const label = button.label ?? "";
    if (!label) return "";
    const fallback = label.split(".").pop() || label;
    return t(label, fallback);
  };

  const buttons: ShellButton[] = slideDefinition.buttons.map((button) => ({
    key: button.key,
    back: button.type === "icon",
    label: resolveLabel(button),
    primary: (button.variant ?? "secondary") === "primary",
    action: button.action,
    disabled: button.disabledWhen?.(flowState) ?? false,
  }));

  return (
    <OnboardingSlideShell
      opened={props.opened}
      hero={hero}
      slideKey={currentSlide.key}
      title={currentSlide.title}
      body={currentSlide.body}
      stepIndex={currentStep}
      stepCount={totalSteps}
      buttons={buttons}
      onAction={(action) => handleButtonAction(action as ButtonAction)}
      onClose={props.onClose}
    />
  );
}