BugReportBubble.tsx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. import { useState, useRef, useCallback, useEffect } from 'react';
  2. import { Bug, X, Loader2, CheckCircle, AlertCircle, AlertTriangle, Trash2, Upload, Circle, CheckCircle2, Stethoscope } from 'lucide-react';
  3. import { useTranslation } from 'react-i18next';
  4. import { useQuery } from '@tanstack/react-query';
  5. import { api, bugReportApi, type PrinterDiagnosticResult } from '../api/client';
  6. import { DiagnosticChecklist } from './ConnectionDiagnostic';
  7. import { SystemHealthPanel } from './SystemHealthPanel';
  8. import { Collapsible } from './Collapsible';
  9. type ViewState = 'form' | 'logging' | 'stopping' | 'submitting' | 'success' | 'error';
  10. /** One scanned printer paired with its name — the diagnostic result alone
  11. * carries no name, and the bug-report panel lists affected printers by name. */
  12. type DiagnosticEntry = { name: string; result: PrinterDiagnosticResult };
  13. const MAX_DIMENSION = 1920;
  14. const JPEG_QUALITY = 0.7;
  15. const MAX_LOG_SECONDS = 300; // 5 minutes
  16. function compressImage(file: File): Promise<string> {
  17. return new Promise((resolve, reject) => {
  18. const img = new Image();
  19. img.onload = () => {
  20. let { width, height } = img;
  21. if (width > MAX_DIMENSION || height > MAX_DIMENSION) {
  22. const scale = MAX_DIMENSION / Math.max(width, height);
  23. width = Math.round(width * scale);
  24. height = Math.round(height * scale);
  25. }
  26. const canvas = document.createElement('canvas');
  27. canvas.width = width;
  28. canvas.height = height;
  29. const ctx = canvas.getContext('2d');
  30. if (!ctx) { reject(new Error('No canvas context')); return; }
  31. ctx.drawImage(img, 0, 0, width, height);
  32. const dataUrl = canvas.toDataURL('image/jpeg', JPEG_QUALITY);
  33. resolve(dataUrl.replace(/^data:[^;]+;base64,/, ''));
  34. };
  35. img.onerror = reject;
  36. img.src = URL.createObjectURL(file);
  37. });
  38. }
  39. function formatElapsed(seconds: number): string {
  40. const m = Math.floor(seconds / 60);
  41. const s = seconds % 60;
  42. return `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
  43. }
  44. export function BugReportBubble() {
  45. const { t } = useTranslation();
  46. const [isOpen, setIsOpen] = useState(false);
  47. const [viewState, setViewState] = useState<ViewState>('form');
  48. const [description, setDescription] = useState('');
  49. const [email, setEmail] = useState('');
  50. const [screenshot, setScreenshot] = useState<string | null>(null);
  51. const [isDragging, setIsDragging] = useState(false);
  52. const [issueUrl, setIssueUrl] = useState<string | null>(null);
  53. const [issueNumber, setIssueNumber] = useState<number | null>(null);
  54. const [errorMessage, setErrorMessage] = useState('');
  55. const [elapsedSeconds, setElapsedSeconds] = useState(0);
  56. const [wasDebug, setWasDebug] = useState(false);
  57. const modalRef = useRef<HTMLDivElement>(null);
  58. const fileInputRef = useRef<HTMLInputElement>(null);
  59. const handleStopLoggingRef = useRef<() => void>(() => {});
  60. // Before the user files a report, diagnose configured printers. Most bug
  61. // reports are setup issues — surfacing a connection problem inline lets the
  62. // user self-fix instead of waiting on a triage round-trip. The result is
  63. // always shown (healthy or not) so the user can see the check ran.
  64. const diagnosticScan = useQuery({
  65. queryKey: ['bugReportDiagnostic'],
  66. enabled: isOpen && viewState === 'form',
  67. staleTime: 30_000,
  68. queryFn: async (): Promise<DiagnosticEntry[]> => {
  69. const printers = await api.getPrinters();
  70. const entries = await Promise.all(
  71. printers.map(async (p) => {
  72. const result = await api.diagnosePrinter(p.id).catch(() => null);
  73. return result ? { name: p.name, result } : null;
  74. }),
  75. );
  76. return entries.filter((e): e is DiagnosticEntry => e !== null);
  77. },
  78. });
  79. const diagnosticEntries = diagnosticScan.data ?? [];
  80. const diagnosticProblems = diagnosticEntries.filter((e) => e.result.overall === 'problems');
  81. // Scan recent logs against the known-issue catalog. Like the diagnostic
  82. // above, this surfaces user-fixable ("layer 8") problems before a report is
  83. // filed. Only shown when something matched — a clean scan stays silent so
  84. // the form is uncluttered.
  85. const logHealthScan = useQuery({
  86. queryKey: ['bugReportLogHealth'],
  87. enabled: isOpen && viewState === 'form',
  88. staleTime: 30_000,
  89. queryFn: api.getSystemHealth,
  90. });
  91. const logFindings = logHealthScan.data?.findings ?? [];
  92. // Elapsed timer for logging phase — auto-stop at 5 minutes
  93. useEffect(() => {
  94. if (viewState !== 'logging') return;
  95. if (elapsedSeconds >= MAX_LOG_SECONDS) {
  96. handleStopLoggingRef.current();
  97. return;
  98. }
  99. const timer = setTimeout(() => setElapsedSeconds((s) => s + 1), 1000);
  100. return () => clearTimeout(timer);
  101. }, [viewState, elapsedSeconds]);
  102. const handleOpen = () => {
  103. setIsOpen(true);
  104. setViewState('form');
  105. setDescription('');
  106. setEmail('');
  107. setScreenshot(null);
  108. setIssueUrl(null);
  109. setIssueNumber(null);
  110. setErrorMessage('');
  111. setElapsedSeconds(0);
  112. setWasDebug(false);
  113. };
  114. const handleClose = () => {
  115. setIsOpen(false);
  116. };
  117. const handleFile = useCallback(async (file: File) => {
  118. if (!file.type.startsWith('image/')) return;
  119. try {
  120. const b64 = await compressImage(file);
  121. setScreenshot(b64);
  122. } catch {
  123. // Ignore read errors
  124. }
  125. }, []);
  126. const handlePaste = useCallback((e: React.ClipboardEvent) => {
  127. const items = e.clipboardData?.items;
  128. if (!items) return;
  129. for (const item of items) {
  130. if (item.type.startsWith('image/')) {
  131. const file = item.getAsFile();
  132. if (file) handleFile(file);
  133. break;
  134. }
  135. }
  136. }, [handleFile]);
  137. const handleDragOver = useCallback((e: React.DragEvent) => {
  138. e.preventDefault();
  139. setIsDragging(true);
  140. }, []);
  141. const handleDragLeave = useCallback((e: React.DragEvent) => {
  142. e.preventDefault();
  143. setIsDragging(false);
  144. }, []);
  145. const handleDrop = useCallback((e: React.DragEvent) => {
  146. e.preventDefault();
  147. setIsDragging(false);
  148. const file = e.dataTransfer.files?.[0];
  149. if (file) handleFile(file);
  150. }, [handleFile]);
  151. const handleStartLogging = async () => {
  152. if (!description.trim()) return;
  153. try {
  154. const result = await bugReportApi.startLogging();
  155. setWasDebug(result.was_debug);
  156. setElapsedSeconds(0);
  157. setViewState('logging');
  158. } catch (err) {
  159. setErrorMessage(err instanceof Error ? err.message : t('bugReport.unexpectedError'));
  160. setViewState('error');
  161. }
  162. };
  163. const handleStopLogging = async () => {
  164. setViewState('stopping');
  165. try {
  166. const stopResult = await bugReportApi.stopLogging(wasDebug);
  167. await handleSubmitReport(stopResult.logs);
  168. } catch (err) {
  169. setErrorMessage(err instanceof Error ? err.message : t('bugReport.unexpectedError'));
  170. setViewState('error');
  171. }
  172. };
  173. handleStopLoggingRef.current = handleStopLogging;
  174. const handleSubmitReport = async (debugLogs: string) => {
  175. setViewState('submitting');
  176. try {
  177. const result = await bugReportApi.submit({
  178. description: description.trim(),
  179. email: email.trim() || undefined,
  180. screenshot_base64: screenshot || undefined,
  181. include_support_info: true,
  182. debug_logs: debugLogs || undefined,
  183. });
  184. if (result.success) {
  185. setIssueUrl(result.issue_url || null);
  186. setIssueNumber(result.issue_number || null);
  187. setViewState('success');
  188. } else {
  189. setErrorMessage(result.message);
  190. setViewState('error');
  191. }
  192. } catch (err) {
  193. setErrorMessage(err instanceof Error ? err.message : t('bugReport.unexpectedError'));
  194. setViewState('error');
  195. }
  196. };
  197. return (
  198. <>
  199. {/* Floating bubble */}
  200. <button
  201. onClick={handleOpen}
  202. className="fixed bottom-4 right-4 z-40 w-12 h-12 rounded-full bg-red-500 hover:bg-red-600 text-white shadow-lg hover:shadow-xl transition-all duration-200 hover:scale-110 flex items-center justify-center"
  203. title={t('bugReport.title')}
  204. >
  205. <Bug className="w-5 h-5" />
  206. </button>
  207. {/* Slide-in panel anchored to bottom-right */}
  208. {isOpen && (
  209. <div
  210. id="bug-report-modal"
  211. className="fixed bottom-20 right-4 z-50 w-full max-w-md"
  212. onPaste={handlePaste}
  213. >
  214. <div
  215. ref={modalRef}
  216. className="bg-white dark:bg-gray-800 rounded-lg shadow-2xl border border-gray-200 dark:border-gray-700 max-h-[80vh] overflow-y-auto"
  217. >
  218. {/* Header */}
  219. <div className="flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 sticky top-0 bg-white dark:bg-gray-800 z-10">
  220. <h2 className="text-lg font-semibold text-gray-900 dark:text-white flex items-center gap-2">
  221. <Bug className="w-5 h-5 text-red-500" />
  222. {t('bugReport.title')}
  223. </h2>
  224. <button
  225. onClick={handleClose}
  226. className="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300"
  227. >
  228. <X className="w-5 h-5" />
  229. </button>
  230. </div>
  231. <div className="p-4 space-y-4">
  232. {viewState === 'form' && (
  233. <>
  234. {/* Connection diagnostic — scanned on form-open. A healthy
  235. fleet shows a single confirmation line. When printers
  236. have problems, each is a collapsed row (auto-expanded
  237. when only one) so the form stays reachable regardless
  238. of how many printers are configured. */}
  239. {diagnosticScan.isLoading && (
  240. <div className="flex items-center gap-2 text-xs text-gray-500 dark:text-gray-400">
  241. <Loader2 className="w-3.5 h-3.5 animate-spin" />
  242. {t('bugReport.diagnosticChecking')}
  243. </div>
  244. )}
  245. {!diagnosticScan.isLoading && diagnosticProblems.length > 0 && (
  246. <div className="rounded-lg bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 p-3 space-y-3">
  247. <div className="flex items-start gap-2">
  248. <Stethoscope className="w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400" />
  249. <div>
  250. <p className="text-sm font-medium text-amber-700 dark:text-amber-300">
  251. {t('bugReport.diagnosticSummary', {
  252. problems: diagnosticProblems.length,
  253. total: diagnosticEntries.length,
  254. })}
  255. </p>
  256. <p className="text-xs text-amber-800 dark:text-amber-200 mt-0.5">
  257. {t('bugReport.diagnosticIntro')}
  258. </p>
  259. </div>
  260. </div>
  261. <div className="space-y-2">
  262. {diagnosticProblems.map((entry) => (
  263. <Collapsible
  264. key={entry.result.printer_id ?? entry.result.ip_address}
  265. defaultOpen={diagnosticProblems.length === 1}
  266. className="rounded-lg bg-amber-100/60 dark:bg-amber-900/30 px-3 py-2"
  267. summary={
  268. <div className="flex items-center gap-2 min-w-0">
  269. <AlertTriangle className="w-4 h-4 flex-shrink-0 text-amber-600 dark:text-amber-400" />
  270. <span className="text-sm font-medium text-amber-800 dark:text-amber-200 truncate">
  271. {entry.name}
  272. </span>
  273. </div>
  274. }
  275. >
  276. <DiagnosticChecklist result={entry.result} />
  277. </Collapsible>
  278. ))}
  279. </div>
  280. </div>
  281. )}
  282. {!diagnosticScan.isLoading &&
  283. diagnosticEntries.length > 0 &&
  284. diagnosticProblems.length === 0 && (
  285. <div className="flex items-start gap-2 rounded-lg bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 p-3">
  286. <CheckCircle className="w-4 h-4 mt-0.5 flex-shrink-0 text-green-600 dark:text-green-400" />
  287. <p className="text-xs text-green-800 dark:text-green-200">
  288. {t('bugReport.diagnosticHealthy')}
  289. </p>
  290. </div>
  291. )}
  292. {/* Log-health scan — known issues found in recent logs.
  293. Shown only when something matched. */}
  294. {!logHealthScan.isLoading && logFindings.length > 0 && logHealthScan.data && (
  295. <div className="rounded-lg bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 p-3 space-y-3">
  296. <div className="flex items-start gap-2">
  297. <Stethoscope className="w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400" />
  298. <div>
  299. <p className="text-sm font-medium text-amber-700 dark:text-amber-300">
  300. {t('bugReport.logHealthSummary')}
  301. </p>
  302. <p className="text-xs text-amber-800 dark:text-amber-200 mt-0.5">
  303. {t('bugReport.logHealthIntro')}
  304. </p>
  305. </div>
  306. </div>
  307. <SystemHealthPanel result={logHealthScan.data} />
  308. </div>
  309. )}
  310. {/* Description */}
  311. <div>
  312. <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
  313. {t('bugReport.description')} *
  314. </label>
  315. <textarea
  316. value={description}
  317. onChange={(e) => setDescription(e.target.value)}
  318. placeholder={t('bugReport.descriptionPlaceholder')}
  319. rows={3}
  320. className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-vertical"
  321. />
  322. </div>
  323. {/* Email (optional) */}
  324. <div>
  325. <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
  326. {t('bugReport.email')}
  327. </label>
  328. <input
  329. type="email"
  330. value={email}
  331. onChange={(e) => setEmail(e.target.value)}
  332. placeholder={t('bugReport.emailPlaceholder')}
  333. className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent"
  334. />
  335. <p className="mt-1 text-xs text-gray-500 dark:text-gray-400">
  336. {t('bugReport.emailPrivacy')}
  337. </p>
  338. </div>
  339. {/* Screenshot — upload, paste, or drag */}
  340. <div>
  341. <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
  342. {t('bugReport.screenshot')}
  343. </label>
  344. {screenshot ? (
  345. <div className="relative">
  346. <img
  347. src={`data:image/jpeg;base64,${screenshot}`}
  348. alt={t('bugReport.screenshot')}
  349. className="w-full max-h-40 object-contain rounded-lg border border-gray-200 dark:border-gray-600"
  350. />
  351. <button
  352. onClick={() => setScreenshot(null)}
  353. className="absolute top-2 right-2 p-1 bg-red-500 hover:bg-red-600 text-white rounded-full shadow"
  354. title={t('common.delete')}
  355. >
  356. <Trash2 className="w-3 h-3" />
  357. </button>
  358. </div>
  359. ) : (
  360. <button
  361. type="button"
  362. onClick={() => fileInputRef.current?.click()}
  363. onDragOver={handleDragOver}
  364. onDragLeave={handleDragLeave}
  365. onDrop={handleDrop}
  366. className={`w-full flex flex-col items-center gap-2 px-4 py-4 border-2 border-dashed rounded-lg transition-colors cursor-pointer ${
  367. isDragging
  368. ? 'border-blue-500 bg-blue-50 dark:bg-blue-900/20 text-blue-500'
  369. : 'border-gray-300 dark:border-gray-600 text-gray-500 dark:text-gray-400 hover:border-gray-400 dark:hover:border-gray-500 hover:text-gray-600 dark:hover:text-gray-300'
  370. }`}
  371. >
  372. <Upload className="w-5 h-5" />
  373. <span className="text-sm">{t('bugReport.uploadOrPaste')}</span>
  374. </button>
  375. )}
  376. <input
  377. ref={fileInputRef}
  378. type="file"
  379. accept="image/*"
  380. className="hidden"
  381. onChange={(e) => {
  382. const file = e.target.files?.[0];
  383. if (file) handleFile(file);
  384. e.target.value = '';
  385. }}
  386. />
  387. </div>
  388. {/* Data collection notice */}
  389. <details className="text-xs bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg p-3">
  390. <summary className="cursor-pointer font-medium text-amber-700 dark:text-amber-300 hover:text-amber-800 dark:hover:text-amber-200">
  391. {t('bugReport.dataCollectedSummary')}
  392. </summary>
  393. <div className="mt-2 space-y-2 pl-2 border-l-2 border-amber-300 dark:border-amber-700 text-amber-800 dark:text-amber-200">
  394. <p className="font-medium">{t('bugReport.dataIncluded')}</p>
  395. <p>{t('bugReport.dataIncludedList')}</p>
  396. <p className="font-medium">{t('bugReport.dataNeverIncluded')}</p>
  397. <p>{t('bugReport.dataNeverIncludedList')}</p>
  398. </div>
  399. </details>
  400. {/* Buttons */}
  401. <div className="flex justify-end gap-2 pt-2">
  402. <button
  403. onClick={handleClose}
  404. className="px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 rounded-lg transition-colors"
  405. >
  406. {t('common.cancel')}
  407. </button>
  408. <button
  409. onClick={handleStartLogging}
  410. disabled={!description.trim()}
  411. className="px-4 py-2 text-sm font-medium text-white bg-red-500 hover:bg-red-600 disabled:opacity-50 disabled:cursor-not-allowed rounded-lg transition-colors"
  412. >
  413. {t('bugReport.startLogging')}
  414. </button>
  415. </div>
  416. </>
  417. )}
  418. {viewState === 'logging' && (
  419. <div className="py-6 space-y-6">
  420. {/* 3-step progress indicator */}
  421. <div className="space-y-3 px-2">
  422. {/* Step 1: Completed */}
  423. <div className="flex items-center gap-3">
  424. <CheckCircle2 className="w-5 h-5 text-green-500 flex-shrink-0" />
  425. <span className="text-sm text-green-700 dark:text-green-400">{t('bugReport.stepEnableLogging')}</span>
  426. </div>
  427. {/* Step 2: Active */}
  428. <div className="flex items-center gap-3">
  429. <span className="relative flex h-5 w-5 flex-shrink-0 items-center justify-center">
  430. <span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"></span>
  431. <span className="relative inline-flex rounded-full h-3 w-3 bg-blue-500"></span>
  432. </span>
  433. <span className="text-sm font-medium text-blue-700 dark:text-blue-300">{t('bugReport.stepReproduce')}</span>
  434. </div>
  435. {/* Step 3: Upcoming */}
  436. <div className="flex items-center gap-3">
  437. <Circle className="w-5 h-5 text-gray-300 dark:text-gray-600 flex-shrink-0" />
  438. <span className="text-sm text-gray-400 dark:text-gray-500">{t('bugReport.stepStopLogging')}</span>
  439. </div>
  440. </div>
  441. {/* Elapsed timer */}
  442. <div className="text-center">
  443. <p className="text-3xl font-mono text-blue-500">{formatElapsed(elapsedSeconds)}</p>
  444. <p className="text-xs text-gray-500 dark:text-gray-400 mt-1">{t('bugReport.maxDuration', { minutes: 5 })}</p>
  445. </div>
  446. {/* Stop & Submit button */}
  447. <div className="flex justify-center">
  448. <button
  449. onClick={handleStopLogging}
  450. className="px-6 py-2.5 text-sm font-medium text-white bg-red-500 hover:bg-red-600 rounded-lg transition-colors"
  451. >
  452. {t('bugReport.stopAndSubmit')}
  453. </button>
  454. </div>
  455. </div>
  456. )}
  457. {(viewState === 'stopping' || viewState === 'submitting') && (
  458. <div className="flex flex-col items-center justify-center py-6 gap-3">
  459. <Loader2 className="w-8 h-8 animate-spin text-blue-500" />
  460. <p className="text-sm text-gray-600 dark:text-gray-400 text-center">
  461. {viewState === 'stopping' ? t('bugReport.stoppingLogs') : t('bugReport.submitting')}
  462. </p>
  463. {viewState === 'submitting' && (
  464. // Diagnostics are run server-side inside the submit call
  465. // (#1506 follow-up): the bubble already displays current
  466. // results inline, but the submitted report now also
  467. // includes a snapshot. Wait is bounded but noticeable —
  468. // list what's running so the user knows why.
  469. <ul className="text-xs text-gray-500 dark:text-gray-400 list-disc list-inside space-y-0.5">
  470. <li>{t('bugReport.submittingStepConnection')}</li>
  471. <li>{t('bugReport.submittingStepVirtualPrinters')}</li>
  472. <li>{t('bugReport.submittingStepLogScan')}</li>
  473. <li>{t('bugReport.submittingStepSubmit')}</li>
  474. </ul>
  475. )}
  476. </div>
  477. )}
  478. {viewState === 'success' && (
  479. <div className="flex flex-col items-center justify-center py-8 gap-3">
  480. <CheckCircle className="w-12 h-12 text-green-500" />
  481. <p className="text-lg font-semibold text-gray-900 dark:text-white">{t('bugReport.thankYou')}</p>
  482. <p className="text-sm text-gray-600 dark:text-gray-400">{t('bugReport.submitted')}</p>
  483. {issueUrl && (
  484. <a
  485. href={issueUrl}
  486. target="_blank"
  487. rel="noopener noreferrer"
  488. className="text-sm text-blue-500 hover:text-blue-600 underline"
  489. >
  490. {t('bugReport.viewIssue')} #{issueNumber}
  491. </a>
  492. )}
  493. <button
  494. onClick={handleClose}
  495. className="mt-4 px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 rounded-lg transition-colors"
  496. >
  497. {t('common.close')}
  498. </button>
  499. </div>
  500. )}
  501. {viewState === 'error' && (
  502. <div className="flex flex-col items-center justify-center py-8 gap-3">
  503. <AlertCircle className="w-12 h-12 text-red-500" />
  504. <p className="text-lg font-semibold text-gray-900 dark:text-white">{t('bugReport.submitFailed')}</p>
  505. <p className="text-sm text-gray-600 dark:text-gray-400 text-center">{errorMessage}</p>
  506. <div className="flex gap-2 mt-4">
  507. <button
  508. onClick={() => setViewState('form')}
  509. className="px-4 py-2 text-sm font-medium text-white bg-red-500 hover:bg-red-600 rounded-lg transition-colors"
  510. >
  511. {t('bugReport.submit')}
  512. </button>
  513. <button
  514. onClick={handleClose}
  515. className="px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 rounded-lg transition-colors"
  516. >
  517. {t('common.close')}
  518. </button>
  519. </div>
  520. </div>
  521. )}
  522. </div>
  523. </div>
  524. </div>
  525. )}
  526. </>
  527. );
  528. }