| 1 |
import React, { useState } from 'react' |
| 2 |
import { __ } from '@wordpress/i18n' |
| 3 |
import { WithRestAPIContext } from '../../hooks/useRestAPI' |
| 4 |
import { FeedbackPanel } from './FeedbackPanel' |
| 5 |
import { HeadingBadge } from './HeadingBadge' |
| 6 |
|
| 7 |
export const FeedbackReporter: React.FC = () => { |
| 8 |
const [isOpen, setIsOpen] = useState(false) |
| 9 |
const config = window.CODE_SNIPPETS_FEEDBACK |
| 10 |
|
| 11 |
if (!config) { |
| 12 |
return null |
| 13 |
} |
| 14 |
|
| 15 |
// The provider registers a heartbeat listener without cleanup, so it is mounted once |
| 16 |
// for the page rather than on each open. |
| 17 |
return <WithRestAPIContext> |
| 18 |
<HeadingBadge label={config.badge} /> |
| 19 |
|
| 20 |
<button |
| 21 |
type="button" |
| 22 |
className="code-snippets-feedback-launcher" |
| 23 |
aria-expanded={isOpen} |
| 24 |
onClick={() => setIsOpen(true)} |
| 25 |
> |
| 26 |
<span className="code-snippets-feedback-launcher__dot" aria-hidden="true"></span> |
| 27 |
{__('Send feedback', 'code-snippets')} |
| 28 |
</button> |
| 29 |
|
| 30 |
{isOpen && <FeedbackPanel config={config} onClose={() => setIsOpen(false)} />} |
| 31 |
</WithRestAPIContext> |
| 32 |
} |
| 33 |
|