@zean-chat/react 0.1.0 → 0.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/README.md +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -11
- package/dist/interfaces.d.ts +2 -5
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -10,13 +10,13 @@ npm install @zean-chat/react
|
|
|
10
10
|
import { ZeanChat, useZean } from "@zean-chat/react";
|
|
11
11
|
|
|
12
12
|
// Once, in the root layout or root route.
|
|
13
|
-
<ZeanChat appKey="app_your_app_key"
|
|
13
|
+
<ZeanChat appKey="app_your_app_key" user={user ? { id: user.id, name: user.name, email: user.email } : undefined} attributes={{ plan: "pro" }} />;
|
|
14
14
|
|
|
15
15
|
// Anywhere.
|
|
16
16
|
const { open, close, toggle, unreadCount, identify, signOut, setAttributes } = useZean();
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Passing `user` signs the person in; `undefined` signs them out. Full guide: [install the chat in React and Next.js](https://zean.chat/docs/install-react), [React reference](https://zean.chat/docs/reference-react).
|
|
20
20
|
|
|
21
21
|
## Why Zean
|
|
22
22
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ZeanChatProps, ZeanControls } from './interfaces.js';
|
|
2
|
-
export type { ZeanAttributes, ZeanLocale,
|
|
2
|
+
export type { ZeanAttributes, ZeanLocale, ZeanUser } from '@zean-chat/js';
|
|
3
3
|
export type { ZeanChatProps, ZeanControls } from './interfaces.js';
|
|
4
4
|
/**
|
|
5
5
|
* Shows the chat. Render it once, near the root, on every page. It renders nothing itself: the chat sits in its own
|
|
6
6
|
* frame, and stays across page changes.
|
|
7
7
|
*/
|
|
8
|
-
export declare function ZeanChat({ appKey,
|
|
8
|
+
export declare function ZeanChat({ appKey, user, attributes, locale, loaderUrl }: ZeanChatProps): null;
|
|
9
9
|
/** Opens and closes the chat, and follows the unread count. Works in any component, before the chat has loaded. */
|
|
10
10
|
export declare function useZean(): ZeanControls;
|
package/dist/index.js
CHANGED
|
@@ -3,23 +3,18 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
5
5
|
import { loadZean, zean } from "@zean-chat/js";
|
|
6
|
-
function ZeanChat({ appKey,
|
|
7
|
-
const
|
|
8
|
-
const tokenSource = useRef(() => latestToken.current?.() ?? Promise.resolve(null));
|
|
6
|
+
function ZeanChat({ appKey, user, attributes, locale, loaderUrl }) {
|
|
7
|
+
const userKey = user ? JSON.stringify(user) : null;
|
|
9
8
|
const identified = useRef(false);
|
|
10
|
-
const signedIn = Boolean(getToken);
|
|
11
9
|
const attributesKey = attributes ? JSON.stringify(attributes) : null;
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
latestToken.current = getToken;
|
|
14
|
-
});
|
|
15
10
|
useEffect(() => {
|
|
16
11
|
loadZean({ appKey, locale, loaderUrl });
|
|
17
12
|
}, [appKey, locale, loaderUrl]);
|
|
18
13
|
useEffect(() => {
|
|
19
|
-
if (
|
|
20
|
-
else if (
|
|
21
|
-
identified.current =
|
|
22
|
-
}, [
|
|
14
|
+
if (userKey) zean.identify(JSON.parse(userKey));
|
|
15
|
+
else if (identified.current) zean.signOut();
|
|
16
|
+
identified.current = userKey !== null;
|
|
17
|
+
}, [userKey]);
|
|
23
18
|
useEffect(() => {
|
|
24
19
|
if (attributesKey) zean.setAttributes(JSON.parse(attributesKey));
|
|
25
20
|
}, [attributesKey]);
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import type { ZeanApi, ZeanAttributes, ZeanOptions } from '@zean-chat/js';
|
|
2
2
|
export interface ZeanChatProps extends ZeanOptions {
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
* leave it out once in between.
|
|
6
|
-
*/
|
|
7
|
-
getToken?: ZeanOptions['getToken'];
|
|
3
|
+
/** The person signed in to your app: `{ id, name, email }`. Leave it out when no one is: the chat signs out. */
|
|
4
|
+
user?: ZeanOptions['user'];
|
|
8
5
|
/** What the page knows about the person, shown on the Contact's profile. */
|
|
9
6
|
attributes?: ZeanAttributes;
|
|
10
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zean-chat/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Live chat widget for React and Next.js: add a free customer support chat to your app with one component and a hook. Intercom and Crisp alternative.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"type": "module",
|
|
37
37
|
"sideEffects": false,
|
|
38
|
+
"main": "./dist/index.js",
|
|
39
|
+
"module": "./dist/index.js",
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
38
41
|
"exports": {
|
|
39
42
|
".": {
|
|
40
43
|
"zean-source": "./src/index.ts",
|
|
@@ -54,7 +57,7 @@
|
|
|
54
57
|
"check-types": "tsc --noEmit"
|
|
55
58
|
},
|
|
56
59
|
"dependencies": {
|
|
57
|
-
"@zean-chat/js": "^0.1.
|
|
60
|
+
"@zean-chat/js": "^0.1.1"
|
|
58
61
|
},
|
|
59
62
|
"peerDependencies": {
|
|
60
63
|
"react": ">=18"
|