Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Allow inbox notification delete #1157
Browse files Browse the repository at this point in the history
  • Loading branch information
wiadev committed Sep 1, 2017
1 parent 52d3f55 commit 730981c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/actions/AppActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ export function markAsRead(id) {
return axios.put(config.API_URL + '/notifications/' + id + '/read');
}

export function deleteUserNotification(id) {
return axios.delete(config.API_URL + `/notifications?ids=${id}`);
}

export function getAttributesInstance(
attrType, tmpId, docType, docId, tabId, rowId, fieldName, entity
) {
Expand Down
10 changes: 10 additions & 0 deletions src/assets/css/inbox.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,13 @@
color: $brand-font-color-weak;
padding-top: .3rem;
}

.inbox-item-delete {
color: $brand-danger-color !important;
text-decoration: none;
margin-right: 1em;
}

.inbox-item-delete:hover {
text-decoration: underline;
}
22 changes: 21 additions & 1 deletion src/components/inbox/Inbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import InboxItem from './InboxItem';

import {
markAllAsRead,
markAsRead
markAsRead,
getNotifications,
getNotificationsSuccess,
deleteUserNotification
} from '../../actions/AppActions';

class Inbox extends Component {
Expand Down Expand Up @@ -56,6 +59,22 @@ class Inbox extends Component {
close && close();
}

handleDelete = (e, item) => {
const { dispatch } = this.props;

e.preventDefault();
e.stopPropagation();

deleteUserNotification(item.id).then( () => {
getNotifications().then(response => {
dispatch(getNotificationsSuccess(
response.data.notifications,
response.data.unreadCount
));
});
});
}

componentDidUpdate() {
const {open} = this.props;
const inboxWrapper =
Expand Down Expand Up @@ -128,6 +147,7 @@ class Inbox extends Component {
item={item}
close={close}
onClick={() => this.handleClick(item)}
onDelete={(e) => this.handleDelete(e, item)}
/>
)}
{inbox && inbox.notifications.length == 0 &&
Expand Down
21 changes: 16 additions & 5 deletions src/components/inbox/InboxItem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import Moment from 'moment';
import counterpart from 'counterpart';

class InboxItem extends Component {
constructor(props){
Expand All @@ -19,7 +20,7 @@ class InboxItem extends Component {
document.getElementsByClassName('js-inbox-wrapper')[0].focus();
}

handleKeyDown = (e) => {
handleKeyDown = (e) => {
const {close} = this.props;
switch(e.key){
case 'ArrowDown':
Expand All @@ -46,7 +47,7 @@ class InboxItem extends Component {
}

render() {
const {item, onClick} = this.props;
const {item, onClick, onDelete} = this.props;
return (
<div
onClick={onClick}
Expand Down Expand Up @@ -75,15 +76,25 @@ class InboxItem extends Component {
{item.message}
</div>
<div className="inbox-item-footer">
<span
<div
title={
Moment(item.timestamp)
.format('DD.MM.YYYY HH:mm:ss')
}
>
{Moment(item.timestamp).fromNow()}
</span>
<span>Notification</span>
</div>
<div>
<a
href="javascript:void(0)"
className="inbox-item-delete"
onClick={onDelete}
>
{counterpart.translate('window.Delete.caption')}
</a>

<span>Notification</span>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 730981c

Please sign in to comment.