import { Plus, Trash2 } from 'lucide-react'; import { LucentIconButton } from '../../../components/lucent/LucentIconButton'; import { LucentSelect } from '../../../components/lucent/LucentSelect'; import { PasswordInput } from '../../../components/PasswordInput'; import type { OnboardingChannelLabels } from '../localeTypes'; import type { ChannelType, WizardChannelConfig } from '../types'; import { EMPTY_CHANNEL_PICKER } from '../types'; interface BotWizardChannelModalProps { open: boolean; lc: OnboardingChannelLabels; passwordToggleLabels: { show: string; hide: string }; channels: WizardChannelConfig[]; sendProgress: boolean; sendToolHints: boolean; addableChannelTypes: ChannelType[]; newChannelType: ChannelType | ''; onClose: () => void; onUpdateGlobalDeliveryFlag: (key: 'sendProgress' | 'sendToolHints', value: boolean) => void; onUpdateChannel: (index: number, patch: Partial) => void; onRemoveChannel: (index: number) => void; onSetNewChannelType: (value: ChannelType | '') => void; onAddChannel: () => void; } function renderChannelFields({ channel, idx, lc, passwordToggleLabels, onUpdateChannel, }: { channel: WizardChannelConfig; idx: number; lc: OnboardingChannelLabels; passwordToggleLabels: { show: string; hide: string }; onUpdateChannel: (index: number, patch: Partial) => void; }) { if (channel.channel_type === 'telegram') { return ( <> onUpdateChannel(idx, { app_secret: e.target.value })} autoComplete="new-password" toggleLabels={passwordToggleLabels} /> onUpdateChannel(idx, { extra_config: { ...(channel.extra_config || {}), proxy: e.target.value } })} autoComplete="off" /> ); } if (channel.channel_type === 'feishu') { return ( <> onUpdateChannel(idx, { external_app_id: e.target.value })} autoComplete="off" /> onUpdateChannel(idx, { app_secret: e.target.value })} autoComplete="new-password" toggleLabels={passwordToggleLabels} /> onUpdateChannel(idx, { extra_config: { ...(channel.extra_config || {}), encryptKey: e.target.value } })} autoComplete="off" /> onUpdateChannel(idx, { extra_config: { ...(channel.extra_config || {}), verificationToken: e.target.value } })} autoComplete="off" /> ); } if (channel.channel_type === 'dingtalk') { return ( <> onUpdateChannel(idx, { external_app_id: e.target.value })} autoComplete="off" /> onUpdateChannel(idx, { app_secret: e.target.value })} autoComplete="new-password" toggleLabels={passwordToggleLabels} /> ); } if (channel.channel_type === 'slack') { return ( <> onUpdateChannel(idx, { external_app_id: e.target.value })} autoComplete="off" /> onUpdateChannel(idx, { app_secret: e.target.value })} autoComplete="new-password" toggleLabels={passwordToggleLabels} /> ); } if (channel.channel_type === 'qq') { return ( <> onUpdateChannel(idx, { external_app_id: e.target.value })} autoComplete="off" /> onUpdateChannel(idx, { app_secret: e.target.value })} autoComplete="new-password" toggleLabels={passwordToggleLabels} /> ); } if (channel.channel_type === 'weixin') { return null; } if (channel.channel_type === 'wecom') { return ( <> onUpdateChannel(idx, { external_app_id: e.target.value })} autoComplete="off" /> onUpdateChannel(idx, { app_secret: e.target.value })} autoComplete="new-password" toggleLabels={passwordToggleLabels} /> ); } return null; } export function BotWizardChannelModal({ open, lc, passwordToggleLabels, channels, sendProgress, sendToolHints, addableChannelTypes, newChannelType, onClose, onUpdateGlobalDeliveryFlag, onUpdateChannel, onRemoveChannel, onSetNewChannelType, onAddChannel, }: BotWizardChannelModalProps) { if (!open) return null; return (
e.stopPropagation()}>

{lc.wizardSectionTitle}

{lc.globalDeliveryTitle}
{lc.globalDeliveryDesc}
{channels.map((channel, idx) => (
{channel.channel_type}
onRemoveChannel(idx)} tooltip={lc.remove} aria-label={lc.remove}>
{renderChannelFields({ channel, idx, lc, passwordToggleLabels, onUpdateChannel })}
))}
{ const next = String(e.target.value || ''); onSetNewChannelType(next === EMPTY_CHANNEL_PICKER ? '' : (next as ChannelType)); }} disabled={addableChannelTypes.length === 0} > {addableChannelTypes.map((channelType) => ( ))}
{lc.wizardSectionDesc}
); }