@cstar.help/react 0.6.1 → 0.7.0
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/README.md +9 -9
- package/dist/index.cjs +14 -13
- package/dist/index.d.cts +20 -20
- package/dist/index.d.ts +20 -20
- package/dist/index.js +13 -12
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ import { CStarChatProvider } from '@cstar.help/react';
|
|
|
24
24
|
|
|
25
25
|
function App() {
|
|
26
26
|
return (
|
|
27
|
-
<CStarChatProvider teamSlug="acme"
|
|
27
|
+
<CStarChatProvider teamSlug="acme">
|
|
28
28
|
<ChatWidget />
|
|
29
29
|
</CStarChatProvider>
|
|
30
30
|
);
|
|
@@ -47,24 +47,24 @@ function ChatWidget() {
|
|
|
47
47
|
}, []);
|
|
48
48
|
|
|
49
49
|
if (!isIdentified) return <p>Connecting...</p>;
|
|
50
|
-
return <
|
|
50
|
+
return <TicketList />;
|
|
51
51
|
}
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
###
|
|
54
|
+
### Tickets
|
|
55
55
|
|
|
56
56
|
```tsx
|
|
57
|
-
import {
|
|
57
|
+
import { useTickets } from '@cstar.help/react';
|
|
58
58
|
|
|
59
|
-
function
|
|
60
|
-
const {
|
|
59
|
+
function TicketList() {
|
|
60
|
+
const { tickets, isLoading, create, refresh, hasMore } = useTickets();
|
|
61
61
|
|
|
62
62
|
if (isLoading) return <Spinner />;
|
|
63
63
|
|
|
64
64
|
return (
|
|
65
65
|
<ul>
|
|
66
|
-
{
|
|
67
|
-
<li key={
|
|
66
|
+
{tickets.map((t) => (
|
|
67
|
+
<li key={t.id}>{t.subject}</li>
|
|
68
68
|
))}
|
|
69
69
|
</ul>
|
|
70
70
|
);
|
|
@@ -270,7 +270,7 @@ function CommunitySearch() {
|
|
|
270
270
|
| Hook | Returns | Description |
|
|
271
271
|
| ----------------------- | ---------------------------------------------------------------- | ---------------------------------------------------- |
|
|
272
272
|
| `useChat()` | `{ identify, disconnect, isIdentified, isRealtimeReady, error }` | Identity verification and connection state |
|
|
273
|
-
| `
|
|
273
|
+
| `useTickets()` | `{ tickets, isLoading, error, hasMore, refresh, create }` | List and create tickets |
|
|
274
274
|
| `useMessages(ticketId)` | `{ messages, isLoading, error, send, refresh }` | Messages with real-time updates and optimistic send |
|
|
275
275
|
| `useTyping(ticketId)` | `{ typingAgents, sendTyping }` | Agent typing indicators with auto-clear (4s timeout) |
|
|
276
276
|
|
package/dist/index.cjs
CHANGED
|
@@ -39,7 +39,6 @@ __export(src_exports, {
|
|
|
39
39
|
useChatClient: () => useChatClient,
|
|
40
40
|
useCommunityClient: () => useCommunityClient,
|
|
41
41
|
useCommunitySearch: () => useCommunitySearch,
|
|
42
|
-
useConversations: () => useConversations,
|
|
43
42
|
useDashboardClient: () => useDashboardClient,
|
|
44
43
|
useGameActivity: () => useGameActivity,
|
|
45
44
|
useLeaderboard: () => useLeaderboard,
|
|
@@ -48,6 +47,7 @@ __export(src_exports, {
|
|
|
48
47
|
usePlayerStats: () => usePlayerStats,
|
|
49
48
|
usePost: () => usePost,
|
|
50
49
|
usePosts: () => usePosts,
|
|
50
|
+
useTickets: () => useTickets,
|
|
51
51
|
useTopics: () => useTopics,
|
|
52
52
|
useTyping: () => useTyping
|
|
53
53
|
});
|
|
@@ -133,11 +133,11 @@ function useChat() {
|
|
|
133
133
|
return { identify, disconnect, isIdentified, isRealtimeReady, error };
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
// src/chat/
|
|
136
|
+
// src/chat/useTickets.ts
|
|
137
137
|
var import_react4 = require("react");
|
|
138
|
-
function
|
|
138
|
+
function useTickets() {
|
|
139
139
|
const client = useChatClient();
|
|
140
|
-
const [
|
|
140
|
+
const [tickets, setTickets] = (0, import_react4.useState)([]);
|
|
141
141
|
const [isLoading, setIsLoading] = (0, import_react4.useState)(true);
|
|
142
142
|
const [error, setError] = (0, import_react4.useState)(null);
|
|
143
143
|
const [hasMore, setHasMore] = (0, import_react4.useState)(false);
|
|
@@ -146,9 +146,9 @@ function useConversations() {
|
|
|
146
146
|
setIsLoading(true);
|
|
147
147
|
setError(null);
|
|
148
148
|
try {
|
|
149
|
-
const result = await client.
|
|
149
|
+
const result = await client.tickets.list();
|
|
150
150
|
if (mountedRef.current) {
|
|
151
|
-
|
|
151
|
+
setTickets(result.tickets);
|
|
152
152
|
setHasMore(result.hasMore);
|
|
153
153
|
}
|
|
154
154
|
} catch (err) {
|
|
@@ -170,15 +170,15 @@ function useConversations() {
|
|
|
170
170
|
}, [refresh]);
|
|
171
171
|
const create = (0, import_react4.useCallback)(
|
|
172
172
|
async (params) => {
|
|
173
|
-
const
|
|
173
|
+
const ticket = await client.tickets.create(params);
|
|
174
174
|
if (mountedRef.current) {
|
|
175
|
-
|
|
175
|
+
setTickets((prev) => [ticket, ...prev]);
|
|
176
176
|
}
|
|
177
|
-
return
|
|
177
|
+
return ticket;
|
|
178
178
|
},
|
|
179
179
|
[client]
|
|
180
180
|
);
|
|
181
|
-
return {
|
|
181
|
+
return { tickets, isLoading, error, hasMore, refresh, create };
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
// src/chat/useMessages.ts
|
|
@@ -241,7 +241,7 @@ function useMessages(ticketId) {
|
|
|
241
241
|
}, [client, ticketId, refresh]);
|
|
242
242
|
const send = (0, import_react5.useCallback)(
|
|
243
243
|
async (content) => {
|
|
244
|
-
if (!ticketId) throw new Error("No
|
|
244
|
+
if (!ticketId) throw new Error("No ticket selected");
|
|
245
245
|
const optimistic = {
|
|
246
246
|
id: `optimistic-${Date.now()}`,
|
|
247
247
|
content,
|
|
@@ -754,7 +754,8 @@ function resolveMutation(client, path) {
|
|
|
754
754
|
const methodName = parts[1];
|
|
755
755
|
const resource = client[resourceName];
|
|
756
756
|
if (!resource || typeof resource !== "object") return null;
|
|
757
|
-
const
|
|
757
|
+
const lookupName = methodName === "delete" ? "del" : methodName;
|
|
758
|
+
const method = resource[lookupName];
|
|
758
759
|
if (typeof method !== "function") return null;
|
|
759
760
|
if (methodName === "update") {
|
|
760
761
|
return (params) => {
|
|
@@ -982,7 +983,6 @@ function useGameActivity() {
|
|
|
982
983
|
useChatClient,
|
|
983
984
|
useCommunityClient,
|
|
984
985
|
useCommunitySearch,
|
|
985
|
-
useConversations,
|
|
986
986
|
useDashboardClient,
|
|
987
987
|
useGameActivity,
|
|
988
988
|
useLeaderboard,
|
|
@@ -991,6 +991,7 @@ function useGameActivity() {
|
|
|
991
991
|
usePlayerStats,
|
|
992
992
|
usePost,
|
|
993
993
|
usePosts,
|
|
994
|
+
useTickets,
|
|
994
995
|
useTopics,
|
|
995
996
|
useTyping
|
|
996
997
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import react__default, { ReactNode } from 'react';
|
|
3
|
-
import { ChatClient, ChatConfig, IdentifyParams, IdentifyResult,
|
|
4
|
-
export { ChatConfig,
|
|
3
|
+
import { ChatClient, ChatConfig, IdentifyParams, IdentifyResult, Ticket, TicketCreateParams, Message } from '@cstar.help/js/chat';
|
|
4
|
+
export { ChatConfig, IdentifyParams, IdentifyResult, Message, Ticket, TicketCreateParams, TicketListResponse, TypingPayload } from '@cstar.help/js/chat';
|
|
5
5
|
import { LibraryClient, LibraryConfig, Category, LibraryArticle, LibraryArticleListParams } from '@cstar.help/js/library';
|
|
6
6
|
export { Category, LibraryArticle, LibraryArticleListParams, LibraryConfig, LibrarySearchParams, LibrarySearchResult } from '@cstar.help/js/library';
|
|
7
7
|
import { CommunityClient, CommunityConfig, CommunityTopic, CommunityPost, CommunityPostListParams, CommunityPostDetail, CommunitySearchResult } from '@cstar.help/js/community';
|
|
@@ -36,7 +36,7 @@ interface CStarChatProviderProps extends ChatConfig {
|
|
|
36
36
|
* Creates the client on mount and disconnects on unmount.
|
|
37
37
|
*
|
|
38
38
|
* ```tsx
|
|
39
|
-
* <CStarChatProvider teamSlug="acme"
|
|
39
|
+
* <CStarChatProvider teamSlug="acme">
|
|
40
40
|
* <ChatWidget />
|
|
41
41
|
* </CStarChatProvider>
|
|
42
42
|
* ```
|
|
@@ -50,7 +50,7 @@ interface UseChatReturn {
|
|
|
50
50
|
disconnect: () => void;
|
|
51
51
|
/** Whether a customer has been successfully identified. */
|
|
52
52
|
isIdentified: boolean;
|
|
53
|
-
/** Whether the
|
|
53
|
+
/** Whether the real-time connection is ready. */
|
|
54
54
|
isRealtimeReady: boolean;
|
|
55
55
|
/** The last error from identify, or null. */
|
|
56
56
|
error: Error | null;
|
|
@@ -69,43 +69,43 @@ interface UseChatReturn {
|
|
|
69
69
|
*/
|
|
70
70
|
declare function useChat(): UseChatReturn;
|
|
71
71
|
|
|
72
|
-
interface
|
|
73
|
-
/** List of
|
|
74
|
-
|
|
72
|
+
interface UseTicketsReturn {
|
|
73
|
+
/** List of tickets for the identified customer. */
|
|
74
|
+
tickets: Ticket[];
|
|
75
75
|
/** Whether the initial fetch is in progress. */
|
|
76
76
|
isLoading: boolean;
|
|
77
77
|
/** The last error, or null. */
|
|
78
78
|
error: Error | null;
|
|
79
|
-
/** Whether there are more
|
|
79
|
+
/** Whether there are more tickets to load. */
|
|
80
80
|
hasMore: boolean;
|
|
81
|
-
/** Re-fetch the
|
|
81
|
+
/** Re-fetch the ticket list. */
|
|
82
82
|
refresh: () => Promise<void>;
|
|
83
|
-
/** Create a new
|
|
84
|
-
create: (params:
|
|
83
|
+
/** Create a new ticket. */
|
|
84
|
+
create: (params: TicketCreateParams) => Promise<Ticket>;
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
|
-
* Manage the customer's
|
|
87
|
+
* Manage the customer's ticket list.
|
|
88
88
|
*
|
|
89
89
|
* ```tsx
|
|
90
|
-
* const {
|
|
90
|
+
* const { tickets, isLoading, create, refresh } = useTickets();
|
|
91
91
|
* ```
|
|
92
92
|
*/
|
|
93
|
-
declare function
|
|
93
|
+
declare function useTickets(): UseTicketsReturn;
|
|
94
94
|
|
|
95
95
|
interface UseMessagesReturn {
|
|
96
|
-
/** Messages
|
|
97
|
-
messages:
|
|
96
|
+
/** Messages on the ticket, oldest first. */
|
|
97
|
+
messages: Message[];
|
|
98
98
|
/** Whether the initial fetch is in progress. */
|
|
99
99
|
isLoading: boolean;
|
|
100
100
|
/** The last error, or null. */
|
|
101
101
|
error: Error | null;
|
|
102
102
|
/** Send a message. Optimistically appended, replaced with server response. */
|
|
103
|
-
send: (content: string) => Promise<
|
|
103
|
+
send: (content: string) => Promise<Message>;
|
|
104
104
|
/** Re-fetch messages from the API. */
|
|
105
105
|
refresh: () => Promise<void>;
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
-
* Manage messages for a single
|
|
108
|
+
* Manage messages for a single ticket with automatic real-time updates.
|
|
109
109
|
*
|
|
110
110
|
* ```tsx
|
|
111
111
|
* const { messages, isLoading, send } = useMessages(ticketId);
|
|
@@ -125,7 +125,7 @@ interface UseTypingReturn {
|
|
|
125
125
|
sendTyping: (isTyping: boolean) => Promise<void>;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
|
-
* Track agent typing indicators for a
|
|
128
|
+
* Track agent typing indicators for a ticket.
|
|
129
129
|
*
|
|
130
130
|
* ```tsx
|
|
131
131
|
* const { typingAgents, sendTyping } = useTyping(ticketId);
|
|
@@ -477,4 +477,4 @@ interface UseGameActivityReturn {
|
|
|
477
477
|
*/
|
|
478
478
|
declare function useGameActivity(): UseGameActivityReturn;
|
|
479
479
|
|
|
480
|
-
export { CStarChatContext, CStarChatProvider, type CStarChatProviderProps, CStarCommunityContext, CStarCommunityProvider, type CStarCommunityProviderProps, CStarDashboardProvider, type CStarDashboardProviderProps, CStarLibraryContext, CStarLibraryProvider, type CStarLibraryProviderProps, type TypingAgent, type UseArticleReturn, type UseArticleSearchReturn, type UseArticlesReturn, type UseBossBattleReturn, type UseCStarEventsReturn, type UseCStarMutationReturn, type UseCStarQueryReturn, type UseCategoriesReturn, type UseChatReturn, type UseCommunitySearchReturn, type
|
|
480
|
+
export { CStarChatContext, CStarChatProvider, type CStarChatProviderProps, CStarCommunityContext, CStarCommunityProvider, type CStarCommunityProviderProps, CStarDashboardProvider, type CStarDashboardProviderProps, CStarLibraryContext, CStarLibraryProvider, type CStarLibraryProviderProps, type TypingAgent, type UseArticleReturn, type UseArticleSearchReturn, type UseArticlesReturn, type UseBossBattleReturn, type UseCStarEventsReturn, type UseCStarMutationReturn, type UseCStarQueryReturn, type UseCategoriesReturn, type UseChatReturn, type UseCommunitySearchReturn, type UseGameActivityReturn, type UseLeaderboardReturn, type UseMessagesReturn, type UsePlayerStatsReturn, type UsePostReturn, type UsePostsReturn, type UseTicketsReturn, type UseTopicsReturn, type UseTypingReturn, useArticle, useArticleSearch, useArticles, useBossBattle, useCStarEvents, useCStarMutation, useCStarQuery, useCategories, useChat, useChatClient, useCommunityClient, useCommunitySearch, useDashboardClient, useGameActivity, useLeaderboard, useLibraryClient, useMessages, usePlayerStats, usePost, usePosts, useTickets, useTopics, useTyping };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import react__default, { ReactNode } from 'react';
|
|
3
|
-
import { ChatClient, ChatConfig, IdentifyParams, IdentifyResult,
|
|
4
|
-
export { ChatConfig,
|
|
3
|
+
import { ChatClient, ChatConfig, IdentifyParams, IdentifyResult, Ticket, TicketCreateParams, Message } from '@cstar.help/js/chat';
|
|
4
|
+
export { ChatConfig, IdentifyParams, IdentifyResult, Message, Ticket, TicketCreateParams, TicketListResponse, TypingPayload } from '@cstar.help/js/chat';
|
|
5
5
|
import { LibraryClient, LibraryConfig, Category, LibraryArticle, LibraryArticleListParams } from '@cstar.help/js/library';
|
|
6
6
|
export { Category, LibraryArticle, LibraryArticleListParams, LibraryConfig, LibrarySearchParams, LibrarySearchResult } from '@cstar.help/js/library';
|
|
7
7
|
import { CommunityClient, CommunityConfig, CommunityTopic, CommunityPost, CommunityPostListParams, CommunityPostDetail, CommunitySearchResult } from '@cstar.help/js/community';
|
|
@@ -36,7 +36,7 @@ interface CStarChatProviderProps extends ChatConfig {
|
|
|
36
36
|
* Creates the client on mount and disconnects on unmount.
|
|
37
37
|
*
|
|
38
38
|
* ```tsx
|
|
39
|
-
* <CStarChatProvider teamSlug="acme"
|
|
39
|
+
* <CStarChatProvider teamSlug="acme">
|
|
40
40
|
* <ChatWidget />
|
|
41
41
|
* </CStarChatProvider>
|
|
42
42
|
* ```
|
|
@@ -50,7 +50,7 @@ interface UseChatReturn {
|
|
|
50
50
|
disconnect: () => void;
|
|
51
51
|
/** Whether a customer has been successfully identified. */
|
|
52
52
|
isIdentified: boolean;
|
|
53
|
-
/** Whether the
|
|
53
|
+
/** Whether the real-time connection is ready. */
|
|
54
54
|
isRealtimeReady: boolean;
|
|
55
55
|
/** The last error from identify, or null. */
|
|
56
56
|
error: Error | null;
|
|
@@ -69,43 +69,43 @@ interface UseChatReturn {
|
|
|
69
69
|
*/
|
|
70
70
|
declare function useChat(): UseChatReturn;
|
|
71
71
|
|
|
72
|
-
interface
|
|
73
|
-
/** List of
|
|
74
|
-
|
|
72
|
+
interface UseTicketsReturn {
|
|
73
|
+
/** List of tickets for the identified customer. */
|
|
74
|
+
tickets: Ticket[];
|
|
75
75
|
/** Whether the initial fetch is in progress. */
|
|
76
76
|
isLoading: boolean;
|
|
77
77
|
/** The last error, or null. */
|
|
78
78
|
error: Error | null;
|
|
79
|
-
/** Whether there are more
|
|
79
|
+
/** Whether there are more tickets to load. */
|
|
80
80
|
hasMore: boolean;
|
|
81
|
-
/** Re-fetch the
|
|
81
|
+
/** Re-fetch the ticket list. */
|
|
82
82
|
refresh: () => Promise<void>;
|
|
83
|
-
/** Create a new
|
|
84
|
-
create: (params:
|
|
83
|
+
/** Create a new ticket. */
|
|
84
|
+
create: (params: TicketCreateParams) => Promise<Ticket>;
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
|
-
* Manage the customer's
|
|
87
|
+
* Manage the customer's ticket list.
|
|
88
88
|
*
|
|
89
89
|
* ```tsx
|
|
90
|
-
* const {
|
|
90
|
+
* const { tickets, isLoading, create, refresh } = useTickets();
|
|
91
91
|
* ```
|
|
92
92
|
*/
|
|
93
|
-
declare function
|
|
93
|
+
declare function useTickets(): UseTicketsReturn;
|
|
94
94
|
|
|
95
95
|
interface UseMessagesReturn {
|
|
96
|
-
/** Messages
|
|
97
|
-
messages:
|
|
96
|
+
/** Messages on the ticket, oldest first. */
|
|
97
|
+
messages: Message[];
|
|
98
98
|
/** Whether the initial fetch is in progress. */
|
|
99
99
|
isLoading: boolean;
|
|
100
100
|
/** The last error, or null. */
|
|
101
101
|
error: Error | null;
|
|
102
102
|
/** Send a message. Optimistically appended, replaced with server response. */
|
|
103
|
-
send: (content: string) => Promise<
|
|
103
|
+
send: (content: string) => Promise<Message>;
|
|
104
104
|
/** Re-fetch messages from the API. */
|
|
105
105
|
refresh: () => Promise<void>;
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
-
* Manage messages for a single
|
|
108
|
+
* Manage messages for a single ticket with automatic real-time updates.
|
|
109
109
|
*
|
|
110
110
|
* ```tsx
|
|
111
111
|
* const { messages, isLoading, send } = useMessages(ticketId);
|
|
@@ -125,7 +125,7 @@ interface UseTypingReturn {
|
|
|
125
125
|
sendTyping: (isTyping: boolean) => Promise<void>;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
|
-
* Track agent typing indicators for a
|
|
128
|
+
* Track agent typing indicators for a ticket.
|
|
129
129
|
*
|
|
130
130
|
* ```tsx
|
|
131
131
|
* const { typingAgents, sendTyping } = useTyping(ticketId);
|
|
@@ -477,4 +477,4 @@ interface UseGameActivityReturn {
|
|
|
477
477
|
*/
|
|
478
478
|
declare function useGameActivity(): UseGameActivityReturn;
|
|
479
479
|
|
|
480
|
-
export { CStarChatContext, CStarChatProvider, type CStarChatProviderProps, CStarCommunityContext, CStarCommunityProvider, type CStarCommunityProviderProps, CStarDashboardProvider, type CStarDashboardProviderProps, CStarLibraryContext, CStarLibraryProvider, type CStarLibraryProviderProps, type TypingAgent, type UseArticleReturn, type UseArticleSearchReturn, type UseArticlesReturn, type UseBossBattleReturn, type UseCStarEventsReturn, type UseCStarMutationReturn, type UseCStarQueryReturn, type UseCategoriesReturn, type UseChatReturn, type UseCommunitySearchReturn, type
|
|
480
|
+
export { CStarChatContext, CStarChatProvider, type CStarChatProviderProps, CStarCommunityContext, CStarCommunityProvider, type CStarCommunityProviderProps, CStarDashboardProvider, type CStarDashboardProviderProps, CStarLibraryContext, CStarLibraryProvider, type CStarLibraryProviderProps, type TypingAgent, type UseArticleReturn, type UseArticleSearchReturn, type UseArticlesReturn, type UseBossBattleReturn, type UseCStarEventsReturn, type UseCStarMutationReturn, type UseCStarQueryReturn, type UseCategoriesReturn, type UseChatReturn, type UseCommunitySearchReturn, type UseGameActivityReturn, type UseLeaderboardReturn, type UseMessagesReturn, type UsePlayerStatsReturn, type UsePostReturn, type UsePostsReturn, type UseTicketsReturn, type UseTopicsReturn, type UseTypingReturn, useArticle, useArticleSearch, useArticles, useBossBattle, useCStarEvents, useCStarMutation, useCStarQuery, useCategories, useChat, useChatClient, useCommunityClient, useCommunitySearch, useDashboardClient, useGameActivity, useLeaderboard, useLibraryClient, useMessages, usePlayerStats, usePost, usePosts, useTickets, useTopics, useTyping };
|
package/dist/index.js
CHANGED
|
@@ -78,11 +78,11 @@ function useChat() {
|
|
|
78
78
|
return { identify, disconnect, isIdentified, isRealtimeReady, error };
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
// src/chat/
|
|
81
|
+
// src/chat/useTickets.ts
|
|
82
82
|
import { useState as useState2, useEffect as useEffect2, useCallback as useCallback2, useRef as useRef2 } from "react";
|
|
83
|
-
function
|
|
83
|
+
function useTickets() {
|
|
84
84
|
const client = useChatClient();
|
|
85
|
-
const [
|
|
85
|
+
const [tickets, setTickets] = useState2([]);
|
|
86
86
|
const [isLoading, setIsLoading] = useState2(true);
|
|
87
87
|
const [error, setError] = useState2(null);
|
|
88
88
|
const [hasMore, setHasMore] = useState2(false);
|
|
@@ -91,9 +91,9 @@ function useConversations() {
|
|
|
91
91
|
setIsLoading(true);
|
|
92
92
|
setError(null);
|
|
93
93
|
try {
|
|
94
|
-
const result = await client.
|
|
94
|
+
const result = await client.tickets.list();
|
|
95
95
|
if (mountedRef.current) {
|
|
96
|
-
|
|
96
|
+
setTickets(result.tickets);
|
|
97
97
|
setHasMore(result.hasMore);
|
|
98
98
|
}
|
|
99
99
|
} catch (err) {
|
|
@@ -115,15 +115,15 @@ function useConversations() {
|
|
|
115
115
|
}, [refresh]);
|
|
116
116
|
const create = useCallback2(
|
|
117
117
|
async (params) => {
|
|
118
|
-
const
|
|
118
|
+
const ticket = await client.tickets.create(params);
|
|
119
119
|
if (mountedRef.current) {
|
|
120
|
-
|
|
120
|
+
setTickets((prev) => [ticket, ...prev]);
|
|
121
121
|
}
|
|
122
|
-
return
|
|
122
|
+
return ticket;
|
|
123
123
|
},
|
|
124
124
|
[client]
|
|
125
125
|
);
|
|
126
|
-
return {
|
|
126
|
+
return { tickets, isLoading, error, hasMore, refresh, create };
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// src/chat/useMessages.ts
|
|
@@ -186,7 +186,7 @@ function useMessages(ticketId) {
|
|
|
186
186
|
}, [client, ticketId, refresh]);
|
|
187
187
|
const send = useCallback3(
|
|
188
188
|
async (content) => {
|
|
189
|
-
if (!ticketId) throw new Error("No
|
|
189
|
+
if (!ticketId) throw new Error("No ticket selected");
|
|
190
190
|
const optimistic = {
|
|
191
191
|
id: `optimistic-${Date.now()}`,
|
|
192
192
|
content,
|
|
@@ -699,7 +699,8 @@ function resolveMutation(client, path) {
|
|
|
699
699
|
const methodName = parts[1];
|
|
700
700
|
const resource = client[resourceName];
|
|
701
701
|
if (!resource || typeof resource !== "object") return null;
|
|
702
|
-
const
|
|
702
|
+
const lookupName = methodName === "delete" ? "del" : methodName;
|
|
703
|
+
const method = resource[lookupName];
|
|
703
704
|
if (typeof method !== "function") return null;
|
|
704
705
|
if (methodName === "update") {
|
|
705
706
|
return (params) => {
|
|
@@ -926,7 +927,6 @@ export {
|
|
|
926
927
|
useChatClient,
|
|
927
928
|
useCommunityClient,
|
|
928
929
|
useCommunitySearch,
|
|
929
|
-
useConversations,
|
|
930
930
|
useDashboardClient,
|
|
931
931
|
useGameActivity,
|
|
932
932
|
useLeaderboard,
|
|
@@ -935,6 +935,7 @@ export {
|
|
|
935
935
|
usePlayerStats,
|
|
936
936
|
usePost,
|
|
937
937
|
usePosts,
|
|
938
|
+
useTickets,
|
|
938
939
|
useTopics,
|
|
939
940
|
useTyping
|
|
940
941
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cstar.help/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "React hooks for the cStar customer support platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": ">=18.0.0",
|
|
33
|
-
"@cstar.help/js": ">=0.
|
|
33
|
+
"@cstar.help/js": ">=0.11.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"react": "^18.3.1",
|