diff --git a/.env b/.env index bd87f0d..54940de 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ #VITE_REACT_APP_BACKEND_URL="https://sandbox.exampaper.vidh.ai" METABASE_BASE_URL="http://metabase.usln.in/public/question/d8774923-09bb-4cd9-903b-559d417e12cf" VITE_REACT_APP_BACKEND_URL="https://api.exampaper.vidh.ai" -# VITE_REACT_APP_BACKEND_URL="http://localhost:9999" +#VITE_REACT_APP_BACKEND_URL="http://localhost:9999" diff --git a/src/App.jsx b/src/App.jsx index 26598d2..d10828e 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -24,6 +24,7 @@ import AnomolyPartC from "./Components/AnomolyPartC"; import BarcodeScanner from "./Components/BarcodeScanner" import EvQrcode from "./Components/EvQrcode"; import QrcodeCardEditor from "./Components/QrCodeCardEditor"; +import StudentResultsData from "./Components/StudentsResultsData"; function App() { return ( @@ -34,6 +35,7 @@ function App() { }> }> }> + }> } diff --git a/src/Components/AnomolyPartC.jsx b/src/Components/AnomolyPartC.jsx index 8eb77ae..ddb71f1 100644 --- a/src/Components/AnomolyPartC.jsx +++ b/src/Components/AnomolyPartC.jsx @@ -42,36 +42,39 @@ function AnomalyPartC() { const [showSystemNoContainer, setShowSystemNoContainer] = useState(false); const [selectedIndex, setSelectedIndex] = useState(null); const [selectedDegreeType, setSelectedDegreeType] = useState(null); + const [dataFetched, setDataFetched] = useState([]); + const [counter, setCounter] = useState(0); const degreeTypes = [ { type: "UG", type_code: "0" }, { type: "PG", type_code: "2" }, + { type: "UNIVERSITY" , type_code: "5"} ]; - const reduxDegreeType = useSelector((state)=> state?.partCDegreeType) - console.log("Redux degree type ...",reduxDegreeType) - useEffect(()=>{ - if(reduxDegreeType){ - setSelectedDegreeType(reduxDegreeType) - }else{ - setSelectedDegreeType("2") + const reduxDegreeType = useSelector((state) => state?.partCDegreeType); + console.log("Redux degree type ...", reduxDegreeType); + useEffect(() => { + if (reduxDegreeType) { + setSelectedDegreeType(reduxDegreeType); + } else { + setSelectedDegreeType("2"); } - },[reduxDegreeType]) + }, [reduxDegreeType]); const handleDegreeTypeChange = (e) => { - const newDegreeType = e.target.value - console.log("Value ===== ",newDegreeType); + const newDegreeType = e.target.value; + console.log("Value ===== ", newDegreeType); setSelectedDegreeType(newDegreeType); - dispatch(updatePartCDegreeType(newDegreeType)) + dispatch(updatePartCDegreeType(newDegreeType)); }; const { token: { colorBgContainer, borderRadiusLG }, } = theme.useToken(); const navigate = useNavigate(); const dispatch = useDispatch(); - const paramsError = searchParams.get("error") - const paramsErrorReason = searchParams.get("error_reason") - const paramsSysNo = searchParams.get("sysNo") - const paramsDegreeType = searchParams.get("degreeType") + const paramsError = searchParams.get("error"); + const paramsErrorReason = searchParams.get("error_reason"); + const paramsSysNo = searchParams.get("sysNo"); + const paramsDegreeType = searchParams.get("degreeType"); const evErrorsList = useSelector((state) => state?.partCErrorList); console.log("evErrorsList = ", evErrorsList); @@ -103,17 +106,18 @@ function AnomalyPartC() { }, [reduxSystemNo]); useEffect(() => { + console.log("Use effect 11 called ..."); if (!reduxSystemNo) { setShowSystemNoContainer(true); } else { if (evErrorsData && evErrorsData.length > 0) { setEvErrors(evErrorsData); } - if (error && errorReason) { + if (error) { fetchAnomalyRecords(reduxSystemNo); } } - }, [error, errorReason]); + }, [error, errorReason,counter]); useEffect(() => { if (evErrors && evErrors.length > 0) { @@ -125,9 +129,10 @@ function AnomalyPartC() { }, [evErrors]); useEffect(() => { - // dispatch(updatePartCErrorData([])); + dispatch(updatePartCErrorData([])); // setAnomalyData([]); - // setEvErrors([]); + setEvErrors([]); + setDataFetched(false); fetchAnomalyData(); }, [selectedDegreeType]); @@ -160,6 +165,7 @@ function AnomalyPartC() { const fetchAnomalyData = async () => { setIsLoading(true); + setDataFetched(false); try { const response = await fetch( `${ @@ -174,6 +180,7 @@ function AnomalyPartC() { ); const responseData = await response.json(); setAnomalyData(responseData.data); + setDataFetched(true); dispatch(updatePartCErrorList(responseData.data)); } catch (error) { console.error("Error fetching data: ", error); @@ -183,8 +190,9 @@ function AnomalyPartC() { }; const fetchAnomalyRecords = async (reduxSystemNo) => { - console.log("fetching anomoly records") + console.log("fetching anomoly records"); setIsLoading(true); + setDataFetched(false); try { const response = await fetch( `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/getpartcEvErrors`, @@ -208,7 +216,7 @@ function AnomalyPartC() { systemRecords = getRecordsBySystemId(responseData?.data, reduxSystemNo); } console.log("System records : ", systemRecords); - + setDataFetched(true); setEvErrors(systemRecords); setIsLoading(false); dispatch(updatePartCErrorData(systemRecords)); @@ -222,7 +230,7 @@ function AnomalyPartC() { function getRecordsBySystemId(records, systemId) { const new_data = []; - if(!records) records = [] + if (!records) records = []; for (var i = 0; i < records.length; i++) { var count = i % 5; if (count === systemId - 1) { @@ -242,6 +250,7 @@ function AnomalyPartC() { tmp["error_reason"] = errorReason; console.log("tmp = ", tmp); dispatch(updateSelectedJson(tmp)); + setCounter(prev=>prev+1) }; const handlePageChange = (page) => { @@ -333,48 +342,55 @@ function AnomalyPartC() { - {anomalyData && - anomalyData.map((item, index) => ( - - handleClick(item.error, item.error_reason, index) - } - key={index} - style={{ - margin: "16px", - borderRadius: borderRadiusLG, - alignItems: "flex-start", - textAlign: "start", - cursor: "pointer", - color: "white", - backgroundColor: - selectedIndex === index ? "#3f51b5" : "#537895", - backgroundImage: - selectedIndex === index - ? "linear-gradient(315deg, #70a1ff 0%, #c2c0c0 74%);" - : "linear-gradient(315deg, #537895 0%, #09203f 74%)", - }} - > - - {item.error && ( - - Code: {item.error} - - )} - {item["count(*)"] && ( - - Count: {item["count(*)"]} - - )} - {/* {item.error_reason && ( + {dataFetched ? ( + anomalyData && anomalyData.length > 0 ? ( + anomalyData.map((item, index) => ( + + handleClick(item.error, item.error_reason, index) + } + key={index} + style={{ + margin: "16px", + borderRadius: borderRadiusLG, + alignItems: "flex-start", + textAlign: "start", + cursor: "pointer", + color: "white", + backgroundColor: + selectedIndex === index ? "#3f51b5" : "#537895", + backgroundImage: + selectedIndex === index + ? "linear-gradient(315deg, #70a1ff 0%, #c2c0c0 74%);" + : "linear-gradient(315deg, #537895 0%, #09203f 74%)", + }} + > + + {item.error && ( + + Code: {item.error} + + )} + {item["count(*)"] && ( + + Count: {item["count(*)"]} + + )} + {/* {item.error_reason && ( Reason: {item.error_reason} )} */} - - - ))} - {evErrors && evErrors.length > 0 && ( + + + )) + ) : ( + +
No data to display ...
+
+ ) + ) : null} + {evErrors && evErrors.length > 0 && dataFetched ? ( <> )) )} - )} + ) : dataFetched && evErrorsList && evErrorsList.length == 0 ? ( + +
No data to display ...
+
+ ) : null} )} diff --git a/src/Components/BarcodeScanner.jsx b/src/Components/BarcodeScanner.jsx index 377210d..0302cfc 100644 --- a/src/Components/BarcodeScanner.jsx +++ b/src/Components/BarcodeScanner.jsx @@ -20,6 +20,9 @@ const BarcodeScanner = () => { }); const fetchBarcodeData = () => { + if(!scanResult){ + return + } setIsLoading(true); try { const payload = { diff --git a/src/Components/EvQrcode.jsx b/src/Components/EvQrcode.jsx index 9b49928..8ee5fa9 100644 --- a/src/Components/EvQrcode.jsx +++ b/src/Components/EvQrcode.jsx @@ -1,13 +1,21 @@ import { Layout, theme } from "antd"; -import React, { useEffect, useState } from "react"; +import React, { useEffect, useState, useRef } from "react"; import { useNavigate } from "react-router-dom/dist"; import ArrowBackIcon from "@mui/icons-material/ArrowBack"; import HomeIcon from "@mui/icons-material/Home"; import { useDispatch, useSelector } from "react-redux"; -import { Box, Button, Card, CardContent, Typography, CircularProgress } from "@mui/material"; +import { + Box, + Button, + Card, + CardContent, + Typography, + CircularProgress, +} from "@mui/material"; import { updateEvQrcodeList } from "../redux/actions/actions"; import SystemNumberDialog from "./SystemNumberDialog"; import { toast, ToastContainer } from "react-toastify"; +import LoadingContainer from "./LoadingContainer"; const { Content, Header } = Layout; @@ -16,6 +24,7 @@ function EvQrcode() { const [showSystemNoContainer, setShowSystemNoContainer] = useState(false); const [anomalyData, setAnomalyData] = useState([]); const [currentIndex, setCurrentIndex] = useState(0); + const inputRef = useRef(null); const navigate = useNavigate(); @@ -26,7 +35,9 @@ function EvQrcode() { console.log("systemno: ", reduxSystemNo); const dispatch = useDispatch(); - const { token: { colorBgContainer } } = theme.useToken(); + const { + token: { colorBgContainer }, + } = theme.useToken(); useEffect(() => { if (!reduxSystemNo) { @@ -82,15 +93,18 @@ function EvQrcode() { const fetchAnomalyData = async () => { setIsLoading(true); try { - const response = await fetch(`${import.meta.env.VITE_REACT_APP_BACKEND_URL}/getEvRecords`, { - method: "POST", - body: JSON.stringify({ - sysno: reduxSystemNo - }), - headers: { - "Content-Type": "application/json", - }, - }); + const response = await fetch( + `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/getEvRecords`, + { + method: "POST", + body: JSON.stringify({ + sysno: reduxSystemNo, + }), + headers: { + "Content-Type": "application/json", + }, + } + ); const responseData = await response.json(); var systemRecords = responseData?.data; console.log("System record ====== ", responseData.systemRecord); @@ -120,59 +134,75 @@ function EvQrcode() { } const handleNext = () => { - const newItems = anomalyData.filter((_, index) => index !== currentIndex); - setAnomalyData(newItems); - if (currentIndex >= newItems.length) { - setCurrentIndex(0); - } + setIsLoading(true); + setAnomalyData([]); + setTimeout(() => { + const newItems = anomalyData.filter((_, index) => index !== currentIndex); + setAnomalyData(newItems); + if (currentIndex >= newItems.length) { + setCurrentIndex(0); + } + setIsLoading(false) + },1000); }; - const handleUpdate = async() => { + const handleUpdate = async () => { try { - const inputValue = document.getElementById('qrcodeInput').value; - console.log("inputvalu = ", inputValue) + const inputValue = document.getElementById("qrcodeInput").value; + console.log("inputvalu = ", inputValue); - const payload = { - imageName: currentItem.image_name, - qrvalue: inputValue, - }; - console.log("payload=", payload) + const payload = { + imageName: currentItem.image_name, + qrvalue: inputValue, + }; + console.log("payload=", payload); - const response = await fetch(`${import.meta.env.VITE_REACT_APP_BACKEND_URL}/updateEvRecord`, { + const response = await fetch( + `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/updateEvRecord`, + { method: "POST", headers: { "Content-Type": "application/json", }, - body:JSON.stringify(payload) - }); - const responseData = await response.json(); - console.log("responsedata: ", responseData) - if (responseData?.status_code === 200) { - toast.success("Record Updated Successfully"); - handleNext() - document.getElementById('qrcodeInput').value = '' - }else{ - toast.error("Updation Failed"); + body: JSON.stringify(payload), } - - } catch (error) { - console.error("Error fetching data: ", error); - } finally { - setIsLoading(false); + ); + const responseData = await response.json(); + console.log("responsedata: ", responseData); + if (responseData?.status_code === 200) { + toast.success("Record Updated Successfully"); + handleNext(); + document.getElementById("qrcodeInput").value = ""; + } else { + toast.error("Updation Failed"); } - } + } catch (error) { + console.error("Error fetching data: ", error); + } finally { + setIsLoading(false); + } + }; const handleArrowBack = () => { dispatch(updateEvQrcodeList([])); - navigate(-1) - } + navigate(-1); + }; if (isLoading) { return ; } const currentItem = anomalyData[currentIndex]; - const imageUrl = currentItem ? `https://docs.exampaper.vidh.ai/${currentItem.s3_path}` : ''; + const imageUrl = currentItem + ? `https://docs.exampaper.vidh.ai/${currentItem.s3_path}` + : ""; + + const handleKeyDown = (e) => { + if (e.key === "Enter") { + console.log("Updating ......"); + handleUpdate(); + } + }; return ( @@ -180,7 +210,10 @@ function EvQrcode() {
- @@ -193,7 +226,10 @@ function EvQrcode() { System No : {reduxSystemNo} )} - @@ -202,36 +238,77 @@ function EvQrcode() { {currentItem ? ( - - - - Records Count: {anomalyData.length} - Image Name: {currentItem.image_name} + + + + + Records Count: {anomalyData.length} + + + Image Name: {currentItem.image_name} + {/* S3 Path: {currentItem.s3_path} */} - Qrcode Value + + Qrcode Value + + onKeyDown={handleKeyDown} + inputRef={inputRef} + /> - - - - {currentItem.image_name} + + {currentItem.image_name} @@ -241,9 +318,13 @@ function EvQrcode() { {showSystemNoContainer && ( - + )} + {isLoading && } ); } diff --git a/src/Components/QueryCardEditor.jsx b/src/Components/QueryCardEditor.jsx index d7e10de..afae27d 100644 --- a/src/Components/QueryCardEditor.jsx +++ b/src/Components/QueryCardEditor.jsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from "react"; +import { useState, useEffect, useRef } from "react"; import { useSelector } from "react-redux"; import { useSearchParams } from "react-router-dom"; import { Box, Button } from "@mui/material"; @@ -37,8 +37,11 @@ const QueryCardEditor = () => { const paramsSysNo = searchParams.get("sysNo"); const paramsDegreeType = searchParams.get("degreeType"); const [items, setItems] = useState([]); - const [evErrorsData,setEvErrorsData] = useState([]); - + const [evErrorsData, setEvErrorsData] = useState([]); + const barcodeInputRef = useRef(null); + const qrInputRef = useRef(null); + const marksInputRef = useRef(null); + const subjectCodeInputRef = useRef(null); const navigate = useNavigate(); const dispatch = useDispatch(); console.log("Ev errors list ==== ", evErrorsList); @@ -71,22 +74,21 @@ const QueryCardEditor = () => { useEffect(() => { const marksLocalData = localStorage.getItem("marks_manual_data"); - console.log("Marks local data 123 ========= ",marksLocalData) + console.log("Marks local data 123 ========= ", marksLocalData); if (marksLocalData) { - console.log("Into if and updating .......") - console.log("marks local data ==== ",marksLocalData) + console.log("Into if and updating ......."); + console.log("marks local data ==== ", marksLocalData); setEvErrorsData(JSON.parse(marksLocalData)); } }, []); - useEffect(()=>{ - dispatch(updateSystemNo(paramsSysNo)) - },[paramsSysNo]) + useEffect(() => { + dispatch(updateSystemNo(paramsSysNo)); + }, [paramsSysNo]); - - useEffect(()=>{ - console.log("Ev error data =============== ",evErrorsData) - },[evErrorsData]) + useEffect(() => { + console.log("Ev error data =============== ", evErrorsData); + }, [evErrorsData]); useEffect(() => { const fetchData = async () => { @@ -116,11 +118,10 @@ const QueryCardEditor = () => { setSubjectCode(recordData?.subject_code); setS3Path(recordData?.s3_path); }, [recordData]); - const updateRecord = async () => { - if(!marks){ - return + if (!marks) { + return; } setIsLoading(true); try { @@ -132,7 +133,7 @@ const QueryCardEditor = () => { subjectCode, marks, imageName, - rotateAngle + rotateAngle, }; const response = await fetch( `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/editPartCdata`, @@ -150,7 +151,10 @@ const QueryCardEditor = () => { if (responseData?.status === "success") { toast.success("Record Updated Successfully ..."); var currentIndex = null; - console.log("Ev errors data before filter ============= ",evErrorsData) + console.log( + "Ev errors data before filter ============= ", + evErrorsData + ); var newRecords = evErrorsData.filter((data, index) => { if (data?.image_name === imageName) { currentIndex = index; @@ -158,8 +162,8 @@ const QueryCardEditor = () => { } return true; }); - if(!currentIndex){ - currentIndex = 0 + if (!currentIndex) { + currentIndex = 0; } console.log("new records ======1 ", newRecords); console.log("Current Index ===== ", currentIndex); @@ -219,10 +223,10 @@ const QueryCardEditor = () => { } }; -const skipPage = () =>{ - try{ - if(evErrorsData){ - var currentIndex = null + const skipPage = () => { + try { + if (evErrorsData) { + var currentIndex = null; var newRecords = evErrorsData.filter((data, index) => { if (data?.image_name === imageName) { currentIndex = index; @@ -230,53 +234,85 @@ const skipPage = () =>{ } return true; }); - if(!currentIndex){ - currentIndex = 0 + if (!currentIndex) { + currentIndex = 0; } console.log("Current Index ===== ", currentIndex); - const newIndex = currentIndex+1 - console.log("new index ===== ",newIndex) + const newIndex = currentIndex + 1; + console.log("new index ===== ", newIndex); if (newRecords.length > 0) { console.log("Has to navigte 12 ....."); const newUrl = `/sqlPlayground/edit?image_name=${evErrorsData[newIndex]?.image_name}&table=ocr_scanned_part_c_v1&error=${paramsError}&error_reason=${paramsErrorReason}°reeType=${paramsDegreeType}&sysNo=${paramsSysNo}`; console.log("new url ==== ", newUrl); window.location.href = newUrl; + } } + } catch (error) { + throw new Error(error); } - }catch(error){ - throw new Error(error) - } -} + }; + + const handleKeyDown = (e) => { + try { + console.log("Handle key down clicked ...", e); + console.log("event target ..... ", e.target); + console.log("barcode targed .....", barcodeInputRef.current); + if (e.key === "Enter") { + if (e.target === barcodeInputRef.current) { + qrInputRef.current.focus(); + } else if (e.target === qrInputRef.current) { + marksInputRef.current.focus(); + } else if (e.target === marksInputRef.current) { + subjectCodeInputRef.current.focus(); + } else if (e.target === subjectCodeInputRef.current) { + updateRecord(); + } + } + } catch (error) {} + }; return ( {imageName &&
ID : {imageName}
} - {paramsError &&
Error Code : {paramsError}
} + {paramsError && ( +
Error Code : {paramsError}
+ )} {paramsDegreeType ? ( - paramsDegreeType === 0 ?
Degree Type : UG
: -
Degree Type : PG
- ): null} + paramsDegreeType === 0 ? ( +
Degree Type : UG
+ ) : ( +
Degree Type : PG
+ ) + ) : null} +
+
+ +
+ ); +}; + +export default StudentResultsData; diff --git a/src/Components/TextInputField.jsx b/src/Components/TextInputField.jsx index 4aa7911..0b86fc0 100644 --- a/src/Components/TextInputField.jsx +++ b/src/Components/TextInputField.jsx @@ -1,10 +1,10 @@ -import { Label } from "@mui/icons-material"; import { TextField, Box } from "@mui/material"; +import React from 'react'; -const TextInputField = ({ placeholder, value, setValue }) => { +const TextInputField = React.forwardRef(({ placeholder, value, setValue, onKeyDown }, ref) => { return ( - ); -}; +}); export default TextInputField;