improvement: trim search params on contacts and tickets filters

This commit is contained in:
canove
2020-09-30 20:00:17 -03:00
parent 0735dddfb4
commit 38d926820c
6 changed files with 26 additions and 13 deletions

View File

@@ -20,8 +20,6 @@ interface Response {
export const RefreshTokenService = async (token: string): Promise<Response> => { export const RefreshTokenService = async (token: string): Promise<Response> => {
let decoded; let decoded;
console.log(token);
try { try {
decoded = verify(token, authConfig.refreshSecret); decoded = verify(token, authConfig.refreshSecret);
} catch (err) { } catch (err) {

View File

@@ -22,10 +22,10 @@ const ListContactsService = async ({
name: Sequelize.where( name: Sequelize.where(
Sequelize.fn("LOWER", Sequelize.col("name")), Sequelize.fn("LOWER", Sequelize.col("name")),
"LIKE", "LIKE",
`%${searchParam.toLowerCase()}%` `%${searchParam.toLowerCase().trim()}%`
) )
}, },
{ number: { [Op.like]: `%${searchParam}%` } } { number: { [Op.like]: `%${searchParam.toLowerCase().trim()}%` } }
] ]
}; };
const limit = 20; const limit = 20;

View File

@@ -55,6 +55,8 @@ const ListTicketsService = async ({
} }
if (searchParam) { if (searchParam) {
const sanitizedSearchParam = searchParam.toLocaleLowerCase().trim();
includeCondition = [ includeCondition = [
...includeCondition, ...includeCondition,
{ {
@@ -65,7 +67,7 @@ const ListTicketsService = async ({
body: where( body: where(
fn("LOWER", col("body")), fn("LOWER", col("body")),
"LIKE", "LIKE",
`%${searchParam.toLowerCase()}%` `%${sanitizedSearchParam}%`
) )
}, },
required: false, required: false,
@@ -79,15 +81,15 @@ const ListTicketsService = async ({
"$contact.name$": where( "$contact.name$": where(
fn("LOWER", col("name")), fn("LOWER", col("name")),
"LIKE", "LIKE",
`%${searchParam.toLowerCase()}%` `%${sanitizedSearchParam}%`
) )
}, },
{ "$contact.number$": { [Op.like]: `%${searchParam}%` } }, { "$contact.number$": { [Op.like]: `%${sanitizedSearchParam}%` } },
{ {
"$message.body$": where( "$message.body$": where(
fn("LOWER", col("body")), fn("LOWER", col("body")),
"LIKE", "LIKE",
`%${searchParam.toLowerCase()}%` `%${sanitizedSearchParam}%`
) )
} }
] ]

View File

@@ -9,7 +9,9 @@ import Dialog from "@material-ui/core/Dialog";
import DialogActions from "@material-ui/core/DialogActions"; import DialogActions from "@material-ui/core/DialogActions";
import DialogContent from "@material-ui/core/DialogContent"; import DialogContent from "@material-ui/core/DialogContent";
import DialogTitle from "@material-ui/core/DialogTitle"; import DialogTitle from "@material-ui/core/DialogTitle";
import Autocomplete from "@material-ui/lab/Autocomplete"; import Autocomplete, {
createFilterOptions,
} from "@material-ui/lab/Autocomplete";
import CircularProgress from "@material-ui/core/CircularProgress"; import CircularProgress from "@material-ui/core/CircularProgress";
import { green } from "@material-ui/core/colors"; import { green } from "@material-ui/core/colors";
@@ -39,6 +41,12 @@ const useStyles = makeStyles(theme => ({
}, },
})); }));
const filterOptions = createFilterOptions({
matchFrom: "start",
trim: true,
stringify: option => option.name,
});
const NewTicketModal = ({ modalOpen, onClose }) => { const NewTicketModal = ({ modalOpen, onClose }) => {
const history = useHistory(); const history = useHistory();
const classes = useStyles(); const classes = useStyles();
@@ -73,6 +81,8 @@ const NewTicketModal = ({ modalOpen, onClose }) => {
return () => clearTimeout(delayDebounceFn); return () => clearTimeout(delayDebounceFn);
}, [searchParam, modalOpen]); }, [searchParam, modalOpen]);
console.log(options);
const handleClose = () => { const handleClose = () => {
onClose(); onClose();
setSearchParam(""); setSearchParam("");
@@ -121,7 +131,8 @@ const NewTicketModal = ({ modalOpen, onClose }) => {
setSelectedContact(newValue); setSelectedContact(newValue);
}} }}
options={options} options={options}
noOptionsText="No contacts found. Try another term." filterOptions={filterOptions}
noOptionsText={i18n.t("newTicketModal.noOptions")}
loading={loading} loading={loading}
renderInput={params => ( renderInput={params => (
<TextField <TextField

View File

@@ -178,7 +178,8 @@ const messages = {
}, },
newTicketModal: { newTicketModal: {
title: "Create Ticket", title: "Create Ticket",
fieldLabel: "Type to search for the contact", fieldLabel: "Type to search for a contact",
noOptions: "No contacts found. Try another name.",
buttons: { buttons: {
ok: "Save", ok: "Save",
cancel: "Cancel", cancel: "Cancel",
@@ -243,8 +244,8 @@ const messages = {
buttons: { buttons: {
return: "Return", return: "Return",
resolve: "Resolve", resolve: "Resolve",
reopen: "Reopen", reopen: "Reopen",
accept: "Accept" accept: "Accept",
}, },
}, },
}, },

View File

@@ -180,6 +180,7 @@ const messages = {
newTicketModal: { newTicketModal: {
title: "Criar Ticket", title: "Criar Ticket",
fieldLabel: "Digite para pesquisar o contato", fieldLabel: "Digite para pesquisar o contato",
noOptions: "Nenhum contato encotrado. Tente outro nome.",
buttons: { buttons: {
ok: "Salvar", ok: "Salvar",
cancel: "Cancelar", cancel: "Cancelar",