2023-09-06 06:21:09 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-09-28 03:15:38 +00:00
|
|
|
import { Button, Notice } from '@wordpress/components';
|
2023-09-06 06:21:09 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { ProgressBar } from '@woocommerce/components';
|
2023-09-28 03:15:38 +00:00
|
|
|
import { useState, createInterpolateElement } from '@wordpress/element';
|
2023-11-10 06:51:00 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2023-09-06 06:21:09 +00:00
|
|
|
|
2023-08-29 06:00:54 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-09-07 09:05:47 +00:00
|
|
|
import { Tone, designWithAiStateMachineContext } from '../types';
|
2023-09-06 06:21:09 +00:00
|
|
|
import { Choice } from '../components/choice/choice';
|
|
|
|
import { CloseButton } from '../components/close-button/close-button';
|
|
|
|
import { aiWizardClosedBeforeCompletionEvent } from '../events';
|
|
|
|
|
|
|
|
export type toneOfVoiceCompleteEvent = {
|
|
|
|
type: 'TONE_OF_VOICE_COMPLETE';
|
2023-09-07 09:05:47 +00:00
|
|
|
payload: Tone;
|
2023-09-06 06:21:09 +00:00
|
|
|
};
|
2023-08-29 06:00:54 +00:00
|
|
|
|
|
|
|
export const ToneOfVoice = ( {
|
|
|
|
sendEvent,
|
|
|
|
context,
|
|
|
|
}: {
|
2023-09-06 06:21:09 +00:00
|
|
|
sendEvent: (
|
|
|
|
event: toneOfVoiceCompleteEvent | aiWizardClosedBeforeCompletionEvent
|
|
|
|
) => void;
|
2023-08-29 06:00:54 +00:00
|
|
|
context: designWithAiStateMachineContext;
|
|
|
|
} ) => {
|
2023-09-06 06:21:09 +00:00
|
|
|
const choices = [
|
|
|
|
{
|
|
|
|
title: __( 'Informal', 'woocommerce' ),
|
2023-09-07 09:05:47 +00:00
|
|
|
key: 'Informal' as const,
|
2023-09-06 06:21:09 +00:00
|
|
|
subtitle: __(
|
|
|
|
'Relaxed and friendly, like a conversation with a friend.',
|
|
|
|
'woocommerce'
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Neutral', 'woocommerce' ),
|
2023-09-07 09:05:47 +00:00
|
|
|
key: 'Neutral' as const,
|
2023-09-06 06:21:09 +00:00
|
|
|
subtitle: __(
|
2023-12-14 11:32:37 +00:00
|
|
|
'Impartial tone with casual expressions without slang.',
|
2023-09-06 06:21:09 +00:00
|
|
|
'woocommerce'
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Formal', 'woocommerce' ),
|
2023-09-07 09:05:47 +00:00
|
|
|
key: 'Formal' as const,
|
2023-09-06 06:21:09 +00:00
|
|
|
subtitle: __(
|
|
|
|
'Direct yet respectful, serious and professional.',
|
|
|
|
'woocommerce'
|
|
|
|
),
|
|
|
|
},
|
|
|
|
];
|
2023-09-07 09:05:47 +00:00
|
|
|
const [ sound, setSound ] = useState< Tone >(
|
2023-09-06 06:21:09 +00:00
|
|
|
context.toneOfVoice.choice === ''
|
2023-09-07 09:05:47 +00:00
|
|
|
? choices[ 0 ].key
|
2023-09-06 06:21:09 +00:00
|
|
|
: context.toneOfVoice.choice
|
|
|
|
);
|
2023-09-28 03:15:38 +00:00
|
|
|
|
|
|
|
const onContinue = () => {
|
2023-11-10 06:51:00 +00:00
|
|
|
if (
|
|
|
|
context.toneOfVoice.aiRecommended &&
|
|
|
|
context.toneOfVoice.aiRecommended !== sound
|
|
|
|
) {
|
|
|
|
recordEvent( 'customize_your_store_ai_wizard_changed_ai_option', {
|
|
|
|
step: 'tone-of-voice',
|
|
|
|
ai_recommended: context.toneOfVoice.aiRecommended,
|
|
|
|
user_choice: sound,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2023-09-28 03:15:38 +00:00
|
|
|
sendEvent( {
|
|
|
|
type: 'TONE_OF_VOICE_COMPLETE',
|
|
|
|
payload: sound,
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2023-08-29 06:00:54 +00:00
|
|
|
return (
|
|
|
|
<div>
|
2023-09-06 06:21:09 +00:00
|
|
|
<ProgressBar
|
|
|
|
percent={ 80 }
|
|
|
|
color={ 'var(--wp-admin-theme-color)' }
|
|
|
|
bgcolor={ 'transparent' }
|
|
|
|
/>
|
|
|
|
<CloseButton
|
|
|
|
onClick={ () => {
|
|
|
|
sendEvent( {
|
|
|
|
type: 'AI_WIZARD_CLOSED_BEFORE_COMPLETION',
|
|
|
|
payload: { step: 'tone-of-voice' },
|
|
|
|
} );
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
<div className="woocommerce-cys-design-with-ai-tone-of-voice woocommerce-cys-layout">
|
|
|
|
<div className="woocommerce-cys-page">
|
|
|
|
<h1>
|
2023-09-20 02:47:05 +00:00
|
|
|
{ __(
|
|
|
|
'Which writing style do you prefer?',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
2023-09-06 06:21:09 +00:00
|
|
|
</h1>
|
2023-09-28 03:15:38 +00:00
|
|
|
{ context.apiCallLoader.hasErrors && (
|
|
|
|
<Notice
|
|
|
|
className="woocommerce-cys-design-with-ai__error-notice"
|
|
|
|
isDismissible={ false }
|
|
|
|
status="error"
|
|
|
|
>
|
|
|
|
{ createInterpolateElement(
|
|
|
|
__(
|
|
|
|
'Oops! We encountered a problem while generating your store. <retryButton/>',
|
|
|
|
'woocommerce'
|
|
|
|
),
|
|
|
|
{
|
|
|
|
retryButton: (
|
|
|
|
<Button
|
|
|
|
onClick={ onContinue }
|
|
|
|
variant="tertiary"
|
|
|
|
>
|
|
|
|
{ __(
|
|
|
|
'Please try again',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</Button>
|
|
|
|
),
|
|
|
|
}
|
|
|
|
) }
|
|
|
|
</Notice>
|
|
|
|
) }
|
2023-09-06 06:21:09 +00:00
|
|
|
<div className="choices">
|
2023-09-07 09:05:47 +00:00
|
|
|
{ choices.map( ( { title, subtitle, key } ) => {
|
2023-09-06 06:21:09 +00:00
|
|
|
return (
|
|
|
|
<Choice
|
2023-09-07 09:05:47 +00:00
|
|
|
key={ key }
|
2023-09-06 06:21:09 +00:00
|
|
|
name="user-profile-choice"
|
|
|
|
title={ title }
|
|
|
|
subtitle={ subtitle }
|
2023-09-07 09:05:47 +00:00
|
|
|
selected={ sound === key }
|
|
|
|
value={ key }
|
|
|
|
onChange={ ( _key ) => {
|
|
|
|
setSound( _key as Tone );
|
2023-09-06 06:21:09 +00:00
|
|
|
} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
</div>
|
2023-09-28 03:15:38 +00:00
|
|
|
<Button variant="primary" onClick={ onContinue }>
|
2023-09-06 06:21:09 +00:00
|
|
|
{ __( 'Continue', 'woocommerce' ) }
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-08-29 06:00:54 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|