File size: 1,815 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { useViewportMatch } from '@wordpress/compose';
import { useTranslate } from 'i18n-calypso';
import { useEffect } from 'react';
import VideosUi from 'calypso/components/videos-ui';
import { COURSE_SLUGS, useCourseData } from 'calypso/data/courses';
import StepWrapper from 'calypso/signup/step-wrapper';
import { useDispatch } from 'calypso/state';
import { saveSignupStep, submitSignupStep } from 'calypso/state/signup/progress/actions';
import CoursesFooter from './footer';
import CoursesHeader from './header';
import './style.scss';

interface Props {
	stepName: string;
	goToNextStep: () => void;
}

export default function CoursesStep( props: Props ) {
	const dispatch = useDispatch();
	const translate = useTranslate();
	const { stepName, goToNextStep } = props;
	const isMobile = useViewportMatch( 'small', '<' );
	const courseSlug = COURSE_SLUGS.BLOGGING_QUICK_START;
	const { isCourseComplete } = useCourseData( courseSlug );
	const hideSkip = isMobile && isCourseComplete;

	const onStartWriting = () => {
		dispatch( submitSignupStep( { stepName } ) );
		goToNextStep();
	};

	useEffect( () => {
		dispatch( saveSignupStep( { stepName } ) );
	}, [] ); // eslint-disable-line react-hooks/exhaustive-deps

	return (
		<StepWrapper
			className="courses"
			isFullLayout
			hideFormattedHeader
			stepContent={
				<VideosUi
					courseSlug={ courseSlug }
					areVideosTranslated={ false }
					HeaderBar={ CoursesHeader }
					FooterBar={ () => (
						<CoursesFooter
							isCourseComplete={ isCourseComplete }
							onStartWriting={ onStartWriting }
						/>
					) }
				/>
			}
			hideSkip={ hideSkip }
			hideNext={ ! hideSkip }
			skipLabelText={ translate( 'Draft your first post' ) }
			skipButtonAlign="top"
			nextLabelText={ translate( 'Start writing' ) }
			{ ...props }
		/>
	);
}