diff --git a/package-lock.json b/package-lock.json index 079647836..faf8a43a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -59,7 +59,7 @@ }, "engines": { "node": ">=20.0.0", - "npm": ">=10.0.0" + "npm": ">=11.6.2" } }, "node_modules/@adobe/css-tools": { diff --git a/package.json b/package.json index 9312341a6..060cf006e 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ }, "engines": { "node": ">=20.0.0", - "npm": ">=10.0.0" + "npm": ">=11.6.2" }, "browserslist": { "production": [ diff --git a/src/components/BugReportForm.tsx b/src/components/BugReportForm.tsx index aad2f46fd..682e9dbe2 100644 --- a/src/components/BugReportForm.tsx +++ b/src/components/BugReportForm.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import bugReportService from '../services/bugReportService'; +import bugReportService, { IssueTemplate, TemplateField } from '../services/bugReportService'; import githubService from '../services/githubService'; import ScreenshotEditor from './ScreenshotEditor'; import repositoryConfig from '../config/repositoryConfig'; @@ -9,12 +9,6 @@ interface BugReportFormProps { contextData?: Record; } -interface TemplateType { - name: string; - type: string; - fields: FieldDefinition[]; -} - interface FieldDefinition { name: string; label: string; @@ -29,8 +23,8 @@ interface FormDataType { } const BugReportForm: React.FC = ({ onClose, contextData = {} }) => { - const [templates, setTemplates] = useState([]); - const [selectedTemplate, setSelectedTemplate] = useState(null); + const [templates, setTemplates] = useState([]); + const [selectedTemplate, setSelectedTemplate] = useState(null); const [formData, setFormData] = useState({}); const [includeConsole, setIncludeConsole] = useState(false); const [includeScreenshot, setIncludeScreenshot] = useState(false); @@ -86,14 +80,14 @@ const BugReportForm: React.FC = ({ onClose, contextData = {} } }; - const handleTemplateChange = (template) => { - setSelectedTemplate(template); + const handleTemplateChange = (template: IssueTemplate | undefined) => { + setSelectedTemplate(template || null); setFormData({}); // Reset form data when template changes - setIncludeConsole(template.type === 'bug'); // Auto-enable console for bug reports - setIncludeScreenshot(template.type === 'bug'); // Auto-enable screenshot for bug reports + setIncludeConsole(template?.type === 'bug'); // Auto-enable console for bug reports + setIncludeScreenshot(template?.type === 'bug'); // Auto-enable screenshot for bug reports }; - const handleFormChange = (fieldId, value) => { + const handleFormChange = (fieldId: string, value: any) => { setFormData(prev => ({ ...prev, [fieldId]: value @@ -118,7 +112,7 @@ const BugReportForm: React.FC = ({ onClose, contextData = {} } } catch (err) { console.error('Failed to take screenshot:', err); - setError('Failed to capture screenshot: ' + err.message); + setError('Failed to capture screenshot: ' + (err instanceof Error ? err.message : String(err))); } finally { setTakingScreenshot(false); } @@ -128,7 +122,7 @@ const BugReportForm: React.FC = ({ onClose, contextData = {} setShowScreenshotEditor(true); }; - const handleScreenshotEditorSave = (editedBlob) => { + const handleScreenshotEditorSave = (editedBlob: Blob) => { // Update the screenshot with the edited version setScreenshotBlob(editedBlob); @@ -165,7 +159,7 @@ const BugReportForm: React.FC = ({ onClose, contextData = {} }; }, [screenshotPreview]); - const handleSubmit = async (e) => { + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!selectedTemplate) { @@ -184,7 +178,7 @@ const BugReportForm: React.FC = ({ onClose, contextData = {} const currentScreenshot = includeScreenshot ? screenshotBlob : null; // Check if user is authenticated and can submit via API - if (githubService.isAuthenticated) { + if (githubService.isAuth()) { const result = await bugReportService.submitIssue( repositoryConfig.getOwner(), repositoryConfig.getName(), @@ -243,7 +237,7 @@ const BugReportForm: React.FC = ({ onClose, contextData = {} } } catch (err) { console.error('Failed to submit bug report:', err); - setError(err.message); + setError(err instanceof Error ? err.message : String(err)); } finally { setSubmitting(false); } @@ -266,7 +260,7 @@ const BugReportForm: React.FC = ({ onClose, contextData = {} ); }; - const renderFormField = (field) => { + const renderFormField = (field: TemplateField) => { const { id, type, attributes = {}, validations = {} } = field; const { label, description, placeholder, options } = attributes; const { required } = validations; @@ -276,7 +270,7 @@ const BugReportForm: React.FC = ({ onClose, contextData = {}
); @@ -342,8 +336,8 @@ const BugReportForm: React.FC = ({ onClose, contextData = {} > {options?.map((option, index) => ( - ))} @@ -359,24 +353,27 @@ const BugReportForm: React.FC = ({ onClose, contextData = {} {required && *} {description &&

{description}

} - {options?.map((option, index) => ( - - ))} + {options?.map((option, index) => { + const optionValue = typeof option === 'string' ? option : option.value; + const optionLabel = typeof option === 'string' ? option : option.label; + return ( + + ); + })}
); @@ -592,7 +589,7 @@ const BugReportForm: React.FC = ({ onClose, contextData = {} ) : (
Screenshot preview @@ -649,7 +646,7 @@ const BugReportForm: React.FC = ({ onClose, contextData = {}
  • Current Page: {contextData.pageId || 'Unknown'}
  • URL: {window.location.href}
  • -
  • Authentication: {githubService.isAuthenticated ? 'Authenticated' : 'Demo Mode'}
  • +
  • Authentication: {githubService.isAuth() ? 'Authenticated' : 'Demo Mode'}
@@ -691,7 +688,7 @@ const BugReportForm: React.FC = ({ onClose, contextData = {} {/* Template Fields */} - {selectedTemplate && ( + {selectedTemplate && Array.isArray(selectedTemplate.body) && (
{selectedTemplate.body.map(field => renderFormField(field))}
@@ -705,7 +702,7 @@ const BugReportForm: React.FC = ({ onClose, contextData = {} disabled={submitting || !selectedTemplate} > {submitting ? 'Opening...' : - githubService.isAuthenticated ? 'Submit Issue' : 'Open in GitHub'} + githubService.isAuth() ? 'Submit Issue' : 'Open in GitHub'}