129 lines
3.5 KiB
JavaScript
129 lines
3.5 KiB
JavaScript
import { MailOutlined, PrinterOutlined, SignatureFilled } from "@ant-design/icons";
|
|
import { Space, Spin } from "antd";
|
|
import { useState } from "react";
|
|
import { connect } from "react-redux";
|
|
import { createStructuredSelector } from "reselect";
|
|
import { selectPrintCenter } from "../../redux/modals/modals.selectors";
|
|
import { selectTechnician } from "../../redux/tech/tech.selectors";
|
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
|
import { GenerateDocument } from "../../utils/RenderTemplate";
|
|
import LockWrapperComponent from "../lock-wrapper/lock-wrapper.component";
|
|
import { HasFeatureAccess } from "./../feature-wrapper/feature-wrapper.component";
|
|
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
|
import axios from "axios";
|
|
import { setModalContext } from "../../redux/modals/modals.actions.js";
|
|
import { hasDocumensoApiKey } from "../../utils/esignature.js";
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
printCenterModal: selectPrintCenter,
|
|
bodyshop: selectBodyshop,
|
|
technician: selectTechnician
|
|
});
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
setEsignatureContext: (context) =>
|
|
dispatch(
|
|
setModalContext({
|
|
context: context,
|
|
modal: "esignature"
|
|
})
|
|
)
|
|
});
|
|
|
|
export function PrintCenterItemComponent({
|
|
printCenterModal,
|
|
setEsignatureContext,
|
|
item,
|
|
id,
|
|
bodyshop,
|
|
disabled,
|
|
technician
|
|
}) {
|
|
const [loading, setLoading] = useState(false);
|
|
const { context } = printCenterModal;
|
|
const notification = useNotification();
|
|
const esignatureEnabled = hasDocumensoApiKey(bodyshop);
|
|
|
|
const renderToNewWindow = async () => {
|
|
setLoading(true);
|
|
await GenerateDocument(
|
|
{
|
|
name: item.key,
|
|
variables: { id: id }
|
|
},
|
|
{},
|
|
"p",
|
|
null,
|
|
notification
|
|
);
|
|
setLoading(false);
|
|
};
|
|
|
|
const esignatureGenerate = async () => {
|
|
setLoading(true);
|
|
try {
|
|
const {
|
|
data: { token, documentId, envelopeId }
|
|
} = await axios.post("/esign/new", {
|
|
name: item.key,
|
|
jobid: id,
|
|
context,
|
|
bodyshop,
|
|
templateObject: {
|
|
name: item.key,
|
|
variables: { id: id }
|
|
}
|
|
});
|
|
|
|
setEsignatureContext({ context: { token, documentId, envelopeId, jobid: id } });
|
|
} catch (error) {
|
|
console.log(error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
if (
|
|
disabled ||
|
|
(item.featureNameRestricted && !HasFeatureAccess({ featureName: item.featureNameRestricted, bodyshop }))
|
|
)
|
|
return (
|
|
<li className="print-center-item">
|
|
<LockWrapperComponent featureName={item.featureNameRestricted} bodyshop={bodyshop}>
|
|
{item.title}
|
|
</LockWrapperComponent>
|
|
</li>
|
|
);
|
|
return (
|
|
<li>
|
|
<Space wrap>
|
|
{item.title}
|
|
{esignatureEnabled && <SignatureFilled onClick={esignatureGenerate} />}
|
|
<PrinterOutlined onClick={renderToNewWindow} />
|
|
{!technician ? (
|
|
<MailOutlined
|
|
onClick={() => {
|
|
GenerateDocument(
|
|
{
|
|
name: item.key,
|
|
variables: { id: id }
|
|
},
|
|
{
|
|
to: context.job?.ownr_ea,
|
|
subject: item.subject
|
|
},
|
|
"e",
|
|
id,
|
|
notification
|
|
);
|
|
}}
|
|
/>
|
|
) : null}
|
|
{loading && <Spin />}
|
|
</Space>
|
|
</li>
|
|
);
|
|
}
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(PrintCenterItemComponent);
|