RowActions.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { useTranslation } from 'react-i18next';
  2. import { Button, Dropdown, type MenuProps } from 'antd';
  3. import {
  4. MoreOutlined,
  5. EditOutlined,
  6. QrcodeOutlined,
  7. CopyOutlined,
  8. ExportOutlined,
  9. RetweetOutlined,
  10. BlockOutlined,
  11. DeleteOutlined,
  12. InfoCircleOutlined,
  13. TagsOutlined,
  14. UsergroupAddOutlined,
  15. UsergroupDeleteOutlined,
  16. } from '@ant-design/icons';
  17. import { isInboundMultiUser, showQrCodeMenu } from './helpers';
  18. import type { DBInboundRecord, RowAction } from './types';
  19. interface RowActionsMenuProps {
  20. record: DBInboundRecord;
  21. subEnable: boolean;
  22. hasClients: boolean;
  23. onClick: (key: RowAction) => void;
  24. isMobile?: boolean;
  25. }
  26. export function buildRowActionsMenu({ record, subEnable, t, isMobile, hasClients }: { record: DBInboundRecord; subEnable: boolean; t: (k: string) => string; isMobile?: boolean; hasClients?: boolean }): MenuProps['items'] {
  27. const items: MenuProps['items'] = [];
  28. if (isMobile) {
  29. items.push({ key: 'edit', icon: <EditOutlined />, label: t('edit') });
  30. }
  31. if (showQrCodeMenu(record)) {
  32. items.push({ key: 'qrcode', icon: <QrcodeOutlined />, label: t('qrCode') });
  33. }
  34. if (isInboundMultiUser(record)) {
  35. items.push({ key: 'export', icon: <ExportOutlined />, label: t('pages.inbounds.export') });
  36. if (subEnable) {
  37. items.push({
  38. key: 'subs',
  39. icon: <ExportOutlined />,
  40. label: `${t('pages.inbounds.export')} — ${t('pages.settings.subSettings')}`,
  41. });
  42. }
  43. } else {
  44. items.push({ key: 'showInfo', icon: <InfoCircleOutlined />, label: t('pages.inbounds.inboundInfo') });
  45. }
  46. items.push({ key: 'clipboard', icon: <CopyOutlined />, label: t('pages.inbounds.exportInbound') });
  47. items.push({ key: 'resetTraffic', icon: <RetweetOutlined />, label: t('pages.inbounds.resetTraffic') });
  48. items.push({ key: 'clone', icon: <BlockOutlined />, label: t('pages.inbounds.clone') });
  49. if (isInboundMultiUser(record)) {
  50. items.push({ key: 'attachExisting', icon: <UsergroupAddOutlined />, label: t('pages.inbounds.attachExistingClients') });
  51. }
  52. if (isInboundMultiUser(record) && hasClients) {
  53. items.push({ key: 'attachClients', icon: <UsergroupAddOutlined />, label: t('pages.inbounds.attachClients') });
  54. items.push({ key: 'detachClients', icon: <UsergroupDeleteOutlined />, label: t('pages.inbounds.detachClients') });
  55. items.push({ key: 'addToGroup', icon: <TagsOutlined />, label: t('pages.inbounds.addClientsToGroup') });
  56. items.push({ type: 'divider' });
  57. items.push({ key: 'delAllClients', icon: <UsergroupDeleteOutlined />, danger: true, label: t('pages.inbounds.delAllClients') });
  58. } else {
  59. items.push({ type: 'divider' });
  60. }
  61. items.push({ key: 'delete', icon: <DeleteOutlined />, danger: true, label: t('delete') });
  62. return items;
  63. }
  64. export function RowActionsCell({ record, subEnable, hasClients, onClick }: RowActionsMenuProps) {
  65. const { t } = useTranslation();
  66. return (
  67. <div className="action-buttons">
  68. <Button type="text" size="small" style={{ fontSize: 16 }} icon={<EditOutlined />} onClick={() => onClick('edit')} />
  69. <Dropdown
  70. trigger={['click']}
  71. menu={{
  72. items: buildRowActionsMenu({ record, subEnable, t, hasClients }),
  73. onClick: ({ key }) => onClick(key as RowAction),
  74. }}
  75. >
  76. <Button type="text" size="small" style={{ fontSize: 16 }} icon={<MoreOutlined />} />
  77. </Dropdown>
  78. </div>
  79. );
  80. }