Skip to content

Commit

Permalink
Visualização dos tickets para todos os usuários
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh committed Jan 30, 2023
1 parent f300f4f commit 3ac4519
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/src/controllers/SettingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import UpdateSettingService from "../services/SettingServices/UpdateSettingServi
import ListSettingsService from "../services/SettingServices/ListSettingsService";

export const index = async (req: Request, res: Response): Promise<Response> => {
if (req.user.profile !== "admin") {
if (req.user.profile === "") {
throw new AppError("ERR_NO_PERMISSION", 403);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { QueryInterface } from "sequelize";

module.exports = {
up: (queryInterface: QueryInterface) => {
return queryInterface.bulkInsert(
"Settings",
[
{
key: "allTicket",
value: "disabled",
createdAt: new Date(),
updatedAt: new Date()
}
],
{}
);
},

down: (queryInterface: QueryInterface) => {
return queryInterface.bulkDelete("Settings", {});
}
};
49 changes: 43 additions & 6 deletions frontend/src/components/TicketsList/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { useState, useEffect, useReducer, useContext } from "react";
import openSocket from "../../services/socket-io";

import { makeStyles } from "@material-ui/core/styles";
import List from "@material-ui/core/List";
import Paper from "@material-ui/core/Paper";
import {
List,
makeStyles,
Paper
} from "@material-ui/core";

import TicketListItem from "../TicketListItem";
import TicketsListSkeleton from "../TicketsListSkeleton";
Expand All @@ -12,6 +14,9 @@ import useTickets from "../../hooks/useTickets";
import { i18n } from "../../translate/i18n";
import { AuthContext } from "../../context/Auth/AuthContext";

import api from "../../services/api";
import toastError from "../../errors/toastError";

const useStyles = makeStyles((theme) => ({
ticketsListWrapper: {
position: "relative",
Expand Down Expand Up @@ -167,6 +172,7 @@ const TicketsList = (props) => {
const [ticketsList, dispatch] = useReducer(reducer, []);
const { user } = useContext(AuthContext);
const { profile, queues } = user;
const [settings, setSettings] = useState([]);

useEffect(() => {
dispatch({ type: "RESET" });
Expand All @@ -182,15 +188,46 @@ const TicketsList = (props) => {
queueIds: JSON.stringify(selectedQueueIds),
});

useEffect(() => {
const fetchSession = async () => {
try {
const { data } = await api.get("/settings");
setSettings(data);
} catch (err) {
toastError(err);
}
};
fetchSession();
}, []);

useEffect(() => {
const queueIds = queues.map((q) => q.id);
const filteredTickets = tickets.filter((t) => queueIds.indexOf(t.queueId) > -1);

if (profile === "user") {
dispatch({ type: "LOAD_TICKETS", payload: filteredTickets });
const getSettingValue = key => {
const { value } = settings.find(s => s.key === key);
return value;
};
const allticket = settings && settings.length > 0 && getSettingValue("allTicket") === "enabled";

if (allticket === true) {

if (profile === "") {
dispatch({ type: "LOAD_TICKETS", payload: filteredTickets });

} else {
dispatch({ type: "LOAD_TICKETS", payload: tickets });
}
} else {
dispatch({ type: "LOAD_TICKETS", payload: tickets });

if (profile === "user") {
dispatch({ type: "LOAD_TICKETS", payload: filteredTickets });

} else {
dispatch({ type: "LOAD_TICKETS", payload: tickets });
}
}
// eslint-disable-next-line
}, [tickets, status, searchParam, queues, profile]);

useEffect(() => {
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/pages/Settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ const Settings = () => {
</Tooltip>
</Paper>

<Typography variant="body2" gutterBottom></Typography>

<Paper className={classes.paper}>
<Tooltip title={i18n.t("settings.settings.allTicket.note")}>
<FormControlLabel
control={
<IOSSwitch
checked={settings && settings.length > 0 && getSettingValue("allTicket") === "enabled"}
onChange={handleChangeBooleanSetting} name="allTicket"
/>}
label={i18n.t("settings.settings.allTicket.name")}
/>
</Tooltip>
</Paper>

<Typography variant="body2" gutterBottom></Typography>

<Paper className={classes.paper}>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/translate/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ const messages = {
disabled: "Disabled",
},
},
allTicket: {
name: "Everyone can see the ticket without department",
note: "Activate this function to let all users see tickets without sector",
options: {
enabled: "Enabled",
disabled: "Disabled",
},
},
CheckMsgIsGroup: {
name: "Ignore Group Messages",
note: "If you disable it, you will receive messages from groups.",
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/translate/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ const messages = {
disabled: "Deshabilitado",
},
},
allTicket: {
name: "Todo el mundo puede ver el ticket sin departamento",
note: "Active esta función para que todos los usuarios vean los boletos sin sector",
options: {
enabled: "Habilitado",
disabled: "Deshabilitado",
},
},
CheckMsgIsGroup: {
name: "Ignorar mensajes de grupo",
note: "Si lo desactivas, recibirás mensajes de grupos.",
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/translate/languages/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ const messages = {
disabled: "Desativado",
},
},
allTicket: {
name: "Todos podem ver o chamado sem departamento",
note: "Ative essa função para deixar todos os usuarios verem os chamados sem setor",
options: {
enabled: "Ativado",
disabled: "Desativado",
},
},
CheckMsgIsGroup: {
name: "Ignorar Mensagens de Grupos",
note: "Se desabilitar, irá receber mensage dos grupos.",
Expand Down

0 comments on commit 3ac4519

Please sign in to comment.