1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/component/demo/Demo.tsx

186 lines
6.3 KiB
TypeScript
Raw Normal View History

import { useEffect, useState } from 'react';
import { DemoTopics } from './DemoTopics/DemoTopics';
import { DemoSteps } from './DemoSteps/DemoSteps';
import { createLocalStorage } from 'utils/createLocalStorage';
import { TOPICS } from './demo-topics';
import { DemoDialogWelcome } from './DemoDialog/DemoDialogWelcome/DemoDialogWelcome';
import { DemoDialogFinish } from './DemoDialog/DemoDialogFinish/DemoDialogFinish';
import { DemoDialogPlans } from './DemoDialog/DemoDialogPlans/DemoDialogPlans';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { DemoBanner } from './DemoBanner/DemoBanner';
feat: add user tracking to demo (#3637) https://linear.app/unleash/issue/2-946/explore-and-implement-options-for-user-tracking Adds user tracking to the interactive demo, so we can measure how users are using this feature and improve it in the feature. ## Events - **start** - When the user starts the demo by clicking on the "Try Unleash Demo" button; - **finish** - When the user finishes the demo by seeing the "You finished the demo" dialog; - **restart** - When the user decides to restart the demo on the "You finished the demo" dialog; - **close** - When the user closes a demo dialog; - **topic** - In what topic this happened (topic title, can also be `start` if user closes on the start dialog); - **step** - In what step this happened (step number, `1` would mean first step); - **start_topic** - When the user decides to start a specific topic by clicking it in the list; - **topic** - What topic was clicked (topic title); - **ask_questions** - When the user decides to ask questions by clicking the appropriate option in the top banner; - **see_plans** - When the user decides to see the plans by clicking the appropriate option in the top banner; - **plan** - What plan was clicked (one of: `open_source`, `pro`, `enterprise` or `compare_plans`); - **open_demo_web** - User decided to open the demo website using the link on the start dialog; - **view_demo_link** - User decided to open the start dialog again on the bottom of the topics list; Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: #3537
2023-04-27 15:12:02 +02:00
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
import { useMediaQuery } from '@mui/material';
import theme from 'themes/theme';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
const defaultProgress = {
welcomeOpen: true,
expanded: true,
topic: -1,
step: 0,
stepsCompletion: Array(TOPICS.length).fill(0),
};
interface IDemoProps {
children: JSX.Element;
}
export const Demo = ({ children }: IDemoProps): JSX.Element => {
const { uiConfig } = useUiConfig();
const isSmallScreen = useMediaQuery(theme.breakpoints.down(768));
feat: add user tracking to demo (#3637) https://linear.app/unleash/issue/2-946/explore-and-implement-options-for-user-tracking Adds user tracking to the interactive demo, so we can measure how users are using this feature and improve it in the feature. ## Events - **start** - When the user starts the demo by clicking on the "Try Unleash Demo" button; - **finish** - When the user finishes the demo by seeing the "You finished the demo" dialog; - **restart** - When the user decides to restart the demo on the "You finished the demo" dialog; - **close** - When the user closes a demo dialog; - **topic** - In what topic this happened (topic title, can also be `start` if user closes on the start dialog); - **step** - In what step this happened (step number, `1` would mean first step); - **start_topic** - When the user decides to start a specific topic by clicking it in the list; - **topic** - What topic was clicked (topic title); - **ask_questions** - When the user decides to ask questions by clicking the appropriate option in the top banner; - **see_plans** - When the user decides to see the plans by clicking the appropriate option in the top banner; - **plan** - What plan was clicked (one of: `open_source`, `pro`, `enterprise` or `compare_plans`); - **open_demo_web** - User decided to open the demo website using the link on the start dialog; - **view_demo_link** - User decided to open the start dialog again on the bottom of the topics list; Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: #3537
2023-04-27 15:12:02 +02:00
const { trackEvent } = usePlausibleTracker();
const { value: storedProgress, setValue: setStoredProgress } =
createLocalStorage('Tutorial:v1.1', defaultProgress);
const [welcomeOpen, setWelcomeOpen] = useState(
storedProgress.welcomeOpen ?? defaultProgress.welcomeOpen
);
const [finishOpen, setFinishOpen] = useState(false);
const [plansOpen, setPlansOpen] = useState(false);
const [expanded, setExpanded] = useState(
storedProgress.expanded ?? defaultProgress.expanded
);
const [topic, setTopic] = useState(
storedProgress.topic ?? defaultProgress.topic
);
const [step, setStep] = useState(
storedProgress.step ?? defaultProgress.step
);
const [stepsCompletion, setStepsCompletion] = useState(
storedProgress.stepsCompletion ?? defaultProgress.stepsCompletion
);
useEffect(() => {
setStoredProgress({
welcomeOpen,
expanded,
topic,
step,
stepsCompletion,
});
}, [welcomeOpen, expanded, topic, step, stepsCompletion]);
const onStart = () => {
setTopic(0);
setStep(0);
setStepsCompletion(Array(TOPICS.length).fill(0));
setExpanded(true);
};
const onFinish = () => {
setFinishOpen(true);
trackEvent('demo-finish');
};
const closeGuide = () => {
setTopic(-1);
setStep(0);
};
if (!uiConfig.flags.demo) return children;
return (
<>
<DemoBanner
onPlans={() => {
closeGuide();
setWelcomeOpen(false);
setPlansOpen(true);
feat: add user tracking to demo (#3637) https://linear.app/unleash/issue/2-946/explore-and-implement-options-for-user-tracking Adds user tracking to the interactive demo, so we can measure how users are using this feature and improve it in the feature. ## Events - **start** - When the user starts the demo by clicking on the "Try Unleash Demo" button; - **finish** - When the user finishes the demo by seeing the "You finished the demo" dialog; - **restart** - When the user decides to restart the demo on the "You finished the demo" dialog; - **close** - When the user closes a demo dialog; - **topic** - In what topic this happened (topic title, can also be `start` if user closes on the start dialog); - **step** - In what step this happened (step number, `1` would mean first step); - **start_topic** - When the user decides to start a specific topic by clicking it in the list; - **topic** - What topic was clicked (topic title); - **ask_questions** - When the user decides to ask questions by clicking the appropriate option in the top banner; - **see_plans** - When the user decides to see the plans by clicking the appropriate option in the top banner; - **plan** - What plan was clicked (one of: `open_source`, `pro`, `enterprise` or `compare_plans`); - **open_demo_web** - User decided to open the demo website using the link on the start dialog; - **view_demo_link** - User decided to open the start dialog again on the bottom of the topics list; Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: #3537
2023-04-27 15:12:02 +02:00
trackEvent('demo-see-plans');
}}
/>
{children}
<DemoDialogPlans
open={plansOpen}
onClose={() => setPlansOpen(false)}
/>
<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}
/>
</>
}
/>
</>
);
};