diff --git a/ee/app/livechat-enterprise/server/api/lib/priorities.js b/ee/app/livechat-enterprise/server/api/lib/priorities.js index 983e2017234..f66d0dff3ec 100644 --- a/ee/app/livechat-enterprise/server/api/lib/priorities.js +++ b/ee/app/livechat-enterprise/server/api/lib/priorities.js @@ -1,11 +1,19 @@ +import s from 'underscore.string'; + import { hasPermissionAsync } from '../../../../../../app/authorization/server/functions/hasPermission'; import LivechatPriority from '../../../../models/server/raw/LivechatPriority'; -export async function findPriorities({ userId, pagination: { offset, count, sort } }) { +export async function findPriorities({ userId, text, pagination: { offset, count, sort } }) { if (!await hasPermissionAsync(userId, 'manage-livechat-priorities') && !await hasPermissionAsync(userId, 'view-l-room')) { throw new Error('error-not-authorized'); } - const cursor = LivechatPriority.find({}, { + + const filterReg = new RegExp(s.escapeRegExp(text), 'i'); + + const query = { ...text && { $or: [{ name: filterReg }, { description: filterReg }] } }; + + + const cursor = LivechatPriority.find(query, { sort: sort || { name: 1 }, skip: offset, limit: count, diff --git a/ee/app/livechat-enterprise/server/api/priorities.js b/ee/app/livechat-enterprise/server/api/priorities.js index 870ba2b7d22..8b577fcdffb 100644 --- a/ee/app/livechat-enterprise/server/api/priorities.js +++ b/ee/app/livechat-enterprise/server/api/priorities.js @@ -5,9 +5,11 @@ API.v1.addRoute('livechat/priorities.list', { authRequired: true }, { get() { const { offset, count } = this.getPaginationItems(); const { sort } = this.parseJsonQuery(); + const { text } = this.queryParams; return API.v1.success(Promise.await(findPriorities({ userId: this.userId, + text, pagination: { offset, count, diff --git a/ee/client/omnichannel/priorities/EditPriority.js b/ee/client/omnichannel/priorities/EditPriority.js index 3edde9edffd..781aef97ec0 100644 --- a/ee/client/omnichannel/priorities/EditPriority.js +++ b/ee/client/omnichannel/priorities/EditPriority.js @@ -74,7 +74,7 @@ export function PriorityEdit({ data, isNew, priorityId, reload, ...props }) { try { await savePriority(priorityId, payload); - dispatchToastMessage({ type: 'success', message: t('saved') }); + dispatchToastMessage({ type: 'success', message: t('Saved') }); reload(); prioritiesRoute.push({}); } catch (error) { @@ -84,21 +84,21 @@ export function PriorityEdit({ data, isNew, priorityId, reload, ...props }) { return - {t('Name')} + {t('Name')}* - + {t('Description')} - + - {t('Estimated_due_time_in_minutes')} + {t('Estimated_due_time_in_minutes')}* - + @@ -106,7 +106,7 @@ export function PriorityEdit({ data, isNew, priorityId, reload, ...props }) { { !isNew && } - + diff --git a/ee/client/omnichannel/priorities/PrioritiesPage.js b/ee/client/omnichannel/priorities/PrioritiesPage.js index 7f53c54a1fb..885eab9da36 100644 --- a/ee/client/omnichannel/priorities/PrioritiesPage.js +++ b/ee/client/omnichannel/priorities/PrioritiesPage.js @@ -29,7 +29,9 @@ function PrioritiesPage({ - + diff --git a/ee/client/omnichannel/priorities/PrioritiesRoute.js b/ee/client/omnichannel/priorities/PrioritiesRoute.js index becb595ddea..daecf981a39 100644 --- a/ee/client/omnichannel/priorities/PrioritiesRoute.js +++ b/ee/client/omnichannel/priorities/PrioritiesRoute.js @@ -23,7 +23,7 @@ export function RemovePriorityButton({ _id, reload }) { const setModal = useSetModal(); const dispatchToastMessage = useToastMessageDispatch(); const t = useTranslation(); - + const prioritiesRoute = useRoute('omnichannel-priorities'); const handleRemoveClick = useMutableCallback(async () => { try { @@ -40,6 +40,7 @@ export function RemovePriorityButton({ _id, reload }) { try { await handleRemoveClick(); dispatchToastMessage({ type: 'success', message: t('Priority_removed') }); + prioritiesRoute.push({}); } catch (error) { dispatchToastMessage({ type: 'error', message: error }); } @@ -98,10 +99,10 @@ function PrioritiesRoute() { const { data, reload } = useEndpointDataExperimental('livechat/priorities.list', query) || {}; const header = useMemo(() => [ - {t('Name')}, - {t('Description')}, - {t('Estimated_due_time')}, - {t('Remove')}, + {t('Name')}, + {t('Description')}, + {t('Estimated_due_time')}, + {t('Remove')}, ].filter(Boolean), [sort, onHeaderClick, t]); const renderRow = useCallback(({ _id, name, description, dueTimeInMinutes }) => @@ -146,7 +147,7 @@ function PrioritiesRoute() { reload={reload} header={header} renderRow={renderRow} - title={'Priorities'}> + title={t('Priorities')}> ; }