Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
99 lines
3.1 KiB
TypeScript
99 lines
3.1 KiB
TypeScript
import { Pagination } from '@rocket.chat/fuselage';
|
|
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
|
|
import {
|
|
GenericTable,
|
|
GenericTableHeader,
|
|
GenericTableBody,
|
|
GenericTableHeaderCell,
|
|
GenericTableLoadingRow,
|
|
usePagination,
|
|
} from '@rocket.chat/ui-client';
|
|
import { useTranslation, useEndpoint, useRouter } from '@rocket.chat/ui-contexts';
|
|
import { useQuery, hashKey } from '@tanstack/react-query';
|
|
import { useMemo, useState } from 'react';
|
|
|
|
import TriggersRow from './TriggersRow';
|
|
import GenericError from '../../../components/GenericError';
|
|
import GenericNoResults from '../../../components/GenericNoResults';
|
|
import { links } from '../../../lib/links';
|
|
|
|
const TriggersTable = () => {
|
|
const t = useTranslation();
|
|
const router = useRouter();
|
|
|
|
const handleAddNew = useStableCallback(() => {
|
|
router.navigate('/omnichannel/triggers/new');
|
|
});
|
|
|
|
const { current, itemsPerPage, setItemsPerPage, setCurrent, ...paginationProps } = usePagination();
|
|
|
|
const query = useMemo(() => ({ offset: current, count: itemsPerPage }), [current, itemsPerPage]);
|
|
|
|
const getTriggers = useEndpoint('GET', '/v1/livechat/triggers');
|
|
const { data, refetch, isSuccess, isLoading, isError } = useQuery({
|
|
queryKey: ['livechat-triggers', query],
|
|
queryFn: async () => getTriggers(query),
|
|
});
|
|
|
|
const [defaultQuery] = useState(hashKey([query]));
|
|
const queryHasChanged = defaultQuery !== hashKey([query]);
|
|
|
|
const headers = (
|
|
<>
|
|
<GenericTableHeaderCell>{t('Name')}</GenericTableHeaderCell>
|
|
<GenericTableHeaderCell>{t('Description')}</GenericTableHeaderCell>
|
|
<GenericTableHeaderCell>{t('Enabled')}</GenericTableHeaderCell>
|
|
<GenericTableHeaderCell width='x60' />
|
|
</>
|
|
);
|
|
|
|
return (
|
|
<>
|
|
{isLoading && (
|
|
<GenericTable>
|
|
<GenericTableHeader>{headers}</GenericTableHeader>
|
|
<GenericTableBody>
|
|
<GenericTableLoadingRow cols={4} />
|
|
</GenericTableBody>
|
|
</GenericTable>
|
|
)}
|
|
{isSuccess && data.triggers.length === 0 && queryHasChanged && <GenericNoResults />}
|
|
{isSuccess && data.triggers.length === 0 && !queryHasChanged && (
|
|
<GenericNoResults
|
|
icon='smart'
|
|
title={t('No_triggers_yet')}
|
|
description={t('No_triggers_yet_description')}
|
|
buttonAction={handleAddNew}
|
|
buttonTitle={t('Create_trigger')}
|
|
linkHref={links.go.omnichannelDocs}
|
|
linkText={t('Learn_more_about_triggers')}
|
|
/>
|
|
)}
|
|
{isSuccess && data.triggers.length > 0 && (
|
|
<>
|
|
<GenericTable aria-label={t('Livechat_Triggers')}>
|
|
<GenericTableHeader>{headers}</GenericTableHeader>
|
|
<GenericTableBody>
|
|
{data.triggers.map(({ _id, name, description, enabled }) => (
|
|
<TriggersRow key={_id} _id={_id} name={name} description={description} enabled={enabled} reload={refetch} />
|
|
))}
|
|
</GenericTableBody>
|
|
</GenericTable>
|
|
<Pagination
|
|
divider
|
|
current={current}
|
|
itemsPerPage={itemsPerPage}
|
|
count={data?.total || 0}
|
|
onSetItemsPerPage={setItemsPerPage}
|
|
onSetCurrent={setCurrent}
|
|
{...paginationProps}
|
|
/>
|
|
</>
|
|
)}
|
|
{isError && <GenericError buttonAction={refetch} />}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default TriggersTable;
|