Newer
Older

Lucas Eduardo Schoenfelder
committed
/*Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
Departamento de Informatica - Universidade Federal do Parana
This file is part of Plataforma Integrada MEC.
Plataforma Integrada MEC is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Plataforma Integrada MEC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/
import React, { useState, useEffect, useContext } from 'react';

Lucas Eduardo Schoenfelder
committed
import NotificationsIcon from '@material-ui/icons/Notifications';
import { Button } from '@material-ui/core';
import Badge from '@material-ui/core/Badge';
import styled from 'styled-components'
import Menu from '@material-ui/core/Menu';
import ActivityListItem from './ActivityListItem.js'
import { getRequest, postRequest } from './HelperFunctions/getAxiosConfig.js'
import { withStyles } from '@material-ui/core/styles';
import { Link } from 'react-router-dom'
import { getRecipientHref } from './Activities/getRecipientHref.js'
import SnackBar from '../Components/SnackbarComponent'

Lucas Eduardo Schoenfelder
committed
.MuiBadge-dot-45{
height : 9px ;
width : 9px ;
transform : scale(1) translate( 01%, -40%);
}
`
const StyledNotificationsIcon = styled(NotificationsIcon)`
flex : 1;
align-self : center;
margin-left : 0 !important;
color: #00bcd4;
`
const StyledNotificationButton = styled(Button)`
height : 56px !important;
width : 56px !important;
border-radius : 50% !important;
&:hover {
color : #00bcd4 !important;

Lucas Eduardo Schoenfelder
committed
}
`
const StyledMenu = withStyles({
})((props) => (
<Menu
elevation={0}
getContentAnchorEl={null}
anchorOrigin={{
horizontal: 'center',
vertical: "bottom",
}}
transformOrigin={{
vertical: 'top',
horizontal: 'center',
}}
{...props}
/>
));
const [anchorEl, setAnchorEl] = React.useState(null);
const [notifications, setNotifications] = useState([]);
const [snack, setSnack] = useState({
open: false,
text: "",
severity: "",
color: ""
});
const [notificatonsLength, setLength] = useState(0);
function handleAxiosSuccess(data) {
if (data.errors)
setSnack({
open: true,
text: "Erro ao buscar suas notificações",
severity: "error",
color: "red"
})
else {
setNotifications(data)
setLength(data.length)
}

Lucas Eduardo Schoenfelder
committed
}
function handleAxiosError(error) {
setSnack({
open: true,
text: "Erro ao buscar suas notificações",
severity: "error",
color: "red"
})

Lucas Eduardo Schoenfelder
committed
}
useEffect(() => {

Lucas Eduardo Schoenfelder
committed
getRequest('/feed?offset=0&limit=30', handleAxiosSuccess, handleAxiosError)
console.log('event.currentTarget: ', event.currentTarget)
setAnchorEl(event.currentTarget);
}
function handleClose() {
setAnchorEl(null);
}
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
function handleClickNotification() {
const payload = {
"activities": {
"ids": []
}
}
for (let index = 0; index < notifications.length; index++) {
const notification = notifications[index];
payload.activities.ids.push(notification.id)
}
postRequest(
'/activities/view',
payload,
(data) => {
if (data.errors)
setSnack({
open: true,
text: "Erro ao marcar as notificações como lidas!",
severity: "error",
color: "red"
})
else {
setSnack({
open: true,
text: "Todas as notificações foram marcadas como lidas!",
severity: "success",
color: "green"
})
setNotifications([])
}
},
(error) => {
setSnack({
open: true,
text: "Erro ao marcar as notificações como lidas!",
severity: "error",
color: "red"
})
},
)
}

Lucas Eduardo Schoenfelder
committed
return (
<SnackBar
snackbarOpen={snack.open}
handleClose={() => {
setSnack({
open: false,
text: "",
severity: "",
color: ""
})
}}
severity={snack.severity}
color={snack.color}
text={snack.text}
/>
<StyledNotificationButton onClick={handleClick}>
<StyledBadge badgeContent={1} color="secondary" variant="dot" overlap="circle" className="badge">
<StyledNotificationsIcon className={`${state.contrast}IconColor`} />
</StyledBadge>
</StyledNotificationButton>
<StyledMenu
id="simple-menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}
<div className="cabecalho">
<span style={{ fontSize: "15px" }}>NOTIFICAÇÕES •</span>
<span className="cabecalho-marcar" onClick={handleClickNotification}>Marcar todas como lidas</span>
</div>
{
notifications.map((notification) =>
(notification.recipient !== null) &&

vgm18
committed
(notification.recipient_type !== "NilClass") &&
onMenuBar={true}
avatar={notification.owner.avatar ? apiDomain + notification.owner.avatar : null}
activity={notification.activity}
actionType={notification.trackable_type}
objectType={notification.recipient_type}
createdAt={notification.created_at}
ownerName={notification.owner.name}
ownerHref={'/perfil'}
recipientName={notification.recipient.name}
recipientHref={getRecipientHref(notification)}
/>
)
}
<div style={{ padding: "0 15px", borderTop: "1px solid #dadada" }}>
<Link to="/perfil">
<NoPadButton>
MOSTRAR TODAS

Lucas Eduardo Schoenfelder
committed
)
const NoPadButton = styled(Button)`
padding : 6px 0 !important;
const ContainerDiv = styled.div`
margin-top : 10px;
right : 5%;
width : 360px;
max-height : 400px;
box-shadow : 8px 8px 8px 8px
rgba(0,0,0,.1);
overflow-y : scroll;
padding : 5px 5px 5px 5px;
min-width : 160px;
background-color: ${props => props.contrast === '' ? "#f1f1f1" : "black"};

Lucas Eduardo Schoenfelder
committed
border-bottom : 1px solid #dadada;
padding : 10px 15px;
color: ${props => props.contrast === '' ? "black" : "yellow"};
.cabecalho-marcar {
font-family: Lato,bold;
font-size: 12px;
-webkit-text-decoration-line: underline;
text-decoration-line: underline;
float: right;