powr-sdk-web 3.3.1 → 3.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -298,7 +298,7 @@ var AdminDashboard = function AdminDashboard(_ref) {
298
298
  }, "Pending Tasks")))));
299
299
  };
300
300
  AdminDashboard.propTypes = {
301
- projectId: _propTypes["default"].string.isRequired,
301
+ projectId: _propTypes["default"].string,
302
302
  sections: _propTypes["default"].arrayOf(_propTypes["default"].string),
303
303
  theme: _propTypes["default"].oneOf(['default', 'dark'])
304
304
  };
@@ -330,25 +330,20 @@ var PowrBaseChat = function PowrBaseChat(_ref) {
330
330
  }
331
331
  }, [selectedChat]);
332
332
 
333
- // Initial load of conversations and users
333
+ // Initial load of conversations
334
334
  (0, _react.useEffect)(function () {
335
- if (projectId) {
336
- fetchConversations();
337
- fetchUsers();
338
- }
339
- }, [projectId]);
335
+ fetchConversations();
336
+ }, []);
340
337
 
341
- // Poll for new conversations every 10 seconds
338
+ // Poll for new conversations every 30 seconds
342
339
  (0, _react.useEffect)(function () {
343
- if (projectId) {
344
- var conversationPolling = setInterval(function () {
345
- fetchConversations();
346
- }, 10000);
347
- return function () {
348
- return clearInterval(conversationPolling);
349
- };
350
- }
351
- }, [projectId]);
340
+ var conversationPolling = setInterval(function () {
341
+ fetchConversations();
342
+ }, 30000);
343
+ return function () {
344
+ return clearInterval(conversationPolling);
345
+ };
346
+ }, []);
352
347
  var filteredConversations = Array.isArray(conversations) ? conversations.filter(function (conv) {
353
348
  return conv.name.toLowerCase().includes(searchQuery.toLowerCase());
354
349
  }) : [];
@@ -556,7 +551,10 @@ var PowrBaseChat = function PowrBaseChat(_ref) {
556
551
  style: styles.searchInput
557
552
  }), /*#__PURE__*/_react["default"].createElement("button", {
558
553
  onClick: function onClick() {
559
- return setShowNewChat(!showNewChat);
554
+ if (!showNewChat) {
555
+ fetchUsers(); // Load users only when opening new chat
556
+ }
557
+ setShowNewChat(!showNewChat);
560
558
  },
561
559
  style: _objectSpread(_objectSpread({}, styles.sendButton), {}, {
562
560
  marginTop: '12px',
@@ -821,7 +819,7 @@ var PowrBaseChat = function PowrBaseChat(_ref) {
821
819
  }, "Choose a conversation from the list to start messaging")))));
822
820
  };
823
821
  PowrBaseChat.propTypes = {
824
- projectId: _propTypes["default"].string.isRequired,
822
+ projectId: _propTypes["default"].string,
825
823
  apiUrl: _propTypes["default"].string,
826
824
  onMessageSent: _propTypes["default"].func,
827
825
  onConversationCreated: _propTypes["default"].func,
@@ -193,10 +193,8 @@ var PowrBaseFunctionsAdmin = function PowrBaseFunctionsAdmin(_ref) {
193
193
  };
194
194
  }();
195
195
  (0, _react.useEffect)(function () {
196
- if (projectId) {
197
- fetchFunctions();
198
- }
199
- }, [projectId]);
196
+ fetchFunctions();
197
+ }, []);
200
198
  var handleInputChange = function handleInputChange(e) {
201
199
  var _e$target = e.target,
202
200
  name = _e$target.name,
@@ -107,52 +107,41 @@ var PowrBaseInvoicesAdmin = function PowrBaseInvoicesAdmin(_ref) {
107
107
  return _regenerator().w(function (_context) {
108
108
  while (1) switch (_context.n) {
109
109
  case 0:
110
- console.log('fetchInvoices called with projectId:', projectId);
111
- if (projectId) {
112
- _context.n = 1;
113
- break;
114
- }
115
- return _context.a(2);
116
- case 1:
117
110
  setLoading(true);
118
111
  setError(null);
119
- _context.p = 2;
120
- console.log('Fetching from:', "".concat(apiUrl, "?projectId=").concat(projectId));
121
- _context.n = 3;
112
+ _context.p = 1;
113
+ _context.n = 2;
122
114
  return (0, _auth.apiCall)(apiUrl, "/invoices", projectId);
123
- case 3:
115
+ case 2:
124
116
  _yield$apiCall = _context.v;
125
117
  data = _yield$apiCall.data;
126
118
  ok = _yield$apiCall.ok;
127
- console.log('Response status:', ok ? 'success' : 'error');
128
119
  if (ok) {
129
- _context.n = 4;
120
+ _context.n = 3;
130
121
  break;
131
122
  }
132
123
  throw new Error('Failed to fetch invoices');
133
- case 4:
134
- console.log('Response data:', data);
124
+ case 3:
135
125
  if (data.success && data.invoices) {
136
126
  setInvoices(data.invoices);
137
127
  } else {
138
128
  setInvoices([]);
139
129
  }
140
- _context.n = 6;
130
+ _context.n = 5;
141
131
  break;
142
- case 5:
143
- _context.p = 5;
132
+ case 4:
133
+ _context.p = 4;
144
134
  _t = _context.v;
145
- console.error('Error fetching invoices:', _t);
146
135
  setError('Failed to load invoices');
147
136
  setInvoices([]);
148
- case 6:
149
- _context.p = 6;
137
+ case 5:
138
+ _context.p = 5;
150
139
  setLoading(false);
151
- return _context.f(6);
152
- case 7:
140
+ return _context.f(5);
141
+ case 6:
153
142
  return _context.a(2);
154
143
  }
155
- }, _callee, null, [[2, 5, 6, 7]]);
144
+ }, _callee, null, [[1, 4, 5, 6]]);
156
145
  }));
157
146
  return function fetchInvoices() {
158
147
  return _ref2.apply(this, arguments);
@@ -160,7 +149,7 @@ var PowrBaseInvoicesAdmin = function PowrBaseInvoicesAdmin(_ref) {
160
149
  }();
161
150
  (0, _react.useEffect)(function () {
162
151
  fetchInvoices();
163
- }, [projectId]);
152
+ }, []);
164
153
  var handleAddInvoice = /*#__PURE__*/function () {
165
154
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
166
155
  var _yield$apiCall2, data, ok, _t2;
@@ -168,32 +157,26 @@ var PowrBaseInvoicesAdmin = function PowrBaseInvoicesAdmin(_ref) {
168
157
  while (1) switch (_context2.n) {
169
158
  case 0:
170
159
  e.preventDefault();
171
- if (projectId) {
172
- _context2.n = 1;
173
- break;
174
- }
175
- return _context2.a(2);
176
- case 1:
177
160
  setAddLoading(true);
178
161
  setAddError(null);
179
- _context2.p = 2;
180
- _context2.n = 3;
162
+ _context2.p = 1;
163
+ _context2.n = 2;
181
164
  return (0, _auth.apiCall)(apiUrl, "/invoices", projectId, {
182
165
  method: 'POST',
183
166
  body: form
184
167
  });
185
- case 3:
168
+ case 2:
186
169
  _yield$apiCall2 = _context2.v;
187
170
  data = _yield$apiCall2.data;
188
171
  ok = _yield$apiCall2.ok;
189
172
  if (ok) {
190
- _context2.n = 4;
173
+ _context2.n = 3;
191
174
  break;
192
175
  }
193
176
  throw new Error('Failed to add invoice');
194
- case 4:
177
+ case 3:
195
178
  if (!data.success) {
196
- _context2.n = 6;
179
+ _context2.n = 5;
197
180
  break;
198
181
  }
199
182
  setShowAddModal(false);
@@ -222,28 +205,28 @@ var PowrBaseInvoicesAdmin = function PowrBaseInvoicesAdmin(_ref) {
222
205
  }
223
206
  });
224
207
  setAddError(null);
225
- _context2.n = 5;
208
+ _context2.n = 4;
226
209
  return fetchInvoices();
227
- case 5:
210
+ case 4:
228
211
  if (onInvoiceAction) {
229
212
  onInvoiceAction('success', 'Invoice added successfully!');
230
213
  } else {
231
214
  _reactToastify.toast.success('Invoice added successfully!');
232
215
  }
233
- _context2.n = 7;
216
+ _context2.n = 6;
234
217
  break;
235
- case 6:
218
+ case 5:
236
219
  setAddError('Failed to add invoice');
237
220
  if (onInvoiceAction) {
238
221
  onInvoiceAction('error', 'Failed to add invoice');
239
222
  } else {
240
223
  _reactToastify.toast.error('Failed to add invoice');
241
224
  }
242
- case 7:
243
- _context2.n = 9;
225
+ case 6:
226
+ _context2.n = 8;
244
227
  break;
245
- case 8:
246
- _context2.p = 8;
228
+ case 7:
229
+ _context2.p = 7;
247
230
  _t2 = _context2.v;
248
231
  setAddError('Failed to add invoice');
249
232
  if (onInvoiceAction) {
@@ -251,14 +234,14 @@ var PowrBaseInvoicesAdmin = function PowrBaseInvoicesAdmin(_ref) {
251
234
  } else {
252
235
  _reactToastify.toast.error('Failed to add invoice');
253
236
  }
254
- case 9:
255
- _context2.p = 9;
237
+ case 8:
238
+ _context2.p = 8;
256
239
  setAddLoading(false);
257
- return _context2.f(9);
258
- case 10:
240
+ return _context2.f(8);
241
+ case 9:
259
242
  return _context2.a(2);
260
243
  }
261
- }, _callee2, null, [[2, 8, 9, 10]]);
244
+ }, _callee2, null, [[1, 7, 8, 9]]);
262
245
  }));
263
246
  return function handleAddInvoice(_x) {
264
247
  return _ref3.apply(this, arguments);
@@ -339,7 +322,7 @@ var PowrBaseInvoicesAdmin = function PowrBaseInvoicesAdmin(_ref) {
339
322
  while (1) switch (_context3.n) {
340
323
  case 0:
341
324
  e.preventDefault();
342
- if (!(!editInvoiceId || !projectId)) {
325
+ if (editInvoiceId) {
343
326
  _context3.n = 1;
344
327
  break;
345
328
  }
@@ -86,52 +86,46 @@ var PowrBaseNotificationsAdmin = function PowrBaseNotificationsAdmin(_ref) {
86
86
  return _regenerator().w(function (_context) {
87
87
  while (1) switch (_context.n) {
88
88
  case 0:
89
- if (projectId) {
90
- _context.n = 1;
91
- break;
92
- }
93
- return _context.a(2);
94
- case 1:
95
89
  setLoading(true);
96
90
  setError(null);
97
- _context.p = 2;
98
- _context.n = 3;
91
+ _context.p = 1;
92
+ _context.n = 2;
99
93
  return (0, _auth.apiCall)(apiUrl, "/notifications", projectId);
100
- case 3:
94
+ case 2:
101
95
  _yield$apiCall = _context.v;
102
96
  data = _yield$apiCall.data;
103
97
  ok = _yield$apiCall.ok;
104
98
  if (ok) {
105
- _context.n = 4;
99
+ _context.n = 3;
106
100
  break;
107
101
  }
108
102
  throw new Error('Failed to fetch notifications');
109
- case 4:
103
+ case 3:
110
104
  if (!data.success) {
111
- _context.n = 5;
105
+ _context.n = 4;
112
106
  break;
113
107
  }
114
108
  setNotifications(data.notification);
115
- _context.n = 6;
109
+ _context.n = 5;
116
110
  break;
117
- case 5:
111
+ case 4:
118
112
  throw new Error('API response indicates failure');
119
- case 6:
120
- _context.n = 8;
113
+ case 5:
114
+ _context.n = 7;
121
115
  break;
122
- case 7:
123
- _context.p = 7;
116
+ case 6:
117
+ _context.p = 6;
124
118
  _t = _context.v;
125
119
  setError(_t instanceof Error ? _t.message : 'Failed to load notifications');
126
120
  setNotifications([]);
127
- case 8:
128
- _context.p = 8;
121
+ case 7:
122
+ _context.p = 7;
129
123
  setLoading(false);
130
- return _context.f(8);
131
- case 9:
124
+ return _context.f(7);
125
+ case 8:
132
126
  return _context.a(2);
133
127
  }
134
- }, _callee, null, [[2, 7, 8, 9]]);
128
+ }, _callee, null, [[1, 6, 7, 8]]);
135
129
  }));
136
130
  return function fetchNotifications() {
137
131
  return _ref2.apply(this, arguments);
@@ -139,7 +133,7 @@ var PowrBaseNotificationsAdmin = function PowrBaseNotificationsAdmin(_ref) {
139
133
  }();
140
134
  (0, _react.useEffect)(function () {
141
135
  fetchNotifications();
142
- }, [projectId]);
136
+ }, []);
143
137
  (0, _react.useEffect)(function () {
144
138
  if (selectedImageurl) {
145
139
  setNotificationData(function (prev) {
@@ -170,14 +164,8 @@ var PowrBaseNotificationsAdmin = function PowrBaseNotificationsAdmin(_ref) {
170
164
  return _regenerator().w(function (_context2) {
171
165
  while (1) switch (_context2.n) {
172
166
  case 0:
173
- if (projectId) {
174
- _context2.n = 1;
175
- break;
176
- }
177
- return _context2.a(2);
178
- case 1:
179
- _context2.p = 1;
180
- _context2.n = 2;
167
+ _context2.p = 0;
168
+ _context2.n = 1;
181
169
  return (0, _auth.apiCall)(apiUrl, "/notifications", projectId, {
182
170
  method: 'POST',
183
171
  body: {
@@ -187,12 +175,12 @@ var PowrBaseNotificationsAdmin = function PowrBaseNotificationsAdmin(_ref) {
187
175
  filter: notificationData.filter
188
176
  }
189
177
  });
190
- case 2:
178
+ case 1:
191
179
  _yield$apiCall2 = _context2.v;
192
180
  result = _yield$apiCall2.data;
193
181
  ok = _yield$apiCall2.ok;
194
182
  if (!result.success) {
195
- _context2.n = 4;
183
+ _context2.n = 3;
196
184
  break;
197
185
  }
198
186
  setShowModal(false);
@@ -205,33 +193,33 @@ var PowrBaseNotificationsAdmin = function PowrBaseNotificationsAdmin(_ref) {
205
193
  isMerchant: false
206
194
  }
207
195
  });
208
- _context2.n = 3;
196
+ _context2.n = 2;
209
197
  return fetchNotifications();
210
- case 3:
198
+ case 2:
211
199
  if (onNotificationAction) {
212
200
  onNotificationAction('success', 'Notification added successfully!');
213
201
  } else {
214
202
  _reactToastify.toast.success('Notification added successfully!');
215
203
  }
216
- _context2.n = 5;
204
+ _context2.n = 4;
217
205
  break;
218
- case 4:
206
+ case 3:
219
207
  throw new Error('Failed to add notification');
220
- case 5:
221
- _context2.n = 7;
208
+ case 4:
209
+ _context2.n = 6;
222
210
  break;
223
- case 6:
224
- _context2.p = 6;
211
+ case 5:
212
+ _context2.p = 5;
225
213
  _t2 = _context2.v;
226
214
  if (onNotificationAction) {
227
215
  onNotificationAction('error', _t2.message || 'Failed to add notification');
228
216
  } else {
229
217
  _reactToastify.toast.error(_t2.message || 'Failed to add notification');
230
218
  }
231
- case 7:
219
+ case 6:
232
220
  return _context2.a(2);
233
221
  }
234
- }, _callee2, null, [[1, 6]]);
222
+ }, _callee2, null, [[0, 5]]);
235
223
  }));
236
224
  return function handleSubmit() {
237
225
  return _ref3.apply(this, arguments);
@@ -289,17 +277,6 @@ var PowrBaseNotificationsAdmin = function PowrBaseNotificationsAdmin(_ref) {
289
277
  className: "animate-spin rounded-full h-8 w-8 border-b-2 border-orange-600"
290
278
  }));
291
279
  }
292
- if (!projectId) {
293
- return /*#__PURE__*/_react["default"].createElement("div", {
294
- className: "flex items-center justify-center h-64"
295
- }, /*#__PURE__*/_react["default"].createElement("div", {
296
- className: "text-center"
297
- }, /*#__PURE__*/_react["default"].createElement("p", {
298
- className: "text-gray-500"
299
- }, "No project selected"), /*#__PURE__*/_react["default"].createElement("p", {
300
- className: "text-sm text-gray-400"
301
- }, "Please select a project to view notifications")));
302
- }
303
280
  if (error) {
304
281
  return /*#__PURE__*/_react["default"].createElement("div", {
305
282
  className: "flex items-center justify-center h-64"
@@ -127,10 +127,8 @@ var PowrBaseSlidesAdmin = function PowrBaseSlidesAdmin(_ref) {
127
127
  };
128
128
  }();
129
129
  (0, _react.useEffect)(function () {
130
- if (projectId) {
131
- fetchBanners(projectId);
132
- }
133
- }, [projectId]);
130
+ fetchBanners(projectId);
131
+ }, []);
134
132
  (0, _react.useEffect)(function () {
135
133
  if (selectedImageurl) {
136
134
  setFormData(function (prev) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powr-sdk-web",
3
- "version": "3.3.1",
3
+ "version": "3.3.3",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "babel src -d dist --copy-files",
@@ -18,7 +18,7 @@
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "https://github.com/lawaziatech/react-byto.git"
21
+ "url": "https://github.com/lawaziatech/powr-sdk-web.git"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "filepond": "*",