Skip to content

Instantly share code, notes, and snippets.

import React, { Component } from 'react'
import { reduxForm } from 'redux-form'
const fields = ['email_marketing_opt_in']
const submit = (values, dispatch) => {
dispatch()
}
class EmailMarketingForm extends Component {
render() {
@marr
marr / gist:8d2b0d86de532bda5c61
Last active March 9, 2016 20:49
flatten a collection of objects
test('map a collection into a new array', assert => {
const expected = [ { a:1 }, { a: 1 } ]
const input = [ [ { a: 1 }, { b: 1 } ], [ { a: 1, c: 1 } ] ]
const actual = [].concat.apply([], input)
.filter(e => e.hasOwnProperty('a'))
.map(e => {
return { a: e.a }
})
assert.deepEqual(actual, expected)
assert.end()
export const LOAD_EMAIL_PREFERENCES = 'LOAD_EMAIL_PREFERENCES'
export const LOADED_EMAIL_PREFERENCES = 'LOADED_EMAIL_PREFERENCES'
export function loadEmailPreferences (personId) {
return async (dispatch, getState) => {
const account = getState().guests[personId].account
const centres = account.newsletter_centre_ids
if (centres.length) {
dispatch({ type: LOAD_EMAIL_PREFERENCES })
const newslettersByCentre = await Promise.all(centres.map(getNewslettersByCentre))
const subscriptions = account.newsletter_subscriptions
import React from 'react'
import { connect } from 'react-redux'
import { reduxForm } from 'redux-form'
import { loadInterests, saveInterests } from 'containers/UserDetail/Interests/actions'
import List from 'components/List'
import Panel from 'components/Panel'
function loadData (props) {
const { userId } = props.params
props.loadInterests(userId)
function activeCardSort(cards) {
const grouped = {
active: [],
expired: [],
deleted: [],
...groupBy(cards.map(getCardInfo), 'status')
}
const byCreatedAt = dateFrom('created_at')
const byDeletedAt = dateFrom('deleted_at')
@marr
marr / extract-strings.js
Last active August 12, 2016 16:49
react-intl-webpack-plugin
import * as fs from 'fs'
import path from 'path'
import { sync as globSync } from 'glob'
import { sync as mkdirpSync } from 'mkdirp'
const MESSAGES_PATTERN = './dist/messages/**/*.json'
const LANG_DIR = './dist/lang/'
export default function() {
// Aggregates the default messages that were extracted from the example app's
export function changeUser(user) {
const personId = user.person_id
return (dispatch, getState) => {
dispatch({ type: CHANGE_USER, payload: { personId } })
const peopleEndpoint = PEOPLE_ENDPOINT(personId).clone()
return secureFetch(peopleEndpoint, {
method: 'PATCH',
body: JSON.stringify(user)
}).then(
res => dispatch(changedUser(user)), // I think i need to combine this user with getState().user
let vehicles = groupBy(this.state.vehicles, 'license_plate')
vehicles = Object.keys(vehicles).map(license_plate => {
const activeVehicles = vehicles[license_plate]
.filter(notDeleted)
if (!activeVehicles.length) {
const byDeleted = dateFrom('deleted_at')
return vehicles[license_plate].sort(byDeleted)[0]
}
// Print all of the news items on Hacker News
var jsdom = require('jsdom')
var fs = require('fs')
var app = fs.readFileSync('./dist/main.js', 'utf-8')
var html = '<div id="root"></div>'
jsdom.env(html, {
src: [app],
virtualConsole: jsdom.createVirtualConsole().sendTo(console),
done: function (err, window) {
switch (action.type) {
case actionTypes.ME_SET:
return setMe(state, action);
default:
return state;
}