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 (