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

View File

@ -141,6 +141,9 @@ export default function Avaliacoes() {
});
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) {
// Show Success Modal
@ -148,9 +151,6 @@ export default function Avaliacoes() {
setModalMsg(`Sua ${typeLabel} foi enviada com sucesso! Clique em OK para ver seu resultado.`);
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(() => {
setResult(data.result);
setView('result');
@ -158,7 +158,8 @@ export default function Avaliacoes() {
});
} else {
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');
}
} catch (err) {