import React, { useState, useEffect } from 'react'; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Checkbox } from "@/components/ui/checkbox"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { SearchSourceConnector } from '@/hooks/useSearchSourceConnectors'; // Adjust path as per your project structure import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; // For grouping interface EditSlackConnectorConfigFormProps { connector: SearchSourceConnector; onConfigChange: (newConfig: Record) => void; disabled: boolean; } const EditSlackConnectorConfigForm: React.FC = ({ connector, onConfigChange, disabled, }) => { const [currentConfig, setCurrentConfig] = useState>(connector.config || {}); useEffect(() => { // Initialize with default values for new fields if they don't exist in the connector's config const initialConfig = { SLACK_BOT_TOKEN: '', slack_membership_filter_type: 'all_member_channels', slack_selected_channel_ids: [], // Placeholder, managed elsewhere slack_initial_indexing_days: 30, slack_initial_max_messages_per_channel: 1000, slack_periodic_indexing_enabled: false, slack_periodic_indexing_frequency: 'daily', slack_max_messages_per_channel_periodic: 100, ...connector.config, // Override defaults with existing config }; setCurrentConfig(initialConfig); // Optionally, call onConfigChange here if you want to ensure parent is updated with defaults // onConfigChange(initialConfig); }, [connector.config]); const handleChange = (key: string, value: any) => { const newConfig = { ...currentConfig, [key]: value }; // Special handling for slack_initial_indexing_days and slack_initial_max_messages_per_channel // to ensure they are numbers if not empty, or specific allowed values like -1 for days if (key === 'slack_initial_indexing_days' || key === 'slack_initial_max_messages_per_channel' || key === 'slack_max_messages_per_channel_periodic') { if (value === '' || value === null) { newConfig[key] = null; // Or some default like 0 or -1 depending on desired behavior for empty } else { const numValue = parseInt(value, 10); newConfig[key] = isNaN(numValue) ? null : numValue; // Store as number or null if not a valid number } } setCurrentConfig(newConfig); onConfigChange(newConfig); }; const handleCheckboxChange = (key: string, checked: boolean) => { const newConfig = { ...currentConfig, [key]: checked }; setCurrentConfig(newConfig); onConfigChange(newConfig); }; return (
Authentication Configure your Slack Bot Token.
handleChange('SLACK_BOT_TOKEN', e.target.value)} disabled={disabled} placeholder="xoxb-..." />
Initial Indexing Settings Control how SurfSense initially syncs messages from Slack.

Channel selection is managed in the 'Channels' tab after saving this basic configuration.

handleChange('slack_initial_indexing_days', e.target.value)} disabled={disabled} placeholder="-1 for all time" />

Enter -1 for all time, 0 for no initial history, or a positive number for specific days.

handleChange('slack_initial_max_messages_per_channel', e.target.value)} disabled={disabled} placeholder="e.g., 1000" />
Periodic Indexing Settings Configure automatic background syncing for new messages.
handleCheckboxChange('slack_periodic_indexing_enabled', !!checked)} disabled={disabled} />
{currentConfig.slack_periodic_indexing_enabled && ( <>
{/* Indent options for enabled periodic indexing */}
handleChange('slack_max_messages_per_channel_periodic', e.target.value)} disabled={disabled || !currentConfig.slack_periodic_indexing_enabled} placeholder="e.g., 100" />
)}
); }; export default EditSlackConnectorConfigForm;