import { ChevronDown, ChevronUp, ExternalLink, Plus, RefreshCw, Save, Trash2, X } from 'lucide-react'; import type { RefObject } from 'react'; import { DrawerShell } from '../../../components/DrawerShell'; import { PasswordInput } from '../../../components/PasswordInput'; import { LucentIconButton } from '../../../components/lucent/LucentIconButton'; import type { BotChannel, BotTopic, ChannelType, TopicPresetTemplate, WeixinLoginStatus } from '../types'; import './DashboardManagementModals.css'; interface PasswordToggleLabels { show: string; hide: string; } function parseChannelListValue(raw: unknown): string { if (!Array.isArray(raw)) return ''; return raw .map((item) => String(item || '').trim()) .filter(Boolean) .join('\n'); } function parseChannelListInput(raw: string): string[] { const rows: string[] = []; String(raw || '') .split(/[\n,]/) .forEach((item) => { const text = String(item || '').trim(); if (text && !rows.includes(text)) rows.push(text); }); return rows; } function isChannelConfigured(channel: BotChannel): boolean { const ctype = String(channel.channel_type || '').trim().toLowerCase(); if (ctype === 'email') { const extra = channel.extra_config || {}; return Boolean( String(extra.imapHost || '').trim() && String(extra.imapUsername || '').trim() && String(extra.imapPassword || '').trim() && String(extra.smtpHost || '').trim() && String(extra.smtpUsername || '').trim() && String(extra.smtpPassword || '').trim(), ); } if (ctype === 'weixin') { return true; } return Boolean(String(channel.external_app_id || '').trim() || String(channel.app_secret || '').trim()); } function ChannelFieldsEditor({ channel, labels, passwordToggleLabels, onPatch, }: { channel: BotChannel; labels: Record; passwordToggleLabels: PasswordToggleLabels; onPatch: (patch: Partial) => void; }) { const ctype = String(channel.channel_type).toLowerCase(); if (ctype === 'telegram') { return ( <> onPatch({ app_secret: e.target.value })} autoComplete="new-password" toggleLabels={passwordToggleLabels} /> onPatch({ extra_config: { ...(channel.extra_config || {}), proxy: e.target.value } })} autoComplete="off" /> ); } if (ctype === 'feishu') { return ( <> onPatch({ external_app_id: e.target.value })} autoComplete="off" /> onPatch({ app_secret: e.target.value })} autoComplete="new-password" toggleLabels={passwordToggleLabels} /> onPatch({ extra_config: { ...(channel.extra_config || {}), encryptKey: e.target.value } })} autoComplete="off" /> onPatch({ extra_config: { ...(channel.extra_config || {}), verificationToken: e.target.value } })} autoComplete="off" /> ); } if (ctype === 'dingtalk') { return ( <> onPatch({ external_app_id: e.target.value })} autoComplete="off" /> onPatch({ app_secret: e.target.value })} autoComplete="new-password" toggleLabels={passwordToggleLabels} /> ); } if (ctype === 'slack') { return ( <> onPatch({ external_app_id: e.target.value })} autoComplete="off" /> onPatch({ app_secret: e.target.value })} autoComplete="new-password" toggleLabels={passwordToggleLabels} /> ); } if (ctype === 'qq') { return ( <> onPatch({ external_app_id: e.target.value })} autoComplete="off" /> onPatch({ app_secret: e.target.value })} autoComplete="new-password" toggleLabels={passwordToggleLabels} /> ); } if (ctype === 'weixin') { return null; } if (ctype === 'email') { const extra = channel.extra_config || {}; return ( <>
onPatch({ extra_config: { ...extra, fromAddress: e.target.value } })} autoComplete="off" />