overleaf/services/web/frontend/js/features/onboarding/components/onboarding-video-tour-modal-footer.tsx
M Fahru f7131b720b Implement onboarding video tour split test (#11889)
* Implement onboarding video tour split test:

- Add split test infrastructure
- Create new `OnboardingVideoTourModal` component
- Place the component inside the editor pug template with a split test

* add event segmentation for `onboarding-video-tour-close-button-click` event:

1. video: `first` | `second`
2. firstVideoWatchingTimeInSecond: total time watching first video
2. secondVideoWatchingTimeInSecond: total time watching second video (0 if skipped)

* add event segmentation for:

1.  `onboarding-video-tour-dismiss-button-click`
2. `onboarding-video-tour-next-button-click`
3. `onboarding-video-tour-done-button-click`

with these key/value:

1. firstVideoWatchingTimeInSecond: total time watching first video
2. secondVideoWatchingTimeInSecond: total time watching second video (0 if skipped/not watched yet)

* Use contentful to host video assets

GitOrigin-RevId: 27a6f38d15d7a03b07455e216dda63d99983ca80
2023-03-02 09:05:43 +00:00

110 lines
3.2 KiB
TypeScript

import {
type Dispatch,
type RefObject,
type SetStateAction,
useCallback,
} from 'react'
import { Button, Modal } from 'react-bootstrap'
import { useTranslation } from 'react-i18next'
import type { Nullable } from '../../../../../types/utils'
import { sendMB } from '../../../infrastructure/event-tracking'
import customLocalStorage from '../../../infrastructure/local-storage'
import type { OnboardingVideoStep } from '../utils/onboarding-video-step'
import { calculateWatchingTimeInSecond } from '../utils/watching-time'
type OnboardingVideoTourModalFooterProps = {
step: OnboardingVideoStep
setStep: Dispatch<SetStateAction<OnboardingVideoStep>>
closeModal: () => void
startTimeWatchedFirstVideo: RefObject<number>
startTimeWatchedSecondVideo: RefObject<Nullable<number>>
}
export default function OnboardingVideoTourModalFooter({
step,
setStep,
closeModal,
startTimeWatchedFirstVideo,
startTimeWatchedSecondVideo,
}: OnboardingVideoTourModalFooterProps) {
const { t } = useTranslation()
const handleClickDismiss = useCallback(() => {
customLocalStorage.setItem(
'has_dismissed_onboarding_video_tour_modal',
true
)
const { firstVideoWatchingTimeInSecond, secondVideoWatchingTimeInSecond } =
calculateWatchingTimeInSecond(
startTimeWatchedFirstVideo.current ?? 0,
startTimeWatchedSecondVideo.current
)
sendMB('onboarding-video-tour-dismiss-button-click', {
firstVideoWatchingTimeInSecond,
secondVideoWatchingTimeInSecond,
})
closeModal()
}, [closeModal, startTimeWatchedFirstVideo, startTimeWatchedSecondVideo])
const handleClickNext = useCallback(() => {
const { firstVideoWatchingTimeInSecond, secondVideoWatchingTimeInSecond } =
calculateWatchingTimeInSecond(
startTimeWatchedFirstVideo.current ?? 0,
startTimeWatchedSecondVideo.current
)
sendMB('onboarding-video-tour-next-button-click', {
firstVideoWatchingTimeInSecond,
secondVideoWatchingTimeInSecond,
})
setStep('second')
}, [setStep, startTimeWatchedFirstVideo, startTimeWatchedSecondVideo])
const handleClickDone = useCallback(() => {
customLocalStorage.setItem(
'has_dismissed_onboarding_video_tour_modal',
true
)
const { firstVideoWatchingTimeInSecond, secondVideoWatchingTimeInSecond } =
calculateWatchingTimeInSecond(
startTimeWatchedFirstVideo.current ?? 0,
startTimeWatchedSecondVideo.current
)
sendMB('onboarding-video-tour-done-button-click', {
firstVideoWatchingTimeInSecond,
secondVideoWatchingTimeInSecond,
})
closeModal()
}, [closeModal, startTimeWatchedFirstVideo, startTimeWatchedSecondVideo])
return (
<Modal.Footer>
{step === 'first' ? (
<>
<Button
type="button"
bsStyle={null}
className="btn-secondary"
onClick={handleClickDismiss}
>
{t('dismiss')}
</Button>
<Button type="submit" bsStyle="primary" onClick={handleClickNext}>
{t('next')}
</Button>
</>
) : (
<Button type="submit" bsStyle="primary" onClick={handleClickDone}>
{t('done')}
</Button>
)}
</Modal.Footer>
)
}