_ = require 'underscore' path = require 'path' React = require 'react' {RetinaImg} = require 'nylas-component-kit' {Actions, Message, Event, Utils, ComponentRegistry, EventRSVPTask, DatabaseStore, AccountStore} = require 'nylas-exports' moment = require 'moment-timezone' class EventHeader extends React.Component @displayName: 'EventHeader' @propTypes: message: React.PropTypes.instanceOf(Message).isRequired constructor: (@props) -> @state = event: @props.message.events[0] _onChange: => return unless @state.event DatabaseStore.find(Event, @state.event.id).then (event) => return unless event @setState({event}) componentDidMount: => # TODO: This should use observables! @_unlisten = DatabaseStore.listen (change) => if @state.event and change.objectClass is Event.name updated = _.find change.objects, (o) => o.id is @state.event.id @setState({event: updated}) if updated @_onChange() componentWillReceiveProps: (nextProps) => @setState({event:nextProps.message.events[0]}) @_onChange() componentWillUnmount: => @_unlisten?() render: => if @state.event?
Event: {@state.event.title}
{moment(@state.event.when['start_time']*1000).tz(Utils.timeZone).format("dddd, MMMM Do")}
{moment(@state.event.when['start_time']*1000).tz(Utils.timeZone).format("h:mm a z")}
{@_renderEventActions()}
else
_renderEventActions: => me = @state.event.participantForMe() return false unless me actions = [["yes", "Accept"], ["maybe", "Maybe"], ["no", "Decline"]]
{actions.map ([status, label]) => classes = "btn-rsvp " classes += status if me.status is status
@_rsvp(status)}> {label}
}
_rsvp: (status) => me = @state.event.participantForMe() Actions.queueTask(new EventRSVPTask(@state.event, me.email, status)) module.exports = EventHeader