From 9b2b0b0a7c7c0cd244ac668c8de101f104ea094e Mon Sep 17 00:00:00 2001 From: adithiyan Date: Mon, 26 Oct 2026 12:26:17 +0530 Subject: [PATCH] feat(admin): add enterprise integrations hub and swarm prediction lab UI --- app/(admin)/integrations/call/page.tsx | 374 +++++ app/(admin)/integrations/email/page.tsx | 331 +++++ .../integrations/google-analytics/page.tsx | 163 +++ app/(admin)/integrations/meta-ads/page.tsx | 279 ++++ app/(admin)/integrations/page.tsx | 350 +++++ app/(admin)/integrations/shipping/page.tsx | 396 ++++++ app/(admin)/integrations/whatsapp/page.tsx | 571 ++++++++ app/(admin)/simulation/page.tsx | 1246 +++++++++++++++++ .../integrations/IntegrationsHeaderNav.tsx | 126 ++ components/layouts/Sidebar.tsx | 17 + lib/rbac.ts | 2 +- services/api/integrationService.ts | 257 ++++ services/api/simulation.ts | 127 ++ 13 files changed, 4238 insertions(+), 1 deletion(-) create mode 100644 app/(admin)/integrations/call/page.tsx create mode 100644 app/(admin)/integrations/email/page.tsx create mode 100644 app/(admin)/integrations/google-analytics/page.tsx create mode 100644 app/(admin)/integrations/meta-ads/page.tsx create mode 100644 app/(admin)/integrations/page.tsx create mode 100644 app/(admin)/integrations/shipping/page.tsx create mode 100644 app/(admin)/integrations/whatsapp/page.tsx create mode 100644 app/(admin)/simulation/page.tsx create mode 100644 components/integrations/IntegrationsHeaderNav.tsx create mode 100644 services/api/integrationService.ts create mode 100644 services/api/simulation.ts diff --git a/app/(admin)/integrations/call/page.tsx b/app/(admin)/integrations/call/page.tsx new file mode 100644 index 0000000..6fefb6b --- /dev/null +++ b/app/(admin)/integrations/call/page.tsx @@ -0,0 +1,374 @@ +'use client'; + +import React, { useState, useEffect } from 'react'; +import { + PhoneCall, + ShieldCheck, + Server, + Lock, + RefreshCw, + CheckCircle2, + AlertCircle, + PhoneForwarded, + Clock, + History, + Play, + Key, +} from 'lucide-react'; +import { toast } from 'sonner'; +import { IntegrationsHeaderNav } from '@/components/integrations/IntegrationsHeaderNav'; +import { integrationService } from '@/services/api/integrationService'; + +export default function KnowlarityCallIntegrationPage() { + const [creds, setCreds] = useState({ + api_key: '', + authorization: '', + virtual_number: '', + call_url: 'https://kpi.knowlarity.com/Basic/v1/account/call/makecall', + log_url: 'https://kpi.knowlarity.com/Basic/v1/account/calllog', + source: 'unconfigured', + is_locked_by_config: false, + }); + const [loading, setLoading] = useState(true); + const [saving, setSaving] = useState(false); + + // Click to call form state + const [agentNumber, setAgentNumber] = useState(''); + const [customerNumber, setCustomerNumber] = useState(''); + const [calling, setCalling] = useState(false); + + // Call logs table + const [logs, setLogs] = useState([]); + const [logsLoading, setLogsLoading] = useState(false); + const [page, setPage] = useState(1); + + const fetchKnowlarityConfig = async () => { + setLoading(true); + try { + const data = await integrationService.getKnowlarityCredentials(); + setCreds(data); + if (data.api_key || data.authorization) { + fetchLogs(); + } + } catch (err: any) { + toast.error('Failed to load Knowlarity settings'); + } finally { + setLoading(false); + } + }; + + const fetchLogs = async () => { + setLogsLoading(true); + try { + const res = await integrationService.getKnowlarityCallLogs(page, 20); + const callData = res.data?.call_logs || res.data?.objects || res.call_logs || []; + setLogs(callData); + } catch (err) { + console.warn('Call logs error:', err); + } finally { + setLogsLoading(false); + } + }; + + useEffect(() => { + fetchKnowlarityConfig(); + }, []); + + const handleSave = async (e: React.FormEvent) => { + e.preventDefault(); + setSaving(true); + try { + await integrationService.saveKnowlarityCredentials(creds); + toast.success('Knowlarity credentials saved successfully'); + fetchLogs(); + } catch (err: any) { + toast.error(err.message || 'Failed to save Knowlarity credentials'); + } finally { + setSaving(false); + } + }; + + const handleMakeCall = async (e: React.FormEvent) => { + e.preventDefault(); + if (!agentNumber.trim() || !customerNumber.trim()) { + toast.error('Both Agent number and Customer number are required for bridging'); + return; + } + setCalling(true); + try { + const res = await integrationService.makeKnowlarityCall({ + agent_number: agentNumber.trim(), + customer_number: customerNumber.trim(), + }); + if (res.status === 'SUCCESS') { + toast.success('Call initiated! Knowlarity is ringing the agent first, then connecting customer.'); + fetchLogs(); + } else { + toast.error(`Call failed: ${res.detail || JSON.stringify(res)}`); + } + } catch (err: any) { + toast.error(err.message || 'Call initiation failed'); + } finally { + setCalling(false); + } + }; + + return ( +
+ + + {/* Top Banner */} +
+
+

+ + Knowlarity Cloud Telephony & SuperReceptionist IVR +

+

+ Cloud IVR call routing, technician click-to-call bridging, customer service recordings, and live call logs. +

+
+ {creds.is_locked_by_config ? ( + + + Configured via Config.py + + ) : ( + + + Database Configuration + + )} +
+ +
+ {/* Credentials Form (Cols 1-7) */} +
+
+

+ + SuperReceptionist Credentials +

+
+ +
+
+ + setCreds({ ...creds, virtual_number: e.target.value })} + placeholder="e.g. +91XXXXXXXXXX" + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60 focus:ring-2 focus:ring-rose-500 focus:outline-none" + /> +
+ +
+
+ + setCreds({ ...creds, api_key: e.target.value })} + placeholder="Knowlarity x-api-key" + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60 focus:ring-2 focus:ring-rose-500 focus:outline-none" + /> +
+ +
+ + setCreds({ ...creds, authorization: e.target.value })} + placeholder="Knowlarity Authorization" + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60 focus:ring-2 focus:ring-rose-500 focus:outline-none" + /> +
+
+ +
+
+ + setCreds({ ...creds, call_url: e.target.value })} + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60" + /> +
+ +
+ + setCreds({ ...creds, log_url: e.target.value })} + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60" + /> +
+
+ + {!creds.is_locked_by_config && ( + + )} +
+
+ + {/* Live Click-to-Call Dialer (Cols 8-12) */} +
+
+

+ + Agent Click-to-Call Bridge +

+

+ Connect a technician or sales rep with a customer through Knowlarity without revealing personal numbers. +

+ +
+
+ + setAgentNumber(e.target.value)} + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-rose-500 focus:outline-none" + /> +
+ +
+ + setCustomerNumber(e.target.value)} + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-rose-500 focus:outline-none" + /> +
+ + +
+
+ +
+ Virtual Number: + {creds.virtual_number || 'SR Number'} +
+
+
+ + {/* Call Logs Table */} +
+
+

+ + Telephony Call Logs & Recordings +

+ +
+ +
+ + + + + + + + + + + + + {logs.length === 0 ? ( + + + + ) : ( + logs.map((log: any, idx: number) => ( + + + + + + + + + )) + )} + +
Date / TimeCustomerAgentStatusDurationRecording
+ {logsLoading ? 'Fetching call logs from Knowlarity...' : 'No call logs recorded yet.'} +
+ {log.start_time || log.call_date || 'Recent'} + + {log.customer_number || log.caller_id || '-'} + + {log.agent_number || log.destination || '-'} + + + {log.status || log.call_type || 'COMPLETED'} + + + {log.duration ? `${log.duration}s` : '0s'} + + {log.recording_url ? ( + + Audio + + ) : ( + - + )} +
+
+
+
+ ); +} diff --git a/app/(admin)/integrations/email/page.tsx b/app/(admin)/integrations/email/page.tsx new file mode 100644 index 0000000..9aa71e9 --- /dev/null +++ b/app/(admin)/integrations/email/page.tsx @@ -0,0 +1,331 @@ +'use client'; + +import React, { useState, useEffect } from 'react'; +import { + Mail, + Send, + ShieldCheck, + Server, + Lock, + RefreshCw, + CheckCircle2, + AlertCircle, + Key, +} from 'lucide-react'; +import { toast } from 'sonner'; +import { IntegrationsHeaderNav } from '@/components/integrations/IntegrationsHeaderNav'; +import { integrationService } from '@/services/api/integrationService'; + +export default function EmailIntegrationsPage() { + const [creds, setCreds] = useState({ + active_provider: 'ZeptoMail', + sender_email: '', + sender_name: 'iFixKart', + smtp_server: '', + smtp_port: 587, + smtp_username: '', + smtp_password: '', + use_tls: true, + source: 'unconfigured', + is_locked_by_config: false, + }); + const [loading, setLoading] = useState(true); + const [saving, setSaving] = useState(false); + + // Test send state + const [testRecipient, setTestRecipient] = useState(''); + const [testSubject, setTestSubject] = useState('iFixKart ERP Email Verification Test'); + const [testBody, setTestBody] = useState('This is a verified test email sent from iFixKart ERP Email Gateway.'); + const [sendingTest, setSendingTest] = useState(false); + + const fetchEmailConfig = async () => { + setLoading(true); + try { + const data = await integrationService.getEmailCredentials(); + setCreds(data); + } catch (err: any) { + toast.error('Failed to load email settings'); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + fetchEmailConfig(); + }, []); + + const handleSaveCredentials = async (e: React.FormEvent) => { + e.preventDefault(); + setSaving(true); + try { + await integrationService.saveEmailCredentials(creds); + toast.success('Email settings saved successfully'); + } catch (err: any) { + toast.error(err.message || 'Failed to save email settings'); + } finally { + setSaving(false); + } + }; + + const handleSendTest = async (e: React.FormEvent) => { + e.preventDefault(); + if (!testRecipient.trim() || !testRecipient.includes('@')) { + toast.error('Please enter a valid recipient email address'); + return; + } + setSendingTest(true); + try { + const res = await integrationService.sendTestEmail({ + recipient: testRecipient.trim(), + subject: testSubject.trim(), + body: testBody.trim(), + }); + if (res.status === 'SUCCESS') { + toast.success(`Verification email dispatched to ${testRecipient}!`); + } else { + toast.error(`Email send failed: ${res.detail || JSON.stringify(res)}`); + } + } catch (err: any) { + toast.error(err.message || 'Failed to send test email'); + } finally { + setSendingTest(false); + } + }; + + return ( +
+ + + {/* Top Banner */} +
+
+

+ + Transactional Email Gateway (ZeptoMail & SMTP) +

+

+ Manages automated order confirmations, password reset links, quotation invoices, and staff alerts. +

+
+ {creds.is_locked_by_config ? ( + + + Active via Config.py ({creds.active_provider}) + + ) : ( + + + Custom Database SMTP + + )} +
+ +
+ {/* Credentials Form (Cols 1-7) */} +
+
+

+ + Provider Configuration +

+ + Provider: {creds.active_provider} + +
+ +
+
+
+ + setCreds({ ...creds, active_provider: e.target.value })} + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60 disabled:cursor-not-allowed focus:ring-2 focus:ring-sky-500 focus:outline-none" + /> +
+ +
+ + setCreds({ ...creds, sender_name: e.target.value })} + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60 disabled:cursor-not-allowed focus:ring-2 focus:ring-sky-500 focus:outline-none" + /> +
+
+ +
+ + setCreds({ ...creds, sender_email: e.target.value })} + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60 disabled:cursor-not-allowed focus:ring-2 focus:ring-sky-500 focus:outline-none" + /> +
+ + {creds.active_provider === 'ZeptoMail' ? ( +
+
+ + Zoho ZeptoMail CPaaS Active +
+

+ ZeptoMail API Token is loaded from production environment variable ZEPTOMAIL_API_KEY. + High delivery inbox rate with SSL/TLS encryption. +

+
+ Endpoint: {creds.endpoint || 'https://api.zeptomail.in/v1.1/email'} +
+
+ ) : ( +
+
+
+ + setCreds({ ...creds, smtp_server: e.target.value })} + placeholder="e.g. smtp.gmail.com" + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60" + /> +
+
+ + setCreds({ ...creds, smtp_port: parseInt(e.target.value) || 587 })} + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60" + /> +
+
+ +
+
+ + setCreds({ ...creds, smtp_username: e.target.value })} + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60" + /> +
+
+ + setCreds({ ...creds, smtp_password: e.target.value })} + placeholder="••••••••••••" + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white disabled:opacity-60" + /> +
+
+
+ )} + + {!creds.is_locked_by_config && ( + + )} +
+
+ + {/* Live Test Email Sender (Cols 8-12) */} +
+
+

+ + Live Test Email Dispatch +

+

+ Sends an immediate verification email to verify SMTP handshake or ZeptoMail CPaaS API delivery. +

+ +
+
+ + setTestRecipient(e.target.value)} + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-sky-500 focus:outline-none" + /> +
+ +
+ + setTestSubject(e.target.value)} + className="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-sky-500 focus:outline-none" + /> +
+ +
+ +