2021-11-22 11:49:09 +05:30
|
|
|
/* eslint-disable react/display-name */
|
2023-02-12 04:23:00 +01:00
|
|
|
import { Button } from 'antd';
|
2021-11-22 11:49:09 +05:30
|
|
|
import { ColumnsType } from 'antd/lib/table';
|
2023-02-03 18:06:26 +05:30
|
|
|
import { ResizeTable } from 'components/ResizeTable';
|
2021-11-22 11:49:09 +05:30
|
|
|
import ROUTES from 'constants/routes';
|
2022-05-03 15:27:09 +05:30
|
|
|
import useComponentPermission from 'hooks/useComponentPermission';
|
2023-02-12 04:23:00 +01:00
|
|
|
import { useNotifications } from 'hooks/useNotifications';
|
2021-11-22 11:49:09 +05:30
|
|
|
import history from 'lib/history';
|
2023-05-19 13:14:32 +05:30
|
|
|
import { useCallback, useState } from 'react';
|
2022-07-31 09:54:58 +05:30
|
|
|
import { useTranslation } from 'react-i18next';
|
2022-05-03 15:27:09 +05:30
|
|
|
import { useSelector } from 'react-redux';
|
2022-03-24 12:06:57 +05:30
|
|
|
import { generatePath } from 'react-router-dom';
|
2022-05-03 15:27:09 +05:30
|
|
|
import { AppState } from 'store/reducers';
|
2021-11-22 11:49:09 +05:30
|
|
|
import { Channels, PayloadProps } from 'types/api/channels/getAll';
|
2022-05-03 15:27:09 +05:30
|
|
|
import AppReducer from 'types/reducer/app';
|
2021-11-22 11:49:09 +05:30
|
|
|
|
|
|
|
|
import Delete from './Delete';
|
|
|
|
|
|
2022-03-22 12:10:31 +05:30
|
|
|
function AlertChannels({ allChannels }: AlertChannelsProps): JSX.Element {
|
2022-07-31 09:54:58 +05:30
|
|
|
const { t } = useTranslation(['channels']);
|
2023-02-12 04:23:00 +01:00
|
|
|
const { notifications } = useNotifications();
|
2021-11-22 11:49:09 +05:30
|
|
|
const [channels, setChannels] = useState<Channels[]>(allChannels);
|
2022-05-03 15:27:09 +05:30
|
|
|
const { role } = useSelector<AppState, AppReducer>((state) => state.app);
|
2022-05-04 20:40:49 +05:30
|
|
|
const [action] = useComponentPermission(['new_alert_action'], role);
|
2021-11-22 11:49:09 +05:30
|
|
|
|
|
|
|
|
const onClickEditHandler = useCallback((id: string) => {
|
|
|
|
|
history.replace(
|
|
|
|
|
generatePath(ROUTES.CHANNELS_EDIT, {
|
|
|
|
|
id,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const columns: ColumnsType<Channels> = [
|
|
|
|
|
{
|
2022-07-31 09:54:58 +05:30
|
|
|
title: t('column_channel_name'),
|
2021-11-22 11:49:09 +05:30
|
|
|
dataIndex: 'name',
|
|
|
|
|
key: 'name',
|
2023-02-02 16:53:15 +05:30
|
|
|
width: 100,
|
2021-11-22 11:49:09 +05:30
|
|
|
},
|
|
|
|
|
{
|
2022-07-31 09:54:58 +05:30
|
|
|
title: t('column_channel_type'),
|
2021-11-22 11:49:09 +05:30
|
|
|
dataIndex: 'type',
|
|
|
|
|
key: 'type',
|
2023-02-02 16:53:15 +05:30
|
|
|
width: 80,
|
2021-11-22 11:49:09 +05:30
|
|
|
},
|
2022-05-03 15:27:09 +05:30
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
|
columns.push({
|
2022-07-31 09:54:58 +05:30
|
|
|
title: t('column_channel_action'),
|
2021-11-22 11:49:09 +05:30
|
|
|
dataIndex: 'id',
|
|
|
|
|
key: 'action',
|
|
|
|
|
align: 'center',
|
2023-02-02 16:53:15 +05:30
|
|
|
width: 80,
|
2021-11-22 11:49:09 +05:30
|
|
|
render: (id: string): JSX.Element => (
|
|
|
|
|
<>
|
|
|
|
|
<Button onClick={(): void => onClickEditHandler(id)} type="link">
|
2022-07-31 09:54:58 +05:30
|
|
|
{t('column_channel_edit')}
|
2021-11-22 11:49:09 +05:30
|
|
|
</Button>
|
|
|
|
|
<Delete id={id} setChannels={setChannels} notifications={notifications} />
|
|
|
|
|
</>
|
|
|
|
|
),
|
2022-05-03 15:27:09 +05:30
|
|
|
});
|
|
|
|
|
}
|
2021-11-22 11:49:09 +05:30
|
|
|
|
2023-02-12 04:23:00 +01:00
|
|
|
return <ResizeTable columns={columns} dataSource={channels} rowKey="id" />;
|
2022-03-22 12:10:31 +05:30
|
|
|
}
|
2021-11-22 11:49:09 +05:30
|
|
|
|
|
|
|
|
interface AlertChannelsProps {
|
|
|
|
|
allChannels: PayloadProps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default AlertChannels;
|