2023-04-18 11:56:15 +02:00
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { DemoTopics } from './DemoTopics/DemoTopics';
|
|
|
|
import { DemoSteps } from './DemoSteps/DemoSteps';
|
|
|
|
import { createLocalStorage } from 'utils/createLocalStorage';
|
2023-04-19 20:40:29 +02:00
|
|
|
import { TOPICS } from './demo-topics';
|
2023-04-20 17:32:26 +02:00
|
|
|
import { DemoDialogWelcome } from './DemoDialog/DemoDialogWelcome/DemoDialogWelcome';
|
2023-04-21 12:48:44 +02:00
|
|
|
import { DemoDialogFinish } from './DemoDialog/DemoDialogFinish/DemoDialogFinish';
|
2023-04-27 09:15:17 +02:00
|
|
|
import { DemoDialogPlans } from './DemoDialog/DemoDialogPlans/DemoDialogPlans';
|
|
|
|
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
|
|
|
import { DemoBanner } from './DemoBanner/DemoBanner';
|
2023-04-27 15:12:02 +02:00
|
|
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
2023-05-25 19:28:08 +02:00
|
|
|
import { useMediaQuery } from '@mui/material';
|
|
|
|
import theme from 'themes/theme';
|
|
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
2023-04-18 11:56:15 +02:00
|
|
|
|
|
|
|
const defaultProgress = {
|
2023-04-20 17:32:26 +02:00
|
|
|
welcomeOpen: true,
|
2023-04-18 11:56:15 +02:00
|
|
|
expanded: true,
|
2023-04-21 12:48:44 +02:00
|
|
|
topic: -1,
|
2023-05-03 20:47:35 +02:00
|
|
|
step: 0,
|
|
|
|
stepsCompletion: Array(TOPICS.length).fill(0),
|
2023-04-18 11:56:15 +02:00
|
|
|
};
|
|
|
|
|
2023-04-27 09:15:17 +02:00
|
|
|
interface IDemoProps {
|
|
|
|
children: JSX.Element;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Demo = ({ children }: IDemoProps): JSX.Element => {
|
|
|
|
const { uiConfig } = useUiConfig();
|
2023-05-25 19:28:08 +02:00
|
|
|
const isSmallScreen = useMediaQuery(theme.breakpoints.down(768));
|
2023-04-27 15:12:02 +02:00
|
|
|
const { trackEvent } = usePlausibleTracker();
|
2023-04-27 09:15:17 +02:00
|
|
|
|
|
|
|
const { value: storedProgress, setValue: setStoredProgress } =
|
2023-05-03 20:47:35 +02:00
|
|
|
createLocalStorage('Tutorial:v1.1', defaultProgress);
|
2023-04-18 11:56:15 +02:00
|
|
|
|
2023-04-20 17:32:26 +02:00
|
|
|
const [welcomeOpen, setWelcomeOpen] = useState(
|
2023-04-21 12:48:44 +02:00
|
|
|
storedProgress.welcomeOpen ?? defaultProgress.welcomeOpen
|
2023-04-20 17:32:26 +02:00
|
|
|
);
|
2023-04-21 12:48:44 +02:00
|
|
|
const [finishOpen, setFinishOpen] = useState(false);
|
2023-04-27 09:15:17 +02:00
|
|
|
const [plansOpen, setPlansOpen] = useState(false);
|
2023-04-18 11:56:15 +02:00
|
|
|
|
2023-04-21 12:48:44 +02:00
|
|
|
const [expanded, setExpanded] = useState(
|
|
|
|
storedProgress.expanded ?? defaultProgress.expanded
|
|
|
|
);
|
|
|
|
const [topic, setTopic] = useState(
|
|
|
|
storedProgress.topic ?? defaultProgress.topic
|
|
|
|
);
|
2023-05-03 20:47:35 +02:00
|
|
|
const [step, setStep] = useState(
|
|
|
|
storedProgress.step ?? defaultProgress.step
|
|
|
|
);
|
|
|
|
const [stepsCompletion, setStepsCompletion] = useState(
|
|
|
|
storedProgress.stepsCompletion ?? defaultProgress.stepsCompletion
|
2023-04-21 12:48:44 +02:00
|
|
|
);
|
2023-04-18 11:56:15 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setStoredProgress({
|
2023-04-20 17:32:26 +02:00
|
|
|
welcomeOpen,
|
2023-04-18 11:56:15 +02:00
|
|
|
expanded,
|
|
|
|
topic,
|
2023-05-03 20:47:35 +02:00
|
|
|
step,
|
|
|
|
stepsCompletion,
|
2023-04-18 11:56:15 +02:00
|
|
|
});
|
2023-05-03 20:47:35 +02:00
|
|
|
}, [welcomeOpen, expanded, topic, step, stepsCompletion]);
|
2023-04-21 12:48:44 +02:00
|
|
|
|
|
|
|
const onStart = () => {
|
|
|
|
setTopic(0);
|
2023-05-03 20:47:35 +02:00
|
|
|
setStep(0);
|
|
|
|
setStepsCompletion(Array(TOPICS.length).fill(0));
|
2023-04-21 12:48:44 +02:00
|
|
|
setExpanded(true);
|
|
|
|
};
|
2023-04-18 11:56:15 +02:00
|
|
|
|
2023-04-21 12:48:44 +02:00
|
|
|
const onFinish = () => {
|
2023-05-03 20:47:35 +02:00
|
|
|
setFinishOpen(true);
|
|
|
|
|
2023-05-19 16:32:08 +02:00
|
|
|
trackEvent('demo-finish');
|
2023-04-21 12:48:44 +02:00
|
|
|
};
|
2023-04-18 11:56:15 +02:00
|
|
|
|
2023-05-11 20:01:08 +02:00
|
|
|
const closeGuide = () => {
|
|
|
|
setTopic(-1);
|
|
|
|
setStep(0);
|
|
|
|
};
|
|
|
|
|
2023-04-27 09:15:17 +02:00
|
|
|
if (!uiConfig.flags.demo) return children;
|
|
|
|
|
2023-04-18 11:56:15 +02:00
|
|
|
return (
|
|
|
|
<>
|
2023-04-27 09:15:17 +02:00
|
|
|
<DemoBanner
|
|
|
|
onPlans={() => {
|
2023-05-11 20:01:08 +02:00
|
|
|
closeGuide();
|
2023-05-12 19:58:06 +02:00
|
|
|
setWelcomeOpen(false);
|
2023-05-11 20:01:08 +02:00
|
|
|
|
2023-04-27 09:15:17 +02:00
|
|
|
setPlansOpen(true);
|
2023-04-27 15:12:02 +02:00
|
|
|
|
2023-05-19 16:32:08 +02:00
|
|
|
trackEvent('demo-see-plans');
|
2023-04-27 09:15:17 +02:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{children}
|
|
|
|
<DemoDialogPlans
|
|
|
|
open={plansOpen}
|
|
|
|
onClose={() => setPlansOpen(false)}
|
|
|
|
/>
|
2023-05-25 19:28:08 +02:00
|
|
|
<ConditionallyRender
|
|
|
|
condition={!isSmallScreen}
|
|
|
|
show={
|
|
|
|
<>
|
|
|
|
<DemoDialogWelcome
|
|
|
|
open={welcomeOpen}
|
|
|
|
onClose={() => {
|
|
|
|
setWelcomeOpen(false);
|
|
|
|
|
|
|
|
setExpanded(false);
|
|
|
|
|
|
|
|
trackEvent('demo-close', {
|
|
|
|
props: {
|
|
|
|
topic: 'welcome',
|
|
|
|
step: 'welcome',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
onStart={() => {
|
|
|
|
setWelcomeOpen(false);
|
|
|
|
|
|
|
|
onStart();
|
|
|
|
|
|
|
|
trackEvent('demo-start');
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<DemoDialogFinish
|
|
|
|
open={finishOpen}
|
|
|
|
onClose={() => {
|
|
|
|
setFinishOpen(false);
|
|
|
|
setPlansOpen(true);
|
|
|
|
}}
|
|
|
|
onRestart={() => {
|
|
|
|
setFinishOpen(false);
|
|
|
|
onStart();
|
|
|
|
|
|
|
|
trackEvent('demo-restart');
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<DemoTopics
|
|
|
|
expanded={expanded}
|
|
|
|
setExpanded={setExpanded}
|
|
|
|
stepsCompletion={stepsCompletion}
|
|
|
|
currentTopic={topic}
|
|
|
|
setCurrentTopic={(topic: number) => {
|
|
|
|
setTopic(topic);
|
|
|
|
setStep(0);
|
|
|
|
|
|
|
|
setWelcomeOpen(false);
|
|
|
|
setPlansOpen(false);
|
|
|
|
|
|
|
|
trackEvent('demo-start-topic', {
|
|
|
|
props: {
|
|
|
|
topic: TOPICS[topic].title,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
topics={TOPICS}
|
|
|
|
onWelcome={() => {
|
|
|
|
closeGuide();
|
|
|
|
setPlansOpen(false);
|
|
|
|
|
|
|
|
setWelcomeOpen(true);
|
|
|
|
|
|
|
|
trackEvent('demo-view-demo-link');
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<DemoSteps
|
|
|
|
setExpanded={setExpanded}
|
|
|
|
step={step}
|
|
|
|
setStep={setStep}
|
|
|
|
stepsCompletion={stepsCompletion}
|
|
|
|
setStepsCompletion={setStepsCompletion}
|
|
|
|
topic={topic}
|
|
|
|
setTopic={setTopic}
|
|
|
|
topics={TOPICS}
|
|
|
|
onFinish={onFinish}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
}
|
2023-04-18 11:56:15 +02:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|