temp/src/Components/PlayGroundEditContainer.jsx

276 lines
8.3 KiB
React
Raw Normal View History

2024-07-10 23:25:34 +05:30
import React, { useState, useEffect } from "react";
import Dialog from "@mui/material/Dialog";
import DialogContent from "@mui/material/DialogContent";
import DialogContentText from "@mui/material/DialogContentText";
import DialogTitle from "@mui/material/DialogTitle";
import { Button, Box } from "@mui/material";
import TextField from "@mui/material/TextField";
import { NavLink, Link } from "react-router-dom";
import TextInputField from "./TextInputField";
import { Height } from "@mui/icons-material";
import HighlightOffIcon from "@mui/icons-material/HighlightOff";
2024-07-14 08:58:24 +05:30
import LoadingContainer from "./LoadingContainer";
2024-07-24 03:22:56 +05:30
//import { toast } from "react-toastify";
2024-07-14 22:47:11 +05:30
import { updatePlayGroundAttendence } from "./Utilities/AttendencePlaygroundUtilities";
import { updateAttendenceBlank } from "./Utilities/AttendencePlaygroundUtilities";
2024-07-10 23:25:34 +05:30
const PlayGroundEditContainer = ({
data,
s3Path,
imageName,
tableName,
setShowEditContainer,
rotateAngle,
2024-07-14 22:47:11 +05:30
type,
2024-07-10 23:25:34 +05:30
}) => {
2024-07-12 17:54:43 +05:30
// const type = "PartC";
// const type = type;
2024-07-10 23:25:34 +05:30
const dialogText = "This is dialog text";
const [marks, setMarks] = useState(null);
2024-07-12 17:54:43 +05:30
const [registerNumber, setRegisterNumber] = useState(null);
2024-07-14 22:47:11 +05:30
const [totalStudents, setTotalStudents] = useState(null);
const [totalPresent, setTotalPresent] = useState(null);
const [totalAbsent, setTotalAbsent] = useState(null);
2024-07-10 23:25:34 +05:30
const [barcode, setBarcode] = useState(null);
const [isLoading, setIsLoading] = useState(false);
const [qrcode, setQrcode] = useState(null);
const [subjectCode, setSubjectCode] = useState(null);
const [open, setOpen] = useState(true); // Set open state to true by default
const handleClose = () => {
setOpen(false);
};
2024-07-16 17:50:16 +05:30
console.log("image_name ======================= ", imageName)
2024-07-10 23:25:34 +05:30
useEffect(() => {
if (data) {
setQrcode(data?.qrcode);
setBarcode(data?.barcode);
setMarks(data?.marks);
2024-07-14 22:47:11 +05:30
setSubjectCode(data?.subject_code);
setRegisterNumber(data?.register_number);
setTotalAbsent(data?.total_absent)
setTotalPresent(data?.total_present)
setTotalStudents(data?.total_students)
2024-07-10 23:25:34 +05:30
}
2024-07-14 22:47:11 +05:30
console.log("the currect editor type: ", type);
2024-07-10 23:25:34 +05:30
}, [data]);
2024-07-12 17:54:43 +05:30
const updateRecordPartC = async () => {
2024-07-10 23:25:34 +05:30
if (!marks) {
return;
}
setIsLoading(true);
try {
const payload = {
qrcode,
barcode,
2024-07-14 22:47:11 +05:30
table: tableName,
2024-07-10 23:25:34 +05:30
s3Path,
subjectCode,
marks,
imageName,
rotateAngle,
};
const response = await fetch(
`${import.meta.env.VITE_REACT_APP_BACKEND_URL}/editPartCdata`,
{
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") {
2024-07-24 03:22:56 +05:30
//toast.success("Record Updated Successfully ...");
2024-07-14 22:47:11 +05:30
setShowEditContainer(false);
2024-07-10 23:25:34 +05:30
}
} catch (error) {
setIsLoading(false);
2024-07-24 03:22:56 +05:30
//toast.error("Something Went Wrong ...");
2024-07-10 23:25:34 +05:30
throw new Error(error);
}
};
2024-07-12 17:54:43 +05:30
const updateRecordPartA = async () => {
2024-07-14 22:47:11 +05:30
console.log(registerNumber);
console.log(subjectCode);
console.log(barcode, qrcode);
2024-07-16 17:50:16 +05:30
console.log("image_name = ", imageName)
2024-07-14 22:47:11 +05:30
console.log(!registerNumber && !subjectCode && (!barcode || !qrcode));
2024-07-12 17:54:43 +05:30
if (!registerNumber && !subjectCode && (!barcode || !qrcode)) {
return;
}
setIsLoading(true);
try {
const payload = {
qrcode,
barcode,
2024-07-14 22:47:11 +05:30
table: tableName,
2024-07-12 17:54:43 +05:30
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") {
2024-07-24 03:24:31 +05:30
toast.success("Record Updated Successfully ...");
2024-07-14 22:47:11 +05:30
setShowEditContainer(false);
2024-07-12 17:54:43 +05:30
}
} catch (error) {
setIsLoading(false);
2024-07-24 03:22:56 +05:30
//toast.error("Something Went Wrong ...");
2024-07-12 17:54:43 +05:30
throw new Error(error);
}
};
2024-07-14 08:58:24 +05:30
const imageStyle = {
2024-07-14 22:47:11 +05:30
transform: `rotate(${rotateAngle})deg !important`,
};
2024-07-14 08:58:24 +05:30
2024-07-14 22:47:11 +05:30
console.log("Image style ====== ", imageStyle);
2024-07-14 08:58:24 +05:30
2024-07-10 23:25:34 +05:30
return (
2024-07-14 22:47:11 +05:30
<Dialog
open={open}
sx={{ zIndex: "fab" }}
onClose={handleClose}
maxWidth="xl"
style={{ zIndex: 100 }}
fullWidth
>
2024-07-10 23:25:34 +05:30
<DialogContent>
<Box className="d-flex justify-content-between align-items-start gap-4">
2024-07-14 22:47:11 +05:30
<Box className="d-flex flex-column" style={imageStyle}>
2024-07-10 23:25:34 +05:30
<img
src={`https://docs.exampaper.vidh.ai/${s3Path}`}
height={"100%"}
width={"100%"}
/>
</Box>
<Box className="py-3 d-flex flex-column justify-content-end w-100 gap-3">
2024-07-14 22:47:11 +05:30
{type !== "Attendence" ? (
<>
<TextInputField
value={qrcode}
setValue={setQrcode}
placeholder={"QR code"}
/>
<TextInputField
value={barcode}
setValue={setBarcode}
placeholder={"BarCode"}
/>
<TextInputField
value={subjectCode}
setValue={setSubjectCode}
placeholder={"Subject code"}
/>
</>
) : (
<>
<TextInputField
value={qrcode}
setValue={setQrcode}
placeholder={"QR code"}
/>
<TextInputField
value={subjectCode}
setValue={setSubjectCode}
placeholder={"Subject Code"}
/>
<TextInputField
value={totalStudents}
setValue={setTotalStudents}
placeholder={"Total Students"}
/>
2024-07-12 17:54:43 +05:30
<TextInputField
2024-07-14 22:47:11 +05:30
value={totalPresent}
setValue={setTotalPresent}
placeholder={"Total Present"}
2024-07-12 17:54:43 +05:30
/>
<TextInputField
2024-07-14 22:47:11 +05:30
value={totalAbsent}
setValue={setTotalAbsent}
placeholder={"Total Absent"}
2024-07-12 17:54:43 +05:30
/>
2024-07-14 22:47:11 +05:30
</>
)}
{type == "PartC" ? (
<TextInputField
value={marks}
setValue={setMarks}
placeholder={"Marks"}
/>
) : type == "PartA" ? (
<TextInputField
value={registerNumber}
setValue={setRegisterNumber}
placeholder={"Register no"}
/>
) : null}
{type == "PartC" ? (
<Button
className="bg-primary text-white p-3"
onClick={() => updateRecordPartC()}
>
Update
</Button>
) : type == "PartA" ? (
<Button
className="bg-primary text-white p-3"
onClick={() => updateRecordPartA()}
>
Update
</Button>
) : type == "Attendence" ? (
<Button
className="bg-primary text-white p-3"
onClick={() =>
updatePlayGroundAttendence(
setIsLoading,
qrcode,
subjectCode,
totalStudents,
totalPresent,
totalAbsent,
data,
setShowEditContainer
)
}
>
Update
</Button>
) : null}
2024-07-10 23:25:34 +05:30
<Button
className="bg-primary text-white p-3"
onClick={() => setShowEditContainer(false)}
>
Close
</Button>
</Box>
</Box>
</DialogContent>
2024-07-14 22:47:11 +05:30
{isLoading && <LoadingContainer />}
2024-07-10 23:25:34 +05:30
</Dialog>
);
};
export default PlayGroundEditContainer;