backfill button and usage
This commit is contained in:
@@ -86,6 +86,11 @@ const s = {
|
||||
fontSize: '9px', fontWeight: 700, background: '#0e2a2a', color: '#4db6ac',
|
||||
border: '1px solid #1a4a4a', verticalAlign: 'middle',
|
||||
},
|
||||
backfillBtn: {
|
||||
background: 'none', border: '1px solid #d4af37', color: '#ffd666',
|
||||
borderRadius: '4px', padding: '4px 10px', fontSize: '11px',
|
||||
cursor: 'pointer', fontWeight: 600,
|
||||
},
|
||||
};
|
||||
|
||||
export default function EmployeeModal({ employeeId, onClose }) {
|
||||
@@ -156,6 +161,26 @@ export default function EmployeeModal({ employeeId, onClose }) {
|
||||
}
|
||||
};
|
||||
|
||||
const handleRecomputeSnapshots = async () => {
|
||||
if (!window.confirm(
|
||||
'Rebuild the "Prior Active Points" snapshot on every violation for this employee?\n\n' +
|
||||
'Use this after back-dating a violation if older PDFs no longer reflect the correct prior-points total. ' +
|
||||
'Existing PDFs will regenerate with up-to-date numbers.'
|
||||
)) return;
|
||||
try {
|
||||
const r = await axios.post(`/api/employees/${employeeId}/recompute-snapshots`);
|
||||
const { scanned, updated } = r.data;
|
||||
if (updated === 0) {
|
||||
toast.success(`Snapshots already up to date (${scanned} checked).`);
|
||||
} else {
|
||||
toast.success(`Updated ${updated} of ${scanned} snapshot${updated === 1 ? '' : 's'}.`);
|
||||
}
|
||||
load();
|
||||
} catch (err) {
|
||||
toast.error('Backfill failed: ' + (err.response?.data?.error || err.message));
|
||||
}
|
||||
};
|
||||
|
||||
const handleNegate = async ({ resolution_type, details, resolved_by }) => {
|
||||
try {
|
||||
await axios.patch(`/api/violations/${negating.id}/negate`, { resolution_type, details, resolved_by });
|
||||
@@ -251,7 +276,18 @@ export default function EmployeeModal({ employeeId, onClose }) {
|
||||
)}
|
||||
|
||||
{/* ── Active Violations ── */}
|
||||
<div style={s.sectionHd}>Active Violations</div>
|
||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginTop: '24px', marginBottom: '10px' }}>
|
||||
<div style={{ ...s.sectionHd, marginTop: 0, marginBottom: 0 }}>Active Violations</div>
|
||||
{violations.length > 0 && (
|
||||
<button
|
||||
style={s.backfillBtn}
|
||||
onClick={handleRecomputeSnapshots}
|
||||
title="Rebuild prior-points snapshot on each violation. Use after a back-dated insert if older PDFs show the wrong Prior Active Points."
|
||||
>
|
||||
↻ Backfill Snapshots
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{active.length === 0 ? (
|
||||
<div style={{ color: '#777990', fontStyle: 'italic', fontSize: '12px' }}>
|
||||
No active violations on record.
|
||||
|
||||
Reference in New Issue
Block a user