Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions apps/next-frontend/components/qr-scanner-free-event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,24 @@ export function QRScannerFreeEvent({ eventoid }: ScannerFreeEventProps) {
}, []);

const handleScan = async (codigo: string) => {
const trimmedCode = codigo.trim();
if (!trimmedCode || isProcessingScanRef.current) {
const normalizedCode = codigo.trim().toUpperCase();
if (!normalizedCode || isProcessingScanRef.current) {
return;
}

const now = Date.now();
const lastScan = lastScanRef.current;
if (lastScan && lastScan.code === trimmedCode && now - lastScan.timestamp < 2000) {
if (lastScan && lastScan.code === normalizedCode && now - lastScan.timestamp < 5000) {
return;
}
lastScanRef.current = { code: trimmedCode, timestamp: now };
lastScanRef.current = { code: normalizedCode, timestamp: now };

isProcessingScanRef.current = true;

setManualCode('');

try {
const data = await validateQrMutation.mutateAsync(trimmedCode);
const data = await validateQrMutation.mutateAsync(normalizedCode);

if (data?.data?.validado) {
const esYaValidado = data.message?.includes('ya fue validado');
Expand All @@ -236,6 +236,7 @@ export function QRScannerFreeEvent({ eventoid }: ScannerFreeEventProps) {
} catch (error) {
const message = error instanceof Error ? error.message : 'Error al validar código QR';
toast.error(message);
lastScanRef.current = { code: normalizedCode, timestamp: Date.now() }; // evitar reintentos instantáneos
} finally {
isProcessingScanRef.current = false;
if (inputRef.current) {
Expand Down
Loading