11import React , { Component } from "react" ;
22import "./TicketDashboard.scss" ;
33import Axios from "axios" ;
4+ import Moment from "react-moment" ;
45import { connect } from "react-redux" ;
6+ import { setUpSocket } from "./socket" ;
57import Form from "react-bootstrap/Form" ;
68import Button from "react-bootstrap/Button" ;
79import NewTicketEditor from "./NewTicketEditor" ;
10+ import socket from "../../dashboard/utils/socket" ;
811import { BASE_URL } from "../../../actions/baseApi" ;
912import TicketDisscussion from "./TicketDiscussions" ;
1013import TicketContent from "./TicketContent/TicketContent" ;
1114import { getTickets } from "../../../actions/ticketAction" ;
15+ import donutIcon from "../../../assets/svgs/donut-icon.svg" ;
1216import Navigation from "../../dashboard/navigation/navigation" ;
1317import SearchOutlinedIcon from "@material-ui/icons/SearchOutlined" ;
18+ import { Drawer , List , ListItem , ListItemText } from "@material-ui/core" ;
19+ import NotificationsNoneOutlinedIcon from "@material-ui/icons/NotificationsNoneOutlined" ;
1420
1521class TicketDashboard extends Component {
1622 constructor ( props ) {
1723 super ( props ) ;
1824 this . state = {
1925 view : "all" ,
26+ ticket : true ,
2027 all : [ ] ,
2128 open : [ ] ,
2229 pending : [ ] ,
2330 onHold : [ ] ,
2431 solved : [ ] ,
2532 closed : [ ] ,
33+ socket : socket ,
34+ notifications : [ ] ,
2635 editorMode : false ,
2736 viewingTicket : null ,
37+ notificationDrawer : false ,
2838 } ;
2939 }
3040
41+ toggleDrawer = ( ) => {
42+ this . setState ( ( state ) => {
43+ return {
44+ notificationDrawer : ! state . notificationDrawer ,
45+ } ;
46+ } ) ;
47+ } ;
48+
49+ addToNotification = ( notification ) => {
50+ this . setState ( {
51+ notifications : [ notification , ...this . state . notifications ] ,
52+ } ) ;
53+ } ;
54+
3155 componentWillReceiveProps ( nextProps ) {
3256 console . log ( nextProps . tickets . tickets ) ;
3357 this . setState ( {
@@ -58,6 +82,8 @@ class TicketDashboard extends Component {
5882 this . props . getTickets ( ) ;
5983 } ) ;
6084 this . divideAsPerStatus ( ) ;
85+ this . getTicketNotifications ( ) ;
86+ setUpSocket ( this . state , donutIcon , this . addToNotification ) ;
6187 }
6288
6389 handleSearchBarChange = ( e ) => { } ;
@@ -74,9 +100,23 @@ class TicketDashboard extends Component {
74100 } ) ;
75101 } ;
76102
103+ getTicketNotifications = async ( ) => {
104+ const notifications = (
105+ await Axios . get ( `${ BASE_URL } /notification/ticket/user/all` )
106+ ) . data . notifications ;
107+ this . setState ( { notifications } ) ;
108+ } ;
109+
77110 handleCreateNewTicket = async ( newTicket ) => {
78111 console . log ( "EXECUTED!" ) ;
79- await Axios . post ( `${ BASE_URL } /ticket` , newTicket ) ;
112+ const ticket = ( await Axios . post ( `${ BASE_URL } /ticket` , newTicket ) ) . data
113+ . ticket ;
114+ ticket . comments = 0 ;
115+ this . setState ( {
116+ all : [ ...this . state . all , ticket ] ,
117+ open : [ ...this . state . open , ticket ] ,
118+ editorMode : false ,
119+ } ) ;
80120 } ;
81121
82122 handleViewTicket = ( id ) => {
@@ -86,15 +126,21 @@ class TicketDashboard extends Component {
86126 } ;
87127
88128 render ( ) {
129+ console . log ( this . state . notifications ) ;
89130 const { view } = this . state ;
90131 return (
91132 < div className = "ticket" >
92133 < div className = "navigation" >
93- < Navigation />
134+ < Navigation ticket = { this . state . ticket } />
94135 </ div >
95- < div className = "ticket-details" >
136+ < div className = "ticket-details" id = "ticket-shadow" >
96137 < div className = "ticket-description" >
97- < div className = "dashboard-title" > Tickets</ div >
138+ < div className = "dashboard-title" >
139+ Tickets
140+ < Button variant = "light" onClick = { this . toggleDrawer } >
141+ < NotificationsNoneOutlinedIcon />
142+ </ Button >
143+ </ div >
98144 { ! this . state . editorMode &&
99145 this . state . all . length &&
100146 ! this . state . viewingTicket && (
@@ -167,6 +213,32 @@ class TicketDashboard extends Component {
167213 ) }
168214 </ div >
169215 </ div >
216+ < Drawer
217+ anchor = { "right" }
218+ open = { this . state . notificationDrawer }
219+ PaperProps = { { style : { position : "absolute" , zIndex : "5000" } } }
220+ BackdropProps = { { style : { position : "absolute" , zIndex : "5000" } } }
221+ ModalProps = { {
222+ container : document . getElementById ( "ticket-shadow" ) ,
223+ style : { position : "absolute" , zIndex : "5000" } ,
224+ } }
225+ variant = "temporary"
226+ onClose = { this . toggleDrawer }
227+ >
228+ < List className = "list" >
229+ { this . state . notifications . map ( ( notification ) => (
230+ < ListItem style = { { display : "flex" , flexDirection : "column" , alignItems : "flex-start" } } >
231+ < div > { notification . tag } </ div >
232+ < div > { notification . heading } </ div >
233+ < div >
234+ < Moment date = { notification . createdAt } durationFromNow />
235+ </ div >
236+ < div > { notification . content } </ div >
237+ < hr > </ hr >
238+ </ ListItem >
239+ ) ) }
240+ </ List >
241+ </ Drawer >
170242 </ div >
171243 ) ;
172244 }
0 commit comments