import cx from 'classnames'
import { canInvite } from '../../models/currentUser'
import { INVITED_COMMUNITY_MEMBERS, trackEvent } from '../../util/analytics'
import { parseEmailString } from '../../util/text'

export const defaultSubject = name =>
  `Join ${name} on Hylo`

export const defaultMessage = name =>
  `${name} is using Hylo, a new kind of social network that's designed to help communities and organizations create things together.\n\n` +
  "We're surrounded by incredible people, skills, and resources. But it can be hard to know whom to connect with, for what, and when. Often the things we need most are closer than we think.\n\n" +
  'Hylo makes it easy to discover the abundant skills, resources, and opportunities in your communities that might otherwise go unnoticed. Together, we can create whatever we can imagine.'

const CommunityInvitations = compose(
  prefetch(({ params: { id }, dispatch }) => Promise.all([
    dispatch(fetchCommunitySettings(id)),
    dispatch(fetchInvitations(id))
  ])),
  connect(({ people, communities, invitationEditor, pending }, { params: { id } }) => ({
    community: communities[id],
    invitationEditor,
    pending: pending[SEND_COMMUNITY_INVITATION],
    currentUser: people.current
  }))
)(props => {
  let { currentUser, community, dispatch, invitationEditor, params: { id }, pending } = props
  if (!canInvite(currentUser, community)) {
    return <div>
      You don't have permission to view this page. <a href='javascript:history.go(-1)'>Back</a>
    </div>
  }
  let invitationUrl = `https://www.hylo.com/c/${community.slug}/join/${community.beta_access_code}`
import React from 'react'
import { compose } from 'redux'
import { prefetch } from 'react-fetcher'
import { connect } from 'react-redux'
import { fetchPeople } from '../../actions/fetchPeople'
import { fetchWithCache, connectedListProps } from '../../util/caching'
import ScrollListener from '../../components/ScrollListener'
import PersonCards from '../../components/PersonCards'
const { array, bool, func, number, object } = React.PropTypes

const subject = 'network'
const fetch = fetchWithCache(fetchPeople)

const NetworkMembers = compose(
  prefetch(({ dispatch, params: { id }, query }) => dispatch(fetch(subject, id, query))),
  connect((state, { params: { id }, location: { query } }) => {
    return {
      ...connectedListProps(state, {subject, id, query}, 'people'),
      network: state.networks[id],
      currentUser: state.people.current
    }
  })
)(props => {
  let { pending, people, location: { query }, currentUser } = props
  if (!currentUser) return <div>Loading...</div>

  let loadMore = () => {
    let { dispatch, total, params: { id } } = props
    let offset = people.length
    if (!pending && offset < total) {
      dispatch(fetch(subject, id, {...query, offset}))
import React from 'react'
import { connect } from 'react-redux'
import { prefetch } from 'react-fetcher'
import { fetch, ConnectedPostList } from '../ConnectedPostList'
import { compose } from 'redux'
const { func, object } = React.PropTypes

const subject = 'network'

const NetworkPosts = props => {
  let { params: { id }, location: { query } } = props

  return <div>
    <ConnectedPostList {...{subject, id, query}}/>
  </div>
}

NetworkPosts.propTypes = {
  dispatch: func,
  params: object,
  location: object
}

export default compose(
  prefetch(({ dispatch, params, query }) => dispatch(fetch(subject, params.id, query))),
  connect((state, { params }) => ({network: state.networks[params.id]}))
)(NetworkPosts)