-
-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathBugReportForm.tsx
More file actions
193 lines (173 loc) · 6.04 KB
/
Copy pathBugReportForm.tsx
File metadata and controls
193 lines (173 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import { CreateIssuePostRequest } from '@hasadna/open-bus-api-client'
import { Alert } from '@mui/material'
import { useMutation } from '@tanstack/react-query'
import { Button, Checkbox, Form, Input, Select } from 'antd'
import { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { ISSUES_API } from 'src/api/apiConfig'
import { EasterEgg } from 'src/pages/components/EasterEgg/EasterEgg'
import InfoYoutubeModal from 'src/pages/components/YoutubeModal'
import Widget from 'src/shared/Widget'
import './BugReportForm.scss'
// File upload is disabled until the server-side implementation is complete.
const BugReportForm = () => {
const { t, i18n } = useTranslation()
const [form] = Form.useForm<CreateIssuePostRequest>()
// const [fileList, setFileList] = useState<UploadFile[]>([])
const mutation = useMutation({
mutationFn: (values: CreateIssuePostRequest) =>
ISSUES_API.issuesCreatePost({ createIssuePostRequest: values }),
onSuccess: () => {
form.resetFields()
},
onError: (error) => {
console.error('Error submitting bug report:', error)
},
})
const onFinish = (values: CreateIssuePostRequest) => {
mutation.reset()
mutation.mutate(values)
}
// const onFileChange = (info: UploadChangeParam) => {
// setFileList(info.fileList)
// }
const options = useMemo(() => {
return [
{ value: 'always', label: t('bug_frequency.always') },
{ value: 'sometimes', label: t('bug_frequency.sometimes') },
{ value: 'rarely', label: t('bug_frequency.rarely') },
{ value: 'once', label: t('bug_frequency.once') },
]
}, [t])
return (
<Widget
className="bug-report-form-container"
title={
<p className="logo">
{t('website_name')}
<InfoYoutubeModal
label={t('open_video_about_this_page')}
title={t('youtube_modal_info_title')}
videoUrl="https://www.youtube-nocookie.com/embed?v=F6sD9Bz4Xj0&list=PL6Rh06rT7uiX1AQE-lm55hy-seL3idx3T&index=11"
/>
</p>
}>
<span>{t('reportBug.description')}</span>
{mutation.isSuccess &&
(() => {
const issueUrl = mutation.data?.data?.url
return (
<Alert severity="success" sx={{ marginBottom: 2 }}>
{issueUrl ? (
<a href={issueUrl} target="_blank" rel="noopener noreferrer">
{t('reportBug.viewIssue')} (GitHub)
</a>
) : (
t('reportBug.success', { defaultValue: 'Bug report submitted successfully!' })
)}
</Alert>
)
})()}
{mutation.isError && (
<Alert severity="error" onClose={mutation.reset} sx={{ marginBottom: 2 }}>
{t('reportBug.error')}
</Alert>
)}
<Form
form={form}
name="bug-report"
onFinish={(values) => {
onFinish(values)
}}
// onFinishFailed={onFinishFailed}
labelCol={{ span: 6 }}
wrapperCol={{ span: 18 }}>
<Form.Item label={t('bug_type')} name="type" rules={[{ required: true }]}>
<Select>
<Select.Option value="bug">{t('bug_type_bug')}</Select.Option>
<Select.Option value="feature">{t('bug_type_feature')}</Select.Option>
<Select.Option value="other">{t('bug_type_other')}</Select.Option>
</Select>
</Form.Item>
<Form.Item
label={t('bug_title')}
name="title"
rules={[{ required: true, min: 5, max: 200 }]}>
<Input />
</Form.Item>
<Form.Item
label={t('bug_contact_name')}
name="contactName"
rules={[{ required: true, min: 1, max: 100 }]}>
<Input />
</Form.Item>
<Form.Item
label={t('bug_contact_email')}
name="contactEmail"
rules={[{ required: true, type: 'email' }]}>
<Input />
</Form.Item>
<Form.Item
label={t('bug_description')}
name="description"
rules={[{ required: true, min: 10, max: 5000 }]}>
<Input.TextArea rows={4} />
</Form.Item>
<Form.Item
label={t('bug_environment')}
name="environment"
rules={[{ required: true, min: 1, max: 200 }]}>
<Input />
</Form.Item>
<Form.Item
label={t('bug_expected_behavior')}
name="expectedBehavior"
rules={[{ required: true, min: 5, max: 1000 }]}>
<Input.TextArea rows={4} />
</Form.Item>
<Form.Item
label={t('bug_actual_behavior')}
name="actualBehavior"
rules={[{ required: true, min: 5, max: 1000 }]}>
<Input.TextArea rows={4} />
</Form.Item>
<Form.Item
label={t('bug_reproducibility')}
name="reproducibility"
rules={[{ required: true, min: 1, max: 100 }]}>
<Select>
{options.map((option) => (
<Select.Option key={option.value} value={option.value}>
{option.label}
</Select.Option>
))}
</Select>
</Form.Item>
<EasterEgg code="debug" autohide={false} onShow={() => form.setFieldValue('debug', true)}>
<Form.Item label="debug" name="debug" valuePropName="checked">
<Checkbox />
</Form.Item>
</EasterEgg>
{/* <Form.Item label={t('bug_attachments')} name="attachments">
<Upload
multiple
maxCount={10}
beforeUpload={() => false}
listType="picture"
fileList={fileList}
onChange={onFileChange}>
<Button icon={<FileUploadOutlined fontSize="small" />}>
{t('bug_attachments_upload_button')}
</Button>
</Upload>
</Form.Item> */}
<Form.Item>
<Button type="primary" htmlType="submit" loading={mutation.isPending} dir={i18n.dir()}>
{t('bug_submit')}
</Button>
</Form.Item>
</Form>
</Widget>
)
}
export default BugReportForm