Welcome.js
92 lines
| 1 | /* global tiobDash */ |
| 2 | import { __ } from '@wordpress/i18n'; |
| 3 | import { withSelect, withDispatch } from '@wordpress/data'; |
| 4 | import { useEffect } from '@wordpress/element'; |
| 5 | import { compose } from '@wordpress/compose'; |
| 6 | import CategoryButtons from '../CategoryButtons'; |
| 7 | import Search from '../Search'; |
| 8 | import { ONBOARDING_CAT } from '../../utils/common'; |
| 9 | import { track } from '../../utils/rest'; |
| 10 | import WelcomeMock from '../WelcomeMock'; |
| 11 | |
| 12 | const Welcome = ( { trackingId, setTrackingId, fetching, setFetching } ) => { |
| 13 | useEffect( () => { |
| 14 | if ( trackingId ) { |
| 15 | setFetching( false ); |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | setFetching( true ); |
| 20 | const data = { |
| 21 | slug: 'neve', |
| 22 | license_id: tiobDash.license, |
| 23 | site: tiobDash.onboarding.homeUrl || '', |
| 24 | }; |
| 25 | track( trackingId, data ) |
| 26 | .then( ( id ) => { |
| 27 | if ( id ) { |
| 28 | setTrackingId( id ); |
| 29 | } |
| 30 | } ) |
| 31 | .catch( ( error ) => { |
| 32 | // eslint-disable-next-line no-console |
| 33 | console.error( error ); |
| 34 | } ) |
| 35 | .finally( () => { |
| 36 | setFetching( false ); |
| 37 | } ); |
| 38 | }, [] ); |
| 39 | |
| 40 | return ( |
| 41 | <div className="ob-container narrow"> |
| 42 | { ! fetching ? ( |
| 43 | <> |
| 44 | <h1> |
| 45 | { __( |
| 46 | 'What type of website are you creating?', |
| 47 | 'templates-patterns-collection' |
| 48 | ) } |
| 49 | </h1> |
| 50 | <p> |
| 51 | { __( |
| 52 | 'Pick a category and we will provide you with relevant suggestions so you can find the starter site that works best for you.', |
| 53 | 'templates-patterns-collection' |
| 54 | ) } |
| 55 | </p> |
| 56 | <CategoryButtons |
| 57 | categories={ ONBOARDING_CAT } |
| 58 | style={ { margin: '26px 0' } } |
| 59 | /> |
| 60 | <div className="ob-search-container"> |
| 61 | <Search |
| 62 | label={ __( |
| 63 | 'Or search for a site', |
| 64 | 'templates-patterns-collection' |
| 65 | ) } |
| 66 | /> |
| 67 | </div> |
| 68 | </> |
| 69 | ) : ( |
| 70 | <WelcomeMock /> |
| 71 | ) } |
| 72 | </div> |
| 73 | ); |
| 74 | }; |
| 75 | |
| 76 | export default compose( |
| 77 | withSelect( ( select ) => { |
| 78 | const { getTrackingId, getFetching } = select( 'ti-onboarding' ); |
| 79 | return { |
| 80 | trackingId: getTrackingId(), |
| 81 | fetching: getFetching(), |
| 82 | }; |
| 83 | } ), |
| 84 | withDispatch( ( dispatch ) => { |
| 85 | const { setTrackingId, setFetching } = dispatch( 'ti-onboarding' ); |
| 86 | return { |
| 87 | setTrackingId, |
| 88 | setFetching, |
| 89 | }; |
| 90 | } ) |
| 91 | )( Welcome ); |
| 92 |