ajustes em adamento
parent
4b23aad804
commit
af2bf7a0f0
|
@ -35,6 +35,7 @@ type IndexQuery = {
|
||||||
withUnreadMessages: string;
|
withUnreadMessages: string;
|
||||||
queueIds: string;
|
queueIds: string;
|
||||||
unlimited?: string;
|
unlimited?: string;
|
||||||
|
searchParamContent?: string
|
||||||
};
|
};
|
||||||
|
|
||||||
interface TicketData {
|
interface TicketData {
|
||||||
|
@ -71,7 +72,8 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||||
showAll,
|
showAll,
|
||||||
queueIds: queueIdsStringified,
|
queueIds: queueIdsStringified,
|
||||||
withUnreadMessages,
|
withUnreadMessages,
|
||||||
unlimited
|
unlimited,
|
||||||
|
searchParamContent
|
||||||
} = req.query as IndexQuery;
|
} = req.query as IndexQuery;
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,14 +94,15 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||||
userId,
|
userId,
|
||||||
queueIds,
|
queueIds,
|
||||||
withUnreadMessages,
|
withUnreadMessages,
|
||||||
unlimited
|
unlimited,
|
||||||
|
searchParamContent
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(200).json({ tickets, count, hasMore });
|
return res.status(200).json({ tickets, count, hasMore });
|
||||||
};
|
};
|
||||||
|
|
||||||
export const store = async (req: Request, res: Response): Promise<Response> => {
|
export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||||
const { contactId, status, userId, msg }: TicketData = req.body;
|
const { contactId, status, userId, msg, queueId }: TicketData = req.body;
|
||||||
|
|
||||||
console.log('TICKET CREATE: ', 'contactId: ', contactId, ' | status: ', status, ' | userId: ', userId)
|
console.log('TICKET CREATE: ', 'contactId: ', contactId, ' | status: ', status, ' | userId: ', userId)
|
||||||
|
|
||||||
|
@ -111,7 +114,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ticket = await CreateTicketService({ contactId, status, userId, msg });
|
ticket = await CreateTicketService({ contactId, status, userId, msg, queueId });
|
||||||
}
|
}
|
||||||
|
|
||||||
const io = getIO();
|
const io = getIO();
|
||||||
|
|
|
@ -29,7 +29,7 @@ interface Request {
|
||||||
status: string;
|
status: string;
|
||||||
userId: number;
|
userId: number;
|
||||||
msg?: string,
|
msg?: string,
|
||||||
queueId?: string | undefined
|
queueId?: number | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateTicketService = async ({
|
const CreateTicketService = async ({
|
||||||
|
@ -42,7 +42,7 @@ const CreateTicketService = async ({
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
console.log('Create contact service........')
|
console.log('*************** Create contact service queueId: ', queueId)
|
||||||
|
|
||||||
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
|
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ interface Request {
|
||||||
withUnreadMessages?: string;
|
withUnreadMessages?: string;
|
||||||
queueIds: number[];
|
queueIds: number[];
|
||||||
unlimited?: string;
|
unlimited?: string;
|
||||||
|
searchParamContent?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
|
@ -49,9 +50,12 @@ const ListTicketsService = async ({
|
||||||
showAll,
|
showAll,
|
||||||
userId,
|
userId,
|
||||||
withUnreadMessages,
|
withUnreadMessages,
|
||||||
unlimited = 'false'
|
unlimited = 'false',
|
||||||
|
searchParamContent = ""
|
||||||
}: Request): Promise<Response> => {
|
}: Request): Promise<Response> => {
|
||||||
|
|
||||||
|
console.log('----------> searchParamContent: ', searchParamContent)
|
||||||
|
|
||||||
let whereCondition: Filterable["where"] = { [Op.or]: [{ userId }, { status: "pending" }], queueId: { [Op.or]: [queueIds, null] } };
|
let whereCondition: Filterable["where"] = { [Op.or]: [{ userId }, { status: "pending" }], queueId: { [Op.or]: [queueIds, null] } };
|
||||||
|
|
||||||
console.log('PAGE NUMBER TICKET: ', pageNumber)
|
console.log('PAGE NUMBER TICKET: ', pageNumber)
|
||||||
|
@ -146,6 +150,7 @@ const ListTicketsService = async ({
|
||||||
|
|
||||||
if (searchParam) {
|
if (searchParam) {
|
||||||
const sanitizedSearchParam = searchParam.toLocaleLowerCase().trim();
|
const sanitizedSearchParam = searchParam.toLocaleLowerCase().trim();
|
||||||
|
const sanitizedSearchParamContent = searchParamContent.toLocaleLowerCase().trim();
|
||||||
|
|
||||||
// includeCondition = [
|
// includeCondition = [
|
||||||
// ...includeCondition,
|
// ...includeCondition,
|
||||||
|
@ -161,20 +166,31 @@ const ListTicketsService = async ({
|
||||||
// }
|
// }
|
||||||
// ];
|
// ];
|
||||||
|
|
||||||
|
if (searchParamContent.length > 0) {
|
||||||
|
|
||||||
|
console.log('LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL')
|
||||||
|
|
||||||
|
includeCondition = [
|
||||||
|
...includeCondition,
|
||||||
|
{
|
||||||
|
model: Message,
|
||||||
|
as: "messages",
|
||||||
|
attributes: ["id", "body"],
|
||||||
|
where: {
|
||||||
|
body: where(fn("LOWER", col("body")), "LIKE", `%${sanitizedSearchParamContent}%`)
|
||||||
|
},
|
||||||
|
required: false,
|
||||||
|
duplicating: false
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
whereCondition = {
|
||||||
|
...whereCondition,
|
||||||
|
"$message.body$": where(fn("LOWER", col("body")), "LIKE", `%${sanitizedSearchParamContent}%`)
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
includeCondition = [
|
|
||||||
...includeCondition,
|
|
||||||
{
|
|
||||||
model: Message,
|
|
||||||
as: "messages",
|
|
||||||
attributes: ["id", "body"],
|
|
||||||
where: {
|
|
||||||
body: where(fn("LOWER", col("body")), "LIKE", `%ADRIANO ROB%`)
|
|
||||||
},
|
|
||||||
required: false,
|
|
||||||
duplicating: false
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
whereCondition = {
|
whereCondition = {
|
||||||
...whereCondition,
|
...whereCondition,
|
||||||
|
@ -185,13 +201,12 @@ const ListTicketsService = async ({
|
||||||
|
|
||||||
{ "$contact.number$": { [Op.like]: `%${sanitizedSearchParam}%` } },
|
{ "$contact.number$": { [Op.like]: `%${sanitizedSearchParam}%` } },
|
||||||
|
|
||||||
// {
|
|
||||||
// "$message.body$": where(fn("LOWER", col("body")), "LIKE", `%${sanitizedSearchParam}%`)
|
|
||||||
// }
|
|
||||||
],
|
],
|
||||||
"$message.body$": where(fn("LOWER", col("body")), "LIKE", `%ADRIANO ROB%`)
|
// "$message.body$": where(fn("LOWER", col("body")), "LIKE", `%ADRIANO ROB%`)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('whereConditionwhereConditionwhereCondition: ', whereCondition)
|
||||||
|
|
||||||
|
|
||||||
// whereCondition = {
|
// whereCondition = {
|
||||||
// ...whereCondition,
|
// ...whereCondition,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useState, useEffect, useReducer, useContext } from "react";
|
import React, { useState, useEffect, useReducer, useContext } from "react";
|
||||||
|
|
||||||
|
|
||||||
import openSocket from "socket.io-client";
|
import openSocket from "socket.io-client";
|
||||||
|
@ -177,31 +177,32 @@ const reducer = (state, action) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const TicketsList = (props) => {
|
const TicketsList = (props) => {
|
||||||
const { status, searchParam, showAll, selectedQueueIds, updateCount, style, tab } = props;
|
const { status, searchParam, searchParamContent, showAll, selectedQueueIds, updateCount, style, tab } = props;
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
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 { searchTicket } = useContext(SearchTicketContext)
|
const { searchTicket } = useContext(SearchTicketContext)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
dispatch({ type: "RESET" });
|
dispatch({ type: "RESET" });
|
||||||
setPageNumber(1);
|
setPageNumber(1);
|
||||||
|
|
||||||
}, [status, searchParam, showAll, selectedQueueIds, searchTicket]);
|
}, [status, searchParam, searchParamContent, showAll, selectedQueueIds, searchTicket]);
|
||||||
|
|
||||||
const { tickets, hasMore, loading } = useTickets({
|
const { tickets, hasMore, loading } = useTickets({
|
||||||
pageNumber,
|
pageNumber,
|
||||||
searchParam,
|
searchParam,
|
||||||
|
searchParamContent,
|
||||||
status,
|
status,
|
||||||
showAll,
|
showAll,
|
||||||
queueIds: JSON.stringify(selectedQueueIds),
|
queueIds: JSON.stringify(selectedQueueIds),
|
||||||
tab
|
tab
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
if (!status && !searchParam) return;
|
if (!status && !searchParam) return;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,9 @@ import Tabs from "@material-ui/core/Tabs";
|
||||||
import Tab from "@material-ui/core/Tab";
|
import Tab from "@material-ui/core/Tab";
|
||||||
import Badge from "@material-ui/core/Badge";
|
import Badge from "@material-ui/core/Badge";
|
||||||
|
|
||||||
|
import Tooltip from "@material-ui/core/Tooltip";
|
||||||
|
|
||||||
|
|
||||||
import SearchIcon from "@material-ui/icons/Search";
|
import SearchIcon from "@material-ui/icons/Search";
|
||||||
import MoveToInboxIcon from "@material-ui/icons/MoveToInbox";
|
import MoveToInboxIcon from "@material-ui/icons/MoveToInbox";
|
||||||
import CheckBoxIcon from "@material-ui/icons/CheckBox";
|
import CheckBoxIcon from "@material-ui/icons/CheckBox";
|
||||||
|
@ -152,6 +155,9 @@ const TicketsManager = () => {
|
||||||
const [inputSearch, setInputSearch] = useState('');
|
const [inputSearch, setInputSearch] = useState('');
|
||||||
const [inputContentSearch, setInputContentSearch] = useState("")
|
const [inputContentSearch, setInputContentSearch] = useState("")
|
||||||
|
|
||||||
|
const [openTooltipSearch, setOpenTooltipSearch] = useState(false)
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user.profile.toUpperCase() === "ADMIN") {
|
if (user.profile.toUpperCase() === "ADMIN") {
|
||||||
setShowAllTickets(true);
|
setShowAllTickets(true);
|
||||||
|
@ -183,6 +189,7 @@ const TicketsManager = () => {
|
||||||
}, [tabOption, setTabOption])
|
}, [tabOption, setTabOption])
|
||||||
|
|
||||||
let searchTimeout;
|
let searchTimeout;
|
||||||
|
let searchContentTimeout;
|
||||||
|
|
||||||
const removeExtraSpace = (str) => {
|
const removeExtraSpace = (str) => {
|
||||||
|
|
||||||
|
@ -203,10 +210,16 @@ const TicketsManager = () => {
|
||||||
if (searchedTerm === "") {
|
if (searchedTerm === "") {
|
||||||
setSearchParam(prev => ({ ...prev, searchParam: searchedTerm }))
|
setSearchParam(prev => ({ ...prev, searchParam: searchedTerm }))
|
||||||
setInputSearch(searchedTerm)
|
setInputSearch(searchedTerm)
|
||||||
|
setShowContentSearch(false)
|
||||||
setTab("open");
|
setTab("open");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (searchedTerm.length < 4) {
|
||||||
|
setSearchParam(prev => ({ ...prev, searchParamContent: "" }))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
searchTimeout = setTimeout(() => {
|
searchTimeout = setTimeout(() => {
|
||||||
|
|
||||||
setSearchParam(prev => ({ ...prev, searchParam: searchedTerm }));
|
setSearchParam(prev => ({ ...prev, searchParam: searchedTerm }));
|
||||||
|
@ -215,8 +228,36 @@ const TicketsManager = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleContentSearch = e => {
|
const handleContentSearch = e => {
|
||||||
let searchedContentText = e.target.value.toLowerCase()
|
|
||||||
setInputContentSearch(searchedContentText)
|
let searchedContentText = removeExtraSpace(e.target.value.toLowerCase())
|
||||||
|
|
||||||
|
console.log('searchedContentText: ', searchedContentText)
|
||||||
|
|
||||||
|
setInputContentSearch(searchedContentText)
|
||||||
|
|
||||||
|
// setInputSearch(removeExtraSpace(searchedContentText))
|
||||||
|
|
||||||
|
clearTimeout(searchContentTimeout);
|
||||||
|
|
||||||
|
searchContentTimeout = setTimeout(() => {
|
||||||
|
|
||||||
|
setSearchParam(prev => ({ ...prev, searchParamContent: inputContentSearch }));
|
||||||
|
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpenTooltipSearch = () => {
|
||||||
|
if (searchParam.searchParam.length < 4) {
|
||||||
|
setOpenTooltipSearch(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCloseTooltipSearch = () => {
|
||||||
|
setOpenTooltipSearch(false)
|
||||||
|
if (searchParam.searchParam.length < 4) {
|
||||||
|
searchInputRef.current.focus()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleChangeTab = (e, newValue) => {
|
const handleChangeTab = (e, newValue) => {
|
||||||
|
@ -281,12 +322,28 @@ const TicketsManager = () => {
|
||||||
value={inputSearch}
|
value={inputSearch}
|
||||||
onChange={handleSearch}
|
onChange={handleSearch}
|
||||||
/>
|
/>
|
||||||
<IconButton onClick={() => setShowContentSearch(prev => !prev)}>
|
{/* <IconButton onClick={() => setShowContentSearch(prev => !prev)}>
|
||||||
<MenuIcon className={classes.menuSearch} />
|
<MenuIcon className={classes.menuSearch} />
|
||||||
</IconButton>
|
</IconButton> */}
|
||||||
|
<Tooltip
|
||||||
|
open={openTooltipSearch}
|
||||||
|
onOpen={() => handleOpenTooltipSearch()}
|
||||||
|
onClose={() => handleCloseTooltipSearch()}
|
||||||
|
title="Digite pelo menos 4 caracteres"
|
||||||
|
arrow>
|
||||||
|
<span>
|
||||||
|
<IconButton
|
||||||
|
disabled={searchParam.searchParam.length < 4}
|
||||||
|
onClick={() => setShowContentSearch(prev => !prev)}
|
||||||
|
>
|
||||||
|
<MenuIcon className={classes.menuSearch} />
|
||||||
|
</IconButton>
|
||||||
|
</span>
|
||||||
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
showContentSearch ?
|
// showContentSearch ?
|
||||||
|
(showContentSearch && searchParam.searchParam.length >= 4) ?
|
||||||
(<div className={classes.searchContentInput}>
|
(<div className={classes.searchContentInput}>
|
||||||
<FindInPageIcon className={classes.searchIcon} />
|
<FindInPageIcon className={classes.searchIcon} />
|
||||||
<InputBase
|
<InputBase
|
||||||
|
@ -400,6 +457,7 @@ const TicketsManager = () => {
|
||||||
|
|
||||||
<TicketsList
|
<TicketsList
|
||||||
searchParam={searchParam.searchParam}
|
searchParam={searchParam.searchParam}
|
||||||
|
searchParamContent={searchParam.searchParamContent}
|
||||||
tab={tab}
|
tab={tab}
|
||||||
showAll={true}
|
showAll={true}
|
||||||
selectedQueueIds={selectedQueueIds}
|
selectedQueueIds={selectedQueueIds}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import api from "../../services/api";
|
||||||
|
|
||||||
const useTickets = ({
|
const useTickets = ({
|
||||||
searchParam,
|
searchParam,
|
||||||
|
searchParamContent,
|
||||||
pageNumber,
|
pageNumber,
|
||||||
status,
|
status,
|
||||||
date,
|
date,
|
||||||
|
@ -35,6 +36,7 @@ const useTickets = ({
|
||||||
const { data } = await api.get("/tickets", {
|
const { data } = await api.get("/tickets", {
|
||||||
params: {
|
params: {
|
||||||
searchParam,
|
searchParam,
|
||||||
|
searchParamContent,
|
||||||
pageNumber,
|
pageNumber,
|
||||||
status,
|
status,
|
||||||
date,
|
date,
|
||||||
|
@ -63,6 +65,7 @@ const useTickets = ({
|
||||||
return () => clearTimeout(delayDebounceFn);
|
return () => clearTimeout(delayDebounceFn);
|
||||||
}, [
|
}, [
|
||||||
searchParam,
|
searchParam,
|
||||||
|
searchParamContent,
|
||||||
pageNumber,
|
pageNumber,
|
||||||
status,
|
status,
|
||||||
date,
|
date,
|
||||||
|
|
Loading…
Reference in New Issue