Further work on async email modal. Correctly sending basic emails.

This commit is contained in:
Patrick Fic
2020-02-20 17:23:56 -08:00
parent cf461b0536
commit 1344198447
7 changed files with 111 additions and 30 deletions

View File

@@ -722,6 +722,63 @@
</folder_node> </folder_node>
</children> </children>
</folder_node> </folder_node>
<folder_node>
<name>emails</name>
<children>
<folder_node>
<name>errors</name>
<children>
<concept_node>
<name>notsent</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
</children>
</folder_node>
<folder_node>
<name>successes</name>
<children>
<concept_node>
<name>sent</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
</children>
</folder_node>
</children>
</folder_node>
<folder_node> <folder_node>
<name>employees</name> <name>employees</name>
<children> <children>

View File

@@ -1,17 +1,13 @@
import { Button, Modal } from "antd"; import { Button, Modal, notification } from "antd";
import axios from "axios";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { useLazyQuery } from "react-apollo"; import { useLazyQuery } from "react-apollo";
import { renderEmail } from "react-html-email"; import { renderEmail } from "react-html-email";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import { import { toggleEmailOverlayVisible } from "../../redux/email/email.actions";
sendEmail, import { selectEmailConfig, selectEmailVisible } from "../../redux/email/email.selectors.js";
toggleEmailOverlayVisible
} from "../../redux/email/email.actions";
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";
@@ -20,18 +16,13 @@ const mapStateToProps = createStructuredSelector({
emailConfig: selectEmailConfig emailConfig: selectEmailConfig
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
toggleEmailOverlayVisible: () => dispatch(toggleEmailOverlayVisible()), toggleEmailOverlayVisible: () => dispatch(toggleEmailOverlayVisible())
sendEmail: email => dispatch(sendEmail(email))
}); });
export default connect( export default connect(
mapStateToProps, mapStateToProps,
mapDispatchToProps mapDispatchToProps
)(function SendEmail({ )(function SendEmail({ emailConfig, modalVisible, toggleEmailOverlayVisible }) {
emailConfig, const { t } = useTranslation();
modalVisible,
sendEmail,
toggleEmailOverlayVisible
}) {
const [messageOptions, setMessageOptions] = useState( const [messageOptions, setMessageOptions] = useState(
emailConfig.messageOptions emailConfig.messageOptions
); );
@@ -57,7 +48,6 @@ export default connect(
} }
if (data && !messageOptions.html && emailConfig.template) { if (data && !messageOptions.html && emailConfig.template) {
//console.log(ReactDOMServer.renderToStaticMarkup(<Template data={data} />));
setMessageOptions({ setMessageOptions({
...messageOptions, ...messageOptions,
//html: ReactDOMServer.renderToStaticMarkup(<Template data={data} />) //html: ReactDOMServer.renderToStaticMarkup(<Template data={data} />)
@@ -66,8 +56,20 @@ export default connect(
} }
const handleOk = () => { const handleOk = () => {
sendEmail("Clicked OK"); //sendEmail(messageOptions);
toggleEmailOverlayVisible(); axios
.post("/sendemail", messageOptions)
.then(response => {
console.log(JSON.stringify(response));
notification["success"]({ message: t("emails.successes.sent") });
toggleEmailOverlayVisible();
})
.catch(error => {
console.log(JSON.stringify(error));
notification["error"]({
message: t("emails.errors.notsent", { message: error.message })
});
});
}; };
const handleConfigChange = event => { const handleConfigChange = event => {
const { name, value } = event.target; const { name, value } = event.target;

View File

@@ -72,12 +72,9 @@ export default function Manage({ match }) {
fallback={ fallback={
<LoadingSpinner message={t("general.labels.loadingapp")} /> <LoadingSpinner message={t("general.labels.loadingapp")} />
}> }>
<div> DELETE THIS
DELETE THESE <Test />
<Test /> <EmailOverlayContainer />
<EmailOverlayContainer />
</div>
<Route exact path={`${match.path}`} component={ManageRootPage} /> <Route exact path={`${match.path}`} component={ManageRootPage} />
<Route exact path={`${match.path}/jobs`} component={JobsPage} /> <Route exact path={`${match.path}/jobs`} component={JobsPage} />
<Route <Route

View File

@@ -1,6 +1,7 @@
import { all, call, put, takeLatest } from "redux-saga/effects"; import { all, call, put, takeLatest } from "redux-saga/effects";
import { sendEmailFailure, sendEmailSuccess } from "./email.actions"; import { sendEmailFailure, sendEmailSuccess } from "./email.actions";
import EmailActionTypes from "./email.types"; import EmailActionTypes from "./email.types";
import axios from "axios";
export function* onSendEmail() { export function* onSendEmail() {
yield takeLatest(EmailActionTypes.SEND_EMAIL, sendEmail); yield takeLatest(EmailActionTypes.SEND_EMAIL, sendEmail);
@@ -8,10 +9,10 @@ export function* onSendEmail() {
export function* sendEmail(payload) { export function* sendEmail(payload) {
try { try {
console.log("Sending thta email", payload); console.log("Sending thta email", payload);
// // axios.post("/sendemail", emailConfig).then(response => { axios.post("/sendemail", payload).then(response => {
// alert(JSON.stringify(response)); console.log(JSON.stringify(response));
// }); put(sendEmailSuccess());
yield put(sendEmailSuccess()); });
} catch (error) { } catch (error) {
console.log("Error in sendEmail saga."); console.log("Error in sendEmail saga.");
yield put(sendEmailFailure(error.message)); yield put(sendEmailFailure(error.message));

View File

@@ -67,6 +67,14 @@
"insert": "Uploaded document successfully. " "insert": "Uploaded document successfully. "
} }
}, },
"emails": {
"errors": {
"notsent": "Email not sent. Error encountered while sending {{message}}"
},
"successes": {
"sent": "Email sent successfully."
}
},
"employees": { "employees": {
"actions": { "actions": {
"new": "New Employee" "new": "New Employee"

View File

@@ -67,6 +67,14 @@
"insert": "Documento cargado con éxito." "insert": "Documento cargado con éxito."
} }
}, },
"emails": {
"errors": {
"notsent": "Correo electrónico no enviado Se encontró un error al enviar {{message}}"
},
"successes": {
"sent": "Correo electrónico enviado con éxito."
}
},
"employees": { "employees": {
"actions": { "actions": {
"new": "Nuevo empleado" "new": "Nuevo empleado"

View File

@@ -67,6 +67,14 @@
"insert": "Document téléchargé avec succès." "insert": "Document téléchargé avec succès."
} }
}, },
"emails": {
"errors": {
"notsent": "Courriel non envoyé. Erreur rencontrée lors de l'envoi de {{message}}"
},
"successes": {
"sent": "E-mail envoyé avec succès."
}
},
"employees": { "employees": {
"actions": { "actions": {
"new": "Nouvel employé" "new": "Nouvel employé"