TelegramTab.tsx 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { useMemo } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { Collapse, Input, InputNumber, Select, Switch } from 'antd';
  4. import { LanguageManager } from '@/utils';
  5. import type { AllSetting } from '@/models/setting';
  6. import SettingListItem from '@/components/SettingListItem';
  7. interface TelegramTabProps {
  8. allSetting: AllSetting;
  9. updateSetting: (patch: Partial<AllSetting>) => void;
  10. }
  11. export default function TelegramTab({ allSetting, updateSetting }: TelegramTabProps) {
  12. const { t } = useTranslation();
  13. const langOptions = useMemo(
  14. () => LanguageManager.supportedLanguages.map((l: { value: string; name: string; icon: string }) => ({
  15. value: l.value,
  16. label: (
  17. <>
  18. <span role="img" aria-label={l.name}>{l.icon}</span>
  19. &nbsp;&nbsp;<span>{l.name}</span>
  20. </>
  21. ),
  22. })),
  23. [],
  24. );
  25. return (
  26. <Collapse defaultActiveKey="1" items={[
  27. {
  28. key: '1',
  29. label: t('pages.settings.panelSettings'),
  30. children: (
  31. <>
  32. <SettingListItem paddings="small" title={t('pages.settings.telegramBotEnable')} description={t('pages.settings.telegramBotEnableDesc')}>
  33. <Switch checked={allSetting.tgBotEnable} onChange={(v) => updateSetting({ tgBotEnable: v })} />
  34. </SettingListItem>
  35. <SettingListItem
  36. paddings="small"
  37. title={t('pages.settings.telegramToken')}
  38. description={allSetting.hasTgBotToken ? 'Configured; leave blank to keep current token.' : t('pages.settings.telegramTokenDesc')}
  39. >
  40. <Input.Password
  41. value={allSetting.tgBotToken}
  42. placeholder={allSetting.hasTgBotToken ? 'Configured - enter a new token to replace' : ''}
  43. onChange={(e) => updateSetting({ tgBotToken: e.target.value })}
  44. />
  45. </SettingListItem>
  46. <SettingListItem paddings="small" title={t('pages.settings.telegramChatId')} description={t('pages.settings.telegramChatIdDesc')}>
  47. <Input value={allSetting.tgBotChatId} onChange={(e) => updateSetting({ tgBotChatId: e.target.value })} />
  48. </SettingListItem>
  49. <SettingListItem paddings="small" title={t('pages.settings.telegramBotLanguage')}>
  50. <Select
  51. value={allSetting.tgLang}
  52. onChange={(v) => updateSetting({ tgLang: v })}
  53. style={{ width: '100%' }}
  54. options={langOptions}
  55. />
  56. </SettingListItem>
  57. <SettingListItem paddings="small" title={t('pages.settings.telegramAPIServer')} description={t('pages.settings.telegramAPIServerDesc')}>
  58. <Input value={allSetting.tgBotAPIServer} placeholder="https://api.example.com"
  59. onChange={(e) => updateSetting({ tgBotAPIServer: e.target.value })} />
  60. </SettingListItem>
  61. </>
  62. ),
  63. },
  64. {
  65. key: '2',
  66. label: t('pages.settings.notifications'),
  67. children: (
  68. <>
  69. <SettingListItem paddings="small" title={t('pages.settings.telegramNotifyTime')} description={t('pages.settings.telegramNotifyTimeDesc')}>
  70. <Input value={allSetting.tgRunTime} onChange={(e) => updateSetting({ tgRunTime: e.target.value })} />
  71. </SettingListItem>
  72. <SettingListItem paddings="small" title={t('pages.settings.tgNotifyBackup')} description={t('pages.settings.tgNotifyBackupDesc')}>
  73. <Switch checked={allSetting.tgBotBackup} onChange={(v) => updateSetting({ tgBotBackup: v })} />
  74. </SettingListItem>
  75. <SettingListItem paddings="small" title={t('pages.settings.tgNotifyLogin')} description={t('pages.settings.tgNotifyLoginDesc')}>
  76. <Switch checked={allSetting.tgBotLoginNotify} onChange={(v) => updateSetting({ tgBotLoginNotify: v })} />
  77. </SettingListItem>
  78. <SettingListItem paddings="small" title={t('pages.settings.tgNotifyCpu')} description={t('pages.settings.tgNotifyCpuDesc')}>
  79. <InputNumber value={allSetting.tgCpu} min={0} max={100} style={{ width: '100%' }}
  80. onChange={(v) => updateSetting({ tgCpu: Number(v) || 0 })} />
  81. </SettingListItem>
  82. </>
  83. ),
  84. },
  85. ]} />
  86. );
  87. }