diff --git a/backend/src/controllers/TicketController.ts b/backend/src/controllers/TicketController.ts index d90020d..43d5678 100644 --- a/backend/src/controllers/TicketController.ts +++ b/backend/src/controllers/TicketController.ts @@ -14,6 +14,7 @@ type IndexQuery = { date: string; showAll: string; withUnreadMessages: string; + queueIds: string; }; interface TicketData { @@ -29,11 +30,18 @@ export const index = async (req: Request, res: Response): Promise => { date, searchParam, showAll, + queueIds: queueIdsStringified, withUnreadMessages } = req.query as IndexQuery; const userId = req.user.id; + let queueIds: number[] = []; + + if (queueIdsStringified) { + queueIds = JSON.parse(queueIdsStringified); + } + const { tickets, count, hasMore } = await ListTicketsService({ searchParam, pageNumber, @@ -41,6 +49,7 @@ export const index = async (req: Request, res: Response): Promise => { date, showAll, userId, + queueIds, withUnreadMessages }); diff --git a/backend/src/services/TicketServices/ListTicketsService.ts b/backend/src/services/TicketServices/ListTicketsService.ts index a62e43a..cc1938a 100644 --- a/backend/src/services/TicketServices/ListTicketsService.ts +++ b/backend/src/services/TicketServices/ListTicketsService.ts @@ -5,6 +5,7 @@ import Ticket from "../../models/Ticket"; import Contact from "../../models/Contact"; import Message from "../../models/Message"; import Queue from "../../models/Queue"; +// import ShowUserService from "../UserServices/ShowUserService"; interface Request { searchParam?: string; @@ -14,6 +15,7 @@ interface Request { showAll?: string; userId: string; withUnreadMessages?: string; + queueIds: number[]; } interface Response { @@ -25,14 +27,22 @@ interface Response { const ListTicketsService = async ({ searchParam = "", pageNumber = "1", + queueIds, status, date, showAll, userId, withUnreadMessages }: Request): Promise => { + // const user = await ShowUserService(userId); + + // const userQueueIds = user.queues.map(queue => queue.id); + + // console.log(userQueueIds); + let whereCondition: Filterable["where"] = { - [Op.or]: [{ userId }, { status: "pending" }] + [Op.or]: [{ userId }, { status: "pending" }], + queueId: { [Op.or]: [queueIds, null] } }; let includeCondition: Includeable[]; @@ -85,7 +95,7 @@ const ListTicketsService = async ({ [Op.or]: [ { "$contact.name$": where( - fn("LOWER", col("name")), + fn("LOWER", col("contact.name")), "LIKE", `%${sanitizedSearchParam}%` ) diff --git a/frontend/src/components/QueueSelector/index.js b/frontend/src/components/QueueSelect/index.js similarity index 81% rename from frontend/src/components/QueueSelector/index.js rename to frontend/src/components/QueueSelect/index.js index f420105..22b0529 100644 --- a/frontend/src/components/QueueSelector/index.js +++ b/frontend/src/components/QueueSelect/index.js @@ -5,7 +5,6 @@ import MenuItem from "@material-ui/core/MenuItem"; import FormControl from "@material-ui/core/FormControl"; import Select from "@material-ui/core/Select"; import Chip from "@material-ui/core/Chip"; -import { OutlinedInput } from "@material-ui/core"; import toastError from "../../errors/toastError"; import api from "../../services/api"; @@ -19,9 +18,8 @@ const useStyles = makeStyles(theme => ({ }, })); -const QueueSelector = ({ selectedQueueIds, onChange }) => { +const QueueSelect = ({ selectedQueueIds, onChange }) => { const classes = useStyles(); - // const [selectedQueues, setSelectedQueues] = useState([]); const [queues, setQueues] = useState([]); useEffect(() => { @@ -45,9 +43,9 @@ const QueueSelector = ({ selectedQueueIds, onChange }) => { Filas "Filas"} + > + {userQueues?.length > 0 && + userQueues.map(queue => ( + + -1} + /> + + + ))} + + + + ); +}; + +export default TicketsListQueueSelect; diff --git a/frontend/src/components/UserModal/index.js b/frontend/src/components/UserModal/index.js index a01012c..b1539c8 100644 --- a/frontend/src/components/UserModal/index.js +++ b/frontend/src/components/UserModal/index.js @@ -22,7 +22,7 @@ import { i18n } from "../../translate/i18n"; import api from "../../services/api"; import toastError from "../../errors/toastError"; -import QueueSelector from "../QueueSelector"; +import QueueSelect from "../QueueSelect"; const useStyles = makeStyles(theme => ({ root: { @@ -198,7 +198,7 @@ const UserModal = ({ open, onClose, userId }) => { - setSelectedQueueIds(values)} /> diff --git a/frontend/src/components/WhatsAppModal/index.js b/frontend/src/components/WhatsAppModal/index.js index 73bdf02..853b8bd 100644 --- a/frontend/src/components/WhatsAppModal/index.js +++ b/frontend/src/components/WhatsAppModal/index.js @@ -21,7 +21,7 @@ import { import api from "../../services/api"; import { i18n } from "../../translate/i18n"; import toastError from "../../errors/toastError"; -import QueueSelector from "../QueueSelector"; +import QueueSelect from "../QueueSelect"; const useStyles = makeStyles(theme => ({ root: { @@ -176,7 +176,7 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => { margin="dense" /> - setSelectedQueueIds(values)} /> diff --git a/frontend/src/context/Auth/useAuth.js b/frontend/src/context/Auth/useAuth.js index 182e3ea..cba200c 100644 --- a/frontend/src/context/Auth/useAuth.js +++ b/frontend/src/context/Auth/useAuth.js @@ -6,7 +6,6 @@ import { toast } from "react-toastify"; import { i18n } from "../../translate/i18n"; import api from "../../services/api"; import toastError from "../../errors/toastError"; -// import { useLocalStorage } from "../../hooks/useLocalStorage"; const useAuth = () => { const history = useHistory(); @@ -62,12 +61,11 @@ const useAuth = () => { api.defaults.headers.Authorization = `Bearer ${data.token}`; setIsAuth(true); setUser(data.user); - setLoading(false); } catch (err) { toastError(err); - setLoading(false); } } + setLoading(false); })(); }, []); diff --git a/frontend/src/hooks/useTickets/index.js b/frontend/src/hooks/useTickets/index.js index e6eeed3..97b6e7f 100644 --- a/frontend/src/hooks/useTickets/index.js +++ b/frontend/src/hooks/useTickets/index.js @@ -9,6 +9,7 @@ const useTickets = ({ status, date, showAll, + queueIds, withUnreadMessages, }) => { const [loading, setLoading] = useState(true); @@ -27,6 +28,7 @@ const useTickets = ({ status, date, showAll, + queueIds, withUnreadMessages, }, }); @@ -41,7 +43,15 @@ const useTickets = ({ fetchTickets(); }, 500); return () => clearTimeout(delayDebounceFn); - }, [searchParam, pageNumber, status, date, showAll, withUnreadMessages]); + }, [ + searchParam, + pageNumber, + status, + date, + showAll, + queueIds, + withUnreadMessages, + ]); return { tickets, loading, hasMore }; };