Spaces:
Paused
Paused
File size: 6,332 Bytes
5eb4857 c2ee3e3 5eb4857 c2ee3e3 8798ebe c2ee3e3 8798ebe c2ee3e3 8798ebe c2ee3e3 5eb4857 c2ee3e3 5eb4857 c2ee3e3 22a1a45 c2ee3e3 1fdd745 c2ee3e3 8798ebe c2ee3e3 5eb4857 c2ee3e3 5eb4857 c2ee3e3 1fdd745 c2ee3e3 5eb4857 c2ee3e3 8798ebe 22a1a45 c2ee3e3 5eb4857 c2ee3e3 5eb4857 | 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 | import React, { useState, useEffect } from 'react';
import { Shield, Zap, Clock, Activity, Send, X, Terminal } from 'lucide-react';
import { motion, AnimatePresence } from 'framer-motion';
import styles from './RuleModal.module.css';
import type { EscalationRule } from '@nexus/shared';
interface RuleModalProps {
rule?: EscalationRule | null;
onClose: () => void;
onSave: (data: any) => void;
loading?: boolean;
}
export const RuleModal: React.FC<RuleModalProps> = ({ rule, onClose, onSave, loading }) => {
const [formData, setFormData] = useState({
name: '',
priority_level: 'P0',
threshold_minutes: 30,
action: 'NOTIFY_LEAD',
is_active: true
});
useEffect(() => {
if (rule) {
setFormData({
name: rule.name,
priority_level: rule.priority_level,
threshold_minutes: rule.threshold_minutes,
action: rule.action,
is_active: rule.is_active
});
}
}, [rule]);
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
onSave(formData);
};
return (
<AnimatePresence>
<div className={styles.overlay} onClick={onClose}>
<motion.div
className={styles.sidebar}
onClick={e => e.stopPropagation()}
initial={{ x: '100%', opacity: 0.8 }}
animate={{ x: 0, opacity: 1 }}
exit={{ x: '100%', opacity: 0 }}
transition={{ type: 'spring', damping: 30, stiffness: 200 }}
>
<div className={styles.header}>
<div className={styles.headerBadge}>LOGIC CONFIGURATOR</div>
<motion.h3
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
transition={{ delay: 0.1 }}
>
{rule ? 'Edit Escalation Protocol' : 'Initialize New Protocol'}
</motion.h3>
<motion.p
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ delay: 0.2 }}
>
Define automated hierarchy and conditional triggers.
</motion.p>
<button className={styles.closeBtn} onClick={onClose}>
<X size={18} />
</button>
</div>
<form onSubmit={handleSubmit} className={styles.form}>
<div className={styles.section}>
<div className={styles.sectionHeader}>
<Shield size={14} /> <span>1. PROTOCOL IDENTITY</span>
</div>
<div className={styles.field}>
<input
type="text"
placeholder="Enter Protocol Identifier (e.g. Critical P0 Alert)"
value={formData.name}
onChange={e => setFormData({ ...formData, name: e.target.value })}
required
/>
</div>
</div>
<div className={styles.segmentGrid}>
<div className={styles.section}>
<div className={styles.sectionHeader}>
<Zap size={14} /> <span>2. TARGET TIER</span>
</div>
<div className={styles.field}>
<select
value={formData.priority_level}
onChange={e => setFormData({ ...formData, priority_level: e.target.value })}
>
<option value="P0">P0 - CRITICAL</option>
<option value="P1">P1 - HIGH</option>
<option value="P2">P2 - MEDIUM</option>
<option value="P3">P3 - LOW</option>
</select>
</div>
</div>
<div className={styles.section}>
<div className={styles.sectionHeader}>
<Clock size={14} /> <span>3. SLA WINDOW</span>
</div>
<div className={styles.thresholdWrapper}>
<input
type="number"
value={formData.threshold_minutes}
onChange={e => setFormData({ ...formData, threshold_minutes: parseInt(e.target.value) || 0 })}
min="1"
required
/>
<span className={styles.thresholdSuffix}>MINS</span>
</div>
</div>
</div>
<div className={styles.section}>
<div className={styles.sectionHeader}>
<Activity size={14} /> <span>4. TRIGGERED ACTION</span>
</div>
<div className={styles.field}>
<select
value={formData.action}
onChange={e => setFormData({ ...formData, action: e.target.value })}
>
<option value="NOTIFY_LEAD">NOTIFY MISSION LEAD</option>
<option value="REASSIGN">AUTOSCALE & REASSIGN</option>
<option value="MARK_ESCALATED">SET ESCALATION FLAG</option>
</select>
</div>
</div>
<motion.div
className={styles.logicPreview}
layout
>
<div className={styles.previewLabel}>
<Terminal size={12} /> LOGIC PREVIEW
</div>
<div className={styles.previewContent}>
IF AGE > <span>{formData.threshold_minutes} MINS</span> (DEADLINE) ➔ <strong>{formData.action.replace(/_/g, ' ')}</strong>
</div>
</motion.div>
<div className={styles.footer}>
<motion.button
type="submit"
className={styles.saveBtn}
disabled={loading}
whileHover={{ scale: 1.01 }}
whileTap={{ scale: 0.99 }}
>
<Send size={14} />
{loading ? 'DEPLOYING...' : rule ? 'UPDATE PROTOCOL' : 'DEPLOY PROTOCOL'}
</motion.button>
<button type="button" className={styles.cancelBtn} onClick={onClose}>ABORT INITIALIZATION</button>
</div>
</form>
</motion.div>
</div>
</AnimatePresence>
);
};
|