Spaces:
Running
Running
axeronis commited on
Commit ·
dc5effe
1
Parent(s): ddc9c51
feat: Восстановлена вкладка LinkedIn + подготовка к WhatsApp QR
Browse filesДОБАВЛЕНО:
1. Восстановлена LinkedIn вкладка в channels/page.tsx
2. LinkedInTab компонент с UI для подключения
3. LinkedIn state, mutations, handlers
4. Поддержка 3 каналов: Telegram, WhatsApp QR, LinkedIn
ПОДГОТОВКА:
- WhatsApp QR UI уже создан
- Следующий шаг: Backend для WhatsApp серого API
frontend/app/channels/page.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import { useToast } from '@/contexts/ToastContext'
|
|
| 7 |
import { channelsApi } from '@/lib/api'
|
| 8 |
import { Send, CheckCircle, XCircle, AlertCircle, Loader2, ExternalLink, Copy, Check } from 'lucide-react'
|
| 9 |
|
| 10 |
-
type Channel = 'telegram' | 'whatsapp'
|
| 11 |
|
| 12 |
interface BotInfo {
|
| 13 |
username: string
|
|
@@ -38,6 +38,11 @@ export default function ChannelsPage() {
|
|
| 38 |
const [waTokenValid, setWaTokenValid] = useState<boolean | null>(null)
|
| 39 |
const [waTokenValidating, setWaTokenValidating] = useState(false)
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
const queryClient = useQueryClient()
|
| 42 |
const { user, isLoading: authLoading } = useAuth()
|
| 43 |
|
|
@@ -56,6 +61,14 @@ export default function ChannelsPage() {
|
|
| 56 |
enabled: !!user,
|
| 57 |
refetchInterval: 15000,
|
| 58 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
// Connect Telegram mutation
|
| 61 |
const connectTelegramMutation = useMutation({
|
|
@@ -87,6 +100,24 @@ export default function ChannelsPage() {
|
|
| 87 |
toast.error('Ошибка подключения', error.message)
|
| 88 |
},
|
| 89 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
// Disconnect mutations
|
| 92 |
const disconnectTelegramMutation = useMutation({
|
|
@@ -110,6 +141,17 @@ export default function ChannelsPage() {
|
|
| 110 |
toast.error('Ошибка', error.message)
|
| 111 |
},
|
| 112 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
// Handlers
|
| 115 |
const handleConnectTelegram = () => {
|
|
@@ -128,6 +170,14 @@ export default function ChannelsPage() {
|
|
| 128 |
connectWhatsAppMutation.mutate()
|
| 129 |
}
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
// Validate WhatsApp token
|
| 132 |
const validateWhatsAppToken = async (token: string) => {
|
| 133 |
if (!token.trim()) {
|
|
@@ -202,6 +252,7 @@ export default function ChannelsPage() {
|
|
| 202 |
const tabs = [
|
| 203 |
{ id: 'telegram' as Channel, label: 'Telegram', icon: Send, status: telegramStatus?.connected },
|
| 204 |
{ id: 'whatsapp' as Channel, label: 'WhatsApp (QR)', icon: Send, status: whatsappStatus?.connected },
|
|
|
|
| 205 |
]
|
| 206 |
|
| 207 |
return (
|
|
@@ -277,6 +328,29 @@ export default function ChannelsPage() {
|
|
| 277 |
tenantId={user.tenant_id}
|
| 278 |
/>
|
| 279 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
</div>
|
| 281 |
</div>
|
| 282 |
</div>
|
|
@@ -971,3 +1045,6 @@ function MetaChannelTab({
|
|
| 971 |
</div>
|
| 972 |
)
|
| 973 |
}
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import { channelsApi } from '@/lib/api'
|
| 8 |
import { Send, CheckCircle, XCircle, AlertCircle, Loader2, ExternalLink, Copy, Check } from 'lucide-react'
|
| 9 |
|
| 10 |
+
type Channel = 'telegram' | 'whatsapp' | 'linkedin'
|
| 11 |
|
| 12 |
interface BotInfo {
|
| 13 |
username: string
|
|
|
|
| 38 |
const [waTokenValid, setWaTokenValid] = useState<boolean | null>(null)
|
| 39 |
const [waTokenValidating, setWaTokenValidating] = useState(false)
|
| 40 |
|
| 41 |
+
// LinkedIn state
|
| 42 |
+
const [liAccessToken, setLiAccessToken] = useState('')
|
| 43 |
+
const [liOrgId, setLiOrgId] = useState('')
|
| 44 |
+
const [liVerifyToken] = useState('microfunnel-verify-token')
|
| 45 |
+
|
| 46 |
const queryClient = useQueryClient()
|
| 47 |
const { user, isLoading: authLoading } = useAuth()
|
| 48 |
|
|
|
|
| 61 |
enabled: !!user,
|
| 62 |
refetchInterval: 15000,
|
| 63 |
})
|
| 64 |
+
|
| 65 |
+
// Get LinkedIn status
|
| 66 |
+
const { data: linkedinStatus, isLoading: linkedinLoading } = useQuery({
|
| 67 |
+
queryKey: ['linkedin-status', user?.tenant_id],
|
| 68 |
+
queryFn: channelsApi.getLinkedInStatus,
|
| 69 |
+
enabled: !!user,
|
| 70 |
+
refetchInterval: 15000,
|
| 71 |
+
})
|
| 72 |
|
| 73 |
// Connect Telegram mutation
|
| 74 |
const connectTelegramMutation = useMutation({
|
|
|
|
| 100 |
toast.error('Ошибка подключения', error.message)
|
| 101 |
},
|
| 102 |
})
|
| 103 |
+
|
| 104 |
+
// Connect LinkedIn mutation
|
| 105 |
+
const connectLinkedInMutation = useMutation({
|
| 106 |
+
mutationFn: () => channelsApi.connectLinkedIn({
|
| 107 |
+
access_token: liAccessToken,
|
| 108 |
+
organization_id: liOrgId,
|
| 109 |
+
verify_token: liVerifyToken,
|
| 110 |
+
}),
|
| 111 |
+
onSuccess: (data) => {
|
| 112 |
+
queryClient.invalidateQueries({ queryKey: ['linkedin-status', user?.tenant_id] })
|
| 113 |
+
setLiAccessToken('')
|
| 114 |
+
setLiOrgId('')
|
| 115 |
+
toast.success('Успех!', data.message)
|
| 116 |
+
},
|
| 117 |
+
onError: (error: Error) => {
|
| 118 |
+
toast.error('Ошибка подключения', error.message)
|
| 119 |
+
},
|
| 120 |
+
})
|
| 121 |
|
| 122 |
// Disconnect mutations
|
| 123 |
const disconnectTelegramMutation = useMutation({
|
|
|
|
| 141 |
toast.error('Ошибка', error.message)
|
| 142 |
},
|
| 143 |
})
|
| 144 |
+
|
| 145 |
+
const disconnectLinkedInMutation = useMutation({
|
| 146 |
+
mutationFn: channelsApi.disconnectLinkedIn,
|
| 147 |
+
onSuccess: (data) => {
|
| 148 |
+
queryClient.invalidateQueries({ queryKey: ['linkedin-status', user?.tenant_id] })
|
| 149 |
+
toast.info('Отключено', data.message)
|
| 150 |
+
},
|
| 151 |
+
onError: (error: Error) => {
|
| 152 |
+
toast.error('Ошибка', error.message)
|
| 153 |
+
},
|
| 154 |
+
})
|
| 155 |
|
| 156 |
// Handlers
|
| 157 |
const handleConnectTelegram = () => {
|
|
|
|
| 170 |
connectWhatsAppMutation.mutate()
|
| 171 |
}
|
| 172 |
|
| 173 |
+
const handleConnectLinkedIn = () => {
|
| 174 |
+
if (!liAccessToken.trim() || !liOrgId.trim()) {
|
| 175 |
+
toast.warning('Внимание', 'Заполните все обязательные поля')
|
| 176 |
+
return
|
| 177 |
+
}
|
| 178 |
+
connectLinkedInMutation.mutate()
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
// Validate WhatsApp token
|
| 182 |
const validateWhatsAppToken = async (token: string) => {
|
| 183 |
if (!token.trim()) {
|
|
|
|
| 252 |
const tabs = [
|
| 253 |
{ id: 'telegram' as Channel, label: 'Telegram', icon: Send, status: telegramStatus?.connected },
|
| 254 |
{ id: 'whatsapp' as Channel, label: 'WhatsApp (QR)', icon: Send, status: whatsappStatus?.connected },
|
| 255 |
+
{ id: 'linkedin' as Channel, label: 'LinkedIn', icon: Send, status: linkedinStatus?.connected },
|
| 256 |
]
|
| 257 |
|
| 258 |
return (
|
|
|
|
| 328 |
tenantId={user.tenant_id}
|
| 329 |
/>
|
| 330 |
)}
|
| 331 |
+
|
| 332 |
+
{/* LinkedIn Tab */}
|
| 333 |
+
{activeTab === 'linkedin' && (
|
| 334 |
+
<LinkedInTab
|
| 335 |
+
status={linkedinStatus}
|
| 336 |
+
loading={linkedinLoading}
|
| 337 |
+
accessToken={liAccessToken}
|
| 338 |
+
setAccessToken={setLiAccessToken}
|
| 339 |
+
orgId={liOrgId}
|
| 340 |
+
setOrgId={setLiOrgId}
|
| 341 |
+
verifyToken={liVerifyToken}
|
| 342 |
+
onConnect={handleConnectLinkedIn}
|
| 343 |
+
onDisconnect={() => {
|
| 344 |
+
if (confirm('Вы уверены, что хотите отключить LinkedIn?')) {
|
| 345 |
+
disconnectLinkedInMutation.mutate()
|
| 346 |
+
}
|
| 347 |
+
}}
|
| 348 |
+
isProcessing={connectLinkedInMutation.isPending || disconnectLinkedInMutation.isPending}
|
| 349 |
+
webhookUrl={getWebhookUrl('linkedin')}
|
| 350 |
+
copyToClipboard={copyToClipboard}
|
| 351 |
+
copiedUrl={copiedUrl}
|
| 352 |
+
/>
|
| 353 |
+
)}
|
| 354 |
</div>
|
| 355 |
</div>
|
| 356 |
</div>
|
|
|
|
| 1045 |
</div>
|
| 1046 |
)
|
| 1047 |
}
|
| 1048 |
+
|
| 1049 |
+
// LinkedIn Tab Component
|
| 1050 |
+
function LinkedInTab({ status, loading, accessToken, setAccessToken, orgId, setOrgId, verifyToken, onConnect, onDisconnect, isProcessing, webhookUrl, copyToClipboard, copiedUrl }: any) { const isConnected = status?.connected || false; return (<div className='space-y-6'><div className='flex items-center justify-between p-4 bg-slate-50 rounded-xl'><div className='flex items-center gap-3'><div className='w-12 h-12 bg-blue-50 rounded-xl flex items-center justify-center text-2xl'>??</div><div><h3 className='font-bold text-slate-900'>LinkedIn Messaging</h3><p className='text-sm text-slate-600'>������������� ����� LinkedIn API</p></div></div>{loading ? (<Loader2 className='w-5 h-5 animate-spin text-slate-400' />) : isConnected ? (<div className='flex items-center gap-2 px-3 py-1.5 bg-emerald-100 text-emerald-700 rounded-full'><div className='w-2 h-2 bg-emerald-500 rounded-full animate-pulse'></div><span className='text-sm font-semibold'>�������</span></div>) : (<div className='flex items-center gap-2 px-3 py-1.5 bg-slate-200 text-slate-600 rounded-full'><div className='w-2 h-2 bg-slate-400 rounded-full'></div><span className='text-sm font-semibold'>�� ���������</span></div>)}</div>{isConnected ? (<div className='space-y-4'><div className='p-6 bg-blue-50 border border-blue-200 rounded-xl'><div className='flex items-center gap-2 mb-4'><CheckCircle className='w-5 h-5 text-blue-600' /><h4 className='font-bold text-blue-900'>LinkedIn ���������</h4></div><div className='space-y-2 text-sm'><p><span className='font-semibold'>Webhook:</span> {status.webhook_url}</p>{status.config?.organization_id && (<p><span className='font-semibold'>Organization ID:</span> {status.config.organization_id}</p>)}</div></div><button onClick={onDisconnect} disabled={isProcessing} className='w-full px-6 py-3 bg-red-50 text-red-700 rounded-xl hover:bg-red-100 disabled:opacity-50 font-semibold border border-red-200 transition'>��������� LinkedIn</button></div>) : (<div className='space-y-6'><div className='p-6 bg-gradient-to-br from-blue-50 to-indigo-50 border-2 border-blue-200 rounded-2xl'><div className='flex items-start gap-4'><div className='w-12 h-12 bg-blue-600 rounded-xl flex items-center justify-center flex-shrink-0'><span className='text-2xl'>??</span></div><div className='flex-1'><h3 className='text-lg font-bold text-slate-900 mb-2'>����������� LinkedIn</h3><p className='text-sm text-slate-600 mb-4'>B2B ������������� ����� LinkedIn</p></div></div></div><div className='space-y-4'><div className='p-4 bg-white border-2 border-slate-200 rounded-xl'><label className='block text-sm font-bold text-slate-900 mb-2'>Access Token *</label><input type='password' value={accessToken} onChange={(e) => setAccessToken(e.target.value)} placeholder='AQV...' className='w-full px-4 py-3 border-2 border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 font-mono text-sm' disabled={isProcessing} /></div><div className='p-4 bg-white border-2 border-slate-200 rounded-xl'><label className='block text-sm font-bold text-slate-900 mb-2'>Organization ID *</label><input type='text' value={orgId} onChange={(e) => setOrgId(e.target.value)} placeholder='12345678' className='w-full px-4 py-3 border-2 border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 font-mono text-sm' disabled={isProcessing} /></div><button onClick={onConnect} disabled={isProcessing || !accessToken.trim() || !orgId.trim()} className='w-full px-6 py-4 bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white rounded-xl disabled:opacity-50 font-bold text-lg flex items-center justify-center gap-3 shadow-xl'>{isProcessing ? (<><Loader2 className='w-6 h-6 animate-spin' />�����������...</>) : (<><Send className='w-6 h-6' />���������� LinkedIn</>)}</button></div></div>)}</div>); }
|