fix: delay de 5s no envio, mensagens de erro detalhadas e cache-busting no Manager

This commit is contained in:
Sidney 2026-05-01 11:10:13 -03:00
parent e2cb0376cf
commit 71f5a4159f
2 changed files with 16 additions and 11 deletions

View File

@ -114,10 +114,10 @@ const ReportCard: React.FC<ReportCardProps> = ({ data, updateData }) => {
setSelectedStudent(student); setSelectedStudent(student);
const initialGrades: Record<string, Record<string, any>> = {}; const initialGrades: Record<string, Record<string, any>> = {};
// Buscar notas do Postgres // Buscar notas do Postgres (com cache busting)
let dbNotas: any[] = []; let dbNotas: any[] = [];
try { try {
const resNotas = await fetch(`/api/notas/${student.id}`); const resNotas = await fetch(`/api/notas/${student.id}?t=${new Date().getTime()}`);
if (resNotas.ok) { if (resNotas.ok) {
const json = await resNotas.json(); const json = await resNotas.json();
dbNotas = json.notas || []; dbNotas = json.notas || [];
@ -127,7 +127,7 @@ const ReportCard: React.FC<ReportCardProps> = ({ data, updateData }) => {
} }
try { try {
const res = await fetch(`/api/student-submissions/${student.id}`); const res = await fetch(`/api/student-submissions/${student.id}?t=${new Date().getTime()}`);
if (res.ok) { if (res.ok) {
const { submissions } = await res.json(); const { submissions } = await res.json();
const subsMap: Record<string, {acertos: number, erros: number}> = {}; const subsMap: Record<string, {acertos: number, erros: number}> = {};
@ -591,10 +591,14 @@ const ReportCard: React.FC<ReportCardProps> = ({ data, updateData }) => {
{exam.description && ( {exam.description && (
<p className="text-xs text-slate-500 leading-snug pr-2">{exam.description}</p> <p className="text-xs text-slate-500 leading-snug pr-2">{exam.description}</p>
)} )}
{studentSubmissions[exam.id] && ( {studentSubmissions[String(exam.id).trim()] && (
<div className="flex items-center gap-2 text-[10px] font-black uppercase tracking-wider mt-1"> <div className="flex gap-2 mt-2">
<span className="text-emerald-600 bg-emerald-50 px-2 py-0.5 rounded-md">{studentSubmissions[exam.id].acertos} Acertos</span> <span className="text-[10px] font-bold px-2 py-0.5 rounded-full bg-emerald-100 text-emerald-700 border border-emerald-200">
<span className="text-red-500 bg-red-50 px-2 py-0.5 rounded-md">{studentSubmissions[exam.id].erros} Erros</span> {studentSubmissions[String(exam.id).trim()].acertos} Acertos
</span>
<span className="text-[10px] font-bold px-2 py-0.5 rounded-full bg-rose-100 text-rose-700 border border-rose-200">
{studentSubmissions[String(exam.id).trim()].erros} Erros
</span>
</div> </div>
)} )}
</div> </div>

View File

@ -142,15 +142,15 @@ export default function Avaliacoes() {
const data = await res.json(); const data = await res.json();
// Artificial delay of 5 seconds to let the student read the message
await new Promise(resolve => setTimeout(resolve, 5000));
if (data.success) { if (data.success) {
// Show Success Modal // Show Success Modal
setModalType('info'); setModalType('info');
setModalMsg(`Sua ${typeLabel} foi enviada com sucesso! Clique em OK para ver seu resultado.`); setModalMsg(`Sua ${typeLabel} foi enviada com sucesso! Clique em OK para ver seu resultado.`);
setShowModal(true); setShowModal(true);
// Wait for user to click OK before showing result?
// No, user wants result. But let's follow the "sent successfully" request.
// We'll set a callback to OK button to show result
setConfirmCallback(() => { setConfirmCallback(() => {
setResult(data.result); setResult(data.result);
setView('result'); setView('result');
@ -158,7 +158,8 @@ export default function Avaliacoes() {
}); });
} else { } else {
const errorCode = `ERR-${activeExam.id.substring(0, 4)}-${new Date().getTime().toString().slice(-4)}`; const errorCode = `ERR-${activeExam.id.substring(0, 4)}-${new Date().getTime().toString().slice(-4)}`;
showAppAlert(`Não foi possível enviar sua nota. Tente novamente ou contate o suporte. (Código: ${errorCode})`, 'error'); // Use the error message from server if available
showAppAlert(data.error || `Não foi possível enviar sua nota. Tente novamente ou contate o suporte. (Código: ${errorCode})`, 'error');
if (!autoSubmit) setView('listing'); if (!autoSubmit) setView('listing');
} }
} catch (err) { } catch (err) {