Skip to content

Commit a2d9103

Browse files
committed
fix(notices): unable to deactivate notice through socket
1 parent 002411b commit a2d9103

File tree

5 files changed

+39
-26
lines changed

5 files changed

+39
-26
lines changed

src/client/components/NoticeBanner/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class NoticeBanner extends React.Component {
2727

2828
return (
2929
<div
30+
id={'notice-banner'}
3031
style={{
3132
width: '100%',
3233
height: '30px',

src/client/containers/Modals/ViewAllNotificationsModal.jsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ import { makeObservable, observable } from 'mobx'
2020
import axios from 'axios'
2121
import Log from '../../logger'
2222

23+
import { NOTIFICATIONS_MARK_READ } from 'serverSocket/socketEventConsts'
24+
2325
import { hideModal } from 'actions/common'
2426

2527
import BaseModal from 'containers/Modals/BaseModal'
2628
import Button from 'components/Button'
2729

2830
import helpers from 'lib/helpers'
29-
import socket from 'lib/socket'
3031

3132
@observer
3233
class ViewAllNotificationsModal extends React.Component {
@@ -55,7 +56,7 @@ class ViewAllNotificationsModal extends React.Component {
5556
if (!notification || !notification.data || !notification.data.ticket || !notification.data.ticket.uid) return false
5657

5758
this.props.hideModal()
58-
socket.socket.emit('markNotificationRead', notification._id)
59+
this.props.socket.emit(NOTIFICATIONS_MARK_READ, notification._id)
5960
History.pushState(null, null, `/tickets/${notification.data.ticket.uid}`)
6061
}
6162

@@ -113,7 +114,12 @@ class ViewAllNotificationsModal extends React.Component {
113114
}
114115

115116
ViewAllNotificationsModal.propTypes = {
116-
hideModal: PropTypes.func.isRequired
117+
hideModal: PropTypes.func.isRequired,
118+
socket: PropTypes.object.isRequired
117119
}
118120

119-
export default connect(null, { hideModal })(ViewAllNotificationsModal)
121+
const mapStateToProps = state => ({
122+
socket: state.shared.socket
123+
})
124+
125+
export default connect(mapStateToProps, { hideModal })(ViewAllNotificationsModal)

src/client/containers/Notice/NoticeContainer.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import axios from 'axios'
77
import { fetchNotices, deleteNotice, unloadNotices } from 'actions/notices'
88
import { showModal } from 'actions/common'
99

10+
import { NOTICE_SHOW, NOTICE_CLEAR } from 'serverSocket/socketEventConsts'
11+
1012
import PageTitle from 'components/PageTitle'
1113
import PageContent from 'components/PageContent'
1214
import Table from 'components/Table'
@@ -17,7 +19,6 @@ import ButtonGroup from 'components/ButtonGroup'
1719
import Button from 'components/Button'
1820

1921
import helpers from 'lib/helpers'
20-
import socket from 'lib/socket'
2122
import UIKit from 'uikit'
2223

2324
class NoticeContainer extends React.Component {
@@ -46,7 +47,7 @@ class NoticeContainer extends React.Component {
4647
axios
4748
.put('/api/v2/notices/' + noticeId + '/activate', { active: true })
4849
.then(() => {
49-
socket.ui.setShowNotice(noticeId)
50+
this.props.socket.emit(NOTICE_SHOW, { noticeId })
5051
})
5152
.catch(err => {
5253
Log.error(err)
@@ -58,7 +59,7 @@ class NoticeContainer extends React.Component {
5859
axios
5960
.get('/api/v1/notices/clearactive')
6061
.then(() => {
61-
socket.ui.setClearNotice()
62+
this.props.socket.emit(NOTICE_CLEAR)
6263

6364
helpers.UI.showSnackbar('Notice has been deactivated', false)
6465
})
@@ -195,6 +196,7 @@ class NoticeContainer extends React.Component {
195196
}
196197

197198
NoticeContainer.propTypes = {
199+
socket: PropTypes.object.isRequired,
198200
notices: PropTypes.object.isRequired,
199201
loading: PropTypes.bool.isRequired,
200202

@@ -205,6 +207,7 @@ NoticeContainer.propTypes = {
205207
}
206208

207209
const mapStateToProps = state => ({
210+
socket: state.shared.socket,
208211
notices: state.noticesState.notices,
209212
loading: state.noticesState.loading
210213
})

src/models/user.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
* Copyright (c) 2014-2019. All rights reserved.
1313
*/
1414

15-
var async = require('async')
16-
var mongoose = require('mongoose')
17-
var winston = require('winston')
18-
var bcrypt = require('bcrypt')
19-
var _ = require('lodash')
20-
var Chance = require('chance')
15+
const async = require('async')
16+
const mongoose = require('mongoose')
17+
const winston = require('winston')
18+
const bcrypt = require('bcrypt')
19+
const _ = require('lodash')
20+
const Chance = require('chance')
2121
const utils = require('../helpers/utils')
2222

2323
// Required for linkage
2424
require('./role')
2525

26-
var SALT_FACTOR = 10
27-
var COLLECTION = 'accounts'
26+
const SALT_FACTOR = 10
27+
const COLLECTION = 'accounts'
2828

2929
/**
3030
* User Schema
@@ -79,23 +79,24 @@ var userSchema = mongoose.Schema({
7979
preferences: {
8080
tourCompleted: { type: Boolean, default: false },
8181
autoRefreshTicketGrid: { type: Boolean, default: true },
82-
openChatWindows: [{ type: String, default: [] }]
82+
openChatWindows: [{ type: String, default: [] }],
83+
keyboardShortcuts: { type: Boolean, default: true }
8384
},
8485

8586
deleted: { type: Boolean, default: false }
8687
})
8788

8889
userSchema.set('toObject', { getters: true })
8990

90-
var autoPopulateRole = function (next) {
91+
const autoPopulateRole = function (next) {
9192
this.populate('role', 'name description normalized _id')
9293
next()
9394
}
9495

9596
userSchema.pre('findOne', autoPopulateRole).pre('find', autoPopulateRole)
9697

9798
userSchema.pre('save', function (next) {
98-
var user = this
99+
const user = this
99100

100101
user.username = utils.applyMaxShortTextLength(utils.sanitizeFieldPlainText(user.username.toLowerCase().trim()))
101102
user.email = utils.sanitizeFieldPlainText(user.email.trim())

src/socketio/noticeSocket.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
* Copyright (c) 2014-2019. All rights reserved.
1313
*/
1414

15-
var winston = require('winston')
16-
var utils = require('../helpers/utils')
17-
var noticeSchema = require('../models/notice')
15+
const winston = require('winston')
16+
const utils = require('../helpers/utils')
17+
const noticeSchema = require('../models/notice')
1818

19-
var events = {}
19+
const socketEventConst = require('../socketio/socketEventConsts')
20+
21+
const events = {}
2022

2123
function register (socket) {
2224
events.onShowNotice(socket)
@@ -26,7 +28,7 @@ function register (socket) {
2628
function eventLoop () {}
2729

2830
events.onShowNotice = function (socket) {
29-
socket.on('setShowNotice', function (noticeId) {
31+
socket.on(socketEventConst.NOTICE_SHOW, function ({ noticeId }) {
3032
noticeSchema.getNotice(noticeId, function (err, notice) {
3133
if (err) return true
3234
notice.activeDate = new Date()
@@ -36,15 +38,15 @@ events.onShowNotice = function (socket) {
3638
return true
3739
}
3840

39-
utils.sendToAllConnectedClients(io, '$trudesk:notice:show', notice)
41+
utils.sendToAllConnectedClients(io, socketEventConst.NOTICE_UI_SHOW, notice)
4042
})
4143
})
4244
})
4345
}
4446

4547
events.onClearNotice = function (socket) {
46-
socket.on('setClearNotice', function () {
47-
utils.sendToAllConnectedClients(io, 'updateClearNotice')
48+
socket.on(socketEventConst.NOTICE_CLEAR, function () {
49+
utils.sendToAllConnectedClients(io, socketEventConst.NOTICE_UI_CLEAR)
4850
})
4951
}
5052

0 commit comments

Comments
 (0)