| 1 |
import React from 'react' |
| 2 |
import { SelectControl, TextareaControl } from '@wordpress/components' |
| 3 |
import { __ } from '@wordpress/i18n' |
| 4 |
import { BugDetailFields } from './BugDetailFields' |
| 5 |
import { ReportSummaryFields } from './ReportSummaryFields' |
| 6 |
import { ReporterFields } from './ReporterFields' |
| 7 |
import type { FeedbackReport } from '../../hooks/useFeedbackReport' |
| 8 |
import type { FeedbackConfig, FeedbackDraft } from '../../types/Feedback' |
| 9 |
|
| 10 |
const TYPE_OPTIONS = [ |
| 11 |
{ label: __('Choose one…', 'code-snippets'), value: '' }, |
| 12 |
{ label: __('Bug — something is broken', 'code-snippets'), value: 'bug' }, |
| 13 |
{ label: __('Feature request — something is missing', 'code-snippets'), value: 'feature' }, |
| 14 |
{ label: __('General feedback', 'code-snippets'), value: 'feedback' } |
| 15 |
] |
| 16 |
|
| 17 |
export interface FeedbackFormProps { |
| 18 |
config: FeedbackConfig |
| 19 |
report: FeedbackReport |
| 20 |
} |
| 21 |
|
| 22 |
export const FeedbackForm: React.FC<FeedbackFormProps> = ({ config, report }) => { |
| 23 |
const { draft, duplicates, errorMessage, updateDraft } = report |
| 24 |
const type = draft.type |
| 25 |
|
| 26 |
return <> |
| 27 |
{errorMessage && |
| 28 |
<p className="code-snippets-feedback-message" role="alert" tabIndex={-1}>{errorMessage}</p>} |
| 29 |
|
| 30 |
<div className="code-snippets-feedback-field"> |
| 31 |
<SelectControl |
| 32 |
label={__('What kind of feedback is this?', 'code-snippets')} |
| 33 |
value={type} |
| 34 |
options={TYPE_OPTIONS} |
| 35 |
onChange={value => updateDraft({ type: value as FeedbackDraft['type'] })} |
| 36 |
/> |
| 37 |
</div> |
| 38 |
|
| 39 |
{type && <> |
| 40 |
<ReportSummaryFields |
| 41 |
type={type} |
| 42 |
draft={draft} |
| 43 |
duplicates={duplicates} |
| 44 |
updateDraft={updateDraft} |
| 45 |
/> |
| 46 |
|
| 47 |
{'bug' === type && <BugDetailFields draft={draft} updateDraft={updateDraft} />} |
| 48 |
|
| 49 |
<div className="code-snippets-feedback-field"> |
| 50 |
<TextareaControl |
| 51 |
label={'bug' === type |
| 52 |
? __('Error messages or logs (optional)', 'code-snippets') |
| 53 |
: __('Anything else (optional)', 'code-snippets')} |
| 54 |
rows={3} |
| 55 |
value={draft.comments} |
| 56 |
placeholder={'bug' === type |
| 57 |
? __('Paste any PHP notices, console output or stack traces.', 'code-snippets') |
| 58 |
: ''} |
| 59 |
onChange={comments => updateDraft({ comments })} |
| 60 |
/> |
| 61 |
</div> |
| 62 |
|
| 63 |
<ReporterFields config={config} draft={draft} updateDraft={updateDraft} /> |
| 64 |
</>} |
| 65 |
</> |
| 66 |
} |
| 67 |
|