Skip to content

Commit

Permalink
Fix Exception in delivering result of invoking 'email/verifySettings' (
Browse files Browse the repository at this point in the history
…#2512)

* Only verify email settings when saving settings

* Move server method call to container component

* Fix import order
  • Loading branch information
Awa Desmoline authored and jshimko committed Jul 7, 2017
1 parent ea05907 commit 16d83b1
Showing 1 changed file with 52 additions and 15 deletions.
67 changes: 52 additions & 15 deletions imports/plugins/core/email/client/containers/emailConfig.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { useDeps } from "react-simple-di";
import getServiceConfig from "nodemailer-wellknown";
import { Meteor } from "meteor/meteor";
Expand All @@ -7,32 +9,67 @@ import actions from "../actions";
import EmailConfig from "../components/emailConfig";
import { composeWithTracker, merge } from "/lib/api/compose";

const composer = ({}, onData) => {
if (Meteor.subscribe("Packages").ready()) {
const shopSettings = Reaction.getShopSettings();
const settings = shopSettings.mail || {};
class EmailConfigContainer extends Component {

if (settings.service && settings.service !== "custom") {
const config = getServiceConfig(settings.service);
constructor(props) {
super(props);

// show localhost for test providers like Maildev that have no host
settings.host = config.host || "localhost";
settings.port = config.port;
}
this.state = {
status: null,
error: null
};
}

componentWillMount() {
const { settings } = this.props;
const { service, host, port, user, password } = settings;

// if all settings exist, check if they work
if (service && host && port && user && password) {
Meteor.call("email/verifySettings", (error) => {
if (error) {
return onData(null, { settings, status: "error", error: error.reason });
this.setState({ status: "error" });
}
return onData(null, { settings, status: "valid", error: null });
this.setState({ status: "valid" });
});
} else {
onData(null, { settings, status: "error", error: null });
this.setState({ status: "error" });
}
}

render() {
const { status } = this.state;
return (
<EmailConfig {...this.props} status={status} />
);
}
}

EmailConfigContainer.propTypes = {
settings: PropTypes.shape({
host: PropTypes.string,
password: PropTypes.string,
port: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string
]),
service: PropTypes.string,
user: PropTypes.string
})
};

const composer = ({}, onData) => {
if (Meteor.subscribe("Packages").ready()) {
const shopSettings = Reaction.getShopSettings();
const settings = shopSettings.mail || {};

if (settings.service && settings.service !== "custom") {
const config = getServiceConfig(settings.service);

// show localhost for test providers like Maildev that have no host
settings.host = config.host || "localhost";
settings.port = config.port;
}
return onData(null, { settings });
}
};

Expand All @@ -43,4 +80,4 @@ const depsMapper = () => ({
export default merge(
composeWithTracker(composer, Loading),
useDeps(depsMapper)
)(EmailConfig);
)(EmailConfigContainer);

0 comments on commit 16d83b1

Please sign in to comment.