import React, { Component } from 'react' import { Link } from 'react-router' import { MAP_ACCESS_REQUEST } from '../../constants' import NotificationsHeader from './NotificationsHeader' import LoadingPage from '../helpers/LoadingPage' import Loading from '../../components/Loading' import NotificationBody from '../../components/NotificationBody' class NotificationPage extends Component { constructor(props) { super(props) this.state = { allowPending: false, declinePending: false, allowed: false, declined: false, error: false } } 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) } } 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 }) } } render = () => { const id = parseInt(this.props.params.id, 10) const notification = this.props.notifications.find(n => n.id === id) if (!notification) { return (
) } const request = notification.data.object const map = notification.data.map const subject = notification.type === MAP_ACCESS_REQUEST ? ({notification.actor.name} wants to collaborate on map { map.name }) : notification.subject const localAnswered = this.state.allowed || this.state.declined return (
Back to notifications

{subject}

{notification.type === MAP_ACCESS_REQUEST &&
{this.state.error &&
There was an error, please refresh and try again
} {request.answered &&
{request.approved && You already responded to this access request, and allowed access.} {!request.approved && 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.}
} {!localAnswered && !request.answered &&
{!this.state.declined && !this.state.declinePending && } {!this.state.allowed && !this.state.allowPending && }
} {this.state.allowed &&
{notification.actor.name} has been shared on the map and notified.
} {this.state.declined &&
Fair enough.
}
Go to map    View mapper profile
} {notification.type !== MAP_ACCESS_REQUEST && }
) } } export default NotificationPage /* */