Fix jwt-token
This commit is contained in:
@@ -20,6 +20,20 @@ export const EditAlertModal = ({ rule, onClose, onSuccess }) => {
|
||||
webhook_url: ''
|
||||
});
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [droneTypes, setDroneTypes] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchDroneTypes = async () => {
|
||||
try {
|
||||
const response = await api.get('/drone-types');
|
||||
setDroneTypes(response.data);
|
||||
} catch (error) {
|
||||
console.error('Error fetching drone types:', error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchDroneTypes();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (rule) {
|
||||
@@ -71,7 +85,19 @@ export const EditAlertModal = ({ rule, onClose, onSuccess }) => {
|
||||
setSaving(true);
|
||||
|
||||
try {
|
||||
await api.put(`/alerts/rules/${rule.id}`, formData);
|
||||
const payload = { ...formData };
|
||||
|
||||
// Clean up empty values
|
||||
if (!payload.description || payload.description.trim() === '') delete payload.description;
|
||||
if (!payload.device_ids || payload.device_ids.length === 0) delete payload.device_ids;
|
||||
if (!payload.drone_types || payload.drone_types.length === 0) delete payload.drone_types;
|
||||
|
||||
// Only include webhook_url if webhook channel is selected
|
||||
if (!payload.alert_channels || !payload.alert_channels.includes('webhook')) {
|
||||
delete payload.webhook_url;
|
||||
}
|
||||
|
||||
await api.put(`/alerts/rules/${rule.id}`, payload);
|
||||
onSuccess();
|
||||
onClose();
|
||||
} catch (error) {
|
||||
@@ -169,13 +195,7 @@ export const EditAlertModal = ({ rule, onClose, onSuccess }) => {
|
||||
<div className="text-xs text-gray-500 mb-2">
|
||||
Leave empty to monitor all drone types
|
||||
</div>
|
||||
{[
|
||||
{ id: 0, name: 'Consumer/Hobby' },
|
||||
{ id: 1, name: 'Orlan/Military' },
|
||||
{ id: 2, name: 'Professional/Commercial' },
|
||||
{ id: 3, name: 'Racing/High-speed' },
|
||||
{ id: 4, name: 'Unknown/Custom' }
|
||||
].map(droneType => (
|
||||
{droneTypes.map(droneType => (
|
||||
<label key={droneType.id} className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
@@ -185,7 +205,7 @@ export const EditAlertModal = ({ rule, onClose, onSuccess }) => {
|
||||
/>
|
||||
<span className="ml-2 text-sm text-gray-700">
|
||||
{droneType.name}
|
||||
{droneType.id === 1 && <span className="text-red-600 font-semibold"> (⚠️ High Threat)</span>}
|
||||
{droneType.threat_level === 'critical' && <span className="text-red-600 font-semibold"> (⚠️ High Threat)</span>}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user