import clsx from "clsx"; import { Fragment, useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import ButtonPrimary from "~/components/ui/buttons/ButtonPrimary"; import ButtonSecondary from "~/components/ui/buttons/ButtonSecondary"; import CustomCarousel from "~/components/ui/images/CustomCarousel"; import InputSelect from "~/components/ui/input/InputSelect"; import InputText from "~/components/ui/input/InputText"; import Modal from "~/components/ui/modals/Modal"; import Tabs from "~/components/ui/tabs/Tabs"; import { renderSanitizedMarkdown } from "~/utils/html-sanitizer"; import { OnboardingBlockDto, OnboardingStepBlockDto } from "./OnboardingBlockUtils"; import OnboardingGridUtils from "./grid/OnboardingGridUtils"; export default function OnboardingVariantModal({ block, currentStepIdx, setStep, open, onClose, onDismiss, onComplete, onLinkClick, onUpdateCurrentStepState, }: { block: OnboardingBlockDto; currentStepIdx: number; open: boolean; setStep: (idx: number) => void; onClose: () => void; onDismiss: () => void; onComplete: () => void; onLinkClick: (item: { text: string; href: string }) => void; onUpdateCurrentStepState: (state: { [key: string]: string }) => void; }) { const { t } = useTranslation(); function dismiss() { onDismiss(); } function onNext() { const nextStep = block.steps[currentStepIdx + 1]; if (nextStep) { setStep(currentStepIdx + 1); } else { onComplete(); } } return ( { if (block.canBeDismissed) { onClose(); } }} padding="none" >
{t(block.title)}
{block.steps.map((step, idx) => { return ( ); })}
setStep(e)} tabs={block.steps.map((step) => { return { name: step.title }; })} />
{block.steps.length > 0 && (
{block.steps.map((step, idx) => { return ( ); })}
)} {block.steps.length > 0 && (
{block.steps.length > currentStepIdx && ( )}
)}
setStep(currentStepIdx - 1)} className="sm:hidden"> {t("shared.back")} {block.canBeDismissed && ( )}
setStep(currentStepIdx - 1)} className="hidden sm:block"> {t("shared.back")} {t("shared.next")} {t("shared.complete")}
); } function OnboardingStep({ step, onLinkClick, onUpdate, }: { step: OnboardingStepBlockDto; onLinkClick: (link: { text: string; href: string }) => void; onUpdate: (state: { [key: string]: string }) => void; }) { const { t } = useTranslation(); const [state, setState] = useState<{ [key: string]: string }>({}); useEffect(() => { if (onUpdate) { onUpdate(state); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [state]); return (
{step.description && (
)} {step.links && step.links.length > 0 && (
{step.links.map((link, idx) => { return (
); })}
)} {step.gallery && step.gallery.length > 0 && (
{/* {step.gallery.map((galleryItem, idx) => { return ( {galleryItem.type === "image" && ( {galleryItem.title )} {galleryItem.type === "video" && ( )} ); })} */}
)} {step.input && step.input.length > 0 && (
{step.input.map((input, idx) => { return (
{input.type === "text" && ( setState({ ...state, [input.name]: e.toString() })} /> )} {input.type === "select" && ( { return { value: f.value, name: t(f.name) }; }) ?? [] } value={state?.[input.name] ?? ""} setValue={(e) => setState({ ...state, [input.name]: e?.toString() ?? "" })} /> )}
); })}
)}
); }