2015-12-01 09:11:57 +08:00
|
|
|
_ = 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: =>
|
2016-01-12 04:20:26 +08:00
|
|
|
# TODO: This should use observables!
|
2015-12-01 09:11:57 +08:00
|
|
|
@_unlisten = DatabaseStore.listen (change) =>
|
2015-12-08 08:52:46 +08:00
|
|
|
if @state.event and change.objectClass is Event.name
|
2015-12-01 09:11:57 +08:00
|
|
|
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?
|
|
|
|
<div className="event-wrapper">
|
|
|
|
<div className="event-header">
|
|
|
|
<RetinaImg name="icon-RSVP-calendar-mini@2x.png"
|
|
|
|
mode={RetinaImg.Mode.ContentPreserve}/>
|
|
|
|
<span className="event-title-text">Event: </span><span className="event-title">{@state.event.title}</span>
|
|
|
|
</div>
|
|
|
|
<div className="event-body">
|
|
|
|
<div className="event-date">
|
|
|
|
<div className="event-day">
|
2016-04-05 06:05:48 +08:00
|
|
|
{moment(@state.event.start*1000).tz(Utils.timeZone).format("dddd, MMMM Do")}
|
2015-12-01 09:11:57 +08:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div className="event-time">
|
2016-04-05 06:05:48 +08:00
|
|
|
{moment(@state.event.start*1000).tz(Utils.timeZone).format("h:mm a z")}
|
2015-12-01 09:11:57 +08:00
|
|
|
</div>
|
|
|
|
{@_renderEventActions()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
else
|
|
|
|
<div></div>
|
|
|
|
|
|
|
|
_renderEventActions: =>
|
2016-01-12 04:20:26 +08:00
|
|
|
me = @state.event.participantForMe()
|
|
|
|
return false unless me
|
|
|
|
|
2015-12-01 09:11:57 +08:00
|
|
|
actions = [["yes", "Accept"], ["maybe", "Maybe"], ["no", "Decline"]]
|
|
|
|
|
|
|
|
<div className="event-actions">
|
|
|
|
{actions.map ([status, label]) =>
|
|
|
|
classes = "btn-rsvp "
|
2016-01-12 04:20:26 +08:00
|
|
|
classes += status if me.status is status
|
2015-12-01 09:11:57 +08:00
|
|
|
<div key={status} className={classes} onClick={=> @_rsvp(status)}>
|
|
|
|
{label}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
_rsvp: (status) =>
|
2016-01-12 04:20:26 +08:00
|
|
|
me = @state.event.participantForMe()
|
|
|
|
Actions.queueTask(new EventRSVPTask(@state.event, me.email, status))
|
2015-12-01 09:11:57 +08:00
|
|
|
|
|
|
|
module.exports = EventHeader
|