2022-01-12 06:46:33 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { useState } from '@wordpress/element';
|
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Modal,
|
|
|
|
CheckboxControl,
|
|
|
|
TextareaControl,
|
|
|
|
} from '@wordpress/components';
|
2023-06-16 14:32:58 +00:00
|
|
|
import { useDispatch, useSelect } from '@wordpress/data';
|
2022-11-16 13:22:16 +00:00
|
|
|
import { OPTIONS_STORE_NAME } from '@woocommerce/data';
|
2022-01-12 06:46:33 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-06-16 14:32:58 +00:00
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
2022-01-12 06:46:33 +00:00
|
|
|
import strings from './strings';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides a modal requesting customer feedback.
|
|
|
|
*
|
|
|
|
*/
|
2023-03-01 22:36:38 +00:00
|
|
|
function ExitSurveyModal( {}: {
|
2022-01-12 06:46:33 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
|
|
setExitSurveyModalOpen: Function;
|
|
|
|
} ): JSX.Element | null {
|
2023-06-16 14:32:58 +00:00
|
|
|
const incentive = getAdminSetting( 'wcpayWelcomePageIncentive' );
|
2022-01-12 06:46:33 +00:00
|
|
|
const [ isOpen, setOpen ] = useState( true );
|
|
|
|
const [ isHappyChecked, setHappyChecked ] = useState( false );
|
|
|
|
const [ isInstallChecked, setInstallChecked ] = useState( false );
|
|
|
|
const [ isMoreInfoChecked, setMoreInfoChecked ] = useState( false );
|
|
|
|
const [ isAnotherTimeChecked, setAnotherTimeChecked ] = useState( false );
|
2022-06-21 08:37:34 +00:00
|
|
|
const [ isSomethingElseChecked, setSomethingElseChecked ] =
|
|
|
|
useState( false );
|
2022-01-12 06:46:33 +00:00
|
|
|
const [ comments, setComments ] = useState( '' );
|
2022-11-16 13:22:16 +00:00
|
|
|
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME );
|
2022-01-12 06:46:33 +00:00
|
|
|
|
2023-06-16 14:32:58 +00:00
|
|
|
const dismissedIncentives = useSelect( ( select ) => {
|
|
|
|
const { getOption } = select( OPTIONS_STORE_NAME );
|
|
|
|
return (
|
|
|
|
( getOption(
|
|
|
|
'wcpay_welcome_page_incentives_dismissed'
|
|
|
|
) as string[] ) || []
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
const closeModal = async () => {
|
2022-01-12 06:46:33 +00:00
|
|
|
setOpen( false );
|
|
|
|
|
2022-11-16 13:22:16 +00:00
|
|
|
// Record that the modal was dismissed.
|
2023-06-16 14:32:58 +00:00
|
|
|
await updateOptions( {
|
|
|
|
wcpay_welcome_page_incentives_dismissed: [
|
|
|
|
...dismissedIncentives,
|
|
|
|
incentive.id,
|
|
|
|
],
|
2022-01-12 06:46:33 +00:00
|
|
|
} );
|
2022-11-16 13:22:16 +00:00
|
|
|
|
|
|
|
// Redirect back to the admin page.
|
|
|
|
window.location.href = 'admin.php?page=wc-admin';
|
2022-10-13 06:14:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const exitSurvey = () => {
|
|
|
|
recordEvent( 'wcpay_exit_survey', {
|
|
|
|
just_remove: true /* eslint-disable-line camelcase */,
|
|
|
|
} );
|
2022-01-12 06:46:33 +00:00
|
|
|
|
2022-10-13 06:14:01 +00:00
|
|
|
closeModal();
|
2022-01-12 06:46:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const sendFeedback = () => {
|
|
|
|
recordEvent( 'wcpay_exit_survey', {
|
2022-08-17 09:11:51 +00:00
|
|
|
/* eslint-disable camelcase */
|
2022-01-12 06:46:33 +00:00
|
|
|
happy: isHappyChecked ? 'Yes' : 'No',
|
|
|
|
install: isInstallChecked ? 'Yes' : 'No',
|
2022-08-17 09:11:51 +00:00
|
|
|
more_info: isMoreInfoChecked ? 'Yes' : 'No',
|
|
|
|
another_time: isAnotherTimeChecked ? 'Yes' : 'No',
|
|
|
|
something_else: isSomethingElseChecked ? 'Yes' : 'No',
|
2022-01-12 06:46:33 +00:00
|
|
|
comments,
|
2022-08-17 09:11:51 +00:00
|
|
|
/* eslint-enable camelcase */
|
2022-01-12 06:46:33 +00:00
|
|
|
} );
|
|
|
|
|
2022-11-16 13:22:16 +00:00
|
|
|
if ( isMoreInfoChecked ) {
|
|
|
|
// Record that the user would possibly consider installing WCPay with more information in the future.
|
|
|
|
updateOptions( {
|
2023-06-16 14:32:58 +00:00
|
|
|
wcpay_welcome_page_exit_survey_more_info_needed_timestamp:
|
|
|
|
Math.floor( Date.now() / 1000 ),
|
2022-11-16 13:22:16 +00:00
|
|
|
} );
|
|
|
|
}
|
2022-10-13 06:14:01 +00:00
|
|
|
closeModal();
|
2022-01-12 06:46:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if ( ! isOpen ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
2023-06-16 14:32:58 +00:00
|
|
|
className="woopayments-welcome-page__survey"
|
|
|
|
title={ strings.survey.title }
|
2022-01-12 06:46:33 +00:00
|
|
|
onRequestClose={ closeModal }
|
|
|
|
shouldCloseOnClickOutside={ false }
|
|
|
|
>
|
2023-06-16 14:32:58 +00:00
|
|
|
<p className="woopayments-welcome-page__survey-intro">
|
|
|
|
{ strings.survey.intro }
|
2022-01-12 06:46:33 +00:00
|
|
|
</p>
|
|
|
|
|
2023-06-16 14:32:58 +00:00
|
|
|
<p className="woopayments-welcome-page__survey-question">
|
|
|
|
{ strings.survey.question }
|
2022-01-12 06:46:33 +00:00
|
|
|
</p>
|
|
|
|
|
2023-06-16 14:32:58 +00:00
|
|
|
<div className="woopayments-welcome-page__survey-selection">
|
2022-01-12 06:46:33 +00:00
|
|
|
<CheckboxControl
|
2023-06-16 14:32:58 +00:00
|
|
|
label={ strings.survey.happyLabel }
|
2022-01-12 06:46:33 +00:00
|
|
|
checked={ isHappyChecked }
|
|
|
|
onChange={ setHappyChecked }
|
|
|
|
/>
|
|
|
|
<CheckboxControl
|
2023-06-16 14:32:58 +00:00
|
|
|
label={ strings.survey.installLabel }
|
2022-01-12 06:46:33 +00:00
|
|
|
checked={ isInstallChecked }
|
|
|
|
onChange={ setInstallChecked }
|
|
|
|
/>
|
|
|
|
<CheckboxControl
|
2023-06-16 14:32:58 +00:00
|
|
|
label={ strings.survey.moreInfoLabel }
|
2022-01-12 06:46:33 +00:00
|
|
|
checked={ isMoreInfoChecked }
|
|
|
|
onChange={ setMoreInfoChecked }
|
|
|
|
/>
|
|
|
|
<CheckboxControl
|
2023-06-16 14:32:58 +00:00
|
|
|
label={ strings.survey.anotherTimeLabel }
|
2022-01-12 06:46:33 +00:00
|
|
|
checked={ isAnotherTimeChecked }
|
|
|
|
onChange={ setAnotherTimeChecked }
|
|
|
|
/>
|
|
|
|
<CheckboxControl
|
2023-06-16 14:32:58 +00:00
|
|
|
label={ strings.survey.somethingElseLabel }
|
2022-01-12 06:46:33 +00:00
|
|
|
checked={ isSomethingElseChecked }
|
|
|
|
onChange={ setSomethingElseChecked }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2023-06-16 14:32:58 +00:00
|
|
|
<div className="woopayments-welcome-page__survey-comments">
|
2022-01-12 06:46:33 +00:00
|
|
|
<TextareaControl
|
2023-06-16 14:32:58 +00:00
|
|
|
label={ strings.survey.commentsLabel }
|
2022-01-12 06:46:33 +00:00
|
|
|
value={ comments }
|
|
|
|
onChange={ ( value: string ) => setComments( value ) }
|
|
|
|
rows={ 3 }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2023-06-16 14:32:58 +00:00
|
|
|
<div className="woopayments-welcome-page__survey-buttons">
|
2022-01-12 06:46:33 +00:00
|
|
|
<Button
|
|
|
|
isTertiary
|
|
|
|
isDestructive
|
2022-10-13 06:14:01 +00:00
|
|
|
onClick={ exitSurvey }
|
2022-01-12 06:46:33 +00:00
|
|
|
name="cancel"
|
|
|
|
>
|
2023-06-16 14:32:58 +00:00
|
|
|
{ strings.survey.cancelButton }
|
2022-01-12 06:46:33 +00:00
|
|
|
</Button>
|
|
|
|
<Button isSecondary onClick={ sendFeedback } name="send">
|
2023-06-16 14:32:58 +00:00
|
|
|
{ strings.survey.submitButton }
|
2022-01-12 06:46:33 +00:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ExitSurveyModal;
|