-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssueReportDialog.tsx
More file actions
235 lines (216 loc) · 7.29 KB
/
Copy pathIssueReportDialog.tsx
File metadata and controls
235 lines (216 loc) · 7.29 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import { useState } from 'react';
import { AlertTriangle, Loader2 } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from './ui/dialog';
import { Button } from './ui/button';
import { Input } from './ui/input';
import { Label } from './ui/label';
import { Textarea } from './ui/textarea';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from './ui/select';
export type IssueSeverity = 'low' | 'medium' | 'high' | 'critical';
export interface IssueReport {
title: string;
description: string;
severity: IssueSeverity;
}
interface IssueReportDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onSubmit?: (report: IssueReport) => Promise<void> | void;
defaultTitle?: string;
defaultDescription?: string;
}
/**
* Dialog for reporting detailed issues or suggestions
* Includes title, description, and severity fields
*/
export function IssueReportDialog({
open,
onOpenChange,
onSubmit,
defaultTitle = '',
defaultDescription = ''
}: IssueReportDialogProps) {
const { t } = useTranslation(['common', 'dialogs']);
const [title, setTitle] = useState(defaultTitle);
const [description, setDescription] = useState(defaultDescription);
const [severity, setSeverity] = useState<IssueSeverity>('medium');
const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState<string | null>(null);
const handleSubmit = async () => {
// Validate form
if (!title.trim()) {
setError(t('common:errors.generic', 'Title is required'));
return;
}
if (!description.trim()) {
setError(t('common:errors.generic', 'Description is required'));
return;
}
setError(null);
setIsSubmitting(true);
try {
await onSubmit?.({
title: title.trim(),
description: description.trim(),
severity
});
// Reset form on successful submission
setTitle('');
setDescription('');
setSeverity('medium');
onOpenChange(false);
} catch (err) {
setError(err instanceof Error ? err.message : t('common:errors.generic', 'An error occurred'));
} finally {
setIsSubmitting(false);
}
};
const handleClose = (newOpen: boolean) => {
if (isSubmitting) return;
// Only reset form when closing, not when opening
if (!newOpen) {
setTitle(defaultTitle);
setDescription(defaultDescription);
setSeverity('medium');
setError(null);
}
onOpenChange(newOpen);
};
// Severity options with translations
const severityOptions: Array<{ value: IssueSeverity; label: string; description: string }> = [
{
value: 'low',
label: t('common:prReview.severity.low', 'Suggestion'),
description: t('common:prReview.severity.lowDesc', 'Consider')
},
{
value: 'medium',
label: t('common:prReview.severity.medium', 'Recommended'),
description: t('common:prReview.severity.mediumDesc', 'Improve quality')
},
{
value: 'high',
label: t('common:prReview.severity.high', 'Required'),
description: t('common:prReview.severity.highDesc', 'Should fix')
},
{
value: 'critical',
label: t('common:prReview.severity.critical', 'Blocker'),
description: t('common:prReview.severity.criticalDesc', 'Must fix')
}
];
return (
<Dialog open={open} onOpenChange={handleClose}>
<DialogContent className="sm:max-w-[600px]">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<AlertTriangle className="h-5 w-5 text-warning" />
{t('common:feedback.reportIssueTitle', 'Report an Issue')}
</DialogTitle>
<DialogDescription>
{t('common:feedback.reportIssueDescription', 'Provide details about the issue or suggestion to help us improve.')}
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-4">
{/* Title Field */}
<div className="space-y-2">
<Label htmlFor="issue-title">
{t('common:feedback.issueTitle', 'Title')}
<span className="text-destructive ml-1">*</span>
</Label>
<Input
id="issue-title"
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder={t('common:feedback.issueTitlePlaceholder', 'Brief summary of the issue...')}
disabled={isSubmitting}
className="w-full"
/>
</div>
{/* Description Field */}
<div className="space-y-2">
<Label htmlFor="issue-description">
{t('common:feedback.issueDescription', 'Description')}
<span className="text-destructive ml-1">*</span>
</Label>
<Textarea
id="issue-description"
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder={t('common:feedback.issueDescriptionPlaceholder', 'Detailed description of the issue, including steps to reproduce if applicable...')}
disabled={isSubmitting}
className="min-h-[150px] resize-none"
/>
</div>
{/* Severity Field */}
<div className="space-y-2">
<Label htmlFor="issue-severity">
{t('common:feedback.issueSeverity', 'Severity')}
</Label>
<Select
value={severity}
onValueChange={(value) => setSeverity(value as IssueSeverity)}
disabled={isSubmitting}
>
<SelectTrigger id="issue-severity" className="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
{severityOptions.map((option) => (
<SelectItem key={option.value} value={option.value}>
<div className="flex flex-col items-start">
<span className="font-medium">{option.label}</span>
<span className="text-xs text-muted-foreground">{option.description}</span>
</div>
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{/* Error Message */}
{error && (
<div className="rounded-md bg-destructive/10 border border-destructive/20 p-3">
<p className="text-sm text-destructive">{error}</p>
</div>
)}
</div>
<DialogFooter>
<Button
variant="outline"
onClick={() => handleClose(false)}
disabled={isSubmitting}
>
{t('common:buttons.cancel', 'Cancel')}
</Button>
<Button
onClick={handleSubmit}
disabled={!title.trim() || !description.trim() || isSubmitting}
>
{isSubmitting ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
{t('common:feedback.submitting', 'Submitting...')}
</>
) : (
t('common:feedback.submitReport', 'Submit Report')
)}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}