-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
325 lines (306 loc) · 12.4 KB
/
App.tsx
File metadata and controls
325 lines (306 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
import React, { useState, useEffect, useCallback } from 'react';
import { Contact, Message, Campaign, CampaignTemplate, Group, Asset, User, CustomFieldDefinition, ApiSettings, SocialPost, Integration, ConBotMessage } from './types';
import { useMockData, MOCK_INTEGRATIONS } from './hooks/useMockData';
import { Sidebar } from './components/Sidebar';
import Header from './components/Header';
import Dashboard from './components/Dashboard';
// Fix: ChatPage is a default export
import ChatPage from './components/ChatPage';
import CampaignsPage from './components/CampaignsPage';
import TemplatesPage from './components/TemplatesPage';
import BroadcastingPage from './components/BroadcastingPage';
import SettingsPage from './components/SettingsPage';
import SegmentsPage from './components/SegmentsPage';
import GroupsPage from './components/GroupsPage';
import AssetsPage from './components/AssetsPage';
// Fix: ContactsPage is a default export
import ContactsPage from './components/ContactsPage';
import UsersPage from './components/UsersPage';
import IntegrationsPage from './components/IntegrationsPage';
import SocialPostingPage from './components/SocialPostingPage';
import ReportsPage from './components/ReportsPage';
import ConBotChat from './components/ConBotChat';
import BotIcon from './components/icons/BotIcon';
function App() {
const {
contacts, addContact, updateContact, deleteContact, // Now managed by useMockData
customFieldDefinitions, addCustomField, updateCustomField, deleteCustomField, // Now managed by useMockData
messages, addMessage,
campaigns, addCampaign, updateCampaign, deleteCampaign,
campaignTemplates, addCampaignTemplate, updateCampaignTemplate, deleteCampaignTemplate, updateCampaignTemplateStatus,
groups, addGroup, updateGroup, deleteGroup, toggleContactInGroup,
assets, addAsset,
users, addUser, updateUser, deleteUser,
socialPosts, addSocialPost,
facebookMessagesTotal, instagramMessagesTotal,
whatsappIncomingMessagesTotal, // New
whatsappOutgoingMessagesTotal, // New
} = useMockData();
const [activeView, setActiveView] = useState('Dashboard');
const [initialContactIdForChat, setInitialContactIdForChat] = useState<string | null>(null);
const [isConBotOpen, setIsConBotOpen] = useState(false);
const [conBotMessages, setConBotMessages] = useState<ConBotMessage[]>([]);
const [showDashboardWelcome, setShowDashboardWelcome] = useState(true);
// Gemini API Key from environment (Dyad compatibility)
const geminiApiKey = process.env.API_KEY || '';
// API Settings
const [apiSettings, setApiSettings] = useState<ApiSettings>({
phoneId: '1234567890',
isConnected: false,
wahaSettings: {
sessionName: 'default',
sessionNumber: '',
apiToken: '',
baseUrl: '',
},
licenseKey: 'DEMO-LICENSE-KEY',
coexistenceEnabled: false,
companyProfile: {
name: 'Acme Inc.',
address: '123 Main St, Anytown, USA',
website: 'https://www.acme.com',
logoUrl: 'https://www.acme.com/logo.png',
},
});
const handleAddContact = async (newContact: Omit<Contact, 'id' | 'avatar' | 'lastSeen'>) => {
try {
addContact(newContact); // Use mock data function
} catch (error: any) {
console.error("Error adding contact:", error);
alert("Failed to add contact. " + error.message);
}
};
const handleUpdateContact = async (updatedContact: Contact) => {
try {
updateContact(updatedContact); // Use mock data function
} catch (error: any) {
console.error("Error updating contact:", error);
alert("Failed to update contact. " + error.message);
}
};
const handleDeleteContact = async (contactId: string) => {
try {
deleteContact(contactId); // Use mock data function
} catch (error: any) {
console.error("Error deleting contact:", error);
alert("Failed to delete contact. " + error.message);
}
};
const handleAddCustomField = async (name: string) => {
try {
addCustomField(name); // Use mock data function
} catch (error: any) {
console.error("Error adding custom field:", error);
alert("Failed to add custom field. " + error.message);
}
};
const handleUpdateCustomField = async (field: CustomFieldDefinition) => {
try {
updateCustomField(field); // Use mock data function
} catch (error: any) {
console.error("Error updating custom field:", error);
alert("Failed to update custom field. " + error.message);
}
};
const handleDeleteCustomField = async (id: string) => {
try {
deleteCustomField(id); // Use mock data function
} catch (error: any) {
console.error("Error deleting custom field:", error);
alert("Failed to delete custom field. " + error.message);
}
};
const setNavigationView = (view: string, payload?: any) => {
setActiveView(view);
if (view === 'Chat' && payload?.contactId) {
setInitialContactIdForChat(payload.contactId);
} else {
setInitialContactIdForChat(null);
}
// For Contacts page with a filter
if (view === 'Contacts' && payload?.filter) {
// This will be handled by ContactsPage internal state on prop change
}
};
const handleConBotNavigation = (viewName: string) => {
const capitalizedViewName = viewName.charAt(0).toUpperCase() + viewName.slice(1);
const validViews = ['Dashboard', 'Chat', 'Reports', 'Contacts', 'Segments', 'Groups', 'Campaigns', 'WhatsApp Broadcasting', 'Social Posting', 'Templates', 'Assets', 'Users', 'Integrations', 'Settings'];
if (validViews.includes(capitalizedViewName)) {
setActiveView(capitalizedViewName);
setConBotMessages(prev => [...prev, {
id: String(Date.now()),
sender: 'bot',
text: `Navigating to the ${capitalizedViewName} page.`,
timestamp: new Date().toISOString(),
}]);
setIsConBotOpen(false); // Close ConBot after navigation
return true;
} else {
setConBotMessages(prev => [...prev, {
id: String(Date.now()),
sender: 'bot',
text: `I can't find a page named "${viewName}". Please try one of the available options.`,
timestamp: new Date().toISOString(),
}]);
return false;
}
};
const addConBotMessage = (message: ConBotMessage) => {
setConBotMessages(prev => [...prev, message]);
};
const integrations: Integration[] = MOCK_INTEGRATIONS; // Use mock integrations for now
return (
<div className="flex h-screen bg-gray-100">
<Sidebar activeView={activeView} setActiveView={setNavigationView} />
<div className="flex-1 flex flex-col overflow-hidden">
<Header title={activeView} />
<main className="flex-1 overflow-x-hidden overflow-y-auto bg-gray-100 p-6">
{activeView === 'Dashboard' && (
<Dashboard
contacts={contacts}
campaigns={campaigns}
users={users}
integrations={integrations}
facebookMessagesTotal={facebookMessagesTotal}
instagramMessagesTotal={instagramMessagesTotal}
whatsappIncomingMessagesTotal={whatsappIncomingMessagesTotal} // New prop
whatsappOutgoingMessagesTotal={whatsappOutgoingMessagesTotal} // New prop
showWelcomeMessage={showDashboardWelcome}
onDismissWelcomeMessage={() => setShowDashboardWelcome(false)}
/>
)}
{activeView === 'Chat' && (
<ChatPage
contacts={contacts}
messages={messages}
addMessage={addMessage}
initialContactId={initialContactIdForChat}
onChatOpened={() => setInitialContactIdForChat(null)}
settings={apiSettings}
geminiApiKey={geminiApiKey} // Pass API key to ChatPage for suggestions
/>
)}
{activeView === 'Reports' && (
<ReportsPage />
)}
{activeView === 'Contacts' && (
<ContactsPage
contacts={contacts}
groups={groups}
customFieldDefinitions={customFieldDefinitions}
onAdd={handleAddContact}
onUpdate={handleUpdateContact}
onDelete={handleDeleteContact}
onGoToChat={contactId => setNavigationView('Chat', { contactId })}
onToggleContactInGroup={toggleContactInGroup}
setNavigationView={setNavigationView}
contactsLoading={false} // No longer loading from Supabase
contactsError={null} // No longer errors from Supabase
/>
)}
{activeView === 'Segments' && (
<SegmentsPage setNavigationView={setNavigationView} />
)}
{activeView === 'Groups' && (
<GroupsPage
groups={groups}
contacts={contacts}
onAddGroup={addGroup}
onUpdateGroup={updateGroup}
onDeleteGroup={deleteGroup}
/>
)}
{activeView === 'Campaigns' && (
<CampaignsPage
campaigns={campaigns}
contacts={contacts}
addCampaign={addCampaign}
updateCampaign={updateCampaign}
deleteCampaign={deleteCampaign}
campaignTemplates={campaignTemplates}
addCampaignTemplate={addCampaignTemplate}
updateCampaignTemplateStatus={updateCampaignTemplateStatus}
/>
)}
{activeView === 'WhatsApp Broadcasting' && (
<BroadcastingPage
templates={campaignTemplates}
contacts={contacts}
addCampaign={addCampaign}
isConnected={apiSettings.isConnected}
/>
)}
{activeView === 'Social Posting' && (
<SocialPostingPage
addSocialPost={addSocialPost}
companyProfile={apiSettings.companyProfile}
/>
)}
{activeView === 'Templates' && (
<TemplatesPage
templates={campaignTemplates}
onAdd={addCampaignTemplate}
onUpdate={updateCampaignTemplate}
onDelete={deleteCampaignTemplate}
onUpdateStatus={updateCampaignTemplateStatus}
/>
)}
{activeView === 'Assets' && (
<AssetsPage
assets={assets}
addAsset={addAsset}
/>
)}
{activeView === 'Users' && (
<UsersPage
users={users}
addUser={addUser}
updateUser={updateUser}
deleteUser={deleteUser}
/>
)}
{activeView === 'Integrations' && (
<IntegrationsPage integrations={integrations} />
)}
{activeView === 'Settings' && (
<SettingsPage
currentSettings={apiSettings}
onSaveSettings={setApiSettings}
customFieldDefinitions={customFieldDefinitions}
onAddCustomField={handleAddCustomField}
onUpdateCustomField={handleUpdateCustomField}
onDeleteCustomField={handleDeleteCustomField}
customFieldsLoading={false} // No longer loading from Supabase
customFieldsError={null} // No longer errors from Supabase
/>
)}
</main>
</div>
{isConBotOpen && (
<ConBotChat
isOpen={isConBotOpen}
onClose={() => setIsConBotOpen(false)}
messages={conBotMessages}
addMessage={addConBotMessage}
onNavigate={handleConBotNavigation}
geminiApiKey={geminiApiKey}
/>
)}
<button
onClick={() => setIsConBotOpen(!isConBotOpen)}
className={`fixed bottom-4 right-4 z-50 flex items-center justify-center p-3 w-16 h-16 rounded-full shadow-lg transition-all duration-300 ease-in-out
${isConBotOpen ? 'bg-blue-800 hover:bg-blue-900' : 'bg-blue-600 hover:bg-blue-700'}
focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 focus:ring-offset-gray-100
text-white text-sm font-semibold
`}
aria-label={isConBotOpen ? "Close ConBot Chat" : "Open ConBot Chat"}
>
<BotIcon className="w-8 h-8" />
<span className="hidden md:block absolute bottom-full mb-2 p-1 px-2 text-xs bg-gray-800 text-white rounded opacity-0 group-hover:opacity-100 transition-opacity">
ConBot
</span>
</button>
</div>
);
}
export default App;