diff --git a/src/components/fingerprint-scanner.js b/src/components/fingerprint-scanner.js index 1c5024e..62f0813 100644 --- a/src/components/fingerprint-scanner.js +++ b/src/components/fingerprint-scanner.js @@ -2,29 +2,40 @@ import { Box, Typography, Button } from "@mui/material"; import FingerprintImg from "../images/fp_3.png"; import { useAppContext } from "../context/appContext"; import { useNavigate } from "react-router-dom"; -import { useEffect } from "react"; +import { useEffect,useState } from "react"; import { socket } from "../utils/socket" -const FingerprintScanner = ({ isStudent, setIsBioLogin, examId }) => { +const FingerprintScanner = ({ isStudent, setIsBioLogin, examId, setPerson1, setMessage1, setOpen }) => { const { loginSupervisor, loginStudent } = useAppContext(); const navigate = useNavigate(); + console.log(setPerson1) - // TODO - call this when fingerprint scanning finished const handleLogIn = (fingerprint) => { - // TODO - Get fingerprint from the input scanner device + const typedArray = new Uint8Array(fingerprint['1']['buffer']); + const temp = [...typedArray]; + const fingerData = {fingerprint:{bioSubType:fingerprint['1']['bioSubType'], buffer:{data: temp}}, eventId:Number(examId)} if (!isStudent) { - loginSupervisor(fingerprint); + loginSupervisor(fingerData); + console.log("Here"); } else { - loginStudent(fingerprint); + const data = loginStudent(fingerData); + console.log(data); + setPerson1(data.person); + setMessage1(data.message); + setOpen(true); } }; useEffect(() => { socket.on("fingerprintData", async (fingerprintData) => { - handleLogIn(fingerprintData) + if (fingerprintData.success === undefined){ + handleLogIn(fingerprintData) + + }else{ + console.log("fingerprint not successfull") + } }); - requestFingerprint() }, []); async function requestFingerprint() { @@ -41,6 +52,17 @@ const FingerprintScanner = ({ isStudent, setIsBioLogin, examId }) => { alt="fingerprint" style={{ margin: "10%" }} /> + {isStudent && ( + + SCAN FINGERPRINT + + )} {isStudent && ( { /> {person.name} - {person.index} + {person.index_number} )} diff --git a/src/context/appContext.js b/src/context/appContext.js index 56933f3..3f9e456 100644 --- a/src/context/appContext.js +++ b/src/context/appContext.js @@ -117,26 +117,34 @@ const AppProvider = ({ children }) => { try { const { data } = await authFetch.post( - "/student/exam-attendance-attendance/mark-exam-attendance", - logInData + "/student/exam-attendance/mark-exam-attendance", + logInData ); - + return { + message:null, + person:data.data + }; // TODO - if (true) { - dispatch({ - type: LOGIN_STUDENT_SUCCESS, - }); - successToast("Login successful"); - } else { - errorToast("Login failed"); - } + // if (true) { + // dispatch({ + // type: LOGIN_STUDENT_SUCCESS, + // }); + // successToast("Login successful"); + // } else { + // errorToast("Login failed"); + // } } catch (error) { + // errorToast("Login failed"); dispatch({ type: LOGIN_STUDENT_ERROR, payload: { msg: error.response.data.msg, }, }); + return { + message:"Login Failed!", + person:null + }; } }; diff --git a/src/index.js b/src/index.js index f28e283..0dd3646 100644 --- a/src/index.js +++ b/src/index.js @@ -7,11 +7,10 @@ import { AppProvider } from './context/appContext' const root = ReactDOM.createRoot(document.getElementById('root')); root.render( - - + ); // If you want to start measuring performance in your app, pass a function diff --git a/src/pages/attendance-marking-page.js b/src/pages/attendance-marking-page.js index 7db4a2d..04f8452 100644 --- a/src/pages/attendance-marking-page.js +++ b/src/pages/attendance-marking-page.js @@ -18,15 +18,22 @@ export default function AttendanceMarkingPage({isStudent}) { const handleFlip = () => { setIsBioLogin(!isBioLogin) } - - const person = { - name:"Yasiru Lakshan", - index:"190331A", - profilePicture:profileImage - } + const [person, setPerson] = useState(null); + const [message, setMessage] = useState(null); + // const person = { + // name:"Yasiru Lakshan", + // index:"190331A", + // profilePicture:profileImage + // } + console.log(person, message) const location = useLocation(); - + const setPersonFunc = (param) => { + setPerson(param); + } + const setMessageFunc = (param) => { + setMessage(param); + } return ( @@ -35,9 +42,9 @@ export default function AttendanceMarkingPage({isStudent}) { {!isBioLogin ? ( ) : ( - + {setOpen(state)}} examId={location.state.examId} setPerson1={setPersonFunc} setMessage1={setMessageFunc}/> )} - + ); diff --git a/src/utils/socket.js b/src/utils/socket.js index c104e70..b551116 100644 --- a/src/utils/socket.js +++ b/src/utils/socket.js @@ -1,5 +1,4 @@ import { io } from "socket.io-client"; -const URL = process.env.REACT_APP_SOCKET_HOST; - +const URL = "http://localhost:7291"; export const socket = io(URL);