diff --git a/backend/public/index.html b/backend/public/index.html index 397e73d..42e9ffb 100644 --- a/backend/public/index.html +++ b/backend/public/index.html @@ -765,8 +765,8 @@ - + + + + +
+

@@ -1058,6 +1066,112 @@
+
+ + +
+
+

+ +
+

+ +
+ + +
+
+ + +
+
+

+ +
+

+ +
+ + +
+
+ + + @@ -1821,6 +1935,14 @@ whatsappSessions: [], whatsappMaxSessions: 1, newSessionName: '', + metaSessions: [], + newMetaSession: { + channel_type: 'messenger', + page_id: '', + page_name: '', + page_access_token: '' + }, + showMetaConnectModal: false, staff: [], showAddStaffModal: false, staffForm: { @@ -2032,6 +2154,7 @@ initializeDashboard() { this.fetchWhatsappSessions(); this.fetchWhatsappStatus(); + this.fetchMetaSessions(); this.fetchSallaStatus(); this.fetchWooCommerceStatus(); // Set up persistent background status check @@ -2195,6 +2318,77 @@ this.actionLoading = false; } }, + async fetchMetaSessions() { + if (!this.token) return; + try { + const response = await fetch('/api/meta/sessions', { + headers: { 'Authorization': `Bearer ${this.token}` } + }); + const data = await response.json(); + if (response.ok && data.status === 'success') { + this.metaSessions = data.data || []; + } + } catch (err) { + console.error('Failed to fetch meta sessions', err); + } + }, + openMetaConnectModal(type) { + this.newMetaSession = { + channel_type: type, + page_id: '', + page_name: '', + page_access_token: '' + }; + this.showMetaConnectModal = true; + }, + async connectMetaSession() { + this.actionLoading = true; + try { + const response = await fetch('/api/meta/sessions/connect', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${this.token}` + }, + body: JSON.stringify(this.newMetaSession) + }); + const data = await response.json(); + if (response.ok && data.status === 'success') { + this.showMetaConnectModal = false; + this.fetchMetaSessions(); + } else { + alert(data.message || 'Connection failed'); + } + } catch (err) { + alert('Network error connecting Meta session'); + } finally { + this.actionLoading = false; + } + }, + async deleteMetaSession(id) { + if (!confirm(this.lang === 'ar' ? 'هل أنت متأكد من حذف هذه القناة؟' : 'Are you sure you want to disconnect this channel?')) { + return; + } + this.actionLoading = true; + try { + const response = await fetch('/api/meta/sessions', { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${this.token}` + }, + body: JSON.stringify({ session_id: id }) + }); + const data = await response.json(); + if (response.ok && data.status === 'success') { + this.fetchMetaSessions(); + } + } catch (err) { + console.error('Failed to delete meta session', err); + } finally { + this.actionLoading = false; + } + }, async fetchWhatsappSessions() { if (!this.token) return; try {