Skip to content

Commit

Permalink
chat-headless-react: Support clients param #52
Browse files Browse the repository at this point in the history
bump headless version for this feature: #51
update ChatHeadlessProvider to accepts `clients` param as a passthrough to headless

J=CLIP-1328
TEST=manual

tested through test-site with chat-core-aws-connect as agent client
  • Loading branch information
yen-tt authored Jul 5, 2024
1 parent 92615d3 commit eee6257
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
14 changes: 2 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/chat-headless-react/THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The following npm packages may be included in this product:

- @yext/[email protected].0
- @yext/chat-headless@0.9.0
- @yext/[email protected].2
- @yext/chat-headless@0.10.0

These packages each contain the following license and notice below:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ Props for [ChatHeadlessProvider()](./chat-headless-react.chatheadlessprovider.md
```typescript
export type ChatHeadlessProviderProps = PropsWithChildren<{
config: HeadlessConfig;
clients?: {
bot?: ChatClient;
agent?: ChatClient;
};
}>;
```
5 changes: 5 additions & 0 deletions packages/chat-headless-react/etc/chat-headless-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/// <reference types="react" />

import { ChatClient } from '@yext/chat-headless';
import { ChatHeadless } from '@yext/chat-headless';
import { Context } from 'react';
import { HeadlessConfig } from '@yext/chat-headless';
Expand Down Expand Up @@ -34,6 +35,10 @@ export function ChatHeadlessProvider(props: ChatHeadlessProviderProps): JSX.Elem
// @public
export type ChatHeadlessProviderProps = PropsWithChildren<{
config: HeadlessConfig;
clients?: {
bot?: ChatClient;
agent?: ChatClient;
};
}>;

// @public
Expand Down
4 changes: 2 additions & 2 deletions packages/chat-headless-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yext/chat-headless-react",
"version": "0.8.0",
"version": "0.9.0",
"description": "the official React UI Bindings layer for Chat Headless",
"main": "./dist/commonjs/src/index.js",
"module": "./dist/esm/src/index.mjs",
Expand Down Expand Up @@ -39,7 +39,7 @@
"homepage": "https://github.com/yext/chat-headless#readme",
"dependencies": {
"@reduxjs/toolkit": "^1.9.5",
"@yext/chat-headless": "^0.9.0",
"@yext/chat-headless": "^0.10.0",
"react-redux": "^8.0.5"
},
"peerDependencies": {
Expand Down
15 changes: 12 additions & 3 deletions packages/chat-headless-react/src/ChatHeadlessProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
provideChatHeadless,
ChatHeadless,
HeadlessConfig,
ChatClient,
} from "@yext/chat-headless";
import React, { PropsWithChildren, useMemo, useEffect, useState } from "react";
import { Provider } from "react-redux";
Expand All @@ -15,6 +16,13 @@ import { updateClientSdk } from "./utils/clientSdk";
*/
export type ChatHeadlessProviderProps = PropsWithChildren<{
config: HeadlessConfig;
/**
* Optional clients to provide to the ChatHeadless instance.
*/
clients?: {
bot?: ChatClient;
agent?: ChatClient;
};
}>;

/**
Expand All @@ -28,15 +36,16 @@ export type ChatHeadlessProviderProps = PropsWithChildren<{
export function ChatHeadlessProvider(
props: ChatHeadlessProviderProps
): JSX.Element {
const { children, config } = props;
const { children, config, clients } = props;

const headless = useMemo(() => {
const configWithoutLocalStorage = { ...config, saveToLocalStorage: false };
const headless = provideChatHeadless(
updateClientSdk(configWithoutLocalStorage)
updateClientSdk(configWithoutLocalStorage),
clients
);
return headless;
}, [config]);
}, [config, clients]);

return (
<ChatHeadlessInstanceProvider
Expand Down

0 comments on commit eee6257

Please sign in to comment.