undefined / index.html
shishko's picture
It does look nice, but that's not a React app
fa6808d verified
Raw History Blame Contribute Delete
26 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IncidentNinja React Edition</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div id="root"></div>
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.net.min.js"></script>
<script type="text/babel">
const { useState, useEffect } = React;
const IncidentNinja = () => {
const [incidents, setIncidents] = useState([]);
const [filteredIncidents, setFilteredIncidents] = useState([]);
const [loading, setLoading] = useState(true);
const [searchTerm, setSearchTerm] = useState('');
const [priorityFilter, setPriorityFilter] = useState('all');
const [statusFilter, setStatusFilter] = useState('all');
const [currentPage, setCurrentPage] = useState(1);
const [selectedIncident, setSelectedIncident] = useState(null);
const [showModal, setShowModal] = useState(false);
const [stats, setStats] = useState({
total: 0,
highPriority: 0,
inProgress: 0,
resolved: 0
});
// Mock data fetch
useEffect(() => {
const fetchData = () => {
setLoading(true);
setTimeout(() => {
const mockData = Array.from({ length: 15 }, (_, i) => ({
id: `mock-id-${i}`,
number: `INC${100000 + i}`,
short_description: `Issue with ${['server', 'database', 'application', 'network', 'printer'][i % 5]}`,
description: `Detailed description of issue with ${['server', 'database', 'application', 'network', 'printer'][i % 5]}.`,
priority: [1, 2, 3][i % 3],
state: ['New', 'In Progress', 'Resolved', 'Closed'][i % 4],
created: new Date(Date.now() - (i * 3600000)).toISOString(),
updated: new Date(Date.now() - (i * 1800000)).toISOString(),
work_notes: i % 2 === 0 ? 'Working on the issue.' : 'Investigating further.'
}));
setIncidents(mockData);
setLoading(false);
}, 1000);
};
fetchData();
}, []);
// Filter and pagination logic
useEffect(() => {
const filtered = incidents.filter(incident => {
const matchesSearch = incident.short_description.toLowerCase().includes(searchTerm.toLowerCase()) ||
incident.number.toLowerCase().includes(searchTerm.toLowerCase());
const matchesPriority = priorityFilter === 'all' || incident.priority == priorityFilter;
const matchesStatus = statusFilter === 'all' || incident.state === statusFilter;
return matchesSearch && matchesPriority && matchesStatus;
});
setFilteredIncidents(filtered);
// Update stats
setStats({
total: incidents.length,
highPriority: incidents.filter(i => i.priority === 1).length,
inProgress: incidents.filter(i => i.state === 'In Progress').length,
resolved: incidents.filter(i => i.state === 'Resolved' || i.state === 'Closed').length
});
}, [incidents, searchTerm, priorityFilter, statusFilter]);
// Vanta.js background effect
useEffect(() => {
VANTA.NET({
el: "#vanta-bg",
color: 0x6366f1,
backgroundColor: 0xf8fafc,
points: 12,
maxDistance: 22,
spacing: 18
});
}, []);
const refreshIcons = () => {
if (window.feather) {
window.feather.replace();
}
};
useEffect(() => {
refreshIcons();
}, [filteredIncidents, showModal]);
const handleIncidentClick = (incident) => {
setSelectedIncident(incident);
setShowModal(true);
};
const handleResolve = () => {
if (selectedIncident) {
const updatedIncidents = incidents.map(inc =>
inc.id === selectedIncident.id ? {...inc, state: 'Resolved'} : inc
);
setIncidents(updatedIncidents);
setShowModal(false);
}
};
const IncidentCard = ({ incident }) => (
<div
className={`incident-card bg-white rounded-lg shadow p-4 cursor-pointer hover:shadow-md transition-shadow duration-200 border-l-4 ${getPriorityBorderClass(incident.priority)}`}
onClick={() => handleIncidentClick(incident)}
>
<div className="flex justify-between items-start">
<div>
<h3 className="font-medium text-gray-900">{incident.number}</h3>
<p className="text-sm text-gray-500 mt-1">{incident.short_description}</p>
</div>
<span className={`px-2 py-1 text-xs rounded-full ${getPriorityBadgeClass(incident.priority)}`}>
{getPriorityText(incident.priority)}
</span>
</div>
<div className="mt-4 flex items-center justify-between">
<span className={`text-sm ${getStatusColorClass(incident.state)}`}>
<i data-feather={getStatusIcon(incident.state)} className="w-3 h-3 inline mr-1"></i>
{incident.state}
</span>
<span className="text-xs text-gray-500">{formatDate(incident.created)}</span>
</div>
</div>
);
const StatsCard = ({ title, value, icon, color }) => (
<div className="bg-white rounded-lg shadow p-4">
<div className="flex justify-between items-center">
<div>
<p className="text-sm text-gray-500">{title}</p>
<h3 className="text-2xl font-bold text-gray-800">{value}</h3>
</div>
<div className={`p-3 rounded-full ${color.bg} ${color.text}`}>
<i data-feather={icon} className="w-5 h-5"></i>
</div>
</div>
</div>
);
return (
<div className="relative min-h-screen">
<div id="vanta-bg" className="fixed inset-0 z-0"></div>
<div className="relative z-10">
{/* Header */}
<header className="bg-white/80 backdrop-blur-md shadow-sm">
<div className="max-w-7xl mx-auto px-4 py-6 sm:px-6 lg:px-8 flex justify-between items-center">
<div className="flex items-center space-x-2">
<i data-feather="alert-triangle" className="text-indigo-600 w-8 h-8"></i>
<h1 className="text-2xl font-bold text-gray-800">Incident<span className="text-indigo-600">Ninja</span></h1>
</div>
<div className="flex items-center space-x-4">
<button
className="flex items-center space-x-1 text-indigo-600 hover:text-indigo-800"
onClick={() => window.location.reload()}
>
<i data-feather="refresh-cw" className="w-5 h-5"></i>
<span>Refresh</span>
</button>
<div className="relative">
<input
type="text"
placeholder="Search incidents..."
className="pl-8 pr-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
<i data-feather="search" className="absolute left-2 top-2.5 text-gray-400 w-4 h-4"></i>
</div>
</div>
</div>
</header>
{/* Main Content */}
<main className="max-w-7xl mx-auto px-4 py-8 sm:px-6 lg:px-8">
<div className="flex justify-between items-center mb-8">
<h2 className="text-xl font-semibold text-gray-800">Recent Incidents</h2>
<div className="flex space-x-2">
<div className="relative">
<select
className="appearance-none pl-3 pr-8 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 bg-white"
value={priorityFilter}
onChange={(e) => setPriorityFilter(e.target.value)}
>
<option value="all">All Priorities</option>
<option value="1">High</option>
<option value="2">Medium</option>
<option value="3">Low</option>
</select>
<i data-feather="chevron-down" className="absolute right-3 top-2.5 text-gray-500 w-4 h-4 pointer-events-none"></i>
</div>
<div className="relative">
<select
className="appearance-none pl-3 pr-8 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 bg-white"
value={statusFilter}
onChange={(e) => setStatusFilter(e.target.value)}
>
<option value="all">All Statuses</option>
<option value="New">New</option>
<option value="In Progress">In Progress</option>
<option value="Resolved">Resolved</option>
<option value="Closed">Closed</option>
</select>
<i data-feather="chevron-down" className="absolute right-3 top-2.5 text-gray-500 w-4 h-4 pointer-events-none"></i>
</div>
</div>
</div>
{/* Stats Cards */}
<div className="grid grid-cols-1 md:grid-cols-4 gap-4 mb-8">
<StatsCard
title="Total Incidents"
value={stats.total}
icon="alert-circle"
color={{ bg: 'bg-indigo-100', text: 'text-indigo-600' }}
/>
<StatsCard
title="High Priority"
value={stats.highPriority}
icon="alert-octagon"
color={{ bg: 'bg-red-100', text: 'text-red-600' }}
/>
<StatsCard
title="In Progress"
value={stats.inProgress}
icon="clock"
color={{ bg: 'bg-yellow-100', text: 'text-yellow-600' }}
/>
<StatsCard
title="Resolved"
value={stats.resolved}
icon="check-circle"
color={{ bg: 'bg-green-100', text: 'text-green-600' }}
/>
</div>
{/* Loading State */}
{loading && (
<div className="flex flex-col items-center justify-center py-12">
<div className="animate-spin border-4 border-indigo-500 border-t-transparent rounded-full w-12 h-12 mb-4"></div>
<p className="text-gray-600">Fetching incidents from ServiceNow...</p>
</div>
)}
{/* Incidents List */}
{!loading && (
<div className="grid grid-cols-1 gap-4">
{filteredIncidents.length > 0 ? (
filteredIncidents.map(incident => (
<IncidentCard key={incident.id} incident={incident} />
))
) : (
<div className="flex flex-col items-center justify-center py-12">
<i data-feather="alert-circle" className="w-16 h-16 text-gray-400 mb-4"></i>
<h3 className="text-lg font-medium text-gray-700 mb-2">No incidents found</h3>
<p className="text-gray-500 text-center max-w-md">
There are currently no incidents matching your criteria. Try adjusting your filters.
</p>
</div>
)}
</div>
)}
</main>
</div>
{/* Incident Details Modal */}
{showModal && selectedIncident && (
<div className="fixed inset-0 z-50 overflow-y-auto">
<div className="flex items-center justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
<div className="fixed inset-0 transition-opacity" aria-hidden="true">
<div className="absolute inset-0 bg-gray-500 opacity-75"></div>
</div>
<span className="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">&#8203;</span>
<div className="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-2xl sm:w-full">
<div className="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
<div className="flex justify-between items-start">
<div>
<h3 className="text-lg leading-6 font-medium text-gray-900">
{selectedIncident.number}: {selectedIncident.short_description}
</h3>
<div className="mt-1 text-sm text-gray-500">
Created {formatDate(selectedIncident.created)}
</div>
</div>
<button
className="text-gray-400 hover:text-gray-500"
onClick={() => setShowModal(false)}
>
<i data-feather="x" className="w-6 h-6"></i>
</button>
</div>
<div className="mt-6 grid grid-cols-1 gap-y-4 gap-x-4 sm:grid-cols-2">
<div>
<label className="block text-sm font-medium text-gray-700">Priority</label>
<div className="mt-1 text-sm text-gray-900">
<span className={`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${getPriorityBadgeClass(selectedIncident.priority)}`}>
{getPriorityText(selectedIncident.priority)}
</span>
</div>
</div>
<div>
<label className="block text-sm font-medium text-gray-700">State</label>
<div className="mt-1 text-sm text-gray-900">
<span className={`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${getStatusBadgeClass(selectedIncident.state)}`}>
{selectedIncident.state}
</span>
</div>
</div>
<div>
<label className="block text-sm font-medium text-gray-700">Created</label>
<div className="mt-1 text-sm text-gray-900">
{formatDateTime(selectedIncident.created)}
</div>
</div>
<div>
<label className="block text-sm font-medium text-gray-700">Updated</label>
<div className="mt-1 text-sm text-gray-900">
{formatDateTime(selectedIncident.updated)}
</div>
</div>
<div className="sm:col-span-2">
<label className="block text-sm font-medium text-gray-700">Description</label>
<div className="mt-1 text-sm text-gray-900">
{selectedIncident.description || 'No description provided'}
</div>
</div>
<div className="sm:col-span-2">
<label className="block text-sm font-medium text-gray-700">Work Notes</label>
<div className="mt-1 text-sm text-gray-900">
{selectedIncident.work_notes || 'No work notes available'}
</div>
</div>
</div>
</div>
<div className="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
{selectedIncident.state !== 'Resolved' && selectedIncident.state !== 'Closed' && (
<button
type="button"
className="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-indigo-600 text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:ml-3 sm:w-auto sm:text-sm"
onClick={handleResolve}
>
Mark as Resolved
</button>
)}
<button
type="button"
className="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm"
onClick={() => setShowModal(false)}
>
Close
</button>
</div>
</div>
</div>
</div>
)}
</div>
);
};
// Helper functions
function getPriorityText(priority) {
switch(priority) {
case 1: return 'High';
case 2: return 'Medium';
case 3: return 'Low';
default: return 'Unknown';
}
}
function getPriorityBorderClass(priority) {
switch(priority) {
case 1: return 'border-red-500';
case 2: return 'border-yellow-500';
case 3: return 'border-green-500';
default: return 'border-gray-500';
}
}
function getPriorityBadgeClass(priority) {
switch(priority) {
case 1: return 'bg-red-100 text-red-800';
case 2: return 'bg-yellow-100 text-yellow-800';
case 3: return 'bg-green-100 text-green-800';
default: return 'bg-gray-100 text-gray-800';
}
}
function getStatusColorClass(status) {
switch(status) {
case 'New': return 'text-blue-600';
case 'In Progress': return 'text-yellow-600';
case 'Resolved': return 'text-green-600';
case 'Closed': return 'text-gray-600';
default: return 'text-gray-600';
}
}
function getStatusBadgeClass(status) {
switch(status) {
case 'New': return 'bg-blue-100 text-blue-800';
case 'In Progress': return 'bg-yellow-100 text-yellow-800';
case 'Resolved': return 'bg-green-100 text-green-800';
case 'Closed': return 'bg-gray-100 text-gray-800';
default: return 'bg-gray-100 text-gray-800';
}
}
function getStatusIcon(status) {
switch(status) {
case 'New': return 'plus-circle';
case 'In Progress': return 'clock';
case 'Resolved': return 'check-circle';
case 'Closed': return 'lock';
default: return 'alert-circle';
}
}
function formatDate(isoString) {
const date = new Date(isoString);
return date.toLocaleDateString();
}
function formatDateTime(isoString) {
const date = new Date(isoString);
return date.toLocaleString();
}
ReactDOM.render(<IncidentNinja />, document.getElementById('root'));
</script>
</body>
</html>