diff --git a/src/app/(admins)/user/layout.tsx b/src/app/(admins)/user/layout.tsx index 239525a..948611a 100644 --- a/src/app/(admins)/user/layout.tsx +++ b/src/app/(admins)/user/layout.tsx @@ -1,6 +1,8 @@ +'use client' +import dynamic from 'next/dynamic'; import Footer from '@/components/layout/footer'; import Header from '@/components/layout/header'; -import Navbar from '@/components/navbar'; +const Navbar = dynamic(() => import('@/components/navbar'), { ssr: false }); import React from 'react'; export default function Layout({ children }: { children: React.ReactNode }) { diff --git a/src/app/(admins)/user/qr/page.tsx b/src/app/(admins)/user/qr/page.tsx index d29168d..974a3f8 100644 --- a/src/app/(admins)/user/qr/page.tsx +++ b/src/app/(admins)/user/qr/page.tsx @@ -10,34 +10,30 @@ import toast from 'react-hot-toast'; const Modal = dynamic(() => import('@/components/modal'), { ssr: false }); export default function Page() { - const [scannedData, setScannedData] = useState<{ - id_participante: number; - id_cuestionario: number; - } | null>(null); - const [showModal, setShowModal] = useState(false); const [enableScan, setEnableScan] = useState(true); const [statusMessage, setStatusMessage] = useState(''); const [participante, setParticipante] = useState(''); + const [message, setMessage] = useState(''); + const [token, setToken] = useState(''); + const [tokenValid, setTokenValid] = useState(false); const handleScan = async (rawValue: string) => { console.log('QR Escaneado:', rawValue); if (!enableScan) return; try { - const data = JSON.parse(rawValue); - if (data.id_participante && data.id_cuestionario) { + if (rawValue) { try { - const response = await axiosInstance.get( - `/participante-evento/${data.id_participante}/${data.id_cuestionario}` + await axiosInstance.post( + `/participante-evento/decode-token`, { + token: rawValue + } ); - setParticipante(response.data.participante.correo); - setScannedData({ - id_participante: data.id_participante, - id_cuestionario: data.id_cuestionario, - }); + setToken(rawValue); + setTokenValid(true); setShowModal(true); setEnableScan(false); } catch (err) { @@ -56,13 +52,17 @@ export default function Page() { }; const handleConfirm = async () => { - if (!scannedData) return; + if (!tokenValid) return; try { const response = await axiosInstance.post( - `/participante-evento/asistencia/${scannedData.id_participante}/${scannedData.id_cuestionario}` + `/participante-evento/asistencia`, { + token: token + } ); + setParticipante(response.data.data.participante); + setMessage(response.data.message); console.log('Asistencia registrada:', response.data); toast.success('✅ Asistencia registrada correctamente'); } catch (err) { @@ -72,7 +72,6 @@ export default function Page() { setShowModal(false); setEnableScan(true); - setScannedData(null); }; return ( @@ -124,6 +123,24 @@ export default function Page() { + {participante && ( +