| 1 |
import React from 'react' |
| 2 |
import { Button, Modal } from '@wordpress/components' |
| 3 |
import { __, sprintf } from '@wordpress/i18n' |
| 4 |
import { useFeedbackReport } from '../../hooks/useFeedbackReport' |
| 5 |
import { FeedbackForm } from './FeedbackForm' |
| 6 |
import { FeedbackSuccess } from './FeedbackSuccess' |
| 7 |
import type { FeedbackConfig } from '../../types/Feedback' |
| 8 |
|
| 9 |
export interface FeedbackPanelProps { |
| 10 |
config: FeedbackConfig |
| 11 |
onClose: VoidFunction |
| 12 |
} |
| 13 |
|
| 14 |
export const FeedbackPanel: React.FC<FeedbackPanelProps> = ({ config, onClose }) => { |
| 15 |
const report = useFeedbackReport(config) |
| 16 |
|
| 17 |
return <Modal |
| 18 |
title={__('Send feedback', 'code-snippets')} |
| 19 |
className="code-snippets-feedback-modal" |
| 20 |
closeButtonLabel={__('Close', 'code-snippets')} |
| 21 |
onRequestClose={onClose} |
| 22 |
> |
| 23 |
<p className="code-snippets-feedback-panel__subtitle"> |
| 24 |
{sprintf( |
| 25 |
// translators: 1: plugin version, 2: plugin edition, either Free or Pro. |
| 26 |
__('Code Snippets %1$s %2$s', 'code-snippets'), |
| 27 |
config.version, |
| 28 |
'pro' === config.edition ? __('Pro', 'code-snippets') : __('Free', 'code-snippets') |
| 29 |
)} |
| 30 |
</p> |
| 31 |
|
| 32 |
<div className="code-snippets-feedback-panel__body"> |
| 33 |
{report.result |
| 34 |
? <FeedbackSuccess result={report.result} /> |
| 35 |
: <FeedbackForm config={config} report={report} />} |
| 36 |
</div> |
| 37 |
|
| 38 |
<div className="code-snippets-feedback-panel__footer"> |
| 39 |
<Button variant="tertiary" onClick={onClose}> |
| 40 |
{report.result ? __('Close', 'code-snippets') : __('Cancel', 'code-snippets')} |
| 41 |
</Button> |
| 42 |
|
| 43 |
{!report.result && |
| 44 |
<Button |
| 45 |
variant="primary" |
| 46 |
disabled={!report.draft.type || report.isSending} |
| 47 |
onClick={report.submit} |
| 48 |
> |
| 49 |
{report.isSending ? __('Sending…', 'code-snippets') : __('Send report', 'code-snippets')} |
| 50 |
</Button>} |
| 51 |
</div> |
| 52 |
</Modal> |
| 53 |
} |
| 54 |
|