@automattic/jetpack-components 0.39.0 → 0.40.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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
### This is a list detailing changes for the Jetpack RNA Components package releases.
|
|
4
4
|
|
|
5
|
+
## [0.40.0] - 2023-06-26
|
|
6
|
+
### Added
|
|
7
|
+
- Add authentication to Zendesk chat. [#31339]
|
|
8
|
+
|
|
5
9
|
## [0.39.0] - 2023-06-23
|
|
6
10
|
### Added
|
|
7
11
|
- Add component Pricing Slider for Stat pricing page.
|
|
@@ -744,4 +748,5 @@
|
|
|
744
748
|
### Changed
|
|
745
749
|
- Update node version requirement to 14.16.1
|
|
746
750
|
|
|
751
|
+
[0.40.0]: https://github.com/Automattic/jetpack-components/compare/0.39.0...0.40.0
|
|
747
752
|
[0.39.0]: https://github.com/Automattic/jetpack-components/compare/0.38.1...0.39.0
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { useEffect, useCallback } from 'react';
|
|
2
2
|
import { chatKey } from './constants';
|
|
3
3
|
import type { ZendeskChatType } from './types';
|
|
4
4
|
|
|
5
|
-
export const ZendeskChat: ZendeskChatType = () => {
|
|
5
|
+
export const ZendeskChat: ZendeskChatType = ( { jwt_token } ) => {
|
|
6
|
+
const authenticateUser = useCallback( () => {
|
|
7
|
+
if ( typeof window !== 'undefined' && typeof window.zE === 'function' ) {
|
|
8
|
+
window.zE( 'messenger', 'loginUser', function ( callback ) {
|
|
9
|
+
callback( jwt_token );
|
|
10
|
+
} );
|
|
11
|
+
}
|
|
12
|
+
}, [ jwt_token ] );
|
|
13
|
+
|
|
6
14
|
useEffect( () => {
|
|
7
15
|
const script = document.createElement( 'script' );
|
|
8
16
|
const container = document.getElementById( 'zendesk-chat-container' );
|
|
@@ -11,10 +19,14 @@ export const ZendeskChat: ZendeskChatType = () => {
|
|
|
11
19
|
script.type = 'text/javascript';
|
|
12
20
|
script.id = 'ze-snippet';
|
|
13
21
|
|
|
22
|
+
script.onload = () => {
|
|
23
|
+
authenticateUser();
|
|
24
|
+
};
|
|
25
|
+
|
|
14
26
|
if ( container ) {
|
|
15
27
|
container.appendChild( script );
|
|
16
28
|
}
|
|
17
|
-
}, [] );
|
|
29
|
+
}, [ authenticateUser ] );
|
|
18
30
|
|
|
19
31
|
return <div data-testid="zendesk-chat-container" id="zendesk-chat-container" />;
|
|
20
32
|
};
|
|
@@ -9,7 +9,7 @@ describe( 'ZendeskChat', () => {
|
|
|
9
9
|
} );
|
|
10
10
|
|
|
11
11
|
it( 'renders the zendesk chat widget', () => {
|
|
12
|
-
render( <ZendeskChat /> );
|
|
12
|
+
render( <ZendeskChat jwt_token="exampletoken" /> );
|
|
13
13
|
|
|
14
14
|
expect( screen.getByTestId( 'zendesk-chat-container' ) ).toBeInTheDocument();
|
|
15
15
|
} );
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import type { FC } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
6
|
+
zE: Function;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ZendeskChatProps {
|
|
11
|
+
jwt_token: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ZendeskChatType = FC< ZendeskChatProps >;
|