@greatapps/greatchat-ui 0.1.1 → 0.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.d.ts +290 -1
- package/dist/index.js +1534 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/components/contact-avatar.tsx +59 -0
- package/src/components/contact-info-panel.tsx +139 -0
- package/src/components/inbox-item.tsx +149 -0
- package/src/components/inbox-sidebar.tsx +148 -0
- package/src/components/index.ts +15 -0
- package/src/components/new-conversation-dialog.tsx +172 -0
- package/src/components/ui/avatar.tsx +51 -0
- package/src/components/ui/command.tsx +106 -0
- package/src/components/ui/dialog.tsx +133 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/scroll-area.tsx +50 -0
- package/src/components/ui/separator.tsx +26 -0
- package/src/components/ui/tabs.tsx +64 -0
- package/src/components/ui/tooltip.tsx +58 -0
- package/src/hooks/index.ts +14 -0
- package/src/hooks/types.ts +40 -0
- package/src/hooks/use-channels.ts +163 -0
- package/src/hooks/use-contacts.ts +94 -0
- package/src/hooks/use-inbox-messages.ts +405 -0
- package/src/hooks/use-inboxes.ts +127 -0
- package/src/index.ts +23 -2
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
2
|
+
import type { Inbox, InboxStats } from "../types";
|
|
3
|
+
import {
|
|
4
|
+
type GchatHookConfig,
|
|
5
|
+
DEFAULT_INBOX_POLLING,
|
|
6
|
+
useGchatClient,
|
|
7
|
+
} from "./types";
|
|
8
|
+
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Queries
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
export function useInboxes(
|
|
14
|
+
config: GchatHookConfig,
|
|
15
|
+
statusFilter?: string,
|
|
16
|
+
pollingInterval?: number,
|
|
17
|
+
) {
|
|
18
|
+
const client = useGchatClient(config);
|
|
19
|
+
|
|
20
|
+
return useQuery({
|
|
21
|
+
queryKey: ["greatchat", "inboxes", config.accountId, statusFilter],
|
|
22
|
+
queryFn: () => {
|
|
23
|
+
const params: Record<string, string> = {};
|
|
24
|
+
if (statusFilter && statusFilter !== "all") {
|
|
25
|
+
params.status = statusFilter;
|
|
26
|
+
}
|
|
27
|
+
return client.listInboxes(config.accountId, params);
|
|
28
|
+
},
|
|
29
|
+
enabled: !!config.accountId && !!config.token,
|
|
30
|
+
refetchInterval: pollingInterval ?? DEFAULT_INBOX_POLLING,
|
|
31
|
+
select: (res) => res.data || [],
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function useInbox(config: GchatHookConfig, id: number | null) {
|
|
36
|
+
const client = useGchatClient(config);
|
|
37
|
+
|
|
38
|
+
return useQuery({
|
|
39
|
+
queryKey: ["greatchat", "inbox", config.accountId, id],
|
|
40
|
+
queryFn: () => client.getInbox(config.accountId, id!),
|
|
41
|
+
enabled: !!config.accountId && !!config.token && !!id,
|
|
42
|
+
select: (res) => {
|
|
43
|
+
const d = res.data;
|
|
44
|
+
return (Array.isArray(d) ? d[0] : d) as Inbox;
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function useInboxStats(
|
|
50
|
+
config: GchatHookConfig,
|
|
51
|
+
pollingInterval?: number,
|
|
52
|
+
) {
|
|
53
|
+
const client = useGchatClient(config);
|
|
54
|
+
|
|
55
|
+
return useQuery({
|
|
56
|
+
queryKey: ["greatchat", "inbox-stats", config.accountId],
|
|
57
|
+
queryFn: () => client.getInboxStats(config.accountId),
|
|
58
|
+
enabled: !!config.accountId && !!config.token,
|
|
59
|
+
refetchInterval: pollingInterval ?? DEFAULT_INBOX_POLLING,
|
|
60
|
+
select: (res) => {
|
|
61
|
+
const d = res.data;
|
|
62
|
+
return (Array.isArray(d) ? d[0] : d) as InboxStats;
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// Mutations
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
|
|
71
|
+
export function useCreateInbox(config: GchatHookConfig) {
|
|
72
|
+
const client = useGchatClient(config);
|
|
73
|
+
const queryClient = useQueryClient();
|
|
74
|
+
|
|
75
|
+
return useMutation({
|
|
76
|
+
mutationFn: (body: { id_channel: number; id_contact: number }) =>
|
|
77
|
+
client.createInbox(config.accountId, body),
|
|
78
|
+
onSuccess: () => {
|
|
79
|
+
queryClient.invalidateQueries({
|
|
80
|
+
queryKey: ["greatchat", "inboxes"],
|
|
81
|
+
});
|
|
82
|
+
queryClient.invalidateQueries({
|
|
83
|
+
queryKey: ["greatchat", "inbox-stats"],
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function useUpdateInbox(config: GchatHookConfig) {
|
|
90
|
+
const client = useGchatClient(config);
|
|
91
|
+
const queryClient = useQueryClient();
|
|
92
|
+
|
|
93
|
+
return useMutation({
|
|
94
|
+
mutationFn: ({
|
|
95
|
+
id,
|
|
96
|
+
body,
|
|
97
|
+
}: {
|
|
98
|
+
id: number;
|
|
99
|
+
body: Partial<Pick<Inbox, "status" | "id_agent">>;
|
|
100
|
+
}) => client.updateInbox(config.accountId, id, body),
|
|
101
|
+
onSuccess: () => {
|
|
102
|
+
queryClient.invalidateQueries({
|
|
103
|
+
queryKey: ["greatchat", "inboxes"],
|
|
104
|
+
});
|
|
105
|
+
queryClient.invalidateQueries({
|
|
106
|
+
queryKey: ["greatchat", "inbox-stats"],
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function useDeleteInbox(config: GchatHookConfig) {
|
|
113
|
+
const client = useGchatClient(config);
|
|
114
|
+
const queryClient = useQueryClient();
|
|
115
|
+
|
|
116
|
+
return useMutation({
|
|
117
|
+
mutationFn: (id: number) => client.deleteInbox(config.accountId, id),
|
|
118
|
+
onSuccess: () => {
|
|
119
|
+
queryClient.invalidateQueries({
|
|
120
|
+
queryKey: ["greatchat", "inboxes"],
|
|
121
|
+
});
|
|
122
|
+
queryClient.invalidateQueries({
|
|
123
|
+
queryKey: ["greatchat", "inbox-stats"],
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,27 @@ export type { GchatClientConfig } from "./client";
|
|
|
18
18
|
export { cn } from "./lib/utils";
|
|
19
19
|
export { groupMessagesByDate, formatDateGroup, formatMessageTime } from "./utils";
|
|
20
20
|
|
|
21
|
+
// Hooks
|
|
22
|
+
export * from "./hooks";
|
|
23
|
+
|
|
21
24
|
// Components
|
|
22
|
-
export {
|
|
23
|
-
|
|
25
|
+
export {
|
|
26
|
+
ChatView,
|
|
27
|
+
ChatInput,
|
|
28
|
+
MessageBubble,
|
|
29
|
+
ContactAvatar,
|
|
30
|
+
InboxItem,
|
|
31
|
+
InboxSidebar,
|
|
32
|
+
ContactInfoPanel,
|
|
33
|
+
NewConversationDialog,
|
|
34
|
+
} from "./components";
|
|
35
|
+
export type {
|
|
36
|
+
ChatViewProps,
|
|
37
|
+
ChatInputProps,
|
|
38
|
+
MessageBubbleProps,
|
|
39
|
+
ContactAvatarProps,
|
|
40
|
+
InboxItemProps,
|
|
41
|
+
InboxSidebarProps,
|
|
42
|
+
ContactInfoPanelProps,
|
|
43
|
+
NewConversationDialogProps,
|
|
44
|
+
} from "./components";
|