2022-04-07 19:56:20 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classnames from 'classnames';
|
2022-04-08 17:28:43 +00:00
|
|
|
import { useState } from '@wordpress/element';
|
|
|
|
import { EllipsisMenu } from '@woocommerce/components';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
|
|
import { OPTIONS_STORE_NAME, WEEK } from '@woocommerce/data';
|
2022-04-07 19:56:20 +00:00
|
|
|
import { Button, Card, CardHeader } from '@wordpress/components';
|
|
|
|
import { Text } from '@woocommerce/experimental';
|
2022-04-08 17:28:43 +00:00
|
|
|
import {
|
|
|
|
CustomerFeedbackModal,
|
|
|
|
CustomerFeedbackSimple,
|
|
|
|
} from '@woocommerce/customer-effort-score';
|
2022-04-07 19:56:20 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './completed-header-with-ces.scss';
|
|
|
|
import HeaderImage from './completed-celebration-header.svg';
|
|
|
|
|
|
|
|
type TaskListCompletedHeaderProps = {
|
2022-04-08 17:28:43 +00:00
|
|
|
hideTasks: () => void;
|
2022-04-07 19:56:20 +00:00
|
|
|
keepTasks: () => void;
|
2022-04-08 18:37:22 +00:00
|
|
|
showCES: boolean;
|
2022-04-07 19:56:20 +00:00
|
|
|
};
|
|
|
|
|
2022-04-08 17:28:43 +00:00
|
|
|
const ADMIN_INSTALL_TIMESTAMP_OPTION_NAME =
|
|
|
|
'woocommerce_admin_install_timestamp';
|
|
|
|
const SHOWN_FOR_ACTIONS_OPTION_NAME = 'woocommerce_ces_shown_for_actions';
|
|
|
|
const CES_ACTION = 'store_setup';
|
|
|
|
|
|
|
|
function getStoreAgeInWeeks( adminInstallTimestamp: number ) {
|
|
|
|
if ( adminInstallTimestamp === 0 ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Date.now() is ms since Unix epoch, adminInstallTimestamp is in
|
|
|
|
// seconds since Unix epoch.
|
|
|
|
const storeAgeInMs = Date.now() - adminInstallTimestamp * 1000;
|
|
|
|
const storeAgeInWeeks = Math.round( storeAgeInMs / WEEK );
|
|
|
|
|
|
|
|
return storeAgeInWeeks;
|
|
|
|
}
|
|
|
|
|
2022-04-07 19:56:20 +00:00
|
|
|
export const TaskListCompletedHeaderWithCES: React.FC< TaskListCompletedHeaderProps > = ( {
|
|
|
|
hideTasks,
|
|
|
|
keepTasks,
|
2022-04-08 18:37:22 +00:00
|
|
|
showCES,
|
2022-04-07 19:56:20 +00:00
|
|
|
} ) => {
|
2022-04-08 17:28:43 +00:00
|
|
|
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME );
|
|
|
|
const [ showCesModal, setShowCesModal ] = useState( false );
|
2022-04-21 19:40:48 +00:00
|
|
|
const [ submittedScore, setSubmittedScore ] = useState( false );
|
2022-04-08 17:28:43 +00:00
|
|
|
const [ score, setScore ] = useState( NaN );
|
|
|
|
const { storeAgeInWeeks, cesShownForActions } = useSelect( ( select ) => {
|
|
|
|
const { getOption } = select( OPTIONS_STORE_NAME );
|
|
|
|
|
2022-04-08 18:37:22 +00:00
|
|
|
if ( showCES ) {
|
|
|
|
const adminInstallTimestamp: number =
|
|
|
|
getOption( ADMIN_INSTALL_TIMESTAMP_OPTION_NAME ) || 0;
|
|
|
|
return {
|
|
|
|
storeAgeInWeeks: getStoreAgeInWeeks( adminInstallTimestamp ),
|
|
|
|
cesShownForActions:
|
|
|
|
getOption( SHOWN_FOR_ACTIONS_OPTION_NAME ) || [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {};
|
2022-04-08 17:28:43 +00:00
|
|
|
} );
|
|
|
|
|
2022-04-21 19:40:48 +00:00
|
|
|
const submitScore = ( recordedScore: number, comments?: string ) => {
|
|
|
|
recordEvent( 'ces_feedback', {
|
|
|
|
action: CES_ACTION,
|
|
|
|
score: recordedScore,
|
|
|
|
comments: comments || '',
|
|
|
|
store_age: storeAgeInWeeks,
|
|
|
|
} );
|
|
|
|
updateOptions( {
|
|
|
|
[ SHOWN_FOR_ACTIONS_OPTION_NAME ]: [
|
|
|
|
CES_ACTION,
|
|
|
|
...cesShownForActions,
|
|
|
|
],
|
|
|
|
} );
|
|
|
|
setSubmittedScore( true );
|
|
|
|
};
|
|
|
|
|
2022-04-08 18:37:22 +00:00
|
|
|
const recordScore = ( recordedScore: number ) => {
|
|
|
|
if ( recordedScore > 2 ) {
|
2022-04-21 19:40:48 +00:00
|
|
|
setScore( recordedScore );
|
|
|
|
submitScore( recordedScore );
|
2022-04-08 17:28:43 +00:00
|
|
|
} else {
|
2022-04-08 18:37:22 +00:00
|
|
|
setScore( recordedScore );
|
2022-04-08 17:28:43 +00:00
|
|
|
setShowCesModal( true );
|
2022-04-08 18:37:22 +00:00
|
|
|
recordEvent( 'ces_view', {
|
|
|
|
action: CES_ACTION,
|
|
|
|
store_age: storeAgeInWeeks,
|
|
|
|
} );
|
2022-04-08 17:28:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-04-08 18:37:22 +00:00
|
|
|
const recordModalScore = ( recordedScore: number, comments: string ) => {
|
2022-04-08 17:28:43 +00:00
|
|
|
setShowCesModal( false );
|
2022-04-21 19:40:48 +00:00
|
|
|
submitScore( recordedScore, comments );
|
2022-04-08 17:28:43 +00:00
|
|
|
};
|
2022-04-07 19:56:20 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div
|
|
|
|
className={ classnames(
|
|
|
|
'woocommerce-task-dashboard__container two-column-experiment'
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<Card
|
|
|
|
size="large"
|
|
|
|
className="woocommerce-task-card woocommerce-homescreen-card completed"
|
|
|
|
>
|
|
|
|
<CardHeader size="medium">
|
|
|
|
<div className="wooocommerce-task-card__header">
|
|
|
|
<img src={ HeaderImage } alt="Completed" />
|
|
|
|
|
|
|
|
<h2>
|
|
|
|
{ __(
|
|
|
|
"You've completed store setup",
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</h2>
|
|
|
|
<Text
|
|
|
|
variant="subtitle.small"
|
|
|
|
as="p"
|
|
|
|
size="13"
|
|
|
|
lineHeight="16px"
|
|
|
|
className="wooocommerce-task-card__header-subtitle"
|
|
|
|
>
|
|
|
|
{ __(
|
|
|
|
'Congratulations! Take a moment to celebrate and look out for the first sale.',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</Text>
|
|
|
|
<div className="woocommerce-task-card__header-menu">
|
|
|
|
<EllipsisMenu
|
|
|
|
label={ __(
|
|
|
|
'Task List Options',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
renderContent={ () => (
|
|
|
|
<div className="woocommerce-task-card__section-controls">
|
|
|
|
<Button
|
|
|
|
onClick={ () => keepTasks() }
|
|
|
|
>
|
|
|
|
{ __(
|
|
|
|
'Show setup task list',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
onClick={ () => hideTasks() }
|
|
|
|
>
|
|
|
|
{ __(
|
|
|
|
'Hide this',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</CardHeader>
|
2022-04-08 18:37:22 +00:00
|
|
|
{ showCES && (
|
2022-04-07 19:56:20 +00:00
|
|
|
<CustomerFeedbackSimple
|
|
|
|
label={ __(
|
|
|
|
'How was your experience?',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
2022-04-21 19:40:48 +00:00
|
|
|
showFeedback={ submittedScore }
|
2022-04-08 17:28:43 +00:00
|
|
|
recordScoreCallback={ recordScore }
|
2022-04-21 19:40:48 +00:00
|
|
|
feedbackScore={ score }
|
2022-04-07 19:56:20 +00:00
|
|
|
/>
|
|
|
|
) }
|
|
|
|
</Card>
|
|
|
|
</div>
|
2022-04-08 17:28:43 +00:00
|
|
|
{ showCesModal ? (
|
|
|
|
<CustomerFeedbackModal
|
|
|
|
label={ __( 'How was your experience?', 'woocommerce' ) }
|
|
|
|
defaultScore={ score }
|
|
|
|
recordScoreCallback={ recordModalScore }
|
2022-04-21 19:40:48 +00:00
|
|
|
onCloseModal={ () => {
|
|
|
|
setScore( NaN );
|
|
|
|
setShowCesModal( false );
|
|
|
|
} }
|
2022-04-08 17:28:43 +00:00
|
|
|
/>
|
|
|
|
) : null }
|
2022-04-07 19:56:20 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|