Compare commits
16 Commits
5ef61f6590
...
claude
| Author | SHA1 | Date | |
|---|---|---|---|
| bcf0e3f3d1 | |||
| 3977c3652f | |||
| f4f191518c | |||
| 69272f71a3 | |||
| a6447970ac | |||
| e0170d71f5 | |||
| 4bb09997ee | |||
| 52a57f21b0 | |||
| 3cc62c2746 | |||
| 47e14ae23b | |||
| a6d4885a53 | |||
| f4869b42b4 | |||
| 98fe9d4a79 | |||
| f52af27114 | |||
| 7ff066011d | |||
| 35b4ded10c |
172
README.md
172
README.md
@@ -1,11 +1,13 @@
|
|||||||
# CPAS Violation Tracker
|
# CPAS Violation Tracker
|
||||||
|
|
||||||
Single-container Dockerized web app for CPAS violation documentation.
|
Single-container Dockerized web app for CPAS violation documentation and workforce standing management.
|
||||||
Built with React + Vite (frontend), Node.js + Express (backend), SQLite (database).
|
Built with **React + Vite** (frontend), **Node.js + Express** (backend), **SQLite** (database), and **Puppeteer** (PDF generation).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## The only requirement on your machine: Docker Desktop
|
## The only requirement on your machine: Docker Desktop
|
||||||
|
|
||||||
Everything else — Node.js, npm, React build — happens inside Docker.
|
Everything else — Node.js, npm, React build, Chromium for PDF — happens inside Docker.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -41,17 +43,87 @@ docker stop cpas-tracker && docker rm cpas-tracker
|
|||||||
docker run -d --name cpas-tracker -p 3001:3001 -v cpas-data:/data cpas-tracker
|
docker run -d --name cpas-tracker -p 3001:3001 -v cpas-data:/data cpas-tracker
|
||||||
```
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
### Company Dashboard
|
||||||
|
- Live table of all employees sorted by active CPAS points (highest risk first)
|
||||||
|
- Summary stat cards: total employees, elite standing (0 pts), with active points, at-risk count, highest active score
|
||||||
|
- **At-risk badge**: flags employees within 2 points of the next tier escalation
|
||||||
|
- Search/filter by name, department, or supervisor
|
||||||
|
- Click any employee name to open their full profile modal
|
||||||
|
|
||||||
|
### Violation Form
|
||||||
|
- Select existing employee or enter new employee by name
|
||||||
|
- **Employee intelligence**: shows current CPAS standing badge and 90-day violation count before submitting
|
||||||
|
- Violation type dropdown grouped by category; shows prior 90-day counts inline
|
||||||
|
- **Recidivist auto-escalation**: if an employee has prior violations of the same type, points slider auto-sets to maximum per policy
|
||||||
|
- Repeat offense badge with prior count displayed
|
||||||
|
- Context-sensitive fields (time, minutes late, amount, location, description) shown only when relevant to violation type
|
||||||
|
- **Tier crossing warning** (TierWarning component): previews what tier the new points would push the employee into before submission
|
||||||
|
- Point slider for discretionary adjustments within the violation's min/max range
|
||||||
|
- One-click PDF download immediately after submission
|
||||||
|
|
||||||
|
### Employee Profile Modal
|
||||||
|
- Full violation history with resolution status
|
||||||
|
- Negate / restore individual violations (soft delete with resolution type + notes)
|
||||||
|
- Hard delete option for data entry errors
|
||||||
|
- PDF download for any historical violation record
|
||||||
|
|
||||||
|
### CPAS Tier System
|
||||||
|
|
||||||
|
| Points | Tier | Label |
|
||||||
|
|--------|------|-------|
|
||||||
|
| 0–4 | 0–1 | Elite Standing |
|
||||||
|
| 5–9 | 1 | Realignment |
|
||||||
|
| 10–14 | 2 | Administrative Lockdown |
|
||||||
|
| 15–19 | 3 | Verification |
|
||||||
|
| 20–24 | 4 | Risk Mitigation |
|
||||||
|
| 25–29 | 5 | Final Decision |
|
||||||
|
| 30+ | 6 | Separation |
|
||||||
|
|
||||||
|
Scores are computed over a **rolling 90-day window** (negated violations excluded).
|
||||||
|
|
||||||
|
### PDF Generation
|
||||||
|
- Puppeteer + system Chromium (bundled in Docker image)
|
||||||
|
- Generated on-demand per violation via `GET /api/violations/:id/pdf`
|
||||||
|
- Filename: `CPAS_<EmployeeName>_<IncidentDate>.pdf`
|
||||||
|
- PDF captures prior active points **at the time of the incident** (snapshot stored on insert)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## API Reference
|
||||||
|
|
||||||
|
| Method | Endpoint | Description |
|
||||||
|
|--------|----------|-------------|
|
||||||
|
| GET | `/api/health` | Health check |
|
||||||
|
| GET | `/api/employees` | List all employees |
|
||||||
|
| POST | `/api/employees` | Create or upsert employee |
|
||||||
|
| GET | `/api/employees/:id/score` | Get active CPAS score for employee |
|
||||||
|
| GET | `/api/dashboard` | All employees with active points + violation counts |
|
||||||
|
| POST | `/api/violations` | Log a new violation |
|
||||||
|
| GET | `/api/violations/employee/:id` | Get violation history for employee (with resolutions) |
|
||||||
|
| PATCH | `/api/violations/:id/negate` | Negate a violation (soft delete + resolution record) |
|
||||||
|
| PATCH | `/api/violations/:id/restore` | Restore a negated violation |
|
||||||
|
| DELETE | `/api/violations/:id` | Hard delete a violation |
|
||||||
|
| GET | `/api/violations/:id/pdf` | Download violation PDF |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
cpas-violation-tracker/
|
cpas/
|
||||||
├── Dockerfile # Multi-stage: builds React + runs Express
|
├── Dockerfile # Multi-stage: builds React + runs Express w/ Chromium
|
||||||
├── .dockerignore
|
├── .dockerignore
|
||||||
├── package.json # Backend (Express) deps
|
├── package.json # Backend (Express) deps
|
||||||
├── server.js # API + static file server
|
├── server.js # API + static file server
|
||||||
├── db/
|
├── db/
|
||||||
│ ├── schema.sql # Tables + 90-day score view
|
│ ├── schema.sql # Tables + 90-day active score view
|
||||||
│ └── database.js # SQLite connection
|
│ └── database.js # SQLite connection (better-sqlite3)
|
||||||
|
├── pdf/
|
||||||
|
│ └── generator.js # Puppeteer PDF generation
|
||||||
└── client/ # React frontend (Vite)
|
└── client/ # React frontend (Vite)
|
||||||
├── package.json
|
├── package.json
|
||||||
├── vite.config.js
|
├── vite.config.js
|
||||||
@@ -60,14 +132,84 @@ cpas-violation-tracker/
|
|||||||
├── main.jsx
|
├── main.jsx
|
||||||
├── App.jsx
|
├── App.jsx
|
||||||
├── data/
|
├── data/
|
||||||
│ └── violations.js # All CPAS violation definitions
|
│ └── violations.js # All CPAS violation definitions + groups
|
||||||
|
├── hooks/
|
||||||
|
│ └── useEmployeeIntelligence.js # Score + history hook
|
||||||
└── components/
|
└── components/
|
||||||
└── ViolationForm.jsx
|
├── CpasBadge.jsx # Tier badge + color logic
|
||||||
|
├── TierWarning.jsx # Pre-submit tier crossing alert
|
||||||
|
├── Dashboard.jsx # Company-wide leaderboard
|
||||||
|
├── ViolationForm.jsx # Violation entry form
|
||||||
|
├── EmployeeModal.jsx # Employee profile + history modal
|
||||||
|
├── NegateModal.jsx # Negate/resolve violation dialog
|
||||||
|
└── ViolationHistory.jsx # Violation list component
|
||||||
```
|
```
|
||||||
|
|
||||||
## Phases
|
---
|
||||||
- [x] Phase 1 — Container scaffold, SQLite schema, base React form
|
|
||||||
- [ ] Phase 2 — Employee history, prior violation highlighting
|
## Database Schema
|
||||||
- [ ] Phase 3 — Puppeteer PDF generation
|
|
||||||
- [ ] Phase 4 — Dashboard, CPAS scores, tier warnings
|
Three tables + one view:
|
||||||
- [ ] Phase 5 — Recidivist point auto-suggest
|
|
||||||
|
- **`employees`** — id, name, department, supervisor
|
||||||
|
- **`violations`** — full incident record including `prior_active_points` snapshot at time of logging
|
||||||
|
- **`violation_resolutions`** — resolution type, details, resolved_by (linked to violations)
|
||||||
|
- **`active_cpas_scores`** (view) — sum of points for non-negated violations in rolling 90 days, grouped by employee
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Roadmap
|
||||||
|
|
||||||
|
### ✅ Completed
|
||||||
|
|
||||||
|
| Phase | Feature | Description |
|
||||||
|
|-------|---------|-------------|
|
||||||
|
| 1 | Container scaffold | Docker multi-stage build, Express server, SQLite schema |
|
||||||
|
| 1 | Base violation form | Employee fields, violation type, incident date, point submission |
|
||||||
|
| 2 | Employee intelligence | Live CPAS standing badge and 90-day count shown before submitting |
|
||||||
|
| 2 | Prior violation highlighting | Violation dropdown annotates types with 90-day recurrence counts |
|
||||||
|
| 2 | Recidivist auto-escalation | Points slider auto-maximizes on repeat same-type violations |
|
||||||
|
| 2 | Violation history | Per-employee history list with resolution status |
|
||||||
|
| 3 | PDF generation | Puppeteer/Chromium PDF per violation, downloadable immediately post-submit |
|
||||||
|
| 3 | Prior-points snapshot | `prior_active_points` captured at insert time for accurate historical PDFs |
|
||||||
|
| 4 | Company dashboard | Sortable employee table with live tier badges and at-risk flags |
|
||||||
|
| 4 | Stat cards | Summary counts: total, clean, active, at-risk, highest score |
|
||||||
|
| 4 | Tier crossing warning | Pre-submit alert when new points push employee to next tier |
|
||||||
|
| 4 | Employee profile modal | Full history, negate/restore, hard delete, per-record PDF download |
|
||||||
|
| 4 | Negate & restore | Soft-delete violations with resolution type + notes, fully reversible |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🔲 Proposed
|
||||||
|
|
||||||
|
#### Reporting & Analytics
|
||||||
|
- **Violation trends chart** — line/bar chart of violations per day/week/month, filterable by department or supervisor; useful for identifying systemic patterns vs. individual incidents
|
||||||
|
- **Department heat map** — grid view showing violation density and average CPAS score by department; helps supervisors identify team-level risk
|
||||||
|
- **Expiration timeline** — visual showing which active violations will roll off the 90-day window and when, so supervisors can anticipate tier drops
|
||||||
|
- **CSV / Excel export** — bulk export of violations or dashboard data for external reporting or payroll integration
|
||||||
|
|
||||||
|
#### Employee Management
|
||||||
|
- **Employee edit / merge** — ability to update employee name, department, or supervisor without losing history; merge duplicate records created by name typos
|
||||||
|
- **Supervisor view** — scoped dashboard showing only the employees under a given supervisor, useful for multi-supervisor environments
|
||||||
|
- **Employee notes / flags** — free-text notes attached to an employee record (e.g. "on PIP", "union member") visible in the profile modal without affecting scoring
|
||||||
|
|
||||||
|
#### Violation Workflow
|
||||||
|
- **Acknowledgment signature field** — a "received by employee" name/date field on the violation form that prints on the PDF, replacing the blank signature line
|
||||||
|
- **Draft / pending violations** — save a violation as draft before finalizing, useful when incidents need review before being officially logged
|
||||||
|
- **Violation amendment** — edit a submitted violation's details (not points) with an audit trail, rather than delete-and-resubmit
|
||||||
|
- **Bulk violation import** — CSV import for migrating historical records from paper logs or a prior system
|
||||||
|
|
||||||
|
#### Notifications & Escalation
|
||||||
|
- **Tier escalation alerts** — email or in-app notification when an employee crosses into Tier 2+ so the relevant supervisor is automatically informed
|
||||||
|
- **Scheduled summary digest** — weekly email to supervisors listing their employees' current standings and any approaching tier thresholds
|
||||||
|
- **At-risk threshold configuration** — make the "at-risk" warning threshold (currently hardcoded at 2 pts) configurable per deployment
|
||||||
|
|
||||||
|
#### Infrastructure & Ops
|
||||||
|
- **Multi-user auth** — simple login with role-based access (admin, supervisor, read-only); currently the app has no auth and is assumed to run on a trusted internal network
|
||||||
|
- **Audit log** — immutable log of all creates, negates, restores, and deletes with timestamp and acting user, stored separately from the violations table
|
||||||
|
- **Automated DB backup** — cron job or Docker health hook to snapshot `/data/cpas.db` to a mounted backup volume or remote location on a schedule
|
||||||
|
- **Dark/light theme toggle** — the UI is currently dark-only; a toggle would improve usability in bright environments
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*Proposed features are suggestions based on common HR documentation workflows. Priority and implementation order should be driven by actual operational needs.*
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const TIERS = [
|
|||||||
{ min: 15, max: 19 },
|
{ min: 15, max: 19 },
|
||||||
{ min: 20, max: 24 },
|
{ min: 20, max: 24 },
|
||||||
{ min: 25, max: 29 },
|
{ min: 25, max: 29 },
|
||||||
{ min: 30, max: 999},
|
{ min: 30, max: 999 },
|
||||||
];
|
];
|
||||||
|
|
||||||
function nextTierBoundary(points) {
|
function nextTierBoundary(points) {
|
||||||
@@ -43,14 +43,14 @@ const s = {
|
|||||||
nameBtn: { background: 'none', border: 'none', cursor: 'pointer', fontWeight: 600, color: '#d4af37', fontSize: '14px', padding: 0, textDecoration: 'underline dotted' },
|
nameBtn: { background: 'none', border: 'none', cursor: 'pointer', fontWeight: 600, color: '#d4af37', fontSize: '14px', padding: 0, textDecoration: 'underline dotted' },
|
||||||
atRiskBadge: { display: 'inline-block', marginLeft: '8px', padding: '2px 8px', borderRadius: '10px', fontSize: '10px', fontWeight: 700, background: '#3b2e00', color: '#ffd666', border: '1px solid #d4af37', verticalAlign: 'middle' },
|
atRiskBadge: { display: 'inline-block', marginLeft: '8px', padding: '2px 8px', borderRadius: '10px', fontSize: '10px', fontWeight: 700, background: '#3b2e00', color: '#ffd666', border: '1px solid #d4af37', verticalAlign: 'middle' },
|
||||||
zeroRow: { color: '#77798a', fontStyle: 'italic', fontSize: '12px' },
|
zeroRow: { color: '#77798a', fontStyle: 'italic', fontSize: '12px' },
|
||||||
refreshBtn:{ padding: '9px 18px', background: '#d4af37', color: '#000', border: 'none', borderRadius: '6px', cursor: 'pointer', fontWeight: 600, fontSize: '13px' },
|
refreshBtn: { padding: '9px 18px', background: '#d4af37', color: '#000', border: 'none', borderRadius: '6px', cursor: 'pointer', fontWeight: 600, fontSize: '13px' },
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Dashboard() {
|
export default function Dashboard() {
|
||||||
const [employees, setEmployees] = useState([]);
|
const [employees, setEmployees] = useState([]);
|
||||||
const [filtered, setFiltered] = useState([]);
|
const [filtered, setFiltered] = useState([]);
|
||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
const [selectedId,setSelectedId] = useState(null);
|
const [selectedId, setSelectedId] = useState(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const load = useCallback(() => {
|
const load = useCallback(() => {
|
||||||
@@ -77,6 +77,10 @@ export default function Dashboard() {
|
|||||||
const maxPoints = employees.reduce((m, e) => Math.max(m, e.active_points), 0);
|
const maxPoints = employees.reduce((m, e) => Math.max(m, e.active_points), 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
// FIX: Fragment wraps both s.wrap AND EmployeeModal so the modal is
|
||||||
|
// outside the s.wrap div — React synthetic events will no longer bubble
|
||||||
|
// from inside the modal up through the Dashboard's DOM tree.
|
||||||
|
<>
|
||||||
<div style={s.wrap}>
|
<div style={s.wrap}>
|
||||||
<div style={s.header}>
|
<div style={s.header}>
|
||||||
<div>
|
<div>
|
||||||
@@ -84,7 +88,12 @@ export default function Dashboard() {
|
|||||||
<div style={s.subtitle}>Click any employee name to view their full profile</div>
|
<div style={s.subtitle}>Click any employee name to view their full profile</div>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ display: 'flex', gap: '10px', alignItems: 'center' }}>
|
<div style={{ display: 'flex', gap: '10px', alignItems: 'center' }}>
|
||||||
<input style={s.search} placeholder="Search name, dept, supervisor…" value={search} onChange={e => setSearch(e.target.value)} />
|
<input
|
||||||
|
style={s.search}
|
||||||
|
placeholder="Search name, dept, supervisor…"
|
||||||
|
value={search}
|
||||||
|
onChange={e => setSearch(e.target.value)}
|
||||||
|
/>
|
||||||
<button style={s.refreshBtn} onClick={load}>↻ Refresh</button>
|
<button style={s.refreshBtn} onClick={load}>↻ Refresh</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -129,17 +138,26 @@ export default function Dashboard() {
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{filtered.length === 0 && (
|
{filtered.length === 0 && (
|
||||||
<tr><td colSpan={7} style={{ ...s.td, textAlign: 'center', ...s.zeroRow }}>No employees found.</td></tr>
|
<tr>
|
||||||
|
<td colSpan={7} style={{ ...s.td, textAlign: 'center', ...s.zeroRow }}>
|
||||||
|
No employees found.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
)}
|
)}
|
||||||
{filtered.map((emp, i) => {
|
{filtered.map((emp, i) => {
|
||||||
const risk = isAtRisk(emp.active_points);
|
const risk = isAtRisk(emp.active_points);
|
||||||
const tier = getTier(emp.active_points);
|
const tier = getTier(emp.active_points);
|
||||||
const boundary = nextTierBoundary(emp.active_points);
|
const boundary = nextTierBoundary(emp.active_points);
|
||||||
return (
|
return (
|
||||||
<tr key={emp.id} style={{ background: risk ? '#181200' : i % 2 === 0 ? '#111217' : '#151622' }}>
|
<tr
|
||||||
|
key={emp.id}
|
||||||
|
style={{ background: risk ? '#181200' : i % 2 === 0 ? '#111217' : '#151622' }}
|
||||||
|
>
|
||||||
<td style={{ ...s.td, color: '#77798a', fontSize: '12px' }}>{i + 1}</td>
|
<td style={{ ...s.td, color: '#77798a', fontSize: '12px' }}>{i + 1}</td>
|
||||||
<td style={s.td}>
|
<td style={s.td}>
|
||||||
<button style={s.nameBtn} onClick={() => setSelectedId(emp.id)}>{emp.name}</button>
|
<button style={s.nameBtn} onClick={() => setSelectedId(emp.id)}>
|
||||||
|
{emp.name}
|
||||||
|
</button>
|
||||||
{risk && (
|
{risk && (
|
||||||
<span style={s.atRiskBadge}>
|
<span style={s.atRiskBadge}>
|
||||||
⚠ {boundary - emp.active_points} pt{boundary - emp.active_points > 1 ? 's' : ''} to {getTier(boundary).label.split('—')[0].trim()}
|
⚠ {boundary - emp.active_points} pt{boundary - emp.active_points > 1 ? 's' : ''} to {getTier(boundary).label.split('—')[0].trim()}
|
||||||
@@ -149,7 +167,9 @@ export default function Dashboard() {
|
|||||||
<td style={{ ...s.td, color: '#c0c2d6' }}>{emp.department || '—'}</td>
|
<td style={{ ...s.td, color: '#c0c2d6' }}>{emp.department || '—'}</td>
|
||||||
<td style={{ ...s.td, color: '#c0c2d6' }}>{emp.supervisor || '—'}</td>
|
<td style={{ ...s.td, color: '#c0c2d6' }}>{emp.supervisor || '—'}</td>
|
||||||
<td style={s.td}><CpasBadge points={emp.active_points} /></td>
|
<td style={s.td}><CpasBadge points={emp.active_points} /></td>
|
||||||
<td style={{ ...s.td, fontWeight: 700, color: tier.color, fontSize: '16px' }}>{emp.active_points}</td>
|
<td style={{ ...s.td, fontWeight: 700, color: tier.color, fontSize: '16px' }}>
|
||||||
|
{emp.active_points}
|
||||||
|
</td>
|
||||||
<td style={{ ...s.td, color: '#c0c2d6' }}>{emp.violation_count}</td>
|
<td style={{ ...s.td, color: '#c0c2d6' }}>{emp.violation_count}</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
@@ -157,13 +177,17 @@ export default function Dashboard() {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* FIX: EmployeeModal is now OUTSIDE <div style={s.wrap}>.
|
||||||
|
React synthetic events no longer bubble from modal buttons
|
||||||
|
up through Dashboard's component tree. */}
|
||||||
{selectedId && (
|
{selectedId && (
|
||||||
<EmployeeModal
|
<EmployeeModal
|
||||||
employeeId={selectedId}
|
employeeId={selectedId}
|
||||||
onClose={() => { setSelectedId(null); load(); }}
|
onClose={() => { setSelectedId(null); load(); }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,24 +4,68 @@ import CpasBadge, { getTier } from './CpasBadge';
|
|||||||
import NegateModal from './NegateModal';
|
import NegateModal from './NegateModal';
|
||||||
|
|
||||||
const s = {
|
const s = {
|
||||||
overlay: { position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.75)', zIndex: 1000, display: 'flex', alignItems: 'flex-start', justifyContent: 'flex-end' },
|
overlay: {
|
||||||
panel: { background: '#111217', color: '#f8f9fa', width: '680px', maxWidth: '95vw', height: '100vh', overflowY: 'auto', boxShadow: '-4px 0 24px rgba(0,0,0,0.7)', display: 'flex', flexDirection: 'column' },
|
position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.75)',
|
||||||
header: { background: 'linear-gradient(135deg, #000000, #151622)', color: 'white', padding: '24px 28px', position: 'sticky', top: 0, zIndex: 10, borderBottom: '1px solid #222' },
|
zIndex: 1000, display: 'flex', alignItems: 'flex-start', justifyContent: 'flex-end',
|
||||||
closeBtn: { float: 'right', background: 'none', border: 'none', color: 'white', fontSize: '22px', cursor: 'pointer', lineHeight: 1, marginTop: '-2px' },
|
},
|
||||||
|
panel: {
|
||||||
|
background: '#111217', color: '#f8f9fa', width: '680px', maxWidth: '95vw',
|
||||||
|
height: '100vh', overflowY: 'auto', boxShadow: '-4px 0 24px rgba(0,0,0,0.7)',
|
||||||
|
display: 'flex', flexDirection: 'column',
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
background: 'linear-gradient(135deg, #000000, #151622)', color: 'white',
|
||||||
|
padding: '24px 28px', position: 'sticky', top: 0, zIndex: 10,
|
||||||
|
borderBottom: '1px solid #222',
|
||||||
|
},
|
||||||
|
closeBtn: {
|
||||||
|
float: 'right', background: 'none', border: 'none', color: 'white',
|
||||||
|
fontSize: '22px', cursor: 'pointer', lineHeight: 1, marginTop: '-2px',
|
||||||
|
},
|
||||||
body: { padding: '24px 28px', flex: 1 },
|
body: { padding: '24px 28px', flex: 1 },
|
||||||
scoreRow: { display: 'flex', gap: '12px', flexWrap: 'wrap', marginBottom: '24px' },
|
scoreRow: { display: 'flex', gap: '12px', flexWrap: 'wrap', marginBottom: '24px' },
|
||||||
scoreCard: { flex: '1', minWidth: '100px', background: '#181924', borderRadius: '8px', padding: '14px', textAlign: 'center', border: '1px solid #2a2b3a' },
|
scoreCard: {
|
||||||
|
flex: '1', minWidth: '100px', background: '#181924', borderRadius: '8px',
|
||||||
|
padding: '14px', textAlign: 'center', border: '1px solid #2a2b3a',
|
||||||
|
},
|
||||||
scoreNum: { fontSize: '26px', fontWeight: 800 },
|
scoreNum: { fontSize: '26px', fontWeight: 800 },
|
||||||
scoreLbl: { fontSize: '11px', color: '#b5b5c0', marginTop: '3px' },
|
scoreLbl: { fontSize: '11px', color: '#b5b5c0', marginTop: '3px' },
|
||||||
sectionHd: { fontSize: '13px', fontWeight: 700, color: '#f8f9fa', textTransform: 'uppercase', letterSpacing: '0.5px', marginBottom: '10px', marginTop: '24px' },
|
sectionHd: {
|
||||||
table: { width: '100%', borderCollapse: 'collapse', fontSize: '12px', background: '#181924', borderRadius: '6px', overflow: 'hidden', border: '1px solid #2a2b3a' },
|
fontSize: '13px', fontWeight: 700, color: '#f8f9fa', textTransform: 'uppercase',
|
||||||
th: { background: '#050608', padding: '8px 10px', textAlign: 'left', color: '#f8f9fa', fontWeight: 600, fontSize: '11px', textTransform: 'uppercase' },
|
letterSpacing: '0.5px', marginBottom: '10px', marginTop: '24px',
|
||||||
td: { padding: '9px 10px', borderBottom: '1px solid #202231', verticalAlign: 'top', color: '#f8f9fa' },
|
},
|
||||||
|
table: {
|
||||||
|
width: '100%', borderCollapse: 'collapse', fontSize: '12px', background: '#181924',
|
||||||
|
borderRadius: '6px', overflow: 'hidden', border: '1px solid #2a2b3a',
|
||||||
|
},
|
||||||
|
th: {
|
||||||
|
background: '#050608', padding: '8px 10px', textAlign: 'left', color: '#f8f9fa',
|
||||||
|
fontWeight: 600, fontSize: '11px', textTransform: 'uppercase',
|
||||||
|
},
|
||||||
|
td: {
|
||||||
|
padding: '9px 10px', borderBottom: '1px solid #202231',
|
||||||
|
verticalAlign: 'top', color: '#f8f9fa',
|
||||||
|
},
|
||||||
negatedRow: { background: '#151622', color: '#9ca0b8' },
|
negatedRow: { background: '#151622', color: '#9ca0b8' },
|
||||||
actionBtn: (color) => ({ background: 'none', border: `1px solid ${color}`, color, borderRadius: '4px', padding: '3px 8px', fontSize: '11px', cursor: 'pointer', marginRight: '4px', fontWeight: 600 }),
|
actionBtn: (color) => ({
|
||||||
resTag: { display: 'inline-block', padding: '2px 8px', borderRadius: '10px', fontSize: '10px', fontWeight: 700, background: '#053321', color: '#9ef7c1', border: '1px solid #0f5132' },
|
background: 'none', border: `1px solid ${color}`, color,
|
||||||
pdfBtn: { background: 'none', border: '1px solid #d4af37', color: '#ffd666', borderRadius: '4px', padding: '3px 8px', fontSize: '11px', cursor: 'pointer', fontWeight: 600 },
|
borderRadius: '4px', padding: '3px 8px', fontSize: '11px',
|
||||||
deleteConfirm: { background: '#3c1114', border: '1px solid #f5c6cb', borderRadius: '6px', padding: '12px', marginTop: '8px', fontSize: '12px', color: '#ffb3b8' },
|
cursor: 'pointer', marginRight: '4px', fontWeight: 600,
|
||||||
|
}),
|
||||||
|
resTag: {
|
||||||
|
display: 'inline-block', padding: '2px 8px', borderRadius: '10px',
|
||||||
|
fontSize: '10px', fontWeight: 700, background: '#053321',
|
||||||
|
color: '#9ef7c1', border: '1px solid #0f5132',
|
||||||
|
},
|
||||||
|
pdfBtn: {
|
||||||
|
background: 'none', border: '1px solid #d4af37', color: '#ffd666',
|
||||||
|
borderRadius: '4px', padding: '3px 8px', fontSize: '11px',
|
||||||
|
cursor: 'pointer', fontWeight: 600,
|
||||||
|
},
|
||||||
|
deleteConfirm: {
|
||||||
|
background: '#3c1114', border: '1px solid #f5c6cb', borderRadius: '6px',
|
||||||
|
padding: '12px', marginTop: '8px', fontSize: '12px', color: '#ffb3b8',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function EmployeeModal({ employeeId, onClose }) {
|
export default function EmployeeModal({ employeeId, onClose }) {
|
||||||
@@ -38,12 +82,14 @@ export default function EmployeeModal({ employeeId, onClose }) {
|
|||||||
axios.get('/api/employees'),
|
axios.get('/api/employees'),
|
||||||
axios.get(`/api/employees/${employeeId}/score`),
|
axios.get(`/api/employees/${employeeId}/score`),
|
||||||
axios.get(`/api/violations/employee/${employeeId}?limit=100`),
|
axios.get(`/api/violations/employee/${employeeId}?limit=100`),
|
||||||
]).then(([empRes, scoreRes, violRes]) => {
|
])
|
||||||
const emp = empRes.data.find(e => e.id === employeeId);
|
.then(([empRes, scoreRes, violRes]) => {
|
||||||
|
const emp = empRes.data.find((e) => e.id === employeeId);
|
||||||
setEmployee(emp || null);
|
setEmployee(emp || null);
|
||||||
setScore(scoreRes.data);
|
setScore(scoreRes.data);
|
||||||
setViolations(violRes.data);
|
setViolations(violRes.data);
|
||||||
}).finally(() => setLoading(false));
|
})
|
||||||
|
.finally(() => setLoading(false));
|
||||||
}, [employeeId]);
|
}, [employeeId]);
|
||||||
|
|
||||||
useEffect(() => { load(); }, [load]);
|
useEffect(() => { load(); }, [load]);
|
||||||
@@ -53,7 +99,7 @@ export default function EmployeeModal({ employeeId, onClose }) {
|
|||||||
const url = window.URL.createObjectURL(new Blob([response.data], { type: 'application/pdf' }));
|
const url = window.URL.createObjectURL(new Blob([response.data], { type: 'application/pdf' }));
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.download = `CPAS_${(empName||'').replace(/[^a-z0-9]/gi,'_')}_${date}.pdf`;
|
link.download = `CPAS_${(empName || '').replace(/[^a-z0-9]/gi, '_')}_${date}.pdf`;
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
link.remove();
|
link.remove();
|
||||||
@@ -68,68 +114,85 @@ export default function EmployeeModal({ employeeId, onClose }) {
|
|||||||
|
|
||||||
const handleRestore = async (id) => {
|
const handleRestore = async (id) => {
|
||||||
await axios.patch(`/api/violations/${id}/restore`);
|
await axios.patch(`/api/violations/${id}/restore`);
|
||||||
|
setConfirmDel(null);
|
||||||
load();
|
load();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleNegate = async ({ resolution_type, details, resolved_by }) => {
|
const handleNegate = async ({ resolution_type, details, resolved_by }) => {
|
||||||
await axios.patch(`/api/violations/${negating.id}/negate`, { resolution_type, details, resolved_by });
|
await axios.patch(`/api/violations/${negating.id}/negate`, {
|
||||||
|
resolution_type, details, resolved_by,
|
||||||
|
});
|
||||||
setNegating(null);
|
setNegating(null);
|
||||||
|
setConfirmDel(null);
|
||||||
load();
|
load();
|
||||||
};
|
};
|
||||||
|
|
||||||
const tier = score ? getTier(score.active_points) : null;
|
const tier = score ? getTier(score.active_points) : null;
|
||||||
const active = violations.filter(v => !v.negated);
|
const active = violations.filter((v) => !v.negated);
|
||||||
const negated = violations.filter(v => v.negated);
|
const negated = violations.filter((v) => v.negated);
|
||||||
|
|
||||||
|
// FIX: overlay click only closes if clicking the backdrop itself, NOT children
|
||||||
|
const handleOverlayClick = (e) => {
|
||||||
|
if (e.target === e.currentTarget) onClose();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={s.overlay} onClick={e => { if (e.target === e.currentTarget) onClose(); }}>
|
// FIX: panel uses onClick stopPropagation to prevent bubbling to overlay
|
||||||
<div style={s.panel}>
|
<div style={s.overlay} onClick={handleOverlayClick}>
|
||||||
|
<div style={s.panel} onClick={(e) => e.stopPropagation()}>
|
||||||
|
|
||||||
|
{/* ── Header ── */}
|
||||||
<div style={s.header}>
|
<div style={s.header}>
|
||||||
<button style={s.closeBtn} onClick={onClose}>✕</button>
|
<button style={s.closeBtn} onClick={onClose}>✕</button>
|
||||||
<div style={{ fontSize: '20px', fontWeight: 700 }}>
|
<div style={{ fontSize: '18px', fontWeight: 700 }}>
|
||||||
{loading ? 'Loading…' : (employee?.name || 'Employee Profile')}
|
{employee ? employee.name : 'Employee'}
|
||||||
</div>
|
</div>
|
||||||
{employee && (
|
{employee && (
|
||||||
<div style={{ fontSize: '12px', opacity: 0.8, marginTop: '4px' }}>
|
<div style={{ fontSize: '12px', color: '#b5b5c0', marginTop: '4px' }}>
|
||||||
{[employee.department, employee.supervisor ? `Supervisor: ${employee.supervisor}` : null].filter(Boolean).join(' · ')}
|
{employee.department} {employee.supervisor && `· Supervisor: ${employee.supervisor}`}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* ── Body ── */}
|
||||||
<div style={s.body}>
|
<div style={s.body}>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<p style={{ color: '#77798a', textAlign: 'center', paddingTop: '40px' }}>Loading…</p>
|
<div style={{ padding: '40px', textAlign: 'center', color: '#b5b5c0' }}>Loading…</div>
|
||||||
) : (<>
|
) : (
|
||||||
|
<>
|
||||||
|
{/* Score Cards */}
|
||||||
|
{score && (
|
||||||
<div style={s.scoreRow}>
|
<div style={s.scoreRow}>
|
||||||
<div style={{ ...s.scoreCard, borderTop: `3px solid ${tier?.color}` }}>
|
<div style={s.scoreCard}>
|
||||||
<div style={{ ...s.scoreNum, color: tier?.color }}>{score?.active_points ?? 0}</div>
|
<div style={{ ...s.scoreNum, color: tier?.color || '#f8f9fa' }}>
|
||||||
|
{score.active_points}
|
||||||
|
</div>
|
||||||
<div style={s.scoreLbl}>Active Points</div>
|
<div style={s.scoreLbl}>Active Points</div>
|
||||||
</div>
|
</div>
|
||||||
<div style={s.scoreCard}>
|
<div style={s.scoreCard}>
|
||||||
<div style={s.scoreNum}>{score?.violation_count ?? 0}</div>
|
<div style={s.scoreNum}>{score.total_violations}</div>
|
||||||
<div style={s.scoreLbl}>90-Day Violations</div>
|
<div style={s.scoreLbl}>Total Violations</div>
|
||||||
</div>
|
</div>
|
||||||
<div style={s.scoreCard}>
|
<div style={s.scoreCard}>
|
||||||
<div style={s.scoreNum}>{active.length}</div>
|
<div style={s.scoreNum}>{score.negated_count}</div>
|
||||||
<div style={s.scoreLbl}>Total On Record</div>
|
|
||||||
</div>
|
|
||||||
<div style={s.scoreCard}>
|
|
||||||
<div style={{ ...s.scoreNum, color: '#ffd666' }}>{negated.length}</div>
|
|
||||||
<div style={s.scoreLbl}>Negated</div>
|
<div style={s.scoreLbl}>Negated</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div style={{ ...s.scoreCard, minWidth: '140px' }}>
|
||||||
|
<div style={{ fontSize: '13px', fontWeight: 700, color: tier?.color || '#f8f9fa' }}>
|
||||||
|
{tier ? tier.label : '—'}
|
||||||
|
</div>
|
||||||
|
<div style={s.scoreLbl}>Current Tier</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{tier && (
|
|
||||||
<div style={{ background: '#181924', borderRadius: '6px', padding: '10px 14px', marginBottom: '16px', fontSize: '13px', border: `1px solid ${tier.color}33` }}>
|
|
||||||
<strong style={{ color: tier.color }}>{tier.label}</strong>
|
|
||||||
<span style={{ color: '#b5b5c0', marginLeft: '10px', fontSize: '12px' }}>Rolling 90-day window · Points expire automatically</span>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{score && <CpasBadge points={score.active_points} style={{ marginBottom: '20px' }} />}
|
||||||
|
|
||||||
|
{/* ── Active Violations ── */}
|
||||||
<div style={s.sectionHd}>Active Violations</div>
|
<div style={s.sectionHd}>Active Violations</div>
|
||||||
{active.length === 0 ? (
|
{active.length === 0 ? (
|
||||||
<p style={{ color: '#77798a', fontSize: '13px', fontStyle: 'italic' }}>No active violations on record.</p>
|
<div style={{ color: '#77798a', fontStyle: 'italic', fontSize: '12px' }}>
|
||||||
|
No active violations on record.
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<table style={s.table}>
|
<table style={s.table}>
|
||||||
<thead>
|
<thead>
|
||||||
@@ -141,29 +204,57 @@ export default function EmployeeModal({ employeeId, onClose }) {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{active.map(v => (
|
{active.map((v) => (
|
||||||
<tr key={v.id}>
|
<tr key={v.id}>
|
||||||
<td style={s.td}>{v.incident_date}</td>
|
<td style={s.td}>{v.incident_date}</td>
|
||||||
<td style={s.td}>
|
<td style={s.td}>
|
||||||
<div style={{ fontWeight: 600 }}>{v.violation_name}</div>
|
<div style={{ fontWeight: 600 }}>{v.violation_name}</div>
|
||||||
<div style={{ color: '#b5b5c0', fontSize: '11px' }}>{v.category}</div>
|
<div style={{ fontSize: '10px', color: '#9ca0b8' }}>{v.category}</div>
|
||||||
{v.details && <div style={{ color: '#d1d3e0', fontSize: '11px', marginTop: '3px', fontStyle: 'italic' }}>{v.details}</div>}
|
{v.details && (
|
||||||
|
<div style={{ fontSize: '10px', color: '#b5b5c0', marginTop: '2px' }}>
|
||||||
|
{v.details}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td style={{ ...s.td, fontWeight: 700, color: '#ff8a80' }}>{v.points}</td>
|
<td style={{ ...s.td, fontWeight: 700 }}>{v.points}</td>
|
||||||
<td style={s.td}>
|
<td style={s.td}>
|
||||||
<button style={s.actionBtn('#ffd666')} onClick={() => setNegating(v)}>⊘ Negate</button>
|
{/* FIX: All buttons use e.stopPropagation() to prevent overlay close */}
|
||||||
<button style={s.pdfBtn} onClick={() => handleDownloadPdf(v.id, employee?.name, v.incident_date)}>PDF</button>
|
<button
|
||||||
<br />
|
style={s.actionBtn('#ffc107')}
|
||||||
{confirmDel === v.id ? (
|
onClick={(e) => { e.stopPropagation(); setNegating(v); setConfirmDel(null); }}
|
||||||
|
>
|
||||||
|
Negate
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
style={s.actionBtn('#ff4d4f')}
|
||||||
|
onClick={(e) => { e.stopPropagation(); setConfirmDel(confirmDel === v.id ? null : v.id); }}
|
||||||
|
>
|
||||||
|
{confirmDel === v.id ? 'Cancel' : 'Delete'}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
style={s.pdfBtn}
|
||||||
|
onClick={(e) => { e.stopPropagation(); handleDownloadPdf(v.id, employee?.name, v.incident_date); }}
|
||||||
|
>
|
||||||
|
PDF
|
||||||
|
</button>
|
||||||
|
{confirmDel === v.id && (
|
||||||
<div style={s.deleteConfirm}>
|
<div style={s.deleteConfirm}>
|
||||||
<strong>Permanently delete?</strong> This cannot be undone.
|
Permanently delete? This cannot be undone.
|
||||||
<div style={{ marginTop: '8px', display: 'flex', gap: '8px' }}>
|
<div style={{ marginTop: '8px' }}>
|
||||||
<button style={s.actionBtn('#ffb3b8')} onClick={() => handleHardDelete(v.id)}>Confirm Delete</button>
|
<button
|
||||||
<button style={s.actionBtn('#9ca0b8')} onClick={() => setConfirmDel(null)}>Cancel</button>
|
style={s.actionBtn('#ff4d4f')}
|
||||||
|
onClick={(e) => { e.stopPropagation(); handleHardDelete(v.id); }}
|
||||||
|
>
|
||||||
|
Confirm Delete
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
style={s.actionBtn('#888')}
|
||||||
|
onClick={(e) => { e.stopPropagation(); setConfirmDel(null); }}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
|
||||||
<button style={{ ...s.actionBtn('#c0392b'), marginTop: '4px' }} onClick={() => setConfirmDel(v.id)}>✕ Delete</button>
|
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -172,8 +263,10 @@ export default function EmployeeModal({ employeeId, onClose }) {
|
|||||||
</table>
|
</table>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{negated.length > 0 && (<>
|
{/* ── Negated / Resolved Violations ── */}
|
||||||
<div style={s.sectionHd}>Negated / Resolved Violations</div>
|
{negated.length > 0 && (
|
||||||
|
<>
|
||||||
|
<div style={s.sectionHd}>Negated / Resolved</div>
|
||||||
<table style={s.table}>
|
<table style={s.table}>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -185,43 +278,78 @@ export default function EmployeeModal({ employeeId, onClose }) {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{negated.map(v => (
|
{negated.map((v) => (
|
||||||
<tr key={v.id} style={s.negatedRow}>
|
<tr key={v.id} style={s.negatedRow}>
|
||||||
<td style={s.td}>{v.incident_date}</td>
|
<td style={s.td}>{v.incident_date}</td>
|
||||||
<td style={s.td}>
|
<td style={s.td}>
|
||||||
<div style={{ textDecoration: 'line-through' }}>{v.violation_name}</div>
|
<div style={{ fontWeight: 600 }}>{v.violation_name}</div>
|
||||||
<div style={{ fontSize: '11px', color: '#9ca0b8' }}>{v.category}</div>
|
<div style={{ fontSize: '10px', color: '#9ca0b8' }}>{v.category}</div>
|
||||||
</td>
|
</td>
|
||||||
<td style={{ ...s.td, textDecoration: 'line-through', color: '#9ca0b8' }}>{v.points}</td>
|
<td style={s.td}>{v.points}</td>
|
||||||
<td style={s.td}>
|
<td style={s.td}>
|
||||||
<span style={s.resTag}>{v.resolution_type}</span>
|
<span style={s.resTag}>{v.resolution_type}</span>
|
||||||
{v.resolution_details && <div style={{ fontSize: '11px', marginTop: '3px', color: '#d1d3e0' }}>{v.resolution_details}</div>}
|
{v.resolution_details && (
|
||||||
{v.resolved_by && <div style={{ fontSize: '10px', color: '#9ca0b8' }}>by {v.resolved_by}</div>}
|
<div style={{ fontSize: '10px', color: '#b5b5c0', marginTop: '2px' }}>
|
||||||
|
{v.resolution_details}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{v.resolved_by && (
|
||||||
|
<div style={{ fontSize: '10px', color: '#9ca0b8' }}>
|
||||||
|
by {v.resolved_by}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td style={s.td}>
|
<td style={s.td}>
|
||||||
<button style={s.actionBtn('#9ef7c1')} onClick={() => handleRestore(v.id)}>↩ Restore</button>
|
<button
|
||||||
{confirmDel === v.id ? (
|
style={s.actionBtn('#4db6ac')}
|
||||||
|
onClick={(e) => { e.stopPropagation(); handleRestore(v.id); }}
|
||||||
|
>
|
||||||
|
Restore
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
style={s.actionBtn('#ff4d4f')}
|
||||||
|
onClick={(e) => { e.stopPropagation(); setConfirmDel(confirmDel === v.id ? null : v.id); }}
|
||||||
|
>
|
||||||
|
{confirmDel === v.id ? 'Cancel' : 'Delete'}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
style={s.pdfBtn}
|
||||||
|
onClick={(e) => { e.stopPropagation(); handleDownloadPdf(v.id, employee?.name, v.incident_date); }}
|
||||||
|
>
|
||||||
|
PDF
|
||||||
|
</button>
|
||||||
|
{confirmDel === v.id && (
|
||||||
<div style={s.deleteConfirm}>
|
<div style={s.deleteConfirm}>
|
||||||
<strong>Permanently delete?</strong>
|
Permanently delete? This cannot be undone.
|
||||||
<div style={{ marginTop: '8px', display: 'flex', gap: '8px' }}>
|
<div style={{ marginTop: '8px' }}>
|
||||||
<button style={s.actionBtn('#ffb3b8')} onClick={() => handleHardDelete(v.id)}>Confirm</button>
|
<button
|
||||||
<button style={s.actionBtn('#9ca0b8')} onClick={() => setConfirmDel(null)}>Cancel</button>
|
style={s.actionBtn('#ff4d4f')}
|
||||||
|
onClick={(e) => { e.stopPropagation(); handleHardDelete(v.id); }}
|
||||||
|
>
|
||||||
|
Confirm Delete
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
style={s.actionBtn('#888')}
|
||||||
|
onClick={(e) => { e.stopPropagation(); setConfirmDel(null); }}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
|
||||||
<button style={s.actionBtn('#c0392b')} onClick={() => setConfirmDel(v.id)}>✕ Delete</button>
|
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</>)}
|
</>
|
||||||
|
)}
|
||||||
</>)}
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* FIX: NegateModal rendered OUTSIDE the panel so it sits at root z-index:2000 */}
|
||||||
{negating && (
|
{negating && (
|
||||||
<NegateModal
|
<NegateModal
|
||||||
violation={negating}
|
violation={negating}
|
||||||
|
|||||||
@@ -1,66 +1,136 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
const RESOLUTION_TYPES = [
|
|
||||||
'Corrective Training Completed',
|
|
||||||
'Management Discretion',
|
|
||||||
'Data Entry Error',
|
|
||||||
'Successfully Appealed',
|
|
||||||
];
|
|
||||||
|
|
||||||
const s = {
|
const s = {
|
||||||
overlay: { position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.65)', zIndex: 2000, display: 'flex', alignItems: 'center', justifyContent: 'center' },
|
overlay: {
|
||||||
box: { background: 'white', borderRadius: '10px', padding: '28px', width: '440px', maxWidth: '95vw', boxShadow: '0 8px 32px rgba(0,0,0,0.22)' },
|
position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.75)',
|
||||||
title: { fontSize: '17px', fontWeight: 700, color: '#2c3e50', marginBottom: '6px' },
|
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||||
sub: { fontSize: '12px', color: '#888', marginBottom: '20px' },
|
zIndex: 2000,
|
||||||
label: { fontWeight: 600, color: '#555', fontSize: '12px', marginBottom: '5px', display: 'block' },
|
},
|
||||||
input: { width: '100%', padding: '9px 12px', border: '1px solid #ddd', borderRadius: '5px', fontSize: '13px', fontFamily: 'inherit', marginBottom: '14px' },
|
modal: {
|
||||||
btnRow: { display: 'flex', gap: '10px', justifyContent: 'flex-end', marginTop: '8px' },
|
width: '480px', maxWidth: '95vw', background: '#111217', borderRadius: '12px',
|
||||||
btnOk: { padding: '10px 22px', background: '#856404', color: 'white', border: 'none', borderRadius: '6px', cursor: 'pointer', fontWeight: 700, fontSize: '13px' },
|
boxShadow: '0 16px 40px rgba(0,0,0,0.8)', color: '#f8f9fa',
|
||||||
btnCancel:{ padding: '10px 22px', background: '#f1f3f5', color: '#555', border: 'none', borderRadius: '6px', cursor: 'pointer', fontWeight: 600, fontSize: '13px' },
|
overflow: 'hidden', border: '1px solid #2a2b3a',
|
||||||
violBox: { background: '#fff3cd', border: '1px solid #ffc107', borderRadius: '6px', padding: '10px 14px', marginBottom: '18px', fontSize: '13px' },
|
},
|
||||||
|
header: {
|
||||||
|
padding: '18px 24px', borderBottom: '1px solid #222',
|
||||||
|
background: 'linear-gradient(135deg, #000000, #151622)',
|
||||||
|
},
|
||||||
|
title: { fontSize: '18px', fontWeight: 700 },
|
||||||
|
subtitle: { fontSize: '12px', color: '#c0c2d6', marginTop: '4px' },
|
||||||
|
body: { padding: '18px 24px 8px 24px' },
|
||||||
|
pill: {
|
||||||
|
background: '#3b2e00', borderRadius: '6px', padding: '8px 10px',
|
||||||
|
fontSize: '12px', color: '#ffd666', border: '1px solid #d4af37', marginBottom: '14px',
|
||||||
|
},
|
||||||
|
label: { fontSize: '13px', fontWeight: 600, marginBottom: '4px', color: '#e5e7f1' },
|
||||||
|
input: {
|
||||||
|
width: '100%', padding: '9px 10px', borderRadius: '6px',
|
||||||
|
border: '1px solid #333544', background: '#050608', color: '#f8f9fa',
|
||||||
|
fontSize: '13px', fontFamily: 'inherit', marginBottom: '14px',
|
||||||
|
boxSizing: 'border-box',
|
||||||
|
},
|
||||||
|
textarea: {
|
||||||
|
width: '100%', minHeight: '80px', resize: 'vertical',
|
||||||
|
padding: '9px 10px', borderRadius: '6px', border: '1px solid #333544',
|
||||||
|
background: '#050608', color: '#f8f9fa', fontSize: '13px',
|
||||||
|
fontFamily: 'inherit', marginBottom: '14px', boxSizing: 'border-box',
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
display: 'flex', justifyContent: 'flex-end', gap: '10px',
|
||||||
|
padding: '16px 24px 20px 24px', background: '#0c0d14', borderTop: '1px solid #222',
|
||||||
|
},
|
||||||
|
btnCancel: {
|
||||||
|
padding: '10px 20px', borderRadius: '6px', border: '1px solid #333544',
|
||||||
|
background: '#050608', color: '#f8f9fa', fontWeight: 600,
|
||||||
|
fontSize: '13px', cursor: 'pointer',
|
||||||
|
},
|
||||||
|
btnConfirm: {
|
||||||
|
padding: '10px 22px', borderRadius: '6px', border: 'none',
|
||||||
|
background: 'linear-gradient(135deg, #d4af37 0%, #ffdf8a 100%)',
|
||||||
|
color: '#000', fontWeight: 700, fontSize: '13px',
|
||||||
|
cursor: 'pointer', textTransform: 'uppercase',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const RESOLUTION_OPTIONS = [
|
||||||
|
'Corrective Training Completed',
|
||||||
|
'Verbal Warning Issued',
|
||||||
|
'Written Warning Issued',
|
||||||
|
'Management Review',
|
||||||
|
'Policy Exception Approved',
|
||||||
|
'Data Entry Error',
|
||||||
|
'Other',
|
||||||
|
];
|
||||||
|
|
||||||
export default function NegateModal({ violation, onConfirm, onCancel }) {
|
export default function NegateModal({ violation, onConfirm, onCancel }) {
|
||||||
const [resType, setResType] = useState('');
|
const [resolutionType, setResolutionType] = useState('Corrective Training Completed');
|
||||||
const [details, setDetails] = useState('');
|
const [details, setDetails] = useState('');
|
||||||
const [resolvedBy, setResolvedBy] = useState('');
|
const [resolvedBy, setResolvedBy] = useState('');
|
||||||
const [error, setError] = useState('');
|
|
||||||
|
|
||||||
const handleSubmit = () => {
|
if (!violation) return null;
|
||||||
if (!resType) { setError('Please select a resolution type.'); return; }
|
|
||||||
onConfirm({ resolution_type: resType, details, resolved_by: resolvedBy });
|
const handleConfirm = () => {
|
||||||
|
if (!onConfirm) return;
|
||||||
|
onConfirm({
|
||||||
|
resolution_type: resolutionType,
|
||||||
|
details,
|
||||||
|
resolved_by: resolvedBy,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// FIX: overlay click only closes on backdrop, NOT modal children
|
||||||
|
const handleOverlayClick = (e) => {
|
||||||
|
if (e.target === e.currentTarget && onCancel) onCancel();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={s.overlay}>
|
<div style={s.overlay} onClick={handleOverlayClick}>
|
||||||
<div style={s.box}>
|
{/* FIX: stopPropagation prevents modal clicks from bubbling to overlay */}
|
||||||
<div style={s.title}>⊘ Negate Violation Points</div>
|
<div style={s.modal} onClick={(e) => e.stopPropagation()}>
|
||||||
<div style={s.sub}>This will zero out the points from this incident. The record remains in the audit log.</div>
|
|
||||||
|
|
||||||
<div style={s.violBox}>
|
<div style={s.header}>
|
||||||
<strong>{violation.violation_name}</strong> · {violation.points} pts · {violation.incident_date}
|
<div style={s.title}>Negate Violation</div>
|
||||||
|
<div style={s.subtitle}>
|
||||||
|
Record resolution for: <strong>{violation.violation_name}</strong>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<label style={s.label}>Resolution Type *</label>
|
<div style={s.body}>
|
||||||
<select style={s.input} value={resType} onChange={e => { setResType(e.target.value); setError(''); }}>
|
<div style={s.pill}>
|
||||||
<option value="">-- Select Resolution --</option>
|
⚠ {violation.points} pt{violation.points !== 1 ? 's' : ''} · {violation.incident_date} · {violation.category}
|
||||||
{RESOLUTION_TYPES.map(r => <option key={r} value={r}>{r}</option>)}
|
</div>
|
||||||
|
|
||||||
|
<div style={s.label}>Resolution Type</div>
|
||||||
|
<select
|
||||||
|
style={s.input}
|
||||||
|
value={resolutionType}
|
||||||
|
onChange={(e) => setResolutionType(e.target.value)}
|
||||||
|
>
|
||||||
|
{RESOLUTION_OPTIONS.map((opt) => (
|
||||||
|
<option key={opt} value={opt}>{opt}</option>
|
||||||
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label style={s.label}>Additional Details</label>
|
<div style={s.label}>Details / Notes</div>
|
||||||
<textarea style={{ ...s.input, resize: 'vertical', minHeight: '70px' }}
|
<textarea
|
||||||
placeholder="Training course completed, specific context, approving manager notes…"
|
style={s.textarea}
|
||||||
value={details} onChange={e => setDetails(e.target.value)} />
|
placeholder="Describe the resolution or context…"
|
||||||
|
value={details}
|
||||||
|
onChange={(e) => setDetails(e.target.value)}
|
||||||
|
/>
|
||||||
|
|
||||||
<label style={s.label}>Resolved By</label>
|
<div style={s.label}>Resolved By</div>
|
||||||
<input style={s.input} type="text" placeholder="Officer / Manager name"
|
<input
|
||||||
value={resolvedBy} onChange={e => setResolvedBy(e.target.value)} />
|
style={s.input}
|
||||||
|
placeholder="Manager or HR name…"
|
||||||
|
value={resolvedBy}
|
||||||
|
onChange={(e) => setResolvedBy(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{error && <div style={{ color: '#c0392b', fontSize: '12px', marginBottom: '10px' }}>{error}</div>}
|
<div style={s.footer}>
|
||||||
|
|
||||||
<div style={s.btnRow}>
|
|
||||||
<button style={s.btnCancel} onClick={onCancel}>Cancel</button>
|
<button style={s.btnCancel} onClick={onCancel}>Cancel</button>
|
||||||
<button style={s.btnOk} onClick={handleSubmit}>Confirm Negation</button>
|
<button style={s.btnConfirm} onClick={handleConfirm}>Confirm Negation</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,19 +2,19 @@ import React, { useState } from 'react';
|
|||||||
|
|
||||||
const s = {
|
const s = {
|
||||||
wrapper: { marginTop: '24px' },
|
wrapper: { marginTop: '24px' },
|
||||||
title: { color: '#2c3e50', fontSize: '16px', fontWeight: 700, marginBottom: '10px' },
|
title: { color: '#b5b5c0', fontSize: '16px', fontWeight: 700, marginBottom: '10px' },
|
||||||
table: { width: '100%', borderCollapse: 'collapse', fontSize: '13px' },
|
table: { width: '100%', borderCollapse: 'collapse', fontSize: '13px', background: '#111217', borderRadius: '6px', overflow: 'hidden', border: '1px solid #222' },
|
||||||
th: { background: '#2c3e50', color: 'white', padding: '8px 10px', textAlign: 'left' },
|
th: { background: '#000000', color: '#f8f9fa', padding: '8px 10px', textAlign: 'left', fontSize: '12px', fontWeight: 600, textTransform: 'uppercase', letterSpacing: '0.5px' },
|
||||||
td: { padding: '8px 10px', borderBottom: '1px solid #dee2e6' },
|
td: { padding: '8px 10px', borderBottom: '1px solid #1c1d29', color: '#f8f9fa', verticalAlign: 'middle' },
|
||||||
trEven: { background: '#f8f9fa' },
|
trEven: { background: '#111217' },
|
||||||
trOdd: { background: 'white' },
|
trOdd: { background: '#151622' },
|
||||||
pts: { fontWeight: 700, color: '#667eea' },
|
pts: { fontWeight: 700, color: '#667eea' },
|
||||||
toggle: { background: 'none', border: 'none', color: '#667eea', cursor: 'pointer', fontSize: '13px', padding: 0, textDecoration: 'underline' },
|
toggle: { background: 'none', border: 'none', color: '#667eea', cursor: 'pointer', fontSize: '13px', padding: 0, textDecoration: 'underline' },
|
||||||
empty: { color: '#888', fontStyle: 'italic', fontSize: '13px', marginTop: '8px' },
|
empty: { color: '#77798a', fontStyle: 'italic', fontSize: '13px', marginTop: '8px' },
|
||||||
};
|
};
|
||||||
|
|
||||||
function formatDate(d) {
|
function formatDate(d) {
|
||||||
if (!d) return '—';
|
if (!d) return '–';
|
||||||
const dt = new Date(d + 'T12:00:00');
|
const dt = new Date(d + 'T12:00:00');
|
||||||
return dt.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', timeZone: 'America/Chicago' });
|
return dt.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', timeZone: 'America/Chicago' });
|
||||||
}
|
}
|
||||||
@@ -44,9 +44,9 @@ export default function ViolationHistory({ history, loading }) {
|
|||||||
<tr key={v.id} style={i % 2 === 0 ? s.trEven : s.trOdd}>
|
<tr key={v.id} style={i % 2 === 0 ? s.trEven : s.trOdd}>
|
||||||
<td style={s.td}>{formatDate(v.incident_date)}</td>
|
<td style={s.td}>{formatDate(v.incident_date)}</td>
|
||||||
<td style={s.td}>{v.violation_name}</td>
|
<td style={s.td}>{v.violation_name}</td>
|
||||||
<td style={s.td}>{v.category}</td>
|
<td style={{ ...s.td, color: '#c0c2d6' }}>{v.category}</td>
|
||||||
<td style={{ ...s.td, ...s.pts }}>{v.points}</td>
|
<td style={{ ...s.td, ...s.pts }}>{v.points}</td>
|
||||||
<td style={s.td}>{v.details || '—'}</td>
|
<td style={{ ...s.td, color: '#c0c2d6' }}>{v.details || '–'}</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -30,18 +30,12 @@ async function generatePdf(violation, score) {
|
|||||||
format: 'Letter',
|
format: 'Letter',
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
margin: {
|
margin: {
|
||||||
top: '0.6in',
|
top: '0.35in',
|
||||||
bottom: '0.7in',
|
bottom: '0.35in',
|
||||||
left: '0.75in',
|
left: '0.4in',
|
||||||
right: '0.75in',
|
right: '0.4in',
|
||||||
},
|
},
|
||||||
displayHeaderFooter: true,
|
displayHeaderFooter: false,
|
||||||
headerTemplate: '<div></div>',
|
|
||||||
footerTemplate: `
|
|
||||||
<div style="font-size:9px; color:#888; width:100%; text-align:center; padding:0 0.75in;">
|
|
||||||
CONFIDENTIAL — MPM Internal HR Document |
|
|
||||||
Page <span class="pageNumber"></span> of <span class="totalPages"></span>
|
|
||||||
</div>`,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return pdf;
|
return pdf;
|
||||||
|
|||||||
597
pdf/template.js
597
pdf/template.js
File diff suppressed because one or more lines are too long
62
server.js
62
server.js
@@ -70,7 +70,7 @@ app.get('/api/violations/employee/:id', (req, res) => {
|
|||||||
res.json(rows);
|
res.json(rows);
|
||||||
});
|
});
|
||||||
|
|
||||||
// NEW helper: compute prior_active_points at time of insert (excluding this violation)
|
// Helper: compute prior_active_points at time of insert
|
||||||
function getPriorActivePoints(employeeId, incidentDate) {
|
function getPriorActivePoints(employeeId, incidentDate) {
|
||||||
const row = db.prepare(
|
const row = db.prepare(
|
||||||
`SELECT COALESCE(SUM(points),0) AS pts
|
`SELECT COALESCE(SUM(points),0) AS pts
|
||||||
@@ -116,9 +116,63 @@ app.post('/api/violations', (req, res) => {
|
|||||||
res.status(201).json({ id: result.lastInsertRowid });
|
res.status(201).json({ id: result.lastInsertRowid });
|
||||||
});
|
});
|
||||||
|
|
||||||
// Negate / restore / delete endpoints unchanged ...
|
// ── Negate a violation ──────────────────────────────────────────────────────
|
||||||
|
app.patch('/api/violations/:id/negate', (req, res) => {
|
||||||
|
const { resolution_type, details, resolved_by } = req.body;
|
||||||
|
const id = req.params.id;
|
||||||
|
|
||||||
// PDF endpoint — use stored prior_active_points snapshot
|
const violation = db.prepare('SELECT * FROM violations WHERE id = ?').get(id);
|
||||||
|
if (!violation) return res.status(404).json({ error: 'Violation not found' });
|
||||||
|
|
||||||
|
// Mark negated
|
||||||
|
db.prepare('UPDATE violations SET negated = 1 WHERE id = ?').run(id);
|
||||||
|
|
||||||
|
// Upsert resolution record
|
||||||
|
const existing = db.prepare('SELECT id FROM violation_resolutions WHERE violation_id = ?').get(id);
|
||||||
|
if (existing) {
|
||||||
|
db.prepare(`
|
||||||
|
UPDATE violation_resolutions
|
||||||
|
SET resolution_type = ?, details = ?, resolved_by = ?, created_at = datetime('now')
|
||||||
|
WHERE violation_id = ?
|
||||||
|
`).run(resolution_type || 'Resolved', details || null, resolved_by || null, id);
|
||||||
|
} else {
|
||||||
|
db.prepare(`
|
||||||
|
INSERT INTO violation_resolutions (violation_id, resolution_type, details, resolved_by)
|
||||||
|
VALUES (?, ?, ?, ?)
|
||||||
|
`).run(id, resolution_type || 'Resolved', details || null, resolved_by || null);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({ success: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Restore a negated violation ─────────────────────────────────────────────
|
||||||
|
app.patch('/api/violations/:id/restore', (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
|
|
||||||
|
const violation = db.prepare('SELECT * FROM violations WHERE id = ?').get(id);
|
||||||
|
if (!violation) return res.status(404).json({ error: 'Violation not found' });
|
||||||
|
|
||||||
|
db.prepare('UPDATE violations SET negated = 0 WHERE id = ?').run(id);
|
||||||
|
db.prepare('DELETE FROM violation_resolutions WHERE violation_id = ?').run(id);
|
||||||
|
|
||||||
|
res.json({ success: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Hard delete a violation ─────────────────────────────────────────────────
|
||||||
|
app.delete('/api/violations/:id', (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
|
|
||||||
|
const violation = db.prepare('SELECT * FROM violations WHERE id = ?').get(id);
|
||||||
|
if (!violation) return res.status(404).json({ error: 'Violation not found' });
|
||||||
|
|
||||||
|
// Delete resolution first (FK safety)
|
||||||
|
db.prepare('DELETE FROM violation_resolutions WHERE violation_id = ?').run(id);
|
||||||
|
db.prepare('DELETE FROM violations WHERE id = ?').run(id);
|
||||||
|
|
||||||
|
res.json({ success: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── PDF endpoint ─────────────────────────────────────────────────────────────
|
||||||
app.get('/api/violations/:id/pdf', async (req, res) => {
|
app.get('/api/violations/:id/pdf', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const violation = db.prepare(`
|
const violation = db.prepare(`
|
||||||
@@ -130,13 +184,11 @@ app.get('/api/violations/:id/pdf', async (req, res) => {
|
|||||||
|
|
||||||
if (!violation) return res.status(404).json({ error: 'Violation not found' });
|
if (!violation) return res.status(404).json({ error: 'Violation not found' });
|
||||||
|
|
||||||
// For PDF, compute score row but pass stored prior_active_points so math is stable
|
|
||||||
const active = db.prepare('SELECT * FROM active_cpas_scores WHERE employee_id = ?')
|
const active = db.prepare('SELECT * FROM active_cpas_scores WHERE employee_id = ?')
|
||||||
.get(violation.employee_id) || { active_points: 0, violation_count: 0 };
|
.get(violation.employee_id) || { active_points: 0, violation_count: 0 };
|
||||||
|
|
||||||
const scoreForPdf = {
|
const scoreForPdf = {
|
||||||
employee_id: violation.employee_id,
|
employee_id: violation.employee_id,
|
||||||
// snapshot at time of violation (if present); fall back to current
|
|
||||||
active_points: violation.prior_active_points != null ? violation.prior_active_points : active.active_points,
|
active_points: violation.prior_active_points != null ? violation.prior_active_points : active.active_points,
|
||||||
violation_count: active.violation_count,
|
violation_count: active.violation_count,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user