@tugitark/react-widget 1.2.0 → 1.3.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.
Files changed (2) hide show
  1. package/index.js +26 -34
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,50 +1,42 @@
1
1
  // Copyright (c) 2026, TugiTark. All rights reserved.
2
2
 
3
- import { useState } from 'react';
3
+ import { useState, useCallback } from 'react';
4
4
 
5
5
  import render from '@tugitark/declarative-widget';
6
6
 
7
- function Widget(props) {
7
+ function Widget({ onNotification, onReady, onOpened, onClosed, onError, ...props }) {
8
8
  // Is this the first time this component has been rendered ever?
9
9
  const [firstTime, setFirstTime] = useState(true);
10
+ const isFree = props.jwtFn == null && props.user == null;
10
11
 
11
- function onNotification(hasNotification) {
12
- if (props.jwtFn == null && props.user == null) {
13
- if (!firstTime) {
14
- // Replicate FAQ internal behaviour at a per-component level.
15
- return;
16
- }
12
+ const onNotification_ = useCallback((hasNotification) => {
13
+ if (isFree && !firstTime) {
14
+ // Replicate FAQ internal behaviour at a per-component level.
15
+ return;
17
16
  }
18
- (props.onNotification && props.onNotification(hasNotification);
19
- }
17
+ onNotification && onNotification(hasNotification);
18
+ }, [onNotification, firstTime, isFree]);
20
19
 
21
- function onReady() {
20
+ rest.onReady = useCallback(() => {
22
21
  if (firstTime) {
23
22
  setFirstTime(false);
24
- props.onReady && props.onReady(hasNotification);
23
+ onReady && onReady();
25
24
  }
26
- }
27
-
28
- function onOpened() {
29
- props.onOpened && props.onOpened();
30
- }
31
-
32
- function onClosed() {
33
- props.onClosed && props.onClosed();
34
- }
35
-
36
- function onError(e) {
37
- props.onError && props.onError(e);
38
- }
39
-
40
- render({
41
- ...props,
42
- onNotification,
43
- onReady,
44
- onOpened,
45
- onClosed,
46
- onError,
47
- });
25
+ }, [onReady, firstTime]);
26
+
27
+ rest.onOpened = useCallback(() => {
28
+ onOpened && onOpened();
29
+ }, [onOpened]);
30
+
31
+ rest.onClosed = useCallback(() => {
32
+ onClosed && onClosed();
33
+ }, [onClosed]);
34
+
35
+ rest.onError = useCallback((e) => {
36
+ onError && onError(e);
37
+ }, [onError]);
38
+
39
+ render(props);
48
40
 
49
41
  return null;
50
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tugitark/react-widget",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Wraps the tugitark widget in a React component.",
5
5
  "scripts": {
6
6
  "release": "npm publish --access public"