Files
bodyshop/client/src/components/print-center-item/print-center-item.component.jsx
Allan Carr 9319f492dd IO-2385 Enabled Emailing of TimeTicket & Attendance from Tech Console
Modify print center so that it will/wont display email option if technician is set and production board detail so that it wont display the remove from production / add to scoreboard if technician is set
2023-08-22 13:29:28 -07:00

77 lines
2.0 KiB
JavaScript

import { MailOutlined, PrinterOutlined } from "@ant-design/icons";
import { Space, Spin } from "antd";
import React, { useState } from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { setEmailOptions } from "../../redux/email/email.actions";
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";
const mapStateToProps = createStructuredSelector({
printCenterModal: selectPrintCenter,
bodyshop: selectBodyshop,
technician: selectTechnician,
});
const mapDispatchToProps = (dispatch) => ({
setEmailOptions: (e) => dispatch(setEmailOptions(e)),
});
export function PrintCenterItemComponent({
printCenterModal,
setEmailOptions,
item,
id,
bodyshop,
disabled,
technician,
}) {
const [loading, setLoading] = useState(false);
const { context } = printCenterModal;
const renderToNewWindow = async () => {
setLoading(true);
await GenerateDocument(
{
name: item.key,
variables: { id: id },
},
{},
"p"
);
setLoading(false);
};
if (disabled) return <li className="print-center-item">{item.title} </li>;
return (
<li>
<Space wrap>
{item.title}
<PrinterOutlined onClick={renderToNewWindow} />
{!technician ? (
<MailOutlined
onClick={() => {
GenerateDocument(
{
name: item.key,
variables: { id: id },
},
{
to: context.job && context.job.ownr_ea,
subject: item.subject,
},
"e",
id
);
}}
/>
) : null}
{loading && <Spin />}
</Space>
</li>
);
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(PrintCenterItemComponent);