Estado funcional da busca de tickets pelo conteudo
parent
af2bf7a0f0
commit
4cd72fdbd6
|
@ -168,7 +168,7 @@ const ListTicketsService = async ({
|
||||||
|
|
||||||
if (searchParamContent.length > 0) {
|
if (searchParamContent.length > 0) {
|
||||||
|
|
||||||
console.log('LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL')
|
// console.log('LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL')
|
||||||
|
|
||||||
includeCondition = [
|
includeCondition = [
|
||||||
...includeCondition,
|
...includeCondition,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useState, useEffect, useContext } from "react";
|
import React, { useState, useEffect, useContext, useRef, useCallback } from "react";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import Select from "@material-ui/core/Select";
|
||||||
import FormControl from "@material-ui/core/FormControl";
|
import FormControl from "@material-ui/core/FormControl";
|
||||||
import InputLabel from "@material-ui/core/InputLabel";
|
import InputLabel from "@material-ui/core/InputLabel";
|
||||||
import MenuItem from "@material-ui/core/MenuItem";
|
import MenuItem from "@material-ui/core/MenuItem";
|
||||||
|
import LinearProgress from "@material-ui/core/LinearProgress";
|
||||||
import { makeStyles } from "@material-ui/core";
|
import { makeStyles } from "@material-ui/core";
|
||||||
|
|
||||||
import DialogActions from "@material-ui/core/DialogActions";
|
import DialogActions from "@material-ui/core/DialogActions";
|
||||||
|
@ -28,11 +29,15 @@ const useStyles = makeStyles((theme) => ({
|
||||||
},
|
},
|
||||||
paper: {
|
paper: {
|
||||||
minWidth: "300px"
|
minWidth: "300px"
|
||||||
|
},
|
||||||
|
linearProgress: {
|
||||||
|
marginTop: "5px"
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const ContactCreateTicketModal = ({ modalOpen, onClose, contactId }) => {
|
const ContactCreateTicketModal = ({ modalOpen, onClose, contactId }) => {
|
||||||
const { user } = useContext(AuthContext);
|
const { user } = useContext(AuthContext);
|
||||||
|
let isMounted = useRef(true)
|
||||||
|
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [queues, setQueues] = useState([]);
|
const [queues, setQueues] = useState([]);
|
||||||
|
@ -42,6 +47,7 @@ const ContactCreateTicketModal = ({ modalOpen, onClose, contactId }) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const userQueues = user.queues.map(({ id, name, color }) => { return { id, name, color } })
|
const userQueues = user.queues.map(({ id, name, color }) => { return { id, name, color } })
|
||||||
|
if (userQueues.length === 1) setSelectedQueue(userQueues[0].id)
|
||||||
setQueues(userQueues)
|
setQueues(userQueues)
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
|
@ -49,32 +55,45 @@ const ContactCreateTicketModal = ({ modalOpen, onClose, contactId }) => {
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveTicket = async (e) => {
|
const handleSaveTicket = useCallback(async (contactId, userId, queueId) => {
|
||||||
e.preventDefault()
|
if (!contactId || !userId) {
|
||||||
if (!contactId) return;
|
console.log("Missing contactId or userId")
|
||||||
if (!selectedQueue) {
|
return
|
||||||
|
};
|
||||||
|
if (!queueId) {
|
||||||
toast.warning("Nenhuma Fila Selecionada")
|
toast.warning("Nenhuma Fila Selecionada")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setLoading(true);
|
if (isMounted.current) setLoading(true);
|
||||||
try {
|
try {
|
||||||
const { data: ticket } = await api.post("/tickets", {
|
const { data: ticket } = await api.post("/tickets", {
|
||||||
contactId: contactId,
|
contactId: contactId,
|
||||||
userId: user?.id,
|
userId: userId,
|
||||||
queueId: selectedQueue,
|
queueId: queueId,
|
||||||
status: "open",
|
status: "open",
|
||||||
});
|
});
|
||||||
history.push(`/tickets/${ticket.id}`);
|
history.push(`/tickets/${ticket.id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toastError(err);
|
toastError(err);
|
||||||
onClose()
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
if (isMounted.current) setLoading(false);
|
||||||
|
}, [history])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (modalOpen && queues.length <= 1) {
|
||||||
|
handleSaveTicket(contactId, user.id, selectedQueue)
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
isMounted.current = false;
|
||||||
};
|
};
|
||||||
|
}, [modalOpen, contactId, user.id, selectedQueue, handleSaveTicket, queues.length]);
|
||||||
|
|
||||||
|
if (modalOpen && queues.length <= 1) {
|
||||||
|
return <LinearProgress />
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={modalOpen} onClose={handleClose} maxWidth="xs" scroll="paper" classes={{ paper: classes.paper }}>
|
<Dialog open={modalOpen} onClose={handleClose} maxWidth="xs" scroll="paper" classes={{ paper: classes.paper }}>
|
||||||
<form onSubmit={handleSaveTicket}>
|
|
||||||
<DialogTitle id="form-dialog-title">
|
<DialogTitle id="form-dialog-title">
|
||||||
{i18n.t("newTicketModal.title")}
|
{i18n.t("newTicketModal.title")}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
|
@ -103,15 +122,14 @@ const ContactCreateTicketModal = ({ modalOpen, onClose, contactId }) => {
|
||||||
{i18n.t("newTicketModal.buttons.cancel")}
|
{i18n.t("newTicketModal.buttons.cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
<ButtonWithSpinner
|
<ButtonWithSpinner
|
||||||
|
onClick={() => handleSaveTicket(contactId, user.id, selectedQueue)}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
type="submit"
|
|
||||||
color="primary"
|
color="primary"
|
||||||
loading={loading}
|
loading={loading}
|
||||||
>
|
>
|
||||||
{i18n.t("newTicketModal.buttons.ok")}
|
{i18n.t("newTicketModal.buttons.ok")}
|
||||||
</ButtonWithSpinner>
|
</ButtonWithSpinner>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</form>
|
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -174,6 +174,26 @@ const TicketsManager = () => {
|
||||||
|
|
||||||
}, [tab, setTabOption]);
|
}, [tab, setTabOption]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
|
||||||
|
|
||||||
|
clearTimeout(searchContentTimeout);
|
||||||
|
|
||||||
|
setSearchParam(prev => ({ ...prev, searchParamContent: "" }))
|
||||||
|
|
||||||
|
// console.log('inputContentSearch1: ', inputContentSearch)
|
||||||
|
|
||||||
|
if (!inputContentSearch) return
|
||||||
|
|
||||||
|
searchContentTimeout = setTimeout(() => {
|
||||||
|
|
||||||
|
setSearchParam(prev => ({ ...prev, searchParamContent: inputContentSearch }));
|
||||||
|
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
|
||||||
|
}, [inputContentSearch,]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
|
|
||||||
|
@ -182,6 +202,7 @@ const TicketsManager = () => {
|
||||||
setTabOption('')
|
setTabOption('')
|
||||||
setSearchParam(DEFAULT_SEARCH_PARAM);
|
setSearchParam(DEFAULT_SEARCH_PARAM);
|
||||||
setInputSearch('');
|
setInputSearch('');
|
||||||
|
setInputContentSearch('')
|
||||||
setTab("open");
|
setTab("open");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -217,6 +238,7 @@ const TicketsManager = () => {
|
||||||
|
|
||||||
if (searchedTerm.length < 4) {
|
if (searchedTerm.length < 4) {
|
||||||
setSearchParam(prev => ({ ...prev, searchParamContent: "" }))
|
setSearchParam(prev => ({ ...prev, searchParamContent: "" }))
|
||||||
|
setInputContentSearch('')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -233,18 +255,16 @@ const TicketsManager = () => {
|
||||||
|
|
||||||
console.log('searchedContentText: ', searchedContentText)
|
console.log('searchedContentText: ', searchedContentText)
|
||||||
|
|
||||||
|
// clearTimeout(searchContentTimeout);
|
||||||
|
|
||||||
|
// searchContentTimeout = setTimeout(() => {
|
||||||
|
|
||||||
|
// setSearchParam(prev => ({ ...prev, searchParamContent: inputContentSearch }));
|
||||||
|
|
||||||
|
// }, 500);
|
||||||
|
|
||||||
setInputContentSearch(searchedContentText)
|
setInputContentSearch(searchedContentText)
|
||||||
|
|
||||||
// setInputSearch(removeExtraSpace(searchedContentText))
|
|
||||||
|
|
||||||
clearTimeout(searchContentTimeout);
|
|
||||||
|
|
||||||
searchContentTimeout = setTimeout(() => {
|
|
||||||
|
|
||||||
setSearchParam(prev => ({ ...prev, searchParamContent: inputContentSearch }));
|
|
||||||
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOpenTooltipSearch = () => {
|
const handleOpenTooltipSearch = () => {
|
||||||
|
@ -352,7 +372,7 @@ const TicketsManager = () => {
|
||||||
placeholder={i18n.t("Busca por conteúdo")}
|
placeholder={i18n.t("Busca por conteúdo")}
|
||||||
type="search"
|
type="search"
|
||||||
value={inputContentSearch}
|
value={inputContentSearch}
|
||||||
onChange={handleContentSearch}
|
onChange={(e) => handleContentSearch(e)}
|
||||||
/>
|
/>
|
||||||
</div>) : null
|
</div>) : null
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue