Added redux based email overlay to parts order modal + built out barebones parts order email template.

This commit is contained in:
Patrick Fic
2020-02-20 19:01:12 -08:00
parent 1344198447
commit a51915c0ea
6 changed files with 125 additions and 40 deletions

View File

@@ -30,14 +30,8 @@ export default function SendEmailButtonComponent({
<CKEditor <CKEditor
editor={ClassicEditor} editor={ClassicEditor}
data={messageOptions.html} data={messageOptions.html}
onInit={editor => {
//You can store the "editor" and use when it is needed.
console.log("Editor is ready to use!", editor);
}}
onChange={(event, editor) => { onChange={(event, editor) => {
const data = editor.getData(); handleHtmlChange(editor.getData());
console.log({ event, editor, data });
handleHtmlChange(data);
}} }}
/> />
</div> </div>

View File

@@ -7,9 +7,13 @@ import { useTranslation } from "react-i18next";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import { toggleEmailOverlayVisible } from "../../redux/email/email.actions"; import { toggleEmailOverlayVisible } from "../../redux/email/email.actions";
import { selectEmailConfig, selectEmailVisible } from "../../redux/email/email.selectors.js"; import {
selectEmailConfig,
selectEmailVisible
} from "../../redux/email/email.selectors.js";
import LoadingSpinner from "../loading-spinner/loading-spinner.component"; import LoadingSpinner from "../loading-spinner/loading-spinner.component";
import EmailOverlayComponent from "./email-overlay.component"; import EmailOverlayComponent from "./email-overlay.component";
import ReactDOMServer from "react-dom/server";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
modalVisible: selectEmailVisible, modalVisible: selectEmailVisible,
@@ -50,8 +54,10 @@ export default connect(
if (data && !messageOptions.html && emailConfig.template) { if (data && !messageOptions.html && emailConfig.template) {
setMessageOptions({ setMessageOptions({
...messageOptions, ...messageOptions,
//html: ReactDOMServer.renderToStaticMarkup(<Template data={data} />) html: ReactDOMServer.renderToStaticMarkup(
html: renderEmail(<emailConfig.template data={data} />) <emailConfig.template data={data} />
)
//html: renderEmail(<emailConfig.template data={data} />)
}); });
} }

View File

@@ -14,21 +14,33 @@ import {
import AlertComponent from "../alert/alert.component"; import AlertComponent from "../alert/alert.component";
import LoadingSpinner from "../loading-spinner/loading-spinner.component"; import LoadingSpinner from "../loading-spinner/loading-spinner.component";
import PartsOrderModalComponent from "./parts-order-modal.component"; import PartsOrderModalComponent from "./parts-order-modal.component";
import {
setEmailOptions,
toggleEmailOverlayVisible
} from "../../redux/email/email.actions";
import PartsOrderEmailTemplate from "../../emails/parts-order/parts-order.email";
import { REPORT_QUERY_PARTS_ORDER_BY_PK } from "../../emails/parts-order/parts-order.query";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
currentUser: selectCurrentUser, currentUser: selectCurrentUser,
bodyshop: selectBodyshop bodyshop: selectBodyshop
}); });
const mapDispatchToProps = dispatch => ({
setEmailOptions: e => dispatch(setEmailOptions(e)),
toggleEmailOverlayVisible: () => dispatch(toggleEmailOverlayVisible())
});
export default connect( export default connect(
mapStateToProps, mapStateToProps,
null mapDispatchToProps
)(function PartsOrderModalContainer({ )(function PartsOrderModalContainer({
partsOrderModalVisible, partsOrderModalVisible,
linesToOrder, linesToOrder,
jobId, jobId,
currentUser, currentUser,
bodyshop, bodyshop,
refetch refetch,
setEmailOptions,
toggleEmailOverlayVisible
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const [modalVisible, setModalVisible] = partsOrderModalVisible; const [modalVisible, setModalVisible] = partsOrderModalVisible;
@@ -51,6 +63,7 @@ export default connect(
const orderLines = orderLinesState[0]; const orderLines = orderLinesState[0];
const sendTypeState = useState("e"); const sendTypeState = useState("e");
const sendType = sendTypeState[0];
const partsOrderState = useState({ const partsOrderState = useState({
vendorid: null, vendorid: null,
jobid: jobId, jobid: jobId,
@@ -92,6 +105,32 @@ export default connect(
}); });
if (refetch) refetch(); if (refetch) refetch();
setModalVisible(false); setModalVisible(false);
if (sendType === "e") {
//Show the email modal and set the data.
//TODO Remove some of the options below.
setEmailOptions({
messageOptions: {
from: {
name: "Kavia Autobdoy",
address: "noreply@bodyshop.app"
},
to: "patrickwf@gmail.com",
replyTo: "snaptsoft@gmail.com"
},
template: PartsOrderEmailTemplate,
queryConfig: [
REPORT_QUERY_PARTS_ORDER_BY_PK,
{
variables: {
id: r.data.insert_parts_orders.returning[0].id
}
}
]
});
toggleEmailOverlayVisible();
}
}) })
.catch(error => { .catch(error => {
notification["error"]({ notification["error"]({

View File

@@ -1,6 +1,6 @@
import React from "react"; import React from "react";
function Cell({ children }) { function Column({ children }) {
return <td>{children}</td>; return <td>{children}</td>;
} }
@@ -8,7 +8,7 @@ function Row({ children }) {
return ( return (
<tr> <tr>
{React.Children.map(children, el => { {React.Children.map(children, el => {
if (el.type === Cell) return el; if (el.type === Column) return el;
return <td>{el}</td>; return <td>{el}</td>;
})} })}
@@ -25,7 +25,7 @@ function Grid({ children }) {
if (el.type === Row) return el; if (el.type === Row) return el;
if (el.type === Cell) { if (el.type === Column) {
return <tr>{el}</tr>; return <tr>{el}</tr>;
} }
@@ -41,6 +41,6 @@ function Grid({ children }) {
} }
Grid.Row = Row; Grid.Row = Row;
Grid.Cell = Cell; Grid.Column = Column;
export default Grid; export default Grid;

View File

@@ -0,0 +1,23 @@
import React from "react";
export default function Header({ bodyshop }) {
return (
<table>
<tr>
<td>
<img alt='' src={bodyshop.logo_img_path} />
</td>
<td>
<div>
<strong>{`${bodyshop.shopname}`}</strong>
</div>
<div>{`${bodyshop.address1} ${bodyshop.address2} ${bodyshop.city} ${bodyshop.state} ${bodyshop.zip_post}`}</div>
<div>
<a href={`mailto:${bodyshop.email}`}>{bodyshop.email}</a>{" "}
{` | ${bodyshop.ph1}`}
</div>
</td>
</tr>
</table>
);
}

View File

@@ -1,30 +1,53 @@
import React from "react"; import React from "react";
import { A, Box, Email, Item, Span } from "react-html-email"; import styled from "styled-components";
import Header from "../components/header/header.component";
const D = styled.div`
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,
th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
`;
export default function PartsOrderEmail({ data }) { export default function PartsOrderEmail({ data }) {
console.log("Data", data); const order = data.parts_orders_by_pk;
return ( return (
<Email title='Hello World!'> <D>
<Box> <Header bodyshop={data.bodyshops[0]} />
<Item align='center'> <table>
<Span fontSize={20}> <tr>
This is an example email made with: <td>{`Deliver By: ${order.deliver_by}`}</td>
<A href='https://github.com/chromakode/react-html-email'> <td>{`Ordered By: ${order.user_email}`}</td>
react-html-email </tr>
</A> </table>
. <table>
</Span> <tr>
</Item> <th>Line Description</th>
<Item align='center'> <th>Part #</th>
<Span fontSize={20}> <th>Price</th>
This is an example email made with: <th>Line Remarks</th>
<A href='https://github.com/chromakode/react-html-email'> </tr>
react-html-email {order.parts_order_lines.map(item => (
</A> <tr key={item.id}>
. <td>{item.line_desc}</td>
</Span> <td>{item.oem_partno}</td>
</Item> <td>{item.act_price}</td>
</Box> <td>{item.line_remarks}</td>
</Email> </tr>
))}
</table>
</D>
); );
} }