@addev-be/ui 0.8.1 → 0.8.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/package.json +2 -1
- package/src/providers/TrackingProvider/hooks.ts +14 -0
- package/src/providers/TrackingProvider/index.tsx +71 -0
- package/src/providers/UiProviders/index.tsx +4 -1
- package/src/providers/index.ts +2 -0
- package/src/services/index.ts +2 -0
- package/src/services/requests/tracking.ts +12 -0
- package/src/services/types/tracking.ts +39 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@addev-be/ui",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"watch": "tsc -b --watch",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"io-ts": "^2.2.21",
|
|
52
52
|
"lodash": "^4.17.21",
|
|
53
53
|
"moment": "^2.30.1",
|
|
54
|
+
"react-router-dom": "^7.0.2",
|
|
54
55
|
"rxjs": "^7.8.1",
|
|
55
56
|
"uuid": "^10.0.0"
|
|
56
57
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useContext, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import { TrackingContext } from '.';
|
|
4
|
+
import { useLocation } from 'react-router-dom';
|
|
5
|
+
|
|
6
|
+
export const useLocationTracking = () => {
|
|
7
|
+
const { sendEvent } = useContext(TrackingContext);
|
|
8
|
+
const { pathname, search } = useLocation();
|
|
9
|
+
const pathWithSearch = `${pathname}${search}`;
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
sendEvent('PageView', { path: pathWithSearch });
|
|
13
|
+
}, [pathWithSearch, sendEvent]);
|
|
14
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FC,
|
|
3
|
+
PropsWithChildren,
|
|
4
|
+
createContext,
|
|
5
|
+
useCallback,
|
|
6
|
+
useMemo,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react';
|
|
9
|
+
|
|
10
|
+
import { useSendTrackingEventRequestHandler } from '../../services';
|
|
11
|
+
|
|
12
|
+
export type TrackingContextType = {
|
|
13
|
+
sendEvent: (
|
|
14
|
+
name: string,
|
|
15
|
+
details?: Record<string, string | number | boolean | null>
|
|
16
|
+
) => void;
|
|
17
|
+
enableTracking: () => void;
|
|
18
|
+
disableTracking: () => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const TrackingContext = createContext<TrackingContextType>({
|
|
22
|
+
sendEvent: () => {},
|
|
23
|
+
enableTracking: () => {},
|
|
24
|
+
disableTracking: () => {},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const TrackingProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
28
|
+
const [trackingEnabled, setTrackingEnabled] = useState(true);
|
|
29
|
+
const sendTrackingEvent = useSendTrackingEventRequestHandler();
|
|
30
|
+
|
|
31
|
+
const sendEvent = useCallback(
|
|
32
|
+
(
|
|
33
|
+
name: string,
|
|
34
|
+
details: Record<string, string | number | boolean | null> = {}
|
|
35
|
+
) => {
|
|
36
|
+
if (trackingEnabled) {
|
|
37
|
+
sendTrackingEvent({
|
|
38
|
+
data: {
|
|
39
|
+
id: '',
|
|
40
|
+
name,
|
|
41
|
+
details,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
[sendTrackingEvent, trackingEnabled]
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const enableTracking = useCallback(() => {
|
|
50
|
+
setTrackingEnabled(true);
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
53
|
+
const disableTracking = useCallback(() => {
|
|
54
|
+
setTrackingEnabled(false);
|
|
55
|
+
}, []);
|
|
56
|
+
|
|
57
|
+
const value = useMemo(
|
|
58
|
+
() => ({
|
|
59
|
+
sendEvent,
|
|
60
|
+
enableTracking,
|
|
61
|
+
disableTracking,
|
|
62
|
+
}),
|
|
63
|
+
[disableTracking, enableTracking, sendEvent]
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<TrackingContext.Provider value={value}>
|
|
68
|
+
{children}
|
|
69
|
+
</TrackingContext.Provider>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import { PortalsProvider } from '../PortalsProvider';
|
|
16
16
|
import { SettingsProvider } from '../SettingsProvider';
|
|
17
17
|
import { ThemeProvider } from '../ThemeProvider/ThemeProvider';
|
|
18
|
+
import { TrackingProvider } from '../TrackingProvider';
|
|
18
19
|
import { defaultTheme } from '../ThemeProvider/defaultTheme';
|
|
19
20
|
|
|
20
21
|
export type UiProvidersProps = PropsWithChildren<{
|
|
@@ -56,7 +57,9 @@ export const UiProviders: FC<UiProvidersProps> = ({ $darkMode, children }) => {
|
|
|
56
57
|
<UiContext.Provider value={value}>
|
|
57
58
|
<styles.Root ref={rootRef}>
|
|
58
59
|
<SettingsProvider>
|
|
59
|
-
<
|
|
60
|
+
<TrackingProvider>
|
|
61
|
+
<PortalsProvider>{children}</PortalsProvider>
|
|
62
|
+
</TrackingProvider>
|
|
60
63
|
</SettingsProvider>
|
|
61
64
|
</styles.Root>
|
|
62
65
|
</UiContext.Provider>
|
package/src/providers/index.ts
CHANGED
package/src/services/index.ts
CHANGED
|
@@ -4,10 +4,12 @@ export * from './hooks';
|
|
|
4
4
|
export * from './globalSearch';
|
|
5
5
|
|
|
6
6
|
export * from './requests/auth';
|
|
7
|
+
export * from './requests/tracking';
|
|
7
8
|
export * from './requests/users';
|
|
8
9
|
export * from './requests/userProfiles';
|
|
9
10
|
|
|
10
11
|
export * from './types/auth';
|
|
11
12
|
export * from './types/base';
|
|
13
|
+
export * from './types/tracking';
|
|
12
14
|
export * from './types/users';
|
|
13
15
|
export * from './types/userProfiles';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SendTrackingEventRequestDTO,
|
|
3
|
+
SendTrackingEventResponseDTO,
|
|
4
|
+
} from '../types/tracking';
|
|
5
|
+
|
|
6
|
+
import { useLoadingRequestHandler } from '../hooks';
|
|
7
|
+
|
|
8
|
+
export const useSendTrackingEventRequestHandler = () =>
|
|
9
|
+
useLoadingRequestHandler<
|
|
10
|
+
SendTrackingEventRequestDTO,
|
|
11
|
+
SendTrackingEventResponseDTO
|
|
12
|
+
>('SendTrackingEvent');
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as t from 'io-ts';
|
|
2
|
+
|
|
3
|
+
import { baseModelDtoCodec } from './base';
|
|
4
|
+
|
|
5
|
+
export const trackingEventDtoCodec = t.type(
|
|
6
|
+
{
|
|
7
|
+
...baseModelDtoCodec.props,
|
|
8
|
+
name: t.string,
|
|
9
|
+
details: t.record(
|
|
10
|
+
t.string,
|
|
11
|
+
t.union([t.string, t.number, t.boolean, t.null])
|
|
12
|
+
),
|
|
13
|
+
},
|
|
14
|
+
'TrackingEventDTO'
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export type TrackingEventDTO = t.TypeOf<typeof trackingEventDtoCodec>;
|
|
18
|
+
|
|
19
|
+
export const sendTrackingEventRequestDtoCodec = t.type(
|
|
20
|
+
{
|
|
21
|
+
data: trackingEventDtoCodec,
|
|
22
|
+
},
|
|
23
|
+
'SendTrackingEventRequestDTO'
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export const sendTrackingEventResponseDtoCodec = t.type(
|
|
27
|
+
{
|
|
28
|
+
status: t.number,
|
|
29
|
+
data: trackingEventDtoCodec,
|
|
30
|
+
},
|
|
31
|
+
'SendTrackingEventResponseDTO'
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export type SendTrackingEventRequestDTO = t.TypeOf<
|
|
35
|
+
typeof sendTrackingEventRequestDtoCodec
|
|
36
|
+
>;
|
|
37
|
+
export type SendTrackingEventResponseDTO = t.TypeOf<
|
|
38
|
+
typeof sendTrackingEventResponseDtoCodec
|
|
39
|
+
>;
|