2018-03-06 07:08:25 -05:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import { Link } from 'react-router'
|
|
|
|
|
2018-03-07 15:35:27 -05:00
|
|
|
import { MAP_ACCESS_REQUEST } from '../../constants'
|
2018-03-06 07:08:25 -05:00
|
|
|
import NotificationsHeader from './NotificationsHeader'
|
2018-03-07 18:38:53 -05:00
|
|
|
import LoadingPage from '../helpers/LoadingPage'
|
2018-03-07 15:35:27 -05:00
|
|
|
import Loading from '../../components/Loading'
|
|
|
|
import NotificationBody from '../../components/NotificationBody'
|
|
|
|
|
2018-03-06 07:08:25 -05:00
|
|
|
class NotificationPage extends Component {
|
2018-03-08 09:46:05 -05:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {
|
|
|
|
allowPending: false,
|
|
|
|
declinePending: false,
|
|
|
|
allowed: false,
|
|
|
|
declined: false,
|
|
|
|
error: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-07 15:35:27 -05:00
|
|
|
componentDidMount() {
|
|
|
|
// the notification id
|
|
|
|
const id = parseInt(this.props.params.id, 10)
|
|
|
|
if (!this.props.notifications.find(n => n.id === id)) {
|
|
|
|
this.props.fetchNotification(id)
|
|
|
|
}
|
|
|
|
}
|
2018-03-08 09:46:05 -05:00
|
|
|
|
|
|
|
deny = async () => {
|
|
|
|
const id = parseInt(this.props.params.id, 10)
|
|
|
|
const notification = this.props.notifications.find(n => n.id === id)
|
|
|
|
const request = notification.data.object
|
|
|
|
const map = notification.data.map
|
|
|
|
this.setState({ declinePending: true })
|
|
|
|
const success = await this.props.denyAccessRequest(map.id, request.id)
|
|
|
|
if (success) {
|
|
|
|
this.setState({ declined: true, declinePending: false })
|
|
|
|
} else {
|
|
|
|
this.setState({ error: true })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
approve = async () => {
|
|
|
|
const id = parseInt(this.props.params.id, 10)
|
|
|
|
const notification = this.props.notifications.find(n => n.id === id)
|
|
|
|
const request = notification.data.object
|
|
|
|
const map = notification.data.map
|
|
|
|
this.setState({ allowPending: true })
|
|
|
|
const success = await this.props.approveAccessRequest(map.id, request.id)
|
|
|
|
if (success) {
|
|
|
|
this.setState({ allowed: true, allowPending: false })
|
|
|
|
} else {
|
|
|
|
this.setState({ error: true })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-06 07:08:25 -05:00
|
|
|
render = () => {
|
2018-03-07 15:35:27 -05:00
|
|
|
const id = parseInt(this.props.params.id, 10)
|
|
|
|
const notification = this.props.notifications.find(n => n.id === id)
|
|
|
|
if (!notification) {
|
|
|
|
return (
|
|
|
|
<div>
|
2018-03-07 18:38:53 -05:00
|
|
|
<LoadingPage />
|
2018-03-07 15:35:27 -05:00
|
|
|
<NotificationsHeader />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
const request = notification.data.object
|
|
|
|
const map = notification.data.map
|
|
|
|
const subject = notification.type === MAP_ACCESS_REQUEST ?
|
2018-03-07 21:10:48 -05:00
|
|
|
(<span><span style={{ fontWeight: 'bold' }} className='requesterName'>{notification.actor.name}</span> wants to collaborate on map <span style={{fontWeight: 'bold'}}>{ map.name }</span></span>)
|
2018-03-07 15:35:27 -05:00
|
|
|
: notification.subject
|
2018-03-08 09:46:05 -05:00
|
|
|
const localAnswered = this.state.allowed || this.state.declined
|
2018-03-07 15:35:27 -05:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div id="yield">
|
|
|
|
<div className="centerContent withPadding back">
|
|
|
|
<Link to="/notifications">Back to notifications</Link>
|
|
|
|
</div>
|
|
|
|
<div className="centerContent notificationPage">
|
|
|
|
<h2 className="notification-title">
|
|
|
|
<img width="32" height="32" src={notification.actor.image} className='thirty-two-avatar' />
|
|
|
|
{subject}
|
|
|
|
</h2>
|
|
|
|
{notification.type === MAP_ACCESS_REQUEST && <div className="notification-body">
|
2018-03-08 09:46:05 -05:00
|
|
|
<div className="main-text">
|
|
|
|
{this.state.error && <div className="accessRequestError">There was an error, please refresh and try again</div>}
|
|
|
|
{request.answered && <div>
|
2018-03-07 15:35:27 -05:00
|
|
|
{request.approved && <span>You already responded to this access request, and allowed access.</span>}
|
|
|
|
{!request.approved && <span>You already responded to this access request, and declined access. If you changed your mind, you can still grant
|
|
|
|
them access by going to the map and adding them as a collaborator.</span>}
|
2018-03-08 09:46:05 -05:00
|
|
|
</div>}
|
|
|
|
{!localAnswered && !request.answered && <div>
|
2018-03-07 15:35:27 -05:00
|
|
|
<img src='/images/ellipsis.gif' className='hidden' />
|
2018-03-08 09:46:05 -05:00
|
|
|
{!this.state.declined && !this.state.declinePending && <button onClick={this.approve} className="button allow">
|
|
|
|
{this.state.allowPending ? <img src='/images/ellipsis.gif' /> : 'Allow'}
|
|
|
|
</button>}
|
|
|
|
{!this.state.allowed && !this.state.allowPending && <button onClick={this.deny} className="button decline">
|
|
|
|
{this.state.declinePending ? <img src='/images/ellipsis.gif' /> : 'Decline'}
|
|
|
|
</button>}
|
|
|
|
</div>}
|
|
|
|
{this.state.allowed && <div>
|
|
|
|
{notification.actor.name} has been shared on the map and notified.
|
|
|
|
</div>}
|
|
|
|
{this.state.declined && <div>
|
|
|
|
Fair enough.
|
|
|
|
</div>}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<Link to={`/maps/${map.id}`}>Go to map</Link>
|
|
|
|
|
|
|
|
<Link to={`/explore/mapper/${notification.actor.id}`}>View mapper profile</Link>
|
|
|
|
</div>
|
2018-03-07 15:35:27 -05:00
|
|
|
</div>}
|
|
|
|
{notification.type !== MAP_ACCESS_REQUEST && <NotificationBody notification={notification} />}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<NotificationsHeader />
|
|
|
|
</div>
|
|
|
|
)
|
2018-03-06 07:08:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-08 10:08:38 -05:00
|
|
|
export default NotificationPage
|