Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP on contact form. Need help. #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@
"jsonwebtoken": "^5.7.0",
"koa": "^1.1.2",
"koa-better-static": "^1.0.5",
"koa-bodyparser": "^2.2.0",
"koa-favicon": "^1.2.0",
"koa-onerror": "^1.3.1",
"koa-proxy": "github:foxcomm/koa-proxy",
"koa-router": "^5.4.0",
"lodash": "^4.3.0",
"lodash.flatmap": "^4.2.0",
"moment": "^2.15.2",
"mandrill-api": "^1.0.45",
"marked": "^0.3.6",
"react": "^15.2.0",
"react-addons-css-transition-group": "^15.3.2",
Expand Down
8 changes: 8 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import verifyJwt from './verify-jwt';
import onerror from 'koa-onerror';
import moment from 'moment';
import chalk from 'chalk';
import bodyParser from 'koa-bodyparser';
import mandrillRouter from './routes/mandrill';

function timestamp() {
return moment().format('D MMM H:mm:ss');
Expand All @@ -22,12 +24,18 @@ export default class App extends KoaApp {
super(...args);
onerror(this);

if (process.env.MAILCHIMP_API_KEY === void 0) {
throw new Error(`Can't load MAILCHIMP_API_KEY from environment.`);
}

this.use(serve('public'))
.use(favicon('public/images/home/top-drawer-favicon.png'))
.use(makeApiProxy())
.use(makeElasticProxy())
.use(bodyParser())
.use(zipcodes.routes())
.use(zipcodes.allowedMethods())
.use(mandrillRouter(process.env.MAILCHIMP_API_KEY))
.use(verifyJwt)
.use(loadI18n)
.use(renderReact);
Expand Down
41 changes: 41 additions & 0 deletions server/routes/mandrill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import makeRouter from 'koa-router';
import { Mandrill } from 'mandrill-api/mandrill';

function *sendMessage(mandrillClient, params) {
return new Promise((resolve, reject) => {
mandrillClient.messages.send(params, result => {
resolve(result);
console.log("RESOLVED : " + result);
}, error => {
const err = new Error(error.message || error);
reject(err);
console.log("REJECTED :" + error.message);
});
});
}

export default function mandrillRouter(apiKey) {
const mandrillClient = new Mandrill(apiKey);

const router = makeRouter()
.post('/api/node/mandrill', function*() {
const { message } = this.request.body;

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

console.log("WE ARE SENDING!");
yield sendMessage(mandrillClient, {
'message': message,
'async': async
});

this.body = {};
});

return router.routes();
}



1 change: 0 additions & 1 deletion src/pages/custom/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@

& .text-field {
width: 100%;
display: none;
padding-bottom: 10px;

& input[type=text] {
Expand Down
51 changes: 43 additions & 8 deletions src/pages/custom/custom.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,41 @@

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 { api } from 'lib/api';

type State = {
name: string,
email: string,
message: string,
}

class Custom extends Component {
state: State = {
name: '',
email: '',
message: '',
};

@autobind
sendCustomEmail() {
const message = {
'html': this.state.message,
'from_email': this.state.email,
'to': [{
email: '[email protected]',
name: 'Adil Wali'
}]
};

api.post('/node/mandrill', { message });
}

get topBanner(): HTMLElement {
return (
<div styleName="custom-banner">
Expand Down Expand Up @@ -39,6 +66,14 @@ class Custom extends Component {
);
}

@autobind
handleFormChange(event) {
const { target } = event;
this.setState({
[target.name]: target.value,
});
}

get reachOut(): HTMLElement {
return (
<div styleName="reach-out">
Expand All @@ -53,24 +88,24 @@ class Custom extends Component {
</p>
</div>
<div styleName="custom-contact-form-container">
<Form styleName="custom-contact-form">
<FormField styleName="text-field">
<TextInput required
<Form styleName="custom-contact-form" onSubmit={this.sendCustomEmail} onChange={this.handleFormChange}>
<FormField styleName="text-field" required>
<TextInput
name="name" placeholder="FIRST & LAST NAME"
/>
</FormField>
<FormField styleName="text-field">
<TextInput required
<FormField styleName="text-field" required>
<TextInput
name="email" placeholder="EMAIL ADDRESS"
/>
</FormField>
<FormField styleName="text-field">
<textarea required
<FormField styleName="text-field" required>
<textarea
name="message" placeholder="TELL US ABOUT YOUR CUSTOM SOCK NEEDS!"
/>
</FormField>
<div styleName="submit-container">
<a styleName="custom-contact-submit" href="mailto:[email protected]">REACH OUT</a>
<Button styleName="custom-contact-submit" type="submit">REACH OUT</Button>
</div>
</Form>
</div>
Expand Down