PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / js / components / FeedbackReporter / FeedbackForm.tsx

FeedbackForm.tsx in Code Snippets 4.0.0-beta.2, at js/components/FeedbackReporter/FeedbackForm.tsx

67 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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