Skip to content

Commit

Permalink
WIP on contact form. Need help.
Browse files Browse the repository at this point in the history
Mandrill should be called server side.
  • Loading branch information
adilwali committed Nov 7, 2016
1 parent a68a4b0 commit 8eb69cd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"koa-router": "^5.4.0",
"lodash": "^4.3.0",
"lodash.flatmap": "^4.2.0",
"mandrill-api": "^1.0.45",
"marked": "^0.3.6",
"react": "^15.2.0",
"react-addons-css-transition-group": "^15.3.2",
Expand Down
4 changes: 4 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ export default class App extends KoaApp {
}

start() {
if (process.env.MAILCHIMP_API_KEY === undefined) {
throw new Error(`Can't load MAILCHIMP_API_KEY from environment.`);
}
const port = process.env.LISTEN_PORT ? Number(process.env.LISTEN_PORT) : 4045;


this.listen(port);
console.info(`Listening on port ${port}`);
}
Expand Down
41 changes: 40 additions & 1 deletion src/pages/custom/custom.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,53 @@

import React, { Component } from 'react';
import type { HTMLElement } from 'types';
import { autobind } from 'core-decorators';

import styles from './custom.css';
import { Form, FormField } from 'ui/forms';
import { TextInput } from 'ui/inputs';
import Button from 'ui/buttons';
import mandrill from 'mandrill-api/mandrill';

type State = {
mandrill_client: any
}

class Custom extends Component {
state: Props;

//const mandrill_client =
componentWillMount() {
console.log("Our Key:" + process.env.MAILCHIMP_API_KEY);
this.setState({
mandrill_client: new mandrill.Mandrill(process.env.MAILCHIMP_API_KEY)
});
}

@autobind
sendCustomEmail() {
let message = {
"html": "<h2>TopDrawer Custom Sock Request</h2><p>The details are below.</p>",
"text": "Top Drawer Custom Sock Request. The details are below.",
"from_email": "[email protected]",
"to": "[email protected]"
}

let async = false;
let ip_pool = "Main Pool";
let send_at = "example send_at";

console.log("WE ARE SENDING!");
this.state.mandrill_client.messages.send({
"message": message,
"async": async
}, function(result) {
console.log(result);
}, function(e) {
console.log('A mandrill error occured:' + e.name + ' - ' + e.message);
})
}

get topBanner(): HTMLElement {
return (
<div styleName="custom-banner">
Expand Down Expand Up @@ -70,7 +109,7 @@ class Custom extends Component {
/>
</FormField>
<div styleName="submit-container">
<Button styleName="custom-contact-submit" type="submit">SUBMIT</Button>
<Button styleName="custom-contact-submit" type="submit" onClick={this.sendCustomEmail}>SUBMIT</Button>
</div>
</Form>
</div>
Expand Down

0 comments on commit 8eb69cd

Please sign in to comment.