_ = require 'underscore' path = require 'path' React = require 'react' {RetinaImg} = require 'nylas-component-kit' {Actions, Utils, ComponentRegistry, EventStore, AccountStore} = require 'nylas-exports' moment = require 'moment-timezone' class EventComponent extends React.Component @displayName: 'EventComponent' @propTypes: event: React.PropTypes.object.isRequired constructor: (@props) -> @state = @_getStateFromStores() _onChange: => @setState(@_getStateFromStores()) _getStateFromStores: -> e = EventStore.getEvent(@props.event.id) e ?= @props.event componentWillMount: -> @unsub = EventStore.listen(@_onChange) componentWillUnmount: -> @unsub() _myStatus: => myEmail = AccountStore.current()?.me().email for p in @state.participants if p['email'] == myEmail return p['status'] return null render: =>
Event: {@state.title}
{moment(@state.when['start_time']*1000).tz(Utils.timeZone).format("dddd, MMMM Do")}
{moment(@state.when['start_time']*1000).tz(Utils.timeZone).format("H:mm a z")}
{@_renderEventActions()}
_renderEventActions: =>
{@_renderAcceptButton()} {@_renderMaybeButton()} {@_renderDeclineButton()}
_renderAcceptButton: -> classes = "btn-rsvp" if @_myStatus() == "yes" classes += " yes"
Accept
_renderDeclineButton: -> classes = "btn-rsvp" if @_myStatus() == "no" classes += " no"
Decline
_renderMaybeButton: -> classes = "btn-rsvp" if @_myStatus() == "maybe" classes += " maybe"
Maybe
_onClickAccept: => Actions.RSVPEvent(@state, "yes") _onClickDecline: => Actions.RSVPEvent(@state, "no") _onClickMaybe: => Actions.RSVPEvent(@state, "maybe") module.exports = EventComponent