@aslaluroba/help-center-react 2.1.1 → 2.1.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.
package/dist/index.esm.js CHANGED
@@ -1155,11 +1155,50 @@ function HelpPopup({ onClose, helpScreen, status, error, onStartChat, onSendMess
1155
1155
  const handleEndAndStartNewChat = useCallback(async () => {
1156
1156
  if (tempSelectedOption) {
1157
1157
  setStartNewChatConfirmation(false);
1158
- setShowChat(true);
1159
- onEndChat(tempSelectedOption);
1160
- setTempSelectedOption(null);
1158
+ try {
1159
+ // First end the current chat and wait for it to complete
1160
+ await onEndChat();
1161
+ // Wait for sessionId to be cleared (indicating the session is fully closed)
1162
+ // We'll use a polling mechanism to wait for the state to update
1163
+ const maxAttempts = 50; // 5 seconds max wait time
1164
+ let attempts = 0;
1165
+ while (sessionId && attempts < maxAttempts) {
1166
+ await new Promise((resolve) => setTimeout(resolve, 100)); // Wait 100ms
1167
+ attempts++;
1168
+ }
1169
+ // Only start new chat after current session is fully closed
1170
+ if (!sessionId) {
1171
+ setShowChat(true);
1172
+ onStartChat(tempSelectedOption);
1173
+ setSelectedOption(tempSelectedOption);
1174
+ }
1175
+ else {
1176
+ console.warn('Session did not close properly, but proceeding with new chat');
1177
+ setShowChat(true);
1178
+ onStartChat(tempSelectedOption);
1179
+ setSelectedOption(tempSelectedOption);
1180
+ }
1181
+ }
1182
+ catch (error) {
1183
+ console.error('Error ending current chat:', error);
1184
+ // Even if ending fails, try to start new chat
1185
+ setShowChat(true);
1186
+ onStartChat(tempSelectedOption);
1187
+ setSelectedOption(tempSelectedOption);
1188
+ }
1189
+ finally {
1190
+ setTempSelectedOption(null);
1191
+ }
1161
1192
  }
1162
- }, [onEndChat, setTempSelectedOption, tempSelectedOption, setStartNewChatConfirmation]);
1193
+ }, [
1194
+ onEndChat,
1195
+ onStartChat,
1196
+ setSelectedOption,
1197
+ setTempSelectedOption,
1198
+ tempSelectedOption,
1199
+ setStartNewChatConfirmation,
1200
+ sessionId,
1201
+ ]);
1163
1202
  const handleEndChat = useCallback(() => {
1164
1203
  setEndChatConfirmation(false);
1165
1204
  onEndChat();
@@ -1248,6 +1287,7 @@ function HelpCenter({ helpScreenId, user, showArrow = true, language = 'en', mes
1248
1287
  const [error, setError] = useState('');
1249
1288
  const [selectedOption, setSelectedOption] = useState(null);
1250
1289
  const [sessionId, setSessionId] = useState(null);
1290
+ const [reviewSessionId, setReviewSessionId] = useState(null);
1251
1291
  const [isSignalRConnected, setIsSignalRConnected] = useState(false);
1252
1292
  const [isChatClosed, setIsChatClosed] = useState(false);
1253
1293
  const [messages, setMessages] = useState([]);
@@ -1288,6 +1328,12 @@ function HelpCenter({ helpScreenId, user, showArrow = true, language = 'en', mes
1288
1328
  const response = await apiRequest(`Client/ClientChatSession/${sessionId}/close`, 'POST');
1289
1329
  if (!response.ok)
1290
1330
  throw new Error('Failed to close chat session');
1331
+ // Store sessionId for review before clearing the main sessionId
1332
+ setReviewSessionId(sessionId);
1333
+ // Clear the sessionId after successfully closing the session
1334
+ setSessionId(null);
1335
+ setSelectedOption(null);
1336
+ setMessages([]);
1291
1337
  setIsReviewDialogOpen(true);
1292
1338
  if (option) {
1293
1339
  handleStartChat(option);
@@ -1297,17 +1343,22 @@ function HelpCenter({ helpScreenId, user, showArrow = true, language = 'en', mes
1297
1343
  console.error('Error ending chat:', error);
1298
1344
  setError('Failed to end chat session');
1299
1345
  setAssistantStatus('idle');
1346
+ // Even if there's an error, clear the session state to prevent stuck state
1347
+ setReviewSessionId(sessionId); // Store for review even if there's an error
1348
+ setSessionId(null);
1349
+ setSelectedOption(null);
1300
1350
  }
1301
1351
  };
1302
1352
  const handleSendChatReview = async ({ comment, rating }) => {
1303
- if (!sessionId)
1353
+ if (!reviewSessionId)
1304
1354
  return;
1305
1355
  const payload = { rating, comment };
1306
1356
  try {
1307
- const response = await apiRequest(`Client/ClientChatSession/${sessionId}/review`, 'POST', payload);
1357
+ const response = await apiRequest(`Client/ClientChatSession/${reviewSessionId}/review`, 'POST', payload);
1308
1358
  if (!response.ok)
1309
1359
  throw new Error('Failed to send chat review');
1310
1360
  setIsReviewDialogOpen(false);
1361
+ setReviewSessionId(null); // Clear review session ID after review is sent
1311
1362
  }
1312
1363
  catch (error) {
1313
1364
  console.error('Error sending chat review:', error);
@@ -1316,6 +1367,7 @@ function HelpCenter({ helpScreenId, user, showArrow = true, language = 'en', mes
1316
1367
  };
1317
1368
  const handleCloseChatReview = () => {
1318
1369
  setIsReviewDialogOpen(false);
1370
+ setReviewSessionId(null); // Clear review session ID when review is closed
1319
1371
  };
1320
1372
  const handleStartChat = async (option) => {
1321
1373
  await startNewChatSession(option);