/** * External dependencies */ import { useState } from '@wordpress/element'; import { Button, Modal, CheckboxControl, TextareaControl, } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import { OPTIONS_STORE_NAME } from '@woocommerce/data'; import { recordEvent } from '@woocommerce/tracks'; /** * Internal dependencies */ import { getAdminSetting } from '~/utils/admin-settings'; import strings from './strings'; /** * Provides a modal requesting customer feedback. * */ function ExitSurveyModal( {}: { // eslint-disable-next-line @typescript-eslint/ban-types setExitSurveyModalOpen: Function; } ): JSX.Element | null { const incentive = getAdminSetting( 'wcpayWelcomePageIncentive' ); 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 ); const [ isSomethingElseChecked, setSomethingElseChecked ] = useState( false ); const [ comments, setComments ] = useState( '' ); const { updateOptions } = useDispatch( OPTIONS_STORE_NAME ); const dismissedIncentives = useSelect( ( select ) => { const { getOption } = select( OPTIONS_STORE_NAME ); return ( ( getOption( 'wcpay_welcome_page_incentives_dismissed' ) as string[] ) || [] ); } ); const closeModal = async () => { setOpen( false ); // Record that the modal was dismissed. await updateOptions( { wcpay_welcome_page_incentives_dismissed: [ ...dismissedIncentives, incentive.id, ], } ); // Redirect back to the admin page. window.location.href = 'admin.php?page=wc-admin'; }; const exitSurvey = () => { recordEvent( 'wcpay_exit_survey', { just_remove: true /* eslint-disable-line camelcase */, } ); closeModal(); }; const sendFeedback = () => { recordEvent( 'wcpay_exit_survey', { /* eslint-disable camelcase */ happy: isHappyChecked ? 'Yes' : 'No', install: isInstallChecked ? 'Yes' : 'No', more_info: isMoreInfoChecked ? 'Yes' : 'No', another_time: isAnotherTimeChecked ? 'Yes' : 'No', something_else: isSomethingElseChecked ? 'Yes' : 'No', comments, /* eslint-enable camelcase */ } ); if ( isMoreInfoChecked ) { // Record that the user would possibly consider installing WCPay with more information in the future. updateOptions( { wcpay_welcome_page_exit_survey_more_info_needed_timestamp: Math.floor( Date.now() / 1000 ), } ); } closeModal(); }; if ( ! isOpen ) { return null; } return (

{ strings.survey.intro }

{ strings.survey.question }

setComments( value ) } rows={ 3 } />
); } export default ExitSurveyModal;