Skip to content

Commit a830a9c

Browse files
committed
sockets setup, notifications and added options to Donut navigation
1 parent 407133e commit a830a9c

File tree

8 files changed

+324
-158
lines changed

8 files changed

+324
-158
lines changed

src/user/Admin/Tickets/TicketContent/TicketContent.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ class TicketContent extends Component {
2929
{
3030
name: "Title",
3131
grow: 2,
32-
selector: "titler",
32+
selector: "title",
3333
sortable: true,
3434
maxWidth: "600px", // when using custom you should use width or maxWidth, otherwise, the table will default to flex grow behavior
3535
cell: (row) => <CustomTitle row={row} />,
3636
},
3737
{
3838
name: "Description",
3939
grow: 3,
40-
selector: "plot",
40+
selector: "shortDescription",
4141
wrap: true,
4242
sortable: true,
4343
format: (row) => `${row.shortDescription.slice(0, 100)}...`,
@@ -55,6 +55,8 @@ class TicketContent extends Component {
5555
{
5656
name: "User",
5757
grow: 1,
58+
sortable: true,
59+
selector: 'createdBy.name',
5860
cell: (row) => (
5961
<div>
6062
<Image
@@ -70,6 +72,8 @@ class TicketContent extends Component {
7072
},
7173
{
7274
name: "Created At",
75+
sortable: true,
76+
selector: 'createdAt',
7377
cell: (row) => (
7478
<div>
7579
<Moment format="DD MMM YYYY">{row.createdAt}</Moment>
@@ -79,6 +83,7 @@ class TicketContent extends Component {
7983
{
8084
name: "Comments",
8185
sortable: true,
86+
selector: 'comments',
8287
cell: (row) => (
8388
<div>
8489
{row.comments}

src/user/Admin/Tickets/TicketDashboard.js

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,57 @@
11
import React, { Component } from "react";
22
import "./TicketDashboard.scss";
33
import Axios from "axios";
4+
import Moment from "react-moment";
45
import { connect } from "react-redux";
6+
import { setUpSocket } from "./socket";
57
import Form from "react-bootstrap/Form";
68
import Button from "react-bootstrap/Button";
79
import NewTicketEditor from "./NewTicketEditor";
10+
import socket from "../../dashboard/utils/socket";
811
import { BASE_URL } from "../../../actions/baseApi";
912
import TicketDisscussion from "./TicketDiscussions";
1013
import TicketContent from "./TicketContent/TicketContent";
1114
import { getTickets } from "../../../actions/ticketAction";
15+
import donutIcon from "../../../assets/svgs/donut-icon.svg";
1216
import Navigation from "../../dashboard/navigation/navigation";
1317
import 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

1521
class 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
}

src/user/Admin/Tickets/TicketDashboard.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
.ticket-description {
2020
display: flex;
2121
flex-direction: column;
22+
height: 100vh;
23+
overflow-y: hidden;
2224
.dashboard-title {
2325
font-family: Inter;
2426
font-style: normal;

0 commit comments

Comments
 (0)