mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-01 20:55:16 +09:00
Add diagnostic setup logging and Windows-friendly error UI, plus a large refactor of security frontend components. - Agent: introduce openSetupDebugLog, write diagnostics during runSetup, LockOSThread for Windows WebView2, and catch panics to surface failures. Add platform-specific showFatalError implementations (MessageBox on Windows, stderr elsewhere). Update setup UI Run behavior to create the native WebView2 window synchronously and fall back to the browser. - Frontend: replace raw HTML buttons/badges/inputs/selects/textareas across many security-related components with shared UI primitives (Button, Badge, Input, Label, Select, Textarea) and update modal forms to use them. - Misc: add /agent/packaging to .gitignore. These changes improve diagnostics for the setup wizard (especially when launched without a console), provide clearer error surfacing on Windows, and standardize the security UI on the new component library.
174 lines
7.9 KiB
React
174 lines
7.9 KiB
React
import { useState, useEffect } from 'react';
|
|
import api from '../../services/api';
|
|
import Modal from '../Modal';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Label } from '@/components/ui/label';
|
|
import { Checkbox } from '@/components/ui/checkbox';
|
|
|
|
const WebhookSubscriptionModal = ({ subscription, onClose, onSubmit }) => {
|
|
const [name, setName] = useState('');
|
|
const [url, setUrl] = useState('');
|
|
const [selectedEvents, setSelectedEvents] = useState([]);
|
|
const [retryCount, setRetryCount] = useState(3);
|
|
const [timeoutSeconds, setTimeoutSeconds] = useState(10);
|
|
const [availableEvents, setAvailableEvents] = useState([]);
|
|
const [saving, setSaving] = useState(false);
|
|
|
|
useEffect(() => {
|
|
api.getAvailableEvents().then(data => {
|
|
setAvailableEvents(data.events || []);
|
|
}).catch(() => {});
|
|
|
|
if (subscription) {
|
|
setName(subscription.name || '');
|
|
setUrl(subscription.url || '');
|
|
setSelectedEvents(subscription.events || []);
|
|
setRetryCount(subscription.retry_count || 3);
|
|
setTimeoutSeconds(subscription.timeout_seconds || 10);
|
|
}
|
|
}, [subscription]);
|
|
|
|
const handleEventToggle = (eventType) => {
|
|
setSelectedEvents(prev =>
|
|
prev.includes(eventType)
|
|
? prev.filter(e => e !== eventType)
|
|
: [...prev, eventType]
|
|
);
|
|
};
|
|
|
|
const handleCategoryToggle = (category) => {
|
|
const categoryEvents = availableEvents
|
|
.filter(e => e.category === category)
|
|
.map(e => e.type);
|
|
const allSelected = categoryEvents.every(e => selectedEvents.includes(e));
|
|
if (allSelected) {
|
|
setSelectedEvents(prev => prev.filter(e => !categoryEvents.includes(e)));
|
|
} else {
|
|
setSelectedEvents(prev => [...new Set([...prev, ...categoryEvents])]);
|
|
}
|
|
};
|
|
|
|
const handleSubmit = async (e) => {
|
|
e.preventDefault();
|
|
if (!name.trim() || !url.trim() || selectedEvents.length === 0) return;
|
|
setSaving(true);
|
|
try {
|
|
await onSubmit({
|
|
name: name.trim(),
|
|
url: url.trim(),
|
|
events: selectedEvents,
|
|
retry_count: retryCount,
|
|
timeout_seconds: timeoutSeconds,
|
|
});
|
|
} finally {
|
|
setSaving(false);
|
|
}
|
|
};
|
|
|
|
// Group events by category
|
|
const groupedEvents = availableEvents.reduce((acc, event) => {
|
|
if (!acc[event.category]) acc[event.category] = [];
|
|
acc[event.category].push(event);
|
|
return acc;
|
|
}, {});
|
|
|
|
return (
|
|
<Modal open={true} onClose={onClose} title={subscription ? 'Edit Subscription' : 'Create Webhook Subscription'} className="webhook-modal">
|
|
<form onSubmit={handleSubmit}>
|
|
<div className="modal-body">
|
|
<div className="form-group">
|
|
<Label>Name</Label>
|
|
<Input
|
|
type="text"
|
|
value={name}
|
|
onChange={e => setName(e.target.value)}
|
|
placeholder="e.g. Slack Notifications, CI Trigger"
|
|
required
|
|
/>
|
|
</div>
|
|
|
|
<div className="form-group">
|
|
<Label>Payload URL</Label>
|
|
<Input
|
|
type="url"
|
|
value={url}
|
|
onChange={e => setUrl(e.target.value)}
|
|
placeholder="https://example.com/webhook"
|
|
required
|
|
/>
|
|
</div>
|
|
|
|
<div className="form-group">
|
|
<Label>Events</Label>
|
|
<div className="webhook-modal__events">
|
|
{Object.entries(groupedEvents).map(([category, events]) => {
|
|
const categoryEvents = events.map(e => e.type);
|
|
const allSelected = categoryEvents.every(e => selectedEvents.includes(e));
|
|
return (
|
|
<div key={category} className="webhook-modal__event-group">
|
|
<label className="webhook-modal__category">
|
|
<Checkbox
|
|
checked={allSelected}
|
|
onCheckedChange={() => handleCategoryToggle(category)}
|
|
/>
|
|
<strong>{category}</strong>
|
|
</label>
|
|
<div className="webhook-modal__event-list">
|
|
{events.map(event => (
|
|
<label key={event.type} className="webhook-modal__event-item">
|
|
<Checkbox
|
|
checked={selectedEvents.includes(event.type)}
|
|
onCheckedChange={() => handleEventToggle(event.type)}
|
|
/>
|
|
<span className="webhook-modal__event-type">{event.type}</span>
|
|
<span className="webhook-modal__event-desc">{event.description}</span>
|
|
</label>
|
|
))}
|
|
</div>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="form-row">
|
|
<div className="form-group">
|
|
<Label>Retry Count</Label>
|
|
<Input
|
|
type="number"
|
|
value={retryCount}
|
|
onChange={e => setRetryCount(parseInt(e.target.value) || 3)}
|
|
min={0}
|
|
max={10}
|
|
/>
|
|
</div>
|
|
<div className="form-group">
|
|
<Label>Timeout (seconds)</Label>
|
|
<Input
|
|
type="number"
|
|
value={timeoutSeconds}
|
|
onChange={e => setTimeoutSeconds(parseInt(e.target.value) || 10)}
|
|
min={1}
|
|
max={30}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="modal-footer">
|
|
<Button type="button" variant="outline" onClick={onClose}>Cancel</Button>
|
|
<Button
|
|
type="submit"
|
|
variant="default"
|
|
disabled={saving || !name.trim() || !url.trim() || selectedEvents.length === 0}
|
|
>
|
|
{saving ? 'Saving...' : (subscription ? 'Update' : 'Create')}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</Modal>
|
|
);
|
|
};
|
|
|
|
export default WebhookSubscriptionModal;
|