Refactor code

This commit is contained in:
RaktimaNXG
2023-12-08 17:11:01 +05:30
parent d224a44e54
commit e51feaa1fe
8 changed files with 243 additions and 171 deletions
@@ -0,0 +1,36 @@
import React from "react";
import Modal from "react-bootstrap/Modal";
import ModalHeader from "react-bootstrap/esm/ModalHeader";
function AlertComponent({ isShow, alertMessage, setIsAlert }) {
return (
<Modal show={isShow}>
<ModalHeader className="bg-danger" style={{ color: "white" }}>
<span>Alert</span>
</ModalHeader>
<Modal.Body>
<span>{alertMessage}</span>
</Modal.Body>
<Modal.Footer>
<button
onClick={() => {
setIsAlert({
isShow: false,
alertMessage: ""
});
}}
style={{
color: "black"
}}
type="button"
className="finishBtn"
>
Ok
</button>
</Modal.Footer>
</Modal>
);
}
export default AlertComponent;
@@ -16,9 +16,9 @@ function EmailComponent({
isCeleb,
setIsEmail,
setSuccessEmail,
signObjId,
pdfName,
sender
sender,
setIsAlert
}) {
const [emailList, setEmailList] = useState([]);
const [emailValue, setEmailValue] = useState();
@@ -62,11 +62,15 @@ function EmailComponent({
} catch (error) {
console.log("error", error);
setIsLoading(false);
alert("Something went wrong!");
setIsEmail(false);
setIsAlert({
isShow: true,
alertMessage: "something went wrong"
});
}
}
if (sendMail.data.result.status === "success") {
if (sendMail && sendMail.data.result.status === "success") {
setSuccessEmail(true);
setTimeout(() => {
setSuccessEmail(false);
@@ -76,12 +80,20 @@ function EmailComponent({
}, 1500);
setIsLoading(false);
} else if (sendMail.data.result.status === "error") {
} else if (sendMail && sendMail.data.result.status === "error") {
setIsLoading(false);
alert("Something went wrong!");
setIsEmail(false);
setIsAlert({
isShow: true,
alertMessage: "something went wrong"
});
} else {
setIsLoading(false);
alert("Something went wrong!");
setIsEmail(false);
setIsAlert({
isShow: true,
alertMessage: "something went wrong"
});
}
};
@@ -63,9 +63,7 @@ function RenderPdf({
width = pos.Width ? pos.Width : 150;
return width;
} else {
width = pos.Width / scale ? pos.Width / scale : 150 / scale;
// width =
// pos.Width * pos.scale ? pos.Width * pos.scale : 150 * pos.scale;
width = (pos.Width || 150) / scale;
return width;
}
} else {
@@ -78,7 +76,7 @@ function RenderPdf({
width = pos.Width ? pos.Width : 150;
return width;
} else {
width = pos.Width ? pos.Width * pos.scale : 150 * pos.scale;
width = (pos.Width || 150) * pos.scale;
return width;
}
} else {
@@ -92,12 +90,10 @@ function RenderPdf({
if (isMobile) {
if (!pos.isMobile) {
if (pos.IsResize) {
// height = pos.Height ? pos.Height / scale : 60 / scale;
height = pos.Height ? pos.Height : 60;
return height;
} else {
height = pos.Height ? pos.Height / scale : 60 / scale;
// height = pos.Height ? pos.Height * pos.scale : 60 * pos.scale;
height = (pos.Height || 60) / scale;
return height;
}
} else {
@@ -110,7 +106,7 @@ function RenderPdf({
height = pos.Height ? pos.Height : 60;
return height;
} else {
height = pos.Height ? pos.Height * pos.scale : 60 * pos.scale;
height = (pos.Height || 60) * pos.scale;
return height;
}
} else {
@@ -298,46 +294,6 @@ function RenderPdf({
}
};
const calculateWidth = (pos) => {
let width;
if (isMobile) {
width = pos.Width ? pos.Width * scale : 150 * scale;
return width;
} else {
if (pos.isMobile) {
if (pos.IsResize) {
width = pos.Width ? pos.Width : 150;
return width;
} else {
width = pos.Width ? pos.Width * pos.scale : 150 * pos.scale;
return width;
}
} else {
width = pos.Width ? pos.Width : 150;
return width;
}
}
};
const calculateHeight = (pos) => {
let height;
if (isMobile) {
height = pos.Height ? pos.Height * scale : 60 * scale;
return height;
} else {
if (pos.isMobile) {
if (pos.IsResize) {
height = pos.Height ? pos.Height : 60;
return height;
} else {
height = pos.Height ? pos.Height * pos.scale : 60 * pos.scale;
return height;
}
} else {
height = pos.Height ? pos.Height : 60;
return height;
}
}
};
return (
<>
{isMobile && scale ? (
@@ -817,8 +773,8 @@ function RenderPdf({
}}
className="placeholderBlock"
size={{
width: calculateWidth(pos),
height: calculateHeight(pos)
width: posWidth(pos),
height: posHeight(pos)
}}
lockAspectRatio={pos.Width && 2.5}
//if pos.isMobile false -- placeholder saved from mobile view then handle position in desktop view to multiply by scale