mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +00:00
feat: add queue filter to tickets list
This commit is contained in:
@@ -14,6 +14,7 @@ type IndexQuery = {
|
|||||||
date: string;
|
date: string;
|
||||||
showAll: string;
|
showAll: string;
|
||||||
withUnreadMessages: string;
|
withUnreadMessages: string;
|
||||||
|
queueIds: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface TicketData {
|
interface TicketData {
|
||||||
@@ -29,11 +30,18 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
date,
|
date,
|
||||||
searchParam,
|
searchParam,
|
||||||
showAll,
|
showAll,
|
||||||
|
queueIds: queueIdsStringified,
|
||||||
withUnreadMessages
|
withUnreadMessages
|
||||||
} = req.query as IndexQuery;
|
} = req.query as IndexQuery;
|
||||||
|
|
||||||
const userId = req.user.id;
|
const userId = req.user.id;
|
||||||
|
|
||||||
|
let queueIds: number[] = [];
|
||||||
|
|
||||||
|
if (queueIdsStringified) {
|
||||||
|
queueIds = JSON.parse(queueIdsStringified);
|
||||||
|
}
|
||||||
|
|
||||||
const { tickets, count, hasMore } = await ListTicketsService({
|
const { tickets, count, hasMore } = await ListTicketsService({
|
||||||
searchParam,
|
searchParam,
|
||||||
pageNumber,
|
pageNumber,
|
||||||
@@ -41,6 +49,7 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
date,
|
date,
|
||||||
showAll,
|
showAll,
|
||||||
userId,
|
userId,
|
||||||
|
queueIds,
|
||||||
withUnreadMessages
|
withUnreadMessages
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import Ticket from "../../models/Ticket";
|
|||||||
import Contact from "../../models/Contact";
|
import Contact from "../../models/Contact";
|
||||||
import Message from "../../models/Message";
|
import Message from "../../models/Message";
|
||||||
import Queue from "../../models/Queue";
|
import Queue from "../../models/Queue";
|
||||||
|
// import ShowUserService from "../UserServices/ShowUserService";
|
||||||
|
|
||||||
interface Request {
|
interface Request {
|
||||||
searchParam?: string;
|
searchParam?: string;
|
||||||
@@ -14,6 +15,7 @@ interface Request {
|
|||||||
showAll?: string;
|
showAll?: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
withUnreadMessages?: string;
|
withUnreadMessages?: string;
|
||||||
|
queueIds: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
@@ -25,14 +27,22 @@ interface Response {
|
|||||||
const ListTicketsService = async ({
|
const ListTicketsService = async ({
|
||||||
searchParam = "",
|
searchParam = "",
|
||||||
pageNumber = "1",
|
pageNumber = "1",
|
||||||
|
queueIds,
|
||||||
status,
|
status,
|
||||||
date,
|
date,
|
||||||
showAll,
|
showAll,
|
||||||
userId,
|
userId,
|
||||||
withUnreadMessages
|
withUnreadMessages
|
||||||
}: Request): Promise<Response> => {
|
}: Request): Promise<Response> => {
|
||||||
|
// const user = await ShowUserService(userId);
|
||||||
|
|
||||||
|
// const userQueueIds = user.queues.map(queue => queue.id);
|
||||||
|
|
||||||
|
// console.log(userQueueIds);
|
||||||
|
|
||||||
let whereCondition: Filterable["where"] = {
|
let whereCondition: Filterable["where"] = {
|
||||||
[Op.or]: [{ userId }, { status: "pending" }]
|
[Op.or]: [{ userId }, { status: "pending" }],
|
||||||
|
queueId: { [Op.or]: [queueIds, null] }
|
||||||
};
|
};
|
||||||
let includeCondition: Includeable[];
|
let includeCondition: Includeable[];
|
||||||
|
|
||||||
@@ -85,7 +95,7 @@ const ListTicketsService = async ({
|
|||||||
[Op.or]: [
|
[Op.or]: [
|
||||||
{
|
{
|
||||||
"$contact.name$": where(
|
"$contact.name$": where(
|
||||||
fn("LOWER", col("name")),
|
fn("LOWER", col("contact.name")),
|
||||||
"LIKE",
|
"LIKE",
|
||||||
`%${sanitizedSearchParam}%`
|
`%${sanitizedSearchParam}%`
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import MenuItem from "@material-ui/core/MenuItem";
|
|||||||
import FormControl from "@material-ui/core/FormControl";
|
import FormControl from "@material-ui/core/FormControl";
|
||||||
import Select from "@material-ui/core/Select";
|
import Select from "@material-ui/core/Select";
|
||||||
import Chip from "@material-ui/core/Chip";
|
import Chip from "@material-ui/core/Chip";
|
||||||
import { OutlinedInput } from "@material-ui/core";
|
|
||||||
import toastError from "../../errors/toastError";
|
import toastError from "../../errors/toastError";
|
||||||
import api from "../../services/api";
|
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 classes = useStyles();
|
||||||
// const [selectedQueues, setSelectedQueues] = useState([]);
|
|
||||||
const [queues, setQueues] = useState([]);
|
const [queues, setQueues] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -45,9 +43,9 @@ const QueueSelector = ({ selectedQueueIds, onChange }) => {
|
|||||||
<InputLabel>Filas</InputLabel>
|
<InputLabel>Filas</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
multiple
|
multiple
|
||||||
|
labelWidth={40}
|
||||||
value={selectedQueueIds}
|
value={selectedQueueIds}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
input={<OutlinedInput label="Filas" id="select-multiple-chip" />}
|
|
||||||
MenuProps={{
|
MenuProps={{
|
||||||
anchorOrigin: {
|
anchorOrigin: {
|
||||||
vertical: "bottom",
|
vertical: "bottom",
|
||||||
@@ -61,12 +59,12 @@ const QueueSelector = ({ selectedQueueIds, onChange }) => {
|
|||||||
}}
|
}}
|
||||||
renderValue={selected => (
|
renderValue={selected => (
|
||||||
<div className={classes.chips}>
|
<div className={classes.chips}>
|
||||||
{selected.length > 0 &&
|
{selected?.length > 0 &&
|
||||||
selected.map(value => {
|
selected.map(id => {
|
||||||
const queue = queues.find(q => q.id === value);
|
const queue = queues.find(q => q.id === id);
|
||||||
return queue ? (
|
return queue ? (
|
||||||
<Chip
|
<Chip
|
||||||
key={value}
|
key={id}
|
||||||
style={{ backgroundColor: queue.color }}
|
style={{ backgroundColor: queue.color }}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
label={queue.name}
|
label={queue.name}
|
||||||
@@ -88,4 +86,4 @@ const QueueSelector = ({ selectedQueueIds, onChange }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default QueueSelector;
|
export default QueueSelect;
|
||||||
@@ -7,7 +7,10 @@ import Paper from "@material-ui/core/Paper";
|
|||||||
|
|
||||||
import TicketListItem from "../TicketListItem";
|
import TicketListItem from "../TicketListItem";
|
||||||
import TicketsListSkeleton from "../TicketsListSkeleton";
|
import TicketsListSkeleton from "../TicketsListSkeleton";
|
||||||
|
import TicketsListQueueSelect from "../TicketsListQueueSelect";
|
||||||
|
|
||||||
import useTickets from "../../hooks/useTickets";
|
import useTickets from "../../hooks/useTickets";
|
||||||
|
import { useLocalStorage } from "../../hooks/useLocalStorage";
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
import { ListSubheader } from "@material-ui/core";
|
import { ListSubheader } from "@material-ui/core";
|
||||||
import { AuthContext } from "../../context/Auth/AuthContext";
|
import { AuthContext } from "../../context/Auth/AuthContext";
|
||||||
@@ -35,6 +38,9 @@ const useStyles = makeStyles(theme => ({
|
|||||||
zIndex: 2,
|
zIndex: 2,
|
||||||
backgroundColor: "white",
|
backgroundColor: "white",
|
||||||
borderBottom: "1px solid rgba(0, 0, 0, 0.12)",
|
borderBottom: "1px solid rgba(0, 0, 0, 0.12)",
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
},
|
},
|
||||||
|
|
||||||
ticketsCount: {
|
ticketsCount: {
|
||||||
@@ -154,17 +160,36 @@ const TicketsList = ({ status, searchParam, showAll }) => {
|
|||||||
const [pageNumber, setPageNumber] = useState(1);
|
const [pageNumber, setPageNumber] = useState(1);
|
||||||
const [ticketsList, dispatch] = useReducer(reducer, []);
|
const [ticketsList, dispatch] = useReducer(reducer, []);
|
||||||
const { user } = useContext(AuthContext);
|
const { user } = useContext(AuthContext);
|
||||||
|
const [pendingSelectedQueueIds, setPendingSelectedQueueIds] = useLocalStorage(
|
||||||
|
"pendingSelectedQueues",
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
const [openSelectedQueueIds, setOpenSelectedQueueIds] = useLocalStorage(
|
||||||
|
"openSelectedQueues",
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch({ type: "RESET" });
|
dispatch({ type: "RESET" });
|
||||||
setPageNumber(1);
|
setPageNumber(1);
|
||||||
}, [status, searchParam, dispatch, showAll]);
|
}, [
|
||||||
|
status,
|
||||||
|
searchParam,
|
||||||
|
dispatch,
|
||||||
|
showAll,
|
||||||
|
openSelectedQueueIds,
|
||||||
|
pendingSelectedQueueIds,
|
||||||
|
]);
|
||||||
|
|
||||||
const { tickets, hasMore, loading } = useTickets({
|
const { tickets, hasMore, loading } = useTickets({
|
||||||
pageNumber,
|
pageNumber,
|
||||||
searchParam,
|
searchParam,
|
||||||
status,
|
status,
|
||||||
showAll,
|
showAll,
|
||||||
|
queueIds:
|
||||||
|
status === "open"
|
||||||
|
? JSON.stringify(openSelectedQueueIds)
|
||||||
|
: JSON.stringify(pendingSelectedQueueIds),
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -251,6 +276,15 @@ const TicketsList = ({ status, searchParam, showAll }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSelectedQueues = values => {
|
||||||
|
if (status === "open") {
|
||||||
|
setOpenSelectedQueueIds(values);
|
||||||
|
}
|
||||||
|
if (status === "pending") {
|
||||||
|
setPendingSelectedQueueIds(values);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.ticketsListWrapper}>
|
<div className={classes.ticketsListWrapper}>
|
||||||
<Paper
|
<Paper
|
||||||
@@ -263,14 +297,32 @@ const TicketsList = ({ status, searchParam, showAll }) => {
|
|||||||
<List style={{ paddingTop: 0 }}>
|
<List style={{ paddingTop: 0 }}>
|
||||||
{status === "open" && (
|
{status === "open" && (
|
||||||
<ListSubheader className={classes.ticketsListHeader}>
|
<ListSubheader className={classes.ticketsListHeader}>
|
||||||
{i18n.t("ticketsList.assignedHeader")}
|
<div>
|
||||||
<span className={classes.ticketsCount}>{ticketsList.length}</span>
|
{i18n.t("ticketsList.assignedHeader")}
|
||||||
|
<span className={classes.ticketsCount}>
|
||||||
|
{ticketsList.length}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<TicketsListQueueSelect
|
||||||
|
selectedQueueIds={openSelectedQueueIds}
|
||||||
|
userQueues={user?.queues}
|
||||||
|
onChange={handleSelectedQueues}
|
||||||
|
/>
|
||||||
</ListSubheader>
|
</ListSubheader>
|
||||||
)}
|
)}
|
||||||
{status === "pending" && (
|
{status === "pending" && (
|
||||||
<ListSubheader className={classes.ticketsListHeader}>
|
<ListSubheader className={classes.ticketsListHeader}>
|
||||||
{i18n.t("ticketsList.pendingHeader")}
|
<div>
|
||||||
<span className={classes.ticketsCount}>{ticketsList.length}</span>
|
{i18n.t("ticketsList.pendingHeader")}
|
||||||
|
<span className={classes.ticketsCount}>
|
||||||
|
{ticketsList.length}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<TicketsListQueueSelect
|
||||||
|
selectedQueueIds={pendingSelectedQueueIds}
|
||||||
|
userQueues={user?.queues}
|
||||||
|
onChange={handleSelectedQueues}
|
||||||
|
/>
|
||||||
</ListSubheader>
|
</ListSubheader>
|
||||||
)}
|
)}
|
||||||
{ticketsList.length === 0 && !loading ? (
|
{ticketsList.length === 0 && !loading ? (
|
||||||
|
|||||||
59
frontend/src/components/TicketsListQueueSelect/index.js
Normal file
59
frontend/src/components/TicketsListQueueSelect/index.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
import MenuItem from "@material-ui/core/MenuItem";
|
||||||
|
import FormControl from "@material-ui/core/FormControl";
|
||||||
|
import Select from "@material-ui/core/Select";
|
||||||
|
import { Checkbox, ListItemText } from "@material-ui/core";
|
||||||
|
|
||||||
|
const TicketsListQueueSelect = ({
|
||||||
|
userQueues,
|
||||||
|
selectedQueueIds = [],
|
||||||
|
onChange,
|
||||||
|
}) => {
|
||||||
|
const handleChange = e => {
|
||||||
|
onChange(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ width: 120, marginTop: -5 }}>
|
||||||
|
<FormControl fullWidth margin="dense">
|
||||||
|
<Select
|
||||||
|
multiple
|
||||||
|
displayEmpty
|
||||||
|
variant="outlined"
|
||||||
|
value={selectedQueueIds}
|
||||||
|
onChange={handleChange}
|
||||||
|
MenuProps={{
|
||||||
|
anchorOrigin: {
|
||||||
|
vertical: "bottom",
|
||||||
|
horizontal: "left",
|
||||||
|
},
|
||||||
|
transformOrigin: {
|
||||||
|
vertical: "top",
|
||||||
|
horizontal: "left",
|
||||||
|
},
|
||||||
|
getContentAnchorEl: null,
|
||||||
|
}}
|
||||||
|
renderValue={() => "Filas"}
|
||||||
|
>
|
||||||
|
{userQueues?.length > 0 &&
|
||||||
|
userQueues.map(queue => (
|
||||||
|
<MenuItem dense key={queue.id} value={queue.id}>
|
||||||
|
<Checkbox
|
||||||
|
style={{
|
||||||
|
color: queue.color,
|
||||||
|
}}
|
||||||
|
size="small"
|
||||||
|
color="primary"
|
||||||
|
checked={selectedQueueIds.indexOf(queue.id) > -1}
|
||||||
|
/>
|
||||||
|
<ListItemText primary={queue.name} />
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TicketsListQueueSelect;
|
||||||
@@ -22,7 +22,7 @@ import { i18n } from "../../translate/i18n";
|
|||||||
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import toastError from "../../errors/toastError";
|
import toastError from "../../errors/toastError";
|
||||||
import QueueSelector from "../QueueSelector";
|
import QueueSelect from "../QueueSelect";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -198,7 +198,7 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
</Field>
|
</Field>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</div>
|
</div>
|
||||||
<QueueSelector
|
<QueueSelect
|
||||||
selectedQueueIds={selectedQueueIds}
|
selectedQueueIds={selectedQueueIds}
|
||||||
onChange={values => setSelectedQueueIds(values)}
|
onChange={values => setSelectedQueueIds(values)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
import toastError from "../../errors/toastError";
|
import toastError from "../../errors/toastError";
|
||||||
import QueueSelector from "../QueueSelector";
|
import QueueSelect from "../QueueSelect";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -176,7 +176,7 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
margin="dense"
|
margin="dense"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<QueueSelector
|
<QueueSelect
|
||||||
selectedQueueIds={selectedQueueIds}
|
selectedQueueIds={selectedQueueIds}
|
||||||
onChange={values => setSelectedQueueIds(values)}
|
onChange={values => setSelectedQueueIds(values)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { toast } from "react-toastify";
|
|||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import toastError from "../../errors/toastError";
|
import toastError from "../../errors/toastError";
|
||||||
// import { useLocalStorage } from "../../hooks/useLocalStorage";
|
|
||||||
|
|
||||||
const useAuth = () => {
|
const useAuth = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@@ -62,12 +61,11 @@ const useAuth = () => {
|
|||||||
api.defaults.headers.Authorization = `Bearer ${data.token}`;
|
api.defaults.headers.Authorization = `Bearer ${data.token}`;
|
||||||
setIsAuth(true);
|
setIsAuth(true);
|
||||||
setUser(data.user);
|
setUser(data.user);
|
||||||
setLoading(false);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toastError(err);
|
toastError(err);
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setLoading(false);
|
||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const useTickets = ({
|
|||||||
status,
|
status,
|
||||||
date,
|
date,
|
||||||
showAll,
|
showAll,
|
||||||
|
queueIds,
|
||||||
withUnreadMessages,
|
withUnreadMessages,
|
||||||
}) => {
|
}) => {
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -27,6 +28,7 @@ const useTickets = ({
|
|||||||
status,
|
status,
|
||||||
date,
|
date,
|
||||||
showAll,
|
showAll,
|
||||||
|
queueIds,
|
||||||
withUnreadMessages,
|
withUnreadMessages,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -41,7 +43,15 @@ const useTickets = ({
|
|||||||
fetchTickets();
|
fetchTickets();
|
||||||
}, 500);
|
}, 500);
|
||||||
return () => clearTimeout(delayDebounceFn);
|
return () => clearTimeout(delayDebounceFn);
|
||||||
}, [searchParam, pageNumber, status, date, showAll, withUnreadMessages]);
|
}, [
|
||||||
|
searchParam,
|
||||||
|
pageNumber,
|
||||||
|
status,
|
||||||
|
date,
|
||||||
|
showAll,
|
||||||
|
queueIds,
|
||||||
|
withUnreadMessages,
|
||||||
|
]);
|
||||||
|
|
||||||
return { tickets, loading, hasMore };
|
return { tickets, loading, hasMore };
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user