@aslaluroba/help-center-react 2.1.0 → 2.1.2

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "dist/index.js",
4
4
  "module": "dist/index.esm.js",
5
5
  "types": "dist/index.d.ts",
6
- "version": "2.1.0",
6
+ "version": "2.1.2",
7
7
  "description": "BabylAI Help Center Widget for React and Next.js",
8
8
  "private": false,
9
9
  "exports": {
@@ -26,7 +26,10 @@
26
26
  "clean": "rimraf dist",
27
27
  "version:patch": "npm version patch --no-git-tag-version",
28
28
  "version:minor": "npm version minor --no-git-tag-version",
29
- "version:major": "npm version major --no-git-tag-version"
29
+ "version:major": "npm version major --no-git-tag-version",
30
+ "publish": "yarn clean && yarn build && yarn version:patch && yarn publish --access public",
31
+ "publish:minor": "yarn clean && yarn build && yarn version:minor && yarn publish --access public",
32
+ "publish:major": "yarn clean && yarn build && yarn version:major && yarn publish --access public"
30
33
  },
31
34
  "files": [
32
35
  "dist",
@@ -48,27 +51,26 @@
48
51
  "author": "BabylAI",
49
52
  "license": "MIT",
50
53
  "peerDependencies": {
51
- "@tabler/icons-react": "^3.0.0",
54
+ "@tabler/icons-react": "^3.34.0",
52
55
  "clsx": "^2.0.0",
53
- "i18next": "^23.0.0",
56
+ "i18next": "^23.0.0 || ^25.0.0",
54
57
  "react": ">=16.8.0",
55
58
  "react-dom": ">=16.8.0",
56
- "react-i18next": "^13.0.0",
59
+ "react-i18next": "^13.0.0 || ^15.0.0",
57
60
  "react-markdown": "^10.0.0",
58
61
  "tailwind-merge": "^3.0.0"
59
62
  },
60
63
  "dependencies": {
61
- "@babel/core": "^7.26.10",
62
- "@babel/preset-env": "^7.26.9",
63
- "@babel/preset-react": "^7.26.3",
64
64
  "@microsoft/signalr": "^7.0.14",
65
- "@rollup/plugin-babel": "^6.0.4",
66
65
  "axios": "^1.7.9",
67
- "babel-loader": "^10.0.0",
68
66
  "class-variance-authority": "^0.7.1"
69
67
  },
70
68
  "devDependencies": {
69
+ "@babel/core": "^7.26.10",
70
+ "@babel/preset-env": "^7.26.9",
71
+ "@babel/preset-react": "^7.26.3",
71
72
  "@rollup/plugin-alias": "^5.1.1",
73
+ "@rollup/plugin-babel": "^6.0.4",
72
74
  "@rollup/plugin-commonjs": "^21.1.0",
73
75
  "@rollup/plugin-image": "^3.0.3",
74
76
  "@rollup/plugin-json": "^6.1.0",
@@ -81,6 +83,7 @@
81
83
  "@types/node": "^16.18.126",
82
84
  "@types/react": "^17.0.83",
83
85
  "autoprefixer": "^10.4.14",
86
+ "babel-loader": "^10.0.0",
84
87
  "clsx": "^2.1.1",
85
88
  "i18next": "^25.2.1",
86
89
  "postcss": "^8.4.24",
@@ -41,6 +41,7 @@ export function HelpCenter({
41
41
  const [selectedOption, setSelectedOption] = useState<Option | null>(null);
42
42
 
43
43
  const [sessionId, setSessionId] = useState<string | null>(null);
44
+ const [reviewSessionId, setReviewSessionId] = useState<string | null>(null);
44
45
  const [isSignalRConnected, setIsSignalRConnected] = useState(false);
45
46
  const [isChatClosed, setIsChatClosed] = useState(false);
46
47
  const [messages, setMessages] = useState<Message[]>([]);
@@ -91,6 +92,14 @@ export function HelpCenter({
91
92
  const response = await apiRequest(`Client/ClientChatSession/${sessionId}/close`, 'POST');
92
93
  if (!response.ok) throw new Error('Failed to close chat session');
93
94
 
95
+ // Store sessionId for review before clearing the main sessionId
96
+ setReviewSessionId(sessionId);
97
+
98
+ // Clear the sessionId after successfully closing the session
99
+ setSessionId(null);
100
+ setSelectedOption(null);
101
+ setMessages([]);
102
+
94
103
  setIsReviewDialogOpen(true);
95
104
  if (option) {
96
105
  handleStartChat(option);
@@ -99,19 +108,24 @@ export function HelpCenter({
99
108
  console.error('Error ending chat:', error);
100
109
  setError('Failed to end chat session');
101
110
  setAssistantStatus('idle');
111
+ // Even if there's an error, clear the session state to prevent stuck state
112
+ setReviewSessionId(sessionId); // Store for review even if there's an error
113
+ setSessionId(null);
114
+ setSelectedOption(null);
102
115
  }
103
116
  };
104
117
 
105
118
  const handleSendChatReview = async ({ comment, rating }: ReviewProps) => {
106
- if (!sessionId) return;
119
+ if (!reviewSessionId) return;
107
120
 
108
121
  const payload = { rating, comment };
109
122
 
110
123
  try {
111
- const response = await apiRequest(`Client/ClientChatSession/${sessionId}/review`, 'POST', payload);
124
+ const response = await apiRequest(`Client/ClientChatSession/${reviewSessionId}/review`, 'POST', payload);
112
125
  if (!response.ok) throw new Error('Failed to send chat review');
113
126
 
114
127
  setIsReviewDialogOpen(false);
128
+ setReviewSessionId(null); // Clear review session ID after review is sent
115
129
  } catch (error) {
116
130
  console.error('Error sending chat review:', error);
117
131
  setError('Failed to send chat review');
@@ -120,6 +134,7 @@ export function HelpCenter({
120
134
 
121
135
  const handleCloseChatReview = () => {
122
136
  setIsReviewDialogOpen(false);
137
+ setReviewSessionId(null); // Clear review session ID when review is closed
123
138
  };
124
139
 
125
140
  const handleStartChat = async (option: Option) => {
@@ -166,11 +166,51 @@ export function HelpPopup({
166
166
  const handleEndAndStartNewChat = useCallback(async () => {
167
167
  if (tempSelectedOption) {
168
168
  setStartNewChatConfirmation(false);
169
- setShowChat(true);
170
- onEndChat(tempSelectedOption);
171
- setTempSelectedOption(null);
169
+
170
+ try {
171
+ // First end the current chat and wait for it to complete
172
+ await onEndChat();
173
+
174
+ // Wait for sessionId to be cleared (indicating the session is fully closed)
175
+ // We'll use a polling mechanism to wait for the state to update
176
+ const maxAttempts = 50; // 5 seconds max wait time
177
+ let attempts = 0;
178
+
179
+ while (sessionId && attempts < maxAttempts) {
180
+ await new Promise((resolve) => setTimeout(resolve, 100)); // Wait 100ms
181
+ attempts++;
182
+ }
183
+
184
+ // Only start new chat after current session is fully closed
185
+ if (!sessionId) {
186
+ setShowChat(true);
187
+ onStartChat(tempSelectedOption);
188
+ setSelectedOption(tempSelectedOption);
189
+ } else {
190
+ console.warn('Session did not close properly, but proceeding with new chat');
191
+ setShowChat(true);
192
+ onStartChat(tempSelectedOption);
193
+ setSelectedOption(tempSelectedOption);
194
+ }
195
+ } catch (error) {
196
+ console.error('Error ending current chat:', error);
197
+ // Even if ending fails, try to start new chat
198
+ setShowChat(true);
199
+ onStartChat(tempSelectedOption);
200
+ setSelectedOption(tempSelectedOption);
201
+ } finally {
202
+ setTempSelectedOption(null);
203
+ }
172
204
  }
173
- }, [onEndChat, setTempSelectedOption, tempSelectedOption, setStartNewChatConfirmation]);
205
+ }, [
206
+ onEndChat,
207
+ onStartChat,
208
+ setSelectedOption,
209
+ setTempSelectedOption,
210
+ tempSelectedOption,
211
+ setStartNewChatConfirmation,
212
+ sessionId,
213
+ ]);
174
214
 
175
215
  const handleEndChat = useCallback(() => {
176
216
  setEndChatConfirmation(false);