import { Box, Button } from "@mui/material"; import DownloadIcon from "@mui/icons-material/Download"; import { LazyLoadImage } from "react-lazy-load-image-component"; import { Label, MoreHorizTwoTone, RotateRight } from "@mui/icons-material"; import { useState, useEffect, useRef } from "react"; import { ToastContainer, toast } from "react-toastify"; import LoadingContainer from "./LoadingContainer"; import { useNavigate } from "react-router-dom"; // import "react-toastify/dist/ReactToastify.css"; import RotateLeftIcon from "@mui/icons-material/RotateLeft"; import RotateRightIcon from "@mui/icons-material/RotateRight"; import PlayGroundEditContainer from "./PlayGroundEditContainer"; import saveRotatedImage from "./Utilities/PartCPlaygroundUtilities"; import markAsPartc from "./Utilities/PartAPlaygroundUtilities"; import { updateAttendenceBlank } from "./Utilities/AttendencePlaygroundUtilities"; import TextInputField from "./TextInputField"; import ArrowBackIcon from "@mui/icons-material/ArrowBack"; import ArrowForwardIcon from "@mui/icons-material/ArrowForward"; const UpdatedPlaygroundUpdater = ({ oldData, s3_image_column, query, error, error_reason, reduxSystemNo, degreeType, type, tableName, currentCardIndex, setCurrentCardIndex, setCardData, totalData, }) => { // console.log("ERROR ============= ",error) // console.log("ERROR REASON ============== ",error_reason) // console.log("REDUX SYSTEM NO ================== ",reduxSystemNo) const navigate = useNavigate(); const [dataValue, setDataValue] = useState({}); const [isLoading, setIsLoading] = useState(false); // console.log("data in query executor Card : ", data); const [keys, setKeys] = useState([]); const [values, setValues] = useState([]); const [rotateAngle, setRotateAngle] = useState(0); const [imageName, setImageName] = useState(null); const [tableNameData, setTableNameData] = useState(null); const imageEleRef = useRef(); const [showEditContainer, setShowEditContainer] = useState(false); const [editorType, setEditorType] = useState(null); const dialogText = "This is dialog text"; const [marks, setMarks] = useState(null); const [registerNumber, setRegisterNumber] = useState(null); const [totalStudents, setTotalStudents] = useState(null); const [totalPresent, setTotalPresent] = useState(null); const [totalAbsent, setTotalAbsent] = useState(null); // const [barcode, setBarcode] = useState(null); const [qrcode, setQrcode] = useState(null); const [bar_code, set_Barcode] = useState(null); const [s3Path, setS3Path] = useState(null); const [subjectCode, setSubjectCode] = useState(null); const [data,setData] = useState(null) const [open, setOpen] = useState(true); // Set open state to true by default const handleClose = () => { setOpen(false); }; useEffect(() => { console.log("data ========== ", data); if (data) { console.log("barcode = ", data.barcode) setQrcode(data.qrcode); // set_Barcode(data.barcode) set_Barcode(data.barcode === '' ? null : data.barcode); setMarks(data.marks); setS3Path(data.s3_path); setSubjectCode(data.subject_code); setRegisterNumber(data.register_number); setTotalAbsent(data?.total_absent); setTotalPresent(data?.total_present); setTotalStudents(data?.total_students); setRotateAngle(0); } console.log("the currect editor type: ", type); }, [data]); // useEffect(() => { // console.log("barcode in use effect ==== ", barcode); // }, [barcode]); console.log("data =================== ", data); // console.log("image column ====== ", s3_image_column); // console.log("s3 image ======= ", data[s3_image_column]); // console.log("Keys ==== ",keys) // console.log("Values ===== ",values) useEffect(() => { if (data) { console.log("Image name ====== ", data?.image_name); setImageName(data?.image_name); } if (tableName) { setTableNameData(tableName); } if (data?.subject_code) { } }, [data]); const updatePartAInstructions = async () => { console.log("update instrunction"); const payload = { data, }; try { setIsLoading(true); const response = await fetch( `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/updatePartAInstructions`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(payload), } ); setIsLoading(false); const responseData = await response.json(); if (responseData?.status === "success") { console.log("Updation successfull ...."); const updatedData = { ...dataValue, is_backpage: 1 }; // console.log("Data ===== ", updatedData); setDataValue(updatedData); // toast.success("Record Marked as Backpage ! ...."); } else { throw new Error(responseData?.message); } } catch (error) { throw new Error(error); } }; const updatePartAFront = async () => { console.log("update front"); const payload = { data, }; try { setIsLoading(true); const response = await fetch( `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/partAFrontSideMarking`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(payload), } ); setIsLoading(false); const responseData = await response.json(); if (responseData.status === "success") { console.log("Updation successfull ...."); const updatedData = { ...dataValue, is_backpage: 1 }; // console.log("Data ===== ", updatedData); setDataValue(updatedData); // toast.success("Record Marked as Backpage ! ...."); } else { throw new Error(responseData?.message); } } catch (error) { throw new Error(error); } }; const updateFront = async () => { console.log("update front"); const payload = { data, }; try { setIsLoading(true); const response = await fetch( `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/partcEvFrontSideMarking`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(payload), } ); setIsLoading(false); const responseData = await response.json(); if (responseData.status === "success") { console.log("Updation successfull ...."); const updatedData = { ...dataValue, is_backpage: 1 }; // console.log("Data ===== ", updatedData); setDataValue(updatedData); toast.success("Record Marked as Frontpage ! ...."); } else { toast.error("Something Went Wrong !..."); setIsLoading(false); throw new Error(responseData?.message); } } catch (error) { throw new Error(error); } }; const updateBack = async () => { const payload = { data, }; try { setIsLoading(true); const response = await fetch( `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/partcEvBacksideMarking`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(payload), } ); setIsLoading(false); const responseData = await response.json(); if (responseData.status === "success") { console.log("Updation successfull ...."); const updatedData = { ...dataValue, is_backpage: 1 }; // console.log("Data ===== ", updatedData); setDataValue(updatedData); toast.success("Record Marked as Backpage ! ...."); } else { setIsLoading(false); toast.error("Something Went Wrong !..."); throw new Error(responseData?.message); } } catch (error) { throw new Error(error); } }; const initateProcess = () => { console.log("inititate process.."); }; const rotateLeft = () => { console.log("rotate left ....."); const newAngle = rotateAngle - 90; setRotateAngle((prev) => prev - 90); console.log("new angle ....", newAngle); const newStyle = `rotate(${newAngle}deg)`; imageEleRef.current.style.transform = newStyle; }; const rotateRight = () => { console.log("rotate right"); const newAngle = rotateAngle + 90; setRotateAngle((prev) => prev + 90); const newStyle = `rotate(${newAngle}deg)`; imageEleRef.current.style.transform = newStyle; }; const updateEvCover = async () => { const payload = { data, }; try { setIsLoading(true); const response = await fetch( `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/partcEvCoverMarking`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(payload), } ); setIsLoading(false); const responseData = await response.json(); if (responseData.status === "success") { const updatedData = { ...dataValue, is_cover: 1 }; // console.log("Data ===== ", updatedData); setDataValue(updatedData); console.log("Updation successfull ...."); // toast.success("Record Marked As Ev !..."); } else { throw new Error(responseData?.message); } } catch (error) { throw new Error(error); } }; const markAsDummy = async () => { const payload = { data, }; try { setIsLoading(true); const response = await fetch( `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/partcEvDummyMarking`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(payload), } ); setIsLoading(false); const responseData = await response.json(); if (responseData.status === "success") { const updatedData = { ...dataValue, is_cover: 1 }; // console.log("Data ===== ", updatedData); setDataValue(updatedData); console.log("Updation successfull ...."); toast.success("Record Marked As Ev !..."); } else { setIsLoading(false); toast.error("Something Went Wrong !..."); throw new Error(responseData?.message); } } catch (error) { setIsLoading(false); toast.error("Something Went Wrong !..."); throw new Error(error); } }; const showContainerAction = () => { setShowEditContainer(true); console.log("type === ", type); // setEditorType(type) }; const updateAttendenceBlankAction = () => { updateAttendenceBlank(setIsLoading, data, setShowEditContainer); }; const buttonActions = { PartC: [ { btnLabel: "Mark As Front", action: updateFront }, { btnLabel: "Mark As Back", action: updateBack }, { btnLabel: "Mark As Ev", action: updateEvCover }, { btnLabel: "Mark As Dummy", action: markAsDummy }, { btnLabel: "Edit", action: showContainerAction }, ], PartA: [ { btnLabel: "Mark As Front", action: updatePartAFront }, { btnLabel: "Mark As Backpage", action: updatePartAInstructions }, // { btnLabel: "Initiate Process", action: initateProcess }, { btnLabel: "Mark As Dummy", action: markAsDummy }, { btnLabel: "Mark As Part-C", action: markAsPartc }, { btnLabel: "Edit", action: showContainerAction }, ], Attendence: [ { btnLabel: "Mark As Blank", action: updateAttendenceBlankAction }, { btnLabel: "Edit", action: showContainerAction }, ], }; // useEffect(() => { // setDataValue(data); // setKeys(Object.keys(data)); // setValues(Object.values(data)); // }, [data]); useEffect(() => { console.log("Data value ===== ", dataValue); setKeys(Object.keys(dataValue)); setValues(Object.values(dataValue)); }, [dataValue]); const rotate_and_process = async () => { setIsLoading(true); try { const payload = { data, }; const response = await fetch( `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/partCRotateProcess`, { method: "POST", header: { "Content-Type": "application/json", }, body: JSON.stringify(payload), } ); const responseData = await response.json(); setIsLoading(false); if (responseData.status === "success") { console.log("Response successfull ..."); } } catch (error) { setIsLoading(false); throw new Error(error); } }; const updateRecordPartA = async () => { console.log(registerNumber); console.log(subjectCode); console.log(bar_code, qrcode); console.log(!registerNumber && !subjectCode && (!bar_code || !qrcode)); if (!registerNumber && !subjectCode && (!bar_code || !qrcode)) { return; } setIsLoading(true); try { const payload = { qrcode, barcode: bar_code, table: tableName, s3Path, subjectCode, registerNumber, imageName, rotateAngle, }; const response = await fetch( `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/editPartAdata`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(payload), } ); const responseData = await response.json(); setIsLoading(false); console.log("response data ========= ", responseData); if (responseData?.status === "success") { //toast.success("Record Updated Successfully ..."); if (totalData) { console.log("current total length ... ", totalData?.length); console.log("current current index ...", currentCardIndex); if (currentCardIndex < totalData?.length - 1) { setCurrentCardIndex((prev) => prev + 1); } } const newCurrentIndex = currentCardIndex + 1; } } catch (error) { setIsLoading(false); //toast.error("Something Went Wrong ..."); throw new Error(error); } }; const saveRotatedImage = async () => { try { if (rotateAngle === 0) { return; } const payload = { imageName, tableNameData, rotateAngle, s3_path: data[s3_image_column], }; setIsLoading(true); const response = await fetch( `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/saveRotatedImage`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(payload), } ); setIsLoading(false); const responseData = await response.json(); if (responseData.status === "success") { toast.success("Image Rotation Saved Successfully"); } else { toast.error("Something Went Wrong !..."); } } catch (error) { setIsLoading(false); toast.error("Something Went Wrong !..."); throw new Error(error); } }; useEffect(() => { if (oldData?.image_name && tableName) { const fetchPrimaryKeyData = async () => { setIsLoading(true) try { const payload = { table: tableName, image_name: oldData?.image_name, }; const response = await fetch( `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/fetchPrimaryKeyData`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(payload), } ); const responseData = await response.json(); console.log("response json 11 === ", responseData); setIsLoading(false) if (responseData?.status === "success") { const results = responseData?.data; console.log("results ==== ", results); if (results?.length > 0) { console.log("results === ", results); setData(results[0]); } } } catch (error) { setIsLoading(false) throw new Error(error); } }; setTimeout(() => { fetchPrimaryKeyData(); }, 200); } }, [oldData]); return ( {/* {query.includes("ocr_scanned_part_c_v1") && data[s3_image_column] && ( <> )} */} {/* */} Image Alt {/* {type && buttonActions[type].map((action) => ( ))} */} {type !== "Attendence" ? ( <> ) : ( <> )} {type == "PartC" ? ( ) : type == "PartA" ? ( ) : null} {/* */} {type == "PartC" ? ( ) : type == "PartA" ? ( ) : type == "Attendence" ? ( ) : null} {/* */} {isLoading && } {showEditContainer && ( )} ); }; export default UpdatedPlaygroundUpdater;