Skip to content

Commit

Permalink
Merge pull request RocketChat#559 from Shailesh351/sb_fix_omni_filters
Browse files Browse the repository at this point in the history
Fix OmniChannel Filters Setting
  • Loading branch information
chadgoss authored Mar 18, 2021
2 parents 9b715c7 + 10bf406 commit 6f4ffbe
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 50 deletions.
5 changes: 0 additions & 5 deletions client/omnichannel/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ registerOmnichannelRoute('/triggers/:context?/:id?', {
lazyRouteComponent: () => import('./triggers/TriggersPage'),
});

registerOmnichannelRoute('/filters/:context?/:id?', {
name: 'omnichannel-filters',
lazyRouteComponent: () => import('./filters/FiltersPage'),
});

registerOmnichannelRoute('/facebook', {
name: 'omnichannel-facebook',
lazyRouteComponent: () => import('./facebook/FacebookPage'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import React from 'react';
import { Button, Callout, FieldGroup, ButtonGroup } from '@rocket.chat/fuselage';
import { Margins, Callout, FieldGroup, Box, Button } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';

import FiltersForm from './FiltersForm';
import PageSkeleton from '../../components/PageSkeleton';
import { useTranslation } from '../../contexts/TranslationContext';
import { useMethod } from '../../contexts/ServerContext';
import { useForm } from '../../hooks/useForm';
import { useEndpointData, ENDPOINT_STATES } from '../../hooks/useEndpointData';
import { useRoute } from '../../contexts/RouterContext';
import { useToastMessageDispatch } from '../../contexts/ToastMessagesContext';
import PageSkeleton from '../../../components/PageSkeleton';
import { useTranslation } from '../../../contexts/TranslationContext';
import { useMethod } from '../../../contexts/ServerContext';
import { useForm } from '../../../hooks/useForm';
import { useRoute } from '../../../contexts/RouterContext';
import { useToastMessageDispatch } from '../../../contexts/ToastMessagesContext';
import { useEndpointData } from '../../../hooks/useEndpointData';
import { AsyncStatePhase } from '../../../hooks/useAsyncState';

const EditFilterPageContainer = ({ id, onSave }) => {
const t = useTranslation();
const { data, state } = useEndpointData(`livechat/filters/${ id }`);
const { value: data, phase: state } = useEndpointData(`livechat/filters/${ id }`);

if (state === ENDPOINT_STATES.LOADING) {
if (state === AsyncStatePhase.LOADING) {
return <PageSkeleton />;
}

if (state === ENDPOINT_STATES.ERROR || !data?.filter) {
if (state === AsyncStatePhase.REJECTED || !data?.filter) {
return <Callout>
{t('Error')}: error
</Callout>;
Expand Down Expand Up @@ -50,7 +51,7 @@ const EditFilterPage = ({ data, onSave }) => {

const save = useMethod('livechat:saveFilter');

const { values, handlers } = useForm(getInitialValues(data));
const { values, handlers, hasUnsavedChanges } = useForm(getInitialValues(data));

const handleSave = useMutableCallback(async () => {
try {
Expand All @@ -66,15 +67,21 @@ const EditFilterPage = ({ data, onSave }) => {
}
});

const { name } = values;

const canSave = name && hasUnsavedChanges;

return <>
<FieldGroup>
<FiltersForm values={values} handlers={handlers}/>
</FieldGroup>
<ButtonGroup align='end'>
<Button primary onClick={handleSave}>
{t('Save')}
</Button>
</ButtonGroup>
<Box display='flex' flexDirection='row' justifyContent='space-between' w='full'>
<Margins inlineEnd='x4'>
<Button flexGrow={1} primary onClick={handleSave} disabled={!canSave}>
{t('Save')}
</Button>
</Margins>
</Box>
</>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { FieldGroup, Box } from '@rocket.chat/fuselage';

import FiltersForm from './FiltersForm';
import { useForm } from '../../hooks/useForm';
import { useForm } from '../../../hooks/useForm';

export default {
title: 'omnichannel/FiltersForm',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC, FormEvent } from 'react';
import { Box, Field, TextInput, ToggleSwitch, BoxClassName } from '@rocket.chat/fuselage';

import { useTranslation } from '../../contexts/TranslationContext';
import { useTranslation } from '../../../contexts/TranslationContext';

type FiltersFormProps = {
values: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import FiltersTable from './FiltersTable';
import EditFilterPage from './EditFilterPage';
import NewFilterPage from './NewFilterPage';
import VerticalBar from '../../components/VerticalBar';
import Page from '../../components/Page';
import NotAuthorizedPage from '../../components/NotAuthorizedPage';
import { useTranslation } from '../../contexts/TranslationContext';
import { useRoute, useRouteParameter } from '../../contexts/RouterContext';
import { usePermission } from '../../contexts/AuthorizationContext';
import VerticalBar from '../../../components/VerticalBar';
import Page from '../../../components/Page';
import NotAuthorizedPage from '../../../components/NotAuthorizedPage';
import { useTranslation } from '../../../contexts/TranslationContext';
import { useRoute, useRouteParameter } from '../../../contexts/RouterContext';
import { usePermission } from '../../../contexts/AuthorizationContext';

const MonitorsPage = () => {
const t = useTranslation();
Expand Down Expand Up @@ -43,13 +43,13 @@ const MonitorsPage = () => {
<Icon name='plus' size='x16' />
</Button>
</Page.Header>
<Page.ScrollableContentWithShadow>
<Page.Content>
<FiltersTable reloadRef={reload}/>
</Page.ScrollableContentWithShadow>
</Page.Content>
</Page>
{context && <VerticalBar className={'contextual-bar'}>
<VerticalBar.Header>
{t('Trigger')}
{t('Filter')}
<VerticalBar.Close onClick={handleCloseVerticalBar} />
</VerticalBar.Header>
<VerticalBar.ScrollableContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { Table, Callout, Icon, Button } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import React, { useState, memo, useMemo } from 'react';

import GenericTable from '../../components/GenericTable';
import DeleteWarningModal from '../../components/DeleteWarningModal';
import { useRoute } from '../../contexts/RouterContext';
import { useSetModal } from '../../contexts/ModalContext';
import { useMethod } from '../../contexts/ServerContext';
import { useTranslation } from '../../contexts/TranslationContext';
import { useToastMessageDispatch } from '../../contexts/ToastMessagesContext';
import { useResizeInlineBreakpoint } from '../../hooks/useResizeInlineBreakpoint';
import { useEndpointData, ENDPOINT_STATES } from '../../hooks/useEndpointData';
import GenericTable from '../../../components/GenericTable';
import DeleteWarningModal from '../../../components/DeleteWarningModal';
import { useRoute } from '../../../contexts/RouterContext';
import { useSetModal } from '../../../contexts/ModalContext';
import { useMethod } from '../../../contexts/ServerContext';
import { useTranslation } from '../../../contexts/TranslationContext';
import { useToastMessageDispatch } from '../../../contexts/ToastMessagesContext';
import { useResizeInlineBreakpoint } from '../../../hooks/useResizeInlineBreakpoint';
import { useEndpointData } from '../../../hooks/useEndpointData';
import { AsyncStatePhase } from '../../../hooks/useAsyncState';

const FiltersRow = memo(function FiltersRow(props) {
const {
Expand Down Expand Up @@ -58,7 +59,10 @@ const FiltersRow = memo(function FiltersRow(props) {
setModal();
};

setModal(<DeleteWarningModal onDelete={onDeleteFilter} onCancel={() => setModal()}/>);
setModal(<DeleteWarningModal
onDelete={onDeleteFilter}
onCancel={() => setModal()}
/>);
});

return <Table.Row
Expand Down Expand Up @@ -95,11 +99,11 @@ const FiltersTableContainer = ({ reloadRef }) => {
itemsPerPage,
} = params;

const { data, state, reload } = useEndpointData('livechat/filters', useMemo(() => ({ offset: current, count: itemsPerPage }), [current, itemsPerPage]));
const { value: data, phase: state, reload } = useEndpointData('livechat/filters', useMemo(() => ({ offset: current, count: itemsPerPage }), [current, itemsPerPage]));

reloadRef.current = reload;

if (state === ENDPOINT_STATES.ERROR) {
if (state === AsyncStatePhase.REJECTED) {
return <Callout>
{t('Error')}: error
</Callout>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Button, FieldGroup, ButtonGroup } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';

import FiltersForm from './FiltersForm';
import { useTranslation } from '../../contexts/TranslationContext';
import { useMethod } from '../../contexts/ServerContext';
import { useForm } from '../../hooks/useForm';
import { useRoute } from '../../contexts/RouterContext';
import { useToastMessageDispatch } from '../../contexts/ToastMessagesContext';
import { useTranslation } from '../../../contexts/TranslationContext';
import { useMethod } from '../../../contexts/ServerContext';
import { useForm } from '../../../hooks/useForm';
import { useRoute } from '../../../contexts/RouterContext';
import { useToastMessageDispatch } from '../../../contexts/ToastMessagesContext';

const NewFilterPage = ({ onSave }) => {
const dispatchToastMessage = useToastMessageDispatch();
Expand Down
6 changes: 6 additions & 0 deletions client/views/omnichannel/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ registerOmnichannelRoute('/triggers/:context?/:id?', {
lazyRouteComponent: () => import('./triggers/TriggersPage'),
});

// WIDECHAT
registerOmnichannelRoute('/filters/:context?/:id?', {
name: 'omnichannel-filters',
lazyRouteComponent: () => import('./filters/FiltersPage'),
});

registerOmnichannelRoute('/facebook', {
name: 'omnichannel-facebook',
lazyRouteComponent: () => import('./facebook/FacebookPage'),
Expand Down

0 comments on commit 6f4ffbe

Please sign in to comment.