BOD-34 Moved template rendering to utility class. Added basic config for some estimate reports.

This commit is contained in:
Patrick Fic
2020-04-28 16:41:36 -07:00
parent 113bf3f0fb
commit c6a29ba417
14 changed files with 396 additions and 133 deletions

View File

@@ -3,9 +3,13 @@ import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { setEmailOptions } from "../../redux/email/email.actions";
import { selectPrintCenter } from "../../redux/modals/modals.selectors";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { MailOutlined, PrinterOutlined } from "@ant-design/icons";
import RenderTemplate from "../../utils/RenderTemplate";
import { useApolloClient } from "@apollo/react-hooks";
const mapStateToProps = createStructuredSelector({
printCenterModal: selectPrintCenter,
bodyshop: selectBodyshop,
});
const mapDispatchToProps = (dispatch) => ({
setEmailOptions: (e) => dispatch(setEmailOptions(e)),
@@ -15,8 +19,46 @@ export function PrintCenterItemComponent({
printCenterModal,
setEmailOptions,
item,
id,
bodyshop,
disabled,
}) {
return <li>{item.title}</li>;
const client = useApolloClient();
const renderToNewWindow = async () => {
const html = await RenderTemplate(
{
name: item.key,
variables: { id: id },
},
client,
bodyshop
);
var newWin = window.open();
newWin.document.write(html);
};
if (disabled) return <li className='print-center-item'>{item.title} </li>;
return (
<li className='print-center-item'>
{item.title}
<PrinterOutlined onClick={renderToNewWindow} />
<MailOutlined
onClick={() => {
setEmailOptions({
messageOptions: {
Subject: "TODO FIX ME",
},
template: {
name: item.key,
variables: { id: id },
},
});
}}
/>
</li>
);
}
export default connect(
mapStateToProps,