@@ -5,8 +5,8 @@ import { __ as NO__ } from '@wordpress/i18n';
55import { Button } from '@wordpress/components' ;
66import { isEmpty , map } from 'lodash' ;
77import { useDispatch , useSelect } from '@wordpress/data' ;
8- import React , { useCallback } from 'react' ;
9-
8+ import React , { useCallback , useState } from 'react' ;
9+ import classNames from 'classnames' ;
1010/**
1111 * Internal dependencies
1212 */
@@ -16,86 +16,150 @@ import VerticalSelect from './vertical-select';
1616import './style.scss' ;
1717
1818const siteTypeOptions : Record < SiteType , string > = {
19- [ SiteType . BLOG ] : NO__ ( 'with a blog.' ) ,
20- [ SiteType . STORE ] : NO__ ( 'for a store.' ) ,
21- [ SiteType . STORY ] : NO__ ( 'to write a story.' ) ,
19+ [ SiteType . BLOG ] : NO__ ( 'with a blog' ) ,
20+ [ SiteType . BUSINESS ] : NO__ ( 'for a business' ) ,
21+ [ SiteType . PORTFOLIO ] : NO__ ( 'to share a portfolio' ) ,
22+ [ SiteType . STORE ] : NO__ ( 'for a store' ) ,
2223} ;
2324
2425export default function OnboardingEdit ( ) {
26+ const [ lastSelectedQuestion , setLastSelectedQuestion ] = useState ( null ) ;
27+
2528 const { siteTitle, siteType, siteVertical } = useSelect ( select =>
2629 select ( STORE_KEY ) . getState ( )
2730 ) ;
2831
29- const { resetSiteType , setSiteType, setSiteTitle } = useDispatch ( STORE_KEY ) ;
32+ const { setSiteType, setSiteTitle } = useDispatch ( STORE_KEY ) ;
3033
3134 const updateTitle = useCallback (
3235 ( e : React . ChangeEvent < HTMLInputElement > ) => setSiteTitle ( e . target . value ) ,
3336 [ setSiteTitle ]
3437 ) ;
38+
3539 const updateSiteType = useCallback (
3640 ( e : React . ChangeEvent < HTMLInputElement > ) => setSiteType ( e . target . value as SiteType ) ,
3741 [ setSiteType ]
3842 ) ;
3943
44+ const selectSiteType = e => {
45+ updateSiteType ( e ) ;
46+ setLastSelectedQuestion ( null ) ;
47+ } ;
48+
49+ const openSiteType = ( ) => {
50+ setLastSelectedQuestion ( 'siteType' ) ;
51+ } ;
52+
53+ const selectSiteVertical = ( ) => {
54+ setLastSelectedQuestion ( 'siteVertical' ) ;
55+ } ;
56+
57+ const selectSiteTitle = ( ) => {
58+ setLastSelectedQuestion ( 'siteTitle' ) ;
59+ } ;
60+
61+ const isSelected = questionType => {
62+ if ( lastSelectedQuestion ) {
63+ return questionType === lastSelectedQuestion ;
64+ } else if ( isEmpty ( siteType ) ) {
65+ return questionType === 'siteType' ;
66+ } else if ( isEmpty ( siteVertical ) ) {
67+ return questionType === 'siteVertical' ;
68+ } else if ( questionType === 'siteTitle' ) {
69+ return true ;
70+ }
71+ return false ;
72+ } ;
73+
4074 return (
41- < div className = "onboarding-block__questions" >
42- < h2 className = "onboarding-block__questions-heading" >
43- { NO__ ( "Let's set up your website – it takes only a moment." ) }
44- </ h2 >
45-
46- < div className = "onboarding-block__question" >
47- < span > { NO__ ( 'I want to create a website ' ) } </ span >
48- { ! isFilledFormValue ( siteType ) ? (
49- < ul className = "onboarding-block__multi-question" >
50- { map ( siteTypeOptions , ( label , value ) => (
51- < li key = { value } >
52- < label >
53- < input
54- name = "onboarding_site_type"
55- onChange = { updateSiteType }
56- type = "radio"
57- value = { value }
58- />
59- < span className = "onboarding-block__multi-question-choice" > { label } </ span >
60- </ label >
61- </ li >
62- ) ) }
63- </ ul >
64- ) : (
65- < div className = "onboarding-block__multi-question" >
66- < button className = "onboarding-block__question-answered" onClick = { resetSiteType } >
67- { siteTypeOptions [ siteType ] }
68- </ button >
75+ < div className = "onboarding-block__acquire-intent" >
76+ < div className = "onboarding-block__questions" >
77+ < h2 className = "onboarding-block__questions-heading" >
78+ { isEmpty ( siteType ) && NO__ ( "Let's set up your website – it takes only a moment." ) }
79+ </ h2 >
80+
81+ < div
82+ className = { classNames ( {
83+ 'onboarding-block__question' : true ,
84+ selected : isSelected ( 'siteType' ) ,
85+ } ) }
86+ >
87+ < span >
88+ { isEmpty ( siteType )
89+ ? NO__ ( 'I want to create a website ' )
90+ : NO__ ( 'Setting up a website ' ) }
91+ </ span >
92+ { isSelected ( 'siteType' ) ? (
93+ < ul className = "onboarding-block__multi-question" >
94+ { map ( siteTypeOptions , ( label , value ) => (
95+ < li key = { value } className = { value === siteType ? 'selected' : '' } >
96+ < label >
97+ < input
98+ name = "onboarding_site_type"
99+ onChange = { selectSiteType }
100+ type = "radio"
101+ value = { value }
102+ />
103+ < span className = "onboarding-block__multi-question-choice" > { label } </ span >
104+ </ label >
105+ </ li >
106+ ) ) }
107+ </ ul >
108+ ) : (
109+ < div className = "onboarding-block__multi-question" >
110+ < button className = "onboarding-block__question-answered" onClick = { openSiteType } >
111+ { siteTypeOptions [ siteType ] }
112+ </ button >
113+ < span > .</ span >
114+ </ div >
115+ ) }
116+ </ div >
117+
118+ { ( isFilledFormValue ( siteType ) || ! isEmpty ( siteVertical ) ) && (
119+ < div
120+ className = { classNames ( {
121+ 'onboarding-block__question' : true ,
122+ selected : isSelected ( 'siteVertical' ) ,
123+ } ) }
124+ >
125+ < span > { NO__ ( 'My site is about' ) } </ span >
126+ < div className = "onboarding-block__multi-question" >
127+ < VerticalSelect
128+ onClick = { selectSiteVertical }
129+ forceHideSuggestions = { ! isSelected ( 'siteVertical' ) }
130+ inputClass = "onboarding-block__question-input"
131+ />
132+ </ div >
69133 </ div >
70134 ) }
71- </ div >
72135
73- { ( isFilledFormValue ( siteType ) || ! isEmpty ( siteVertical ) ) && (
74- < div className = "onboarding-block__question" >
75- < span > { NO__ ( 'My site is about' ) } </ span >
76- < div className = "onboarding-block__multi-question" >
77- < VerticalSelect inputClass = "onboarding-block__question-input" />
136+ { ( ! isEmpty ( siteVertical ) || siteTitle ) && (
137+ < div
138+ className = { classNames ( {
139+ 'onboarding-block__question' : true ,
140+ selected : isSelected ( 'siteTitle' ) ,
141+ } ) }
142+ >
143+ < label >
144+ < span > { NO__ ( "It's called" ) } </ span >
145+ < input
146+ className = "onboarding-block__question-input bbb"
147+ onClick = { selectSiteTitle }
148+ onChange = { updateTitle }
149+ value = { siteTitle }
150+ />
151+ </ label >
78152 </ div >
79- </ div >
80- ) }
81-
82- { ( ! isEmpty ( siteVertical ) || siteTitle ) && (
83- < >
84- < label className = "onboarding-block__question" >
85- < span > { NO__ ( "It's called" ) } </ span >
86- < input
87- className = "onboarding-block__question-input"
88- onChange = { updateTitle }
89- value = { siteTitle }
90- />
91- </ label >
92- { ! siteTitle && (
153+ ) }
154+
155+ { ! isEmpty ( siteVertical ) && (
156+ < div className = "onboarding-block__footer" >
93157 < Button className = "onboarding-block__question-skip" isLink >
94158 { NO__ ( "Don't know yet" ) } →
95159 </ Button >
96- ) }
97- </ >
98- ) }
160+ </ div >
161+ ) }
162+ </ div >
99163 </ div >
100164 ) ;
101165}
0 commit comments