@tugitark/react-widget 1.2.1 → 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.
- package/index.js +26 -34
- 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
|
-
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
19
|
-
}
|
|
17
|
+
onNotification && onNotification(hasNotification);
|
|
18
|
+
}, [onNotification, firstTime, isFree]);
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
rest.onReady = useCallback(() => {
|
|
22
21
|
if (firstTime) {
|
|
23
22
|
setFirstTime(false);
|
|
24
|
-
|
|
23
|
+
onReady && onReady();
|
|
25
24
|
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
}
|