2023-11-07 09:34:20 +00:00
|
|
|
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* External dependencies
|
|
|
|
|
*/
|
|
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
CheckboxControl,
|
|
|
|
|
TextareaControl,
|
|
|
|
|
} from '@wordpress/components';
|
|
|
|
|
import { useDispatch } from '@wordpress/data';
|
|
|
|
|
import { useState } from '@wordpress/element';
|
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Internal dependencies
|
|
|
|
|
*/
|
2024-04-23 17:38:06 +00:00
|
|
|
|
import { trackEvent } from '~/customize-store/tracking';
|
2023-11-07 09:34:20 +00:00
|
|
|
|
|
|
|
|
|
interface CloseSurveyFunction {
|
|
|
|
|
(): void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface StarRatingChangeFunction {
|
|
|
|
|
( value: number ): void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const StarRating = ( {
|
|
|
|
|
value,
|
|
|
|
|
onChange,
|
|
|
|
|
}: {
|
|
|
|
|
value: number;
|
|
|
|
|
onChange: StarRatingChangeFunction;
|
|
|
|
|
} ): JSX.Element => {
|
|
|
|
|
return (
|
|
|
|
|
<div className="woocommerce-survey-star-rating">
|
|
|
|
|
{ [ ...Array( 5 ) ].map( ( star, index ) => {
|
|
|
|
|
index += 1;
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
key={ index }
|
|
|
|
|
className={
|
|
|
|
|
index <= value
|
|
|
|
|
? 'woocommerce-survey-star-rating__button-on'
|
|
|
|
|
: 'woocommerce-survey-star-rating__button-off'
|
|
|
|
|
}
|
|
|
|
|
onClick={ () => {
|
|
|
|
|
onChange( index );
|
|
|
|
|
} }
|
|
|
|
|
>
|
|
|
|
|
<span className="woocommerce-survey-star-rating__star">
|
|
|
|
|
★
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
} ) }
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const SurveyForm = ( {
|
2024-01-30 08:58:05 +00:00
|
|
|
|
showAISurvey,
|
2023-11-10 08:35:46 +00:00
|
|
|
|
onSend,
|
2023-11-07 09:34:20 +00:00
|
|
|
|
closeFunction,
|
|
|
|
|
}: {
|
2024-01-30 08:58:05 +00:00
|
|
|
|
showAISurvey: boolean;
|
2023-11-10 08:35:46 +00:00
|
|
|
|
onSend: () => void;
|
2023-11-07 09:34:20 +00:00
|
|
|
|
closeFunction: CloseSurveyFunction;
|
|
|
|
|
} ): JSX.Element => {
|
|
|
|
|
const [ isStreamlineChecked, setStreamlineChecked ] = useState( false );
|
|
|
|
|
const [ isDislikeThemesChecked, setDislikeChecked ] = useState( false );
|
|
|
|
|
const [ isThemeNoMatchChecked, setThemeNoMatchChecked ] = useState( false );
|
|
|
|
|
const [ isOtherChecked, setOtherChecked ] = useState( false );
|
|
|
|
|
const [ feedbackText, setFeedbackText ] = useState( '' );
|
|
|
|
|
const [ spillBeansText, setSpillBeansText ] = useState( '' );
|
|
|
|
|
const { createSuccessNotice } = useDispatch( 'core/notices' );
|
|
|
|
|
const [ rating, setRating ] = useState( 0 );
|
|
|
|
|
|
2024-01-30 08:58:05 +00:00
|
|
|
|
const disableSendButton =
|
|
|
|
|
rating === 0 ||
|
|
|
|
|
( ! isStreamlineChecked &&
|
|
|
|
|
! isDislikeThemesChecked &&
|
|
|
|
|
! isThemeNoMatchChecked &&
|
|
|
|
|
! isOtherChecked );
|
|
|
|
|
|
2023-11-07 09:34:20 +00:00
|
|
|
|
const sendData = () => {
|
2024-08-02 15:38:25 +00:00
|
|
|
|
if ( showAISurvey ) {
|
|
|
|
|
trackEvent( 'customize_your_store_transitional_survey_complete', {
|
|
|
|
|
rating,
|
|
|
|
|
choose_streamline: isStreamlineChecked,
|
|
|
|
|
choose_dislike_themes: isDislikeThemesChecked,
|
|
|
|
|
choose_themes_not_match: isThemeNoMatchChecked,
|
|
|
|
|
choose_other: isOtherChecked,
|
|
|
|
|
feedback: feedbackText,
|
|
|
|
|
spill_beans: spillBeansText,
|
|
|
|
|
} );
|
|
|
|
|
} else {
|
|
|
|
|
trackEvent( 'ces_feedback', {
|
|
|
|
|
action: 'customize_your_store_on_core_transitional_survey_complete',
|
2024-08-08 15:27:18 +00:00
|
|
|
|
score: rating,
|
2024-08-02 15:38:25 +00:00
|
|
|
|
choose_design_my_own_theme: isStreamlineChecked,
|
|
|
|
|
choose_dislike_themes: isDislikeThemesChecked,
|
|
|
|
|
choose_themes_not_match: isThemeNoMatchChecked,
|
|
|
|
|
choose_other: isOtherChecked,
|
2024-08-08 15:27:18 +00:00
|
|
|
|
comments: feedbackText,
|
2024-08-02 15:38:25 +00:00
|
|
|
|
spill_beans: spillBeansText,
|
|
|
|
|
} );
|
|
|
|
|
}
|
2023-11-10 08:35:46 +00:00
|
|
|
|
|
|
|
|
|
onSend();
|
2023-11-07 09:34:20 +00:00
|
|
|
|
createSuccessNotice(
|
|
|
|
|
__(
|
|
|
|
|
"Thanks for the feedback. We'll put it to good use!",
|
|
|
|
|
'woocommerce'
|
|
|
|
|
),
|
|
|
|
|
{
|
|
|
|
|
type: 'snackbar',
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className="woocommerce-ai-survey-form">
|
2024-03-21 17:30:40 +00:00
|
|
|
|
<div className="content">
|
|
|
|
|
<p className="woocommerce-ai-survey-form__description">
|
|
|
|
|
{ __(
|
|
|
|
|
'Our goal is to make sure you have all the right tools to start customizing your store. We’d love to know if we hit our mark and how we can improve.',
|
|
|
|
|
'woocommerce'
|
|
|
|
|
) }
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<h4>
|
|
|
|
|
{ __(
|
|
|
|
|
'On a scale of 1 = difficult to 5 = very easy, how would you rate the overall experience?',
|
|
|
|
|
'woocommerce'
|
|
|
|
|
) }
|
|
|
|
|
<span>*</span>
|
|
|
|
|
</h4>
|
|
|
|
|
<StarRating value={ rating } onChange={ setRating } />
|
|
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
|
|
<h4>
|
|
|
|
|
{ showAISurvey
|
2024-01-30 08:58:05 +00:00
|
|
|
|
? __(
|
2024-03-21 17:30:40 +00:00
|
|
|
|
'What motivated you to choose the “Design with AI” option?',
|
2024-01-30 08:58:05 +00:00
|
|
|
|
'woocommerce'
|
|
|
|
|
)
|
|
|
|
|
: __(
|
2024-03-21 17:30:40 +00:00
|
|
|
|
'What motivated you to choose the "Design your own theme" option?',
|
|
|
|
|
'woocommerce'
|
|
|
|
|
) }
|
|
|
|
|
<span>*</span>
|
|
|
|
|
</h4>
|
|
|
|
|
<CheckboxControl
|
|
|
|
|
label={
|
|
|
|
|
showAISurvey
|
|
|
|
|
? __(
|
|
|
|
|
'I wanted to see how AI could help me streamline the process.',
|
|
|
|
|
'woocommerce'
|
|
|
|
|
)
|
|
|
|
|
: __(
|
|
|
|
|
'I wanted to design my own theme.',
|
|
|
|
|
'woocommerce'
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
checked={ isStreamlineChecked }
|
|
|
|
|
onChange={ setStreamlineChecked }
|
|
|
|
|
/>
|
|
|
|
|
<CheckboxControl
|
|
|
|
|
label={ __(
|
|
|
|
|
"I didn't like any of the available themes.",
|
|
|
|
|
'woocommerce'
|
|
|
|
|
) }
|
|
|
|
|
checked={ isDislikeThemesChecked }
|
|
|
|
|
onChange={ setDislikeChecked }
|
|
|
|
|
/>
|
|
|
|
|
<CheckboxControl
|
|
|
|
|
label={ __(
|
|
|
|
|
"I didn't find a theme that matched my needs.",
|
|
|
|
|
'woocommerce'
|
|
|
|
|
) }
|
|
|
|
|
checked={ isThemeNoMatchChecked }
|
|
|
|
|
onChange={ setThemeNoMatchChecked }
|
|
|
|
|
/>
|
|
|
|
|
<CheckboxControl
|
|
|
|
|
label={ __( 'Other.', 'woocommerce' ) }
|
|
|
|
|
checked={ isOtherChecked }
|
|
|
|
|
onChange={ setOtherChecked }
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
|
|
<h4>
|
|
|
|
|
{ __(
|
|
|
|
|
'Did you find anything confusing, irrelevant, or not useful?',
|
|
|
|
|
'woocommerce'
|
|
|
|
|
) }
|
|
|
|
|
</h4>
|
|
|
|
|
<TextareaControl
|
|
|
|
|
value={ feedbackText }
|
|
|
|
|
onChange={ setFeedbackText }
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
|
|
<h4>
|
|
|
|
|
{ showAISurvey
|
|
|
|
|
? __(
|
|
|
|
|
'Feel free to spill the beans here. All suggestions, feedback, or comments about the AI-generated store experience are welcome.',
|
2024-01-30 08:58:05 +00:00
|
|
|
|
'woocommerce'
|
|
|
|
|
)
|
2024-03-21 17:30:40 +00:00
|
|
|
|
: __(
|
|
|
|
|
'Feel free to spill the beans here. All suggestions, feedback, or comments about the "Design your own theme" experience are welcome.',
|
|
|
|
|
'woocommerce'
|
|
|
|
|
) }
|
|
|
|
|
</h4>
|
|
|
|
|
<TextareaControl
|
|
|
|
|
value={ spillBeansText }
|
|
|
|
|
onChange={ setSpillBeansText }
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2023-11-07 09:34:20 +00:00
|
|
|
|
|
2024-03-21 17:30:40 +00:00
|
|
|
|
<div>
|
|
|
|
|
<hr />
|
|
|
|
|
<div className="buttons">
|
|
|
|
|
<Button
|
|
|
|
|
className="is-spinner"
|
|
|
|
|
variant="tertiary"
|
|
|
|
|
onClick={ closeFunction }
|
|
|
|
|
>
|
|
|
|
|
{ __( 'Cancel', 'woocommerce' ) }
|
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
variant="primary"
|
|
|
|
|
onClick={ sendData }
|
|
|
|
|
disabled={ disableSendButton }
|
|
|
|
|
>
|
|
|
|
|
{ __( 'Send', 'woocommerce' ) }
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2023-11-07 09:34:20 +00:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|