| 
									
										
										
										
											2022-01-06 01:26:15 +00:00
										 |  |  | import React, { useContext } from "react" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import Paper from "@material-ui/core/Paper" | 
					
						
							|  |  |  | import Container from "@material-ui/core/Container" | 
					
						
							|  |  |  | import Grid from "@material-ui/core/Grid" | 
					
						
							|  |  |  | import { makeStyles } from "@material-ui/core/styles" | 
					
						
							|  |  |  | import Typography from "@material-ui/core/Typography"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import useTickets from "../../hooks/useTickets" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { AuthContext } from "../../context/Auth/AuthContext"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { i18n } from "../../translate/i18n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import Chart from "./Chart" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-10 20:35:45 +00:00
										 |  |  | import { Can } from "../../components/Can"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-06 01:26:15 +00:00
										 |  |  | const useStyles = makeStyles(theme => ({ | 
					
						
							|  |  |  | 	container: { | 
					
						
							|  |  |  | 		paddingTop: theme.spacing(4), | 
					
						
							|  |  |  | 		paddingBottom: theme.spacing(4), | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	fixedHeightPaper: { | 
					
						
							|  |  |  | 		padding: theme.spacing(2), | 
					
						
							|  |  |  | 		display: "flex", | 
					
						
							|  |  |  | 		overflow: "auto", | 
					
						
							|  |  |  | 		flexDirection: "column", | 
					
						
							|  |  |  | 		height: 240, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	customFixedHeightPaper: { | 
					
						
							|  |  |  | 		padding: theme.spacing(2), | 
					
						
							|  |  |  | 		display: "flex", | 
					
						
							|  |  |  | 		overflow: "auto", | 
					
						
							|  |  |  | 		flexDirection: "column", | 
					
						
							|  |  |  | 		height: 120, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	customFixedHeightPaperLg: { | 
					
						
							|  |  |  | 		padding: theme.spacing(2), | 
					
						
							|  |  |  | 		display: "flex", | 
					
						
							|  |  |  | 		overflow: "auto", | 
					
						
							|  |  |  | 		flexDirection: "column", | 
					
						
							|  |  |  | 		height: "100%", | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | })) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Dashboard = () => { | 
					
						
							|  |  |  | 	const classes = useStyles() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const { user } = useContext(AuthContext); | 
					
						
							|  |  |  | 	var userQueueIds = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (user.queues && user.queues.length > 0) { | 
					
						
							|  |  |  | 		userQueueIds = user.queues.map(q => q.id); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-18 18:21:28 +00:00
										 |  |  | 	const GetTickets = (status, showAll, withUnreadMessages, unlimited) => { | 
					
						
							| 
									
										
										
										
											2022-01-06 01:26:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		const { tickets } = useTickets({ | 
					
						
							|  |  |  | 			status: status, | 
					
						
							|  |  |  | 			showAll: showAll, | 
					
						
							|  |  |  | 			withUnreadMessages: withUnreadMessages, | 
					
						
							| 
									
										
										
										
											2022-04-18 18:21:28 +00:00
										 |  |  | 			queueIds: JSON.stringify(userQueueIds), | 
					
						
							|  |  |  | 			unlimited: unlimited | 
					
						
							| 
									
										
										
										
											2022-01-06 01:26:15 +00:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 		return tickets.length; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-10 20:35:45 +00:00
										 |  |  | 	return (  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		<Can | 
					
						
							|  |  |  | 			role={user.profile} | 
					
						
							|  |  |  | 			perform="dashboard-view:show" | 
					
						
							|  |  |  | 			yes={() => ( | 
					
						
							|  |  |  | 				<div> | 
					
						
							|  |  |  | 					<Container maxWidth="lg" className={classes.container}> | 
					
						
							|  |  |  | 						<Grid container spacing={3}> | 
					
						
							| 
									
										
										
										
											2022-07-28 21:21:14 +00:00
										 |  |  | 							 | 
					
						
							| 
									
										
										
										
											2022-01-10 20:35:45 +00:00
										 |  |  | 							<Grid item xs={4}> | 
					
						
							|  |  |  | 								<Paper className={classes.customFixedHeightPaper} style={{ overflow: "hidden" }}> | 
					
						
							|  |  |  | 									<Typography component="h3" variant="h6" color="primary" paragraph> | 
					
						
							|  |  |  | 										{i18n.t("dashboard.messages.inAttendance.title")} | 
					
						
							|  |  |  | 									</Typography> | 
					
						
							|  |  |  | 									<Grid item> | 
					
						
							|  |  |  | 										<Typography component="h1" variant="h4"> | 
					
						
							| 
									
										
										
										
											2022-04-18 18:21:28 +00:00
										 |  |  | 											{GetTickets("open", "true", "false", "true")} | 
					
						
							| 
									
										
										
										
											2022-01-10 20:35:45 +00:00
										 |  |  | 										</Typography> | 
					
						
							|  |  |  | 									</Grid> | 
					
						
							|  |  |  | 								</Paper> | 
					
						
							| 
									
										
										
										
											2022-01-06 01:26:15 +00:00
										 |  |  | 							</Grid> | 
					
						
							| 
									
										
										
										
											2022-01-10 20:35:45 +00:00
										 |  |  | 							<Grid item xs={4}> | 
					
						
							|  |  |  | 								<Paper className={classes.customFixedHeightPaper} style={{ overflow: "hidden" }}> | 
					
						
							|  |  |  | 									<Typography component="h3" variant="h6" color="primary" paragraph> | 
					
						
							|  |  |  | 										{i18n.t("dashboard.messages.waiting.title")} | 
					
						
							|  |  |  | 									</Typography> | 
					
						
							|  |  |  | 									<Grid item> | 
					
						
							|  |  |  | 										<Typography component="h1" variant="h4"> | 
					
						
							| 
									
										
										
										
											2022-04-18 18:21:28 +00:00
										 |  |  | 											{GetTickets("pending", "true", "false", "true")} | 
					
						
							| 
									
										
										
										
											2022-01-10 20:35:45 +00:00
										 |  |  | 										</Typography> | 
					
						
							|  |  |  | 									</Grid> | 
					
						
							|  |  |  | 								</Paper> | 
					
						
							| 
									
										
										
										
											2022-01-06 01:26:15 +00:00
										 |  |  | 							</Grid> | 
					
						
							| 
									
										
										
										
											2022-01-10 20:35:45 +00:00
										 |  |  | 							<Grid item xs={4}> | 
					
						
							|  |  |  | 								<Paper className={classes.customFixedHeightPaper} style={{ overflow: "hidden" }}> | 
					
						
							|  |  |  | 									<Typography component="h3" variant="h6" color="primary" paragraph> | 
					
						
							|  |  |  | 										{i18n.t("dashboard.messages.closed.title")} | 
					
						
							|  |  |  | 									</Typography> | 
					
						
							|  |  |  | 									<Grid item> | 
					
						
							|  |  |  | 										<Typography component="h1" variant="h4"> | 
					
						
							| 
									
										
										
										
											2022-04-18 18:21:28 +00:00
										 |  |  | 											{GetTickets("closed", "true", "false", "true")} | 
					
						
							| 
									
										
										
										
											2022-07-28 21:21:14 +00:00
										 |  |  | 										</Typography>  | 
					
						
							|  |  |  | 									</Grid>  | 
					
						
							| 
									
										
										
										
											2022-01-10 20:35:45 +00:00
										 |  |  | 								</Paper> | 
					
						
							| 
									
										
										
										
											2022-01-06 01:26:15 +00:00
										 |  |  | 							</Grid> | 
					
						
							| 
									
										
										
										
											2022-07-28 21:21:14 +00:00
										 |  |  | 						 | 
					
						
							| 
									
										
										
										
											2022-01-10 20:35:45 +00:00
										 |  |  | 							<Grid item xs={12}> | 
					
						
							|  |  |  | 								<Paper className={classes.fixedHeightPaper}> | 
					
						
							|  |  |  | 									<Chart /> | 
					
						
							|  |  |  | 								</Paper> | 
					
						
							|  |  |  | 							</Grid> | 
					
						
							| 
									
										
										
										
											2022-07-28 21:21:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-10 20:35:45 +00:00
										 |  |  | 						</Grid> | 
					
						
							|  |  |  | 					</Container> | 
					
						
							|  |  |  | 				</div> | 
					
						
							|  |  |  | 			)} | 
					
						
							|  |  |  | 		/> | 
					
						
							|  |  |  | 				  | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/**/ | 
					
						
							| 
									
										
										
										
											2022-01-06 01:26:15 +00:00
										 |  |  | 	) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default Dashboard |