import React, { FC, useEffect, useRef } from 'react' import { useI18n } from '@wordpress/react-i18n' import bringLogo from '../../assets/img/Bring_logo.svg' import { Button, SelectControl, TextareaControl } from '@wordpress/components' import apiFetch from '@wordpress/api-fetch' import { useEnableWpCompatOverlaySlot } from '@wordpress/ui' const Deactivate: FC = () => { const [reason, setReason] = React.useState('') const [additionalFeedback, setAdditionalFeedback] = React.useState('') const { __ } = useI18n() const [saving, setSaving] = React.useState(false) const ref = useRef(null) useEnableWpCompatOverlaySlot() useEffect(() => { const focus = () => { ref.current?.focus() } window.addEventListener('posten-bring-checkout:deactivate:open', focus) }, []) const reset = () => { setSaving(false) setReason('') setAdditionalFeedback('') } const closeModal = () => { reset() window.dispatchEvent( new CustomEvent('posten-bring-checkout:deactivate:continue') ) } const handleDeactivationFeedback = () => { if (reason === '' && additionalFeedback === '') { closeModal() } else { setSaving(true) apiFetch({ path: `/posten-bring-checkout/deactivate`, method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ reason, feedback: additionalFeedback, }), }) .then(() => { closeModal() }) .catch(() => { closeModal() }) } } return (
{''}

{__('Sorry to see you leave!', 'posten-bring-checkout')}

{__( 'Would you like to share why? Any feedback is much appreciated', 'posten-bring-checkout' )}

setReason(selectedReason)} /> {reason !== '' && ( setAdditionalFeedback(value)} /> )} {reason === '' ? ( ) : ( )}
) } export default Deactivate