Spaces:
Runtime error
Runtime error
Greg Claude Sonnet 4.6 commited on
Commit ·
47a0040
1
Parent(s): ddae258
feat(developer): UI button + modal to trigger demo purge
Browse filesAdds PurgeDemoModal (two-step: warning then password confirmation) and wires a
"Zona peligrosa" section into the DeveloperPage dashboard tab. Button is guarded
by user.role === 'developer'. On success shows row count and refreshes dashboard.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
frontend/src/components/PurgeDemoModal.tsx
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState } from 'react';
|
| 2 |
+
import { purgeDemoData } from '../services/developerService';
|
| 3 |
+
import { AlertTriangle, Trash2 } from 'lucide-react';
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
open: boolean;
|
| 7 |
+
onClose: () => void;
|
| 8 |
+
onSuccess?: (deleted: Record<string, number>) => void;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
export default function PurgeDemoModal({ open, onClose, onSuccess }: Props) {
|
| 12 |
+
const [stage, setStage] = useState<'warn' | 'auth'>('warn');
|
| 13 |
+
const [password, setPassword] = useState('');
|
| 14 |
+
const [busy, setBusy] = useState(false);
|
| 15 |
+
const [err, setErr] = useState<string | null>(null);
|
| 16 |
+
|
| 17 |
+
if (!open) return null;
|
| 18 |
+
|
| 19 |
+
const reset = () => { setStage('warn'); setPassword(''); setErr(null); setBusy(false); };
|
| 20 |
+
const close = () => { reset(); onClose(); };
|
| 21 |
+
|
| 22 |
+
const submit = async () => {
|
| 23 |
+
setBusy(true);
|
| 24 |
+
setErr(null);
|
| 25 |
+
try {
|
| 26 |
+
const res = await purgeDemoData(password);
|
| 27 |
+
onSuccess?.(res.deleted);
|
| 28 |
+
close();
|
| 29 |
+
} catch (e: any) {
|
| 30 |
+
setErr(e?.response?.data?.detail || 'Error al purgar');
|
| 31 |
+
} finally {
|
| 32 |
+
setBusy(false);
|
| 33 |
+
}
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
return (
|
| 37 |
+
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4" onClick={close}>
|
| 38 |
+
<div className="bg-white rounded-2xl shadow-2xl max-w-md w-full" onClick={(e) => e.stopPropagation()}>
|
| 39 |
+
{stage === 'warn' && (
|
| 40 |
+
<>
|
| 41 |
+
<div className="px-6 py-4 border-b border-gray-200 flex items-center gap-3">
|
| 42 |
+
<div className="w-10 h-10 bg-red-100 rounded-full flex items-center justify-center">
|
| 43 |
+
<AlertTriangle size={20} className="text-red-600" />
|
| 44 |
+
</div>
|
| 45 |
+
<h2 className="text-lg font-bold text-gray-800">Purgar datos demo</h2>
|
| 46 |
+
</div>
|
| 47 |
+
<div className="p-6 space-y-3 text-sm text-gray-600">
|
| 48 |
+
<p>Esta acción <b>borra TODOS los datos de la cuenta demo</b>: estudiantes, docentes, asistencias, secciones, materias, horarios, registros faciales, todo. Luego repone el seeder original.</p>
|
| 49 |
+
<p className="text-red-600 font-medium">No se puede deshacer.</p>
|
| 50 |
+
<p>Te pediré tu contraseña en el siguiente paso para confirmar.</p>
|
| 51 |
+
</div>
|
| 52 |
+
<div className="px-6 py-4 bg-gray-50 rounded-b-2xl flex items-center justify-end gap-3">
|
| 53 |
+
<button onClick={close} className="px-4 py-2 rounded-lg border border-gray-300 text-gray-700 text-sm hover:bg-gray-100">Cancelar</button>
|
| 54 |
+
<button onClick={() => setStage('auth')} className="px-4 py-2 rounded-lg bg-red-600 text-white text-sm hover:bg-red-700 inline-flex items-center gap-2">
|
| 55 |
+
<Trash2 size={14} /> Sí, quiero purgar
|
| 56 |
+
</button>
|
| 57 |
+
</div>
|
| 58 |
+
</>
|
| 59 |
+
)}
|
| 60 |
+
{stage === 'auth' && (
|
| 61 |
+
<>
|
| 62 |
+
<div className="px-6 py-4 border-b border-gray-200">
|
| 63 |
+
<h2 className="text-lg font-bold text-gray-800">Confirma con tu contraseña</h2>
|
| 64 |
+
</div>
|
| 65 |
+
<div className="p-6 space-y-3">
|
| 66 |
+
<label className="block text-sm text-gray-700">Contraseña de tu cuenta developer</label>
|
| 67 |
+
<input
|
| 68 |
+
type="password"
|
| 69 |
+
value={password}
|
| 70 |
+
onChange={(e) => setPassword(e.target.value)}
|
| 71 |
+
disabled={busy}
|
| 72 |
+
className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm"
|
| 73 |
+
autoFocus
|
| 74 |
+
onKeyDown={(e) => { if (e.key === 'Enter' && password) submit(); }}
|
| 75 |
+
/>
|
| 76 |
+
{err && <p className="text-sm text-red-600">{err}</p>}
|
| 77 |
+
</div>
|
| 78 |
+
<div className="px-6 py-4 bg-gray-50 rounded-b-2xl flex items-center justify-end gap-3">
|
| 79 |
+
<button onClick={close} disabled={busy} className="px-4 py-2 rounded-lg border border-gray-300 text-gray-700 text-sm hover:bg-gray-100 disabled:opacity-50">Cancelar</button>
|
| 80 |
+
<button
|
| 81 |
+
onClick={submit}
|
| 82 |
+
disabled={busy || !password}
|
| 83 |
+
className="px-4 py-2 rounded-lg bg-red-600 text-white text-sm hover:bg-red-700 disabled:opacity-50 inline-flex items-center gap-2"
|
| 84 |
+
>
|
| 85 |
+
<Trash2 size={14} /> {busy ? 'Purgando...' : 'Confirmar y purgar'}
|
| 86 |
+
</button>
|
| 87 |
+
</div>
|
| 88 |
+
</>
|
| 89 |
+
)}
|
| 90 |
+
</div>
|
| 91 |
+
</div>
|
| 92 |
+
);
|
| 93 |
+
}
|
frontend/src/pages/DeveloperPage.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import { useEffect, useState } from 'react';
|
| 2 |
import { useAuthStore } from '../store/authStore';
|
| 3 |
import LoadingState from '../components/LoadingState';
|
|
|
|
| 4 |
import {
|
| 5 |
getDeveloperDashboard,
|
| 6 |
toggleAccountActive,
|
|
@@ -16,7 +17,7 @@ import {
|
|
| 16 |
} from 'recharts';
|
| 17 |
import {
|
| 18 |
Building2, Users, Activity, Download, ToggleLeft, ToggleRight,
|
| 19 |
-
AlertTriangle, Calendar, Search, RefreshCw,
|
| 20 |
} from 'lucide-react';
|
| 21 |
|
| 22 |
export default function DeveloperPage() {
|
|
@@ -30,6 +31,7 @@ export default function DeveloperPage() {
|
|
| 30 |
const [searchAcct, setSearchAcct] = useState('');
|
| 31 |
const [trialDays, setTrialDays] = useState<Record<number, string>>({});
|
| 32 |
const [tab, setTab] = useState<'dashboard' | 'accounts' | 'logs'>('dashboard');
|
|
|
|
| 33 |
|
| 34 |
const loadDashboard = async () => {
|
| 35 |
setLoading(true);
|
|
@@ -171,6 +173,30 @@ export default function DeveloperPage() {
|
|
| 171 |
</ResponsiveContainer>
|
| 172 |
</div>
|
| 173 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
</div>
|
| 175 |
)}
|
| 176 |
|
|
|
|
| 1 |
import { useEffect, useState } from 'react';
|
| 2 |
import { useAuthStore } from '../store/authStore';
|
| 3 |
import LoadingState from '../components/LoadingState';
|
| 4 |
+
import PurgeDemoModal from '../components/PurgeDemoModal';
|
| 5 |
import {
|
| 6 |
getDeveloperDashboard,
|
| 7 |
toggleAccountActive,
|
|
|
|
| 17 |
} from 'recharts';
|
| 18 |
import {
|
| 19 |
Building2, Users, Activity, Download, ToggleLeft, ToggleRight,
|
| 20 |
+
AlertTriangle, Calendar, Search, RefreshCw, Trash2,
|
| 21 |
} from 'lucide-react';
|
| 22 |
|
| 23 |
export default function DeveloperPage() {
|
|
|
|
| 31 |
const [searchAcct, setSearchAcct] = useState('');
|
| 32 |
const [trialDays, setTrialDays] = useState<Record<number, string>>({});
|
| 33 |
const [tab, setTab] = useState<'dashboard' | 'accounts' | 'logs'>('dashboard');
|
| 34 |
+
const [showPurge, setShowPurge] = useState(false);
|
| 35 |
|
| 36 |
const loadDashboard = async () => {
|
| 37 |
setLoading(true);
|
|
|
|
| 173 |
</ResponsiveContainer>
|
| 174 |
</div>
|
| 175 |
)}
|
| 176 |
+
|
| 177 |
+
{user?.role === 'developer' && (
|
| 178 |
+
<div className="bg-red-50 border border-red-200 rounded-xl p-4 mt-6">
|
| 179 |
+
<div className="flex items-center justify-between gap-4">
|
| 180 |
+
<div>
|
| 181 |
+
<h3 className="font-semibold text-red-700 flex items-center gap-2"><AlertTriangle size={16} /> Zona peligrosa</h3>
|
| 182 |
+
<p className="text-sm text-red-600 mt-1">Purga todos los datos subidos al demo y restaura el seeder original. Esta acción NO se puede deshacer.</p>
|
| 183 |
+
</div>
|
| 184 |
+
<button onClick={() => setShowPurge(true)} className="px-4 py-2 bg-red-600 text-white rounded-lg text-sm hover:bg-red-700 inline-flex items-center gap-2 shrink-0">
|
| 185 |
+
<Trash2 size={14} /> Purgar demo
|
| 186 |
+
</button>
|
| 187 |
+
</div>
|
| 188 |
+
</div>
|
| 189 |
+
)}
|
| 190 |
+
|
| 191 |
+
<PurgeDemoModal
|
| 192 |
+
open={showPurge}
|
| 193 |
+
onClose={() => setShowPurge(false)}
|
| 194 |
+
onSuccess={(deleted) => {
|
| 195 |
+
const total = Object.values(deleted).reduce((a, b) => a + b, 0);
|
| 196 |
+
alert(`Demo purgado y re-sembrado. Total filas eliminadas: ${total}`);
|
| 197 |
+
loadDashboard();
|
| 198 |
+
}}
|
| 199 |
+
/>
|
| 200 |
</div>
|
| 201 |
)}
|
| 202 |
|
frontend/src/services/developerService.ts
CHANGED
|
@@ -81,3 +81,15 @@ export async function getUsersByAccount(): Promise<{ account_name: string; accou
|
|
| 81 |
export function getExportUrl(): string {
|
| 82 |
return `${api.defaults.baseURL}/developer/export`;
|
| 83 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
export function getExportUrl(): string {
|
| 82 |
return `${api.defaults.baseURL}/developer/export`;
|
| 83 |
}
|
| 84 |
+
|
| 85 |
+
export interface PurgeDemoResponse {
|
| 86 |
+
success: boolean;
|
| 87 |
+
demo_account_id: number;
|
| 88 |
+
deleted: Record<string, number>;
|
| 89 |
+
reseeded: boolean;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
export async function purgeDemoData(password: string): Promise<PurgeDemoResponse> {
|
| 93 |
+
const { data } = await api.post('/developer/purge-demo', { password });
|
| 94 |
+
return data;
|
| 95 |
+
}
|