authscape 1.0.456 → 1.0.460

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,247 @@
1
+ import React, {useEffect, useState} from 'react';
2
+ // import {apiService, authService} from 'authscape';
3
+ import Button from '@mui/material/Button';
4
+ import { Box } from '@mui/system';
5
+ import {
6
+ DataGrid,
7
+ GridActionsCellItem,
8
+ } from "@mui/x-data-grid";
9
+ import DeleteRoundedIcon from "@mui/icons-material/DeleteRounded";
10
+ import Typography from '@mui/material/Typography';
11
+ import AppBar from '@mui/material/AppBar';
12
+ import Toolbar from '@mui/material/Toolbar';
13
+ import YesNoDialog from '../../components/yesNoDialog';
14
+ import VisibilityRoundedIcon from '@mui/icons-material/VisibilityRounded';
15
+ import AddRoundedIcon from '@mui/icons-material/AddRounded';
16
+ import InputLabel from '@mui/material/InputLabel';
17
+ import MenuItem from '@mui/material/MenuItem';
18
+ import FormControl from '@mui/material/FormControl';
19
+ import Select, { SelectChangeEvent } from '@mui/material/Select';
20
+ import Grid from '@mui/material/Grid';
21
+ // import TicketDetail from './TicketDetail';
22
+ import { useRouter } from 'next/router';
23
+
24
+ export default function Tickets({loadedUser, setIsLoading, currentUser, customTabName = null, customTabElement = null }) {
25
+
26
+ const [tickets, setTickets] = useState([]);
27
+
28
+ const [archiveTicketId, setArchiveTicketId] = useState(null);
29
+ const [totalTickets, setTotalTickets] = useState(0);
30
+ const [pageNumber, setPageNumber] = useState(1);
31
+
32
+ const [ticketStatuses, setTicketStatuses] = useState([]);
33
+ const [ticketTypes, setTicketTypes] = useState([]);
34
+
35
+ const [ticketTypeId, setTicketTypeId] = useState(null);
36
+ const [statusId, setStatusId] = useState(null);
37
+
38
+ const [selectedTicketId, setSelectedTicketId] = useState(null);
39
+
40
+ const router = useRouter();
41
+
42
+
43
+ useEffect(() => {
44
+
45
+ if (router.query.id != null)
46
+ {
47
+ setSelectedTicketId(router.query.id);
48
+ }
49
+
50
+ }, [router.isReady])
51
+
52
+ const columns = [
53
+ { field: 'id', headerName: 'Id', width: 150 },
54
+ { field: 'title', flex: 1, headerName: 'Customer', width: 200 },
55
+ { field: 'ticketStatus', headerName: 'Status', width: 150 },
56
+ { field: 'ticketType', headerName: 'Ticket Type', width: 150 },
57
+ { field: 'created', headerName: 'Created', width: 150 },
58
+ { field: 'ticketParticipants', headerName: 'Participants', width: 150 },
59
+ { field: 'messages', headerName: 'Messages', width: 150 },
60
+ {
61
+ field: "actions",
62
+ type: "actions",
63
+ width: 200,
64
+ headerName: "Actions",
65
+ cellClassName: "actions",
66
+ getActions: ({ id, row }) => {
67
+ return [
68
+ <GridActionsCellItem key={id}
69
+ icon={<VisibilityRoundedIcon />}
70
+ label="View"
71
+ onClick={() => {
72
+ setSelectedTicketId(row.id);
73
+ }}
74
+ />,
75
+ <GridActionsCellItem key={id}
76
+ icon={<DeleteRoundedIcon />}
77
+ label="Delete"
78
+ className="textPrimary"
79
+ onClick={() => {
80
+ setArchiveTicketId(row.id);
81
+ }}
82
+ />,
83
+ ];
84
+ },
85
+ }
86
+ ];
87
+
88
+ const reloadTickets = async () => {
89
+ let response = await apiService().get("/ticket/GetTickets?pageNumber=" + pageNumber + "&pageSize=20&ticketStatusId=" + (statusId != null ? statusId: "") + "&ticketTypeId=" + (ticketTypeId != null ? ticketTypeId : ""));
90
+ if (response != null && response.status == 200)
91
+ {
92
+ setTotalTickets(response.data.data.length);
93
+ setTickets(response.data.data);
94
+ }
95
+ }
96
+
97
+ useEffect(() => {
98
+
99
+ if (loadedUser)
100
+ {
101
+ let fetchStatusesAndTypes = async () => {
102
+ let responseStatus = await apiService().get("/Ticket/GetStatuses");
103
+ if (responseStatus != null && responseStatus.status == 200)
104
+ {
105
+ setTicketStatuses(responseStatus.data);
106
+ }
107
+
108
+ let responseType = await apiService().get("/Ticket/GetTicketTypes");
109
+ if (responseType != null && responseType.status == 200)
110
+ {
111
+ setTicketTypes(responseType.data);
112
+ }
113
+ }
114
+
115
+ fetchStatusesAndTypes();
116
+ setTicketStatuses();
117
+ }
118
+
119
+ }, [loadedUser]);
120
+
121
+
122
+ useEffect(() => {
123
+
124
+ if (loadedUser)
125
+ {
126
+ reloadTickets();
127
+ }
128
+
129
+ }, [loadedUser, ticketTypeId, statusId]);
130
+
131
+ return (
132
+ <div>
133
+
134
+ {selectedTicketId != null &&
135
+ <TicketDetail ticketId={selectedTicketId} setIsLoading={setIsLoading} currentUser={currentUser} customTabName={customTabName} customTabElement={customTabElement} GoBackToViewTickets={() =>
136
+ {
137
+ setSelectedTicketId(null);
138
+ }} />
139
+ }
140
+ {selectedTicketId == null &&
141
+ <>
142
+ <Box sx={{ flexGrow: 1 }}>
143
+ <AppBar position="static" color='inherit' elevation={0}>
144
+ <Toolbar>
145
+ <Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
146
+ Tickets
147
+ </Typography>
148
+ <Button color="primary" variant="contained" startIcon={<AddRoundedIcon/>} onClick={async () => {
149
+
150
+ let response = await apiService().post("/Ticket/CreateTicket", {
151
+ ticketTypeId: 1,
152
+ ticketStatusId: 1,
153
+ description: "about this",
154
+ message: "More about this"
155
+ });
156
+
157
+ window.location.href = "/ticket/" + response.data;
158
+
159
+ }}>Create Ticket</Button>
160
+ </Toolbar>
161
+ </AppBar>
162
+ </Box>
163
+
164
+ <Grid container spacing={2} sx={{paddingTop:2, paddingBottom:2}}>
165
+ <Grid item xs={4}>
166
+
167
+ <Box>
168
+ <FormControl fullWidth>
169
+ <InputLabel id="demo-simple-select-label">Ticket Status</InputLabel>
170
+ <Select
171
+ labelId="demo-simple-select-label"
172
+ id="demo-simple-select"
173
+ value={statusId}
174
+ label="ticketStatus"
175
+ onChange={(event) => {
176
+ setStatusId(event.target.value);
177
+ }}>
178
+
179
+ <MenuItem value={null}>Not Assigned</MenuItem>
180
+
181
+ {ticketStatuses != null && ticketStatuses.map((tStatus) => {
182
+ return (
183
+ <MenuItem value={tStatus.id}>{tStatus.name}</MenuItem>
184
+ )
185
+ })}
186
+
187
+ </Select>
188
+ </FormControl>
189
+ </Box>
190
+
191
+ </Grid>
192
+ <Grid item xs={4}>
193
+
194
+ <Box>
195
+ <FormControl fullWidth>
196
+ <InputLabel id="demo-simple-select-label">Ticket Type</InputLabel>
197
+ <Select
198
+ labelId="demo-simple-select-label"
199
+ id="demo-simple-select"
200
+ value={ticketTypeId}
201
+ label="TicketType"
202
+ onChange={(event) => {
203
+ setTicketTypeId(event.target.value);
204
+ }}>
205
+
206
+ <MenuItem value={null}>Not Assigned</MenuItem>
207
+
208
+ {ticketTypes != null && ticketTypes.map((tTicketType) => {
209
+ return (
210
+ <MenuItem value={tTicketType.id}>{tTicketType.name}</MenuItem>
211
+ )
212
+ })}
213
+
214
+ </Select>
215
+ </FormControl>
216
+ </Box>
217
+
218
+ </Grid>
219
+ </Grid>
220
+
221
+ <Box sx={{height: 600, width: '100%' }}>
222
+ <DataGrid
223
+ rows={tickets}
224
+ columns={columns}
225
+ onPageChange={(newPage) => {
226
+ setPageNumber(newPage);
227
+ }}
228
+ pageSize={totalTickets}
229
+ rowsPerPageOptions={[20]}
230
+ />
231
+ </Box>
232
+
233
+ <YesNoDialog open={archiveTicketId != null ? true : false} title={"Remove Ticket"} message={"Are you sure you want to archive this ticket?"}
234
+ YesAction={async () => {
235
+ await apiService().delete("/Ticket/ArchiveTicket?id=" + archiveTicketId);
236
+ await reloadTickets();
237
+ setArchiveTicketId(null);
238
+ }}
239
+ NoAction={() => {
240
+ setArchiveTicketId(null);
241
+ }} />
242
+ </>
243
+ }
244
+ </div>
245
+
246
+ )
247
+ }