@developer_tribe/react-native-comnyx 0.3.15 → 0.4.1
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/lib/commonjs/Accumulator.js +100 -0
- package/lib/commonjs/Accumulator.js.map +1 -0
- package/lib/commonjs/App.js +6 -6
- package/lib/commonjs/App.js.map +1 -1
- package/lib/commonjs/api/customers.js +1 -0
- package/lib/commonjs/api/customers.js.map +1 -1
- package/lib/commonjs/collectData.js +27 -0
- package/lib/commonjs/collectData.js.map +1 -0
- package/lib/commonjs/components/ChatList.js +1 -1
- package/lib/commonjs/components/CustomerForm.js +28 -2
- package/lib/commonjs/components/CustomerForm.js.map +1 -1
- package/lib/commonjs/data/fake/customers.js +0 -1
- package/lib/commonjs/data/fake/customers.js.map +1 -1
- package/lib/commonjs/index.js +13 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/register.js +8 -0
- package/lib/commonjs/register.js.map +1 -1
- package/lib/commonjs/store.js +14 -5
- package/lib/commonjs/store.js.map +1 -1
- package/lib/module/Accumulator.js +96 -0
- package/lib/module/Accumulator.js.map +1 -0
- package/lib/module/App.js +6 -6
- package/lib/module/App.js.map +1 -1
- package/lib/module/api/customers.js +1 -0
- package/lib/module/api/customers.js.map +1 -1
- package/lib/module/collectData.js +22 -0
- package/lib/module/collectData.js.map +1 -0
- package/lib/module/components/ChatList.js +1 -1
- package/lib/module/components/CustomerForm.js +30 -4
- package/lib/module/components/CustomerForm.js.map +1 -1
- package/lib/module/data/fake/customers.js +0 -1
- package/lib/module/data/fake/customers.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/register.js +8 -0
- package/lib/module/register.js.map +1 -1
- package/lib/module/store.js +14 -5
- package/lib/module/store.js.map +1 -1
- package/lib/typescript/commonjs/src/Accumulator.d.ts +18 -0
- package/lib/typescript/commonjs/src/Accumulator.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/api/customers.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/collectData.d.ts +3 -0
- package/lib/typescript/commonjs/src/collectData.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/CustomerForm.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/data/fake/customers.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +1 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/register.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/store.d.ts +3 -1
- package/lib/typescript/commonjs/src/store.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/Customer.d.ts +17 -7
- package/lib/typescript/commonjs/src/types/Customer.d.ts.map +1 -1
- package/lib/typescript/module/src/Accumulator.d.ts +18 -0
- package/lib/typescript/module/src/Accumulator.d.ts.map +1 -0
- package/lib/typescript/module/src/api/customers.d.ts.map +1 -1
- package/lib/typescript/module/src/collectData.d.ts +3 -0
- package/lib/typescript/module/src/collectData.d.ts.map +1 -0
- package/lib/typescript/module/src/components/CustomerForm.d.ts.map +1 -1
- package/lib/typescript/module/src/data/fake/customers.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +1 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/register.d.ts.map +1 -1
- package/lib/typescript/module/src/store.d.ts +3 -1
- package/lib/typescript/module/src/store.d.ts.map +1 -1
- package/lib/typescript/module/src/types/Customer.d.ts +17 -7
- package/lib/typescript/module/src/types/Customer.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Accumulator.ts +111 -0
- package/src/App.tsx +5 -5
- package/src/api/customers.ts +1 -0
- package/src/collectData.ts +26 -0
- package/src/components/ChatList.tsx +1 -1
- package/src/components/CustomerForm.tsx +33 -3
- package/src/data/fake/customers.ts +6 -7
- package/src/index.tsx +4 -0
- package/src/register.ts +12 -0
- package/src/store.ts +13 -5
- package/src/types/Customer.ts +19 -7
|
@@ -18,7 +18,7 @@ interface AppStoreState {
|
|
|
18
18
|
init: ({ externalId }: {
|
|
19
19
|
externalId: string;
|
|
20
20
|
}) => void;
|
|
21
|
-
|
|
21
|
+
setCustomer: (createCustomerResponse: Customer) => void;
|
|
22
22
|
setLanguage: (language: LanguageCode) => void;
|
|
23
23
|
setTheme: (theme: 'light' | 'dark') => void;
|
|
24
24
|
setFake: (fake: boolean) => void;
|
|
@@ -27,6 +27,8 @@ interface AppStoreState {
|
|
|
27
27
|
baseHeight: number;
|
|
28
28
|
baseWidth: number;
|
|
29
29
|
}) => void;
|
|
30
|
+
formSubmitted: boolean;
|
|
31
|
+
setForm: (form: Customer) => void;
|
|
30
32
|
}
|
|
31
33
|
export declare const useAppStore: import("zustand/traditional").UseBoundStoreWithEqualityFn<Omit<import("zustand").StoreApi<AppStoreState>, "persist"> & {
|
|
32
34
|
persist: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../../src/store.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,UAAU,aAAa;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,sBAAsB,EAAE,GAAG,IAAI,CAAC;IACtC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,GAAG,CAAC;IACZ,YAAY,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC5C,OAAO,EAAE,CACP,EAAE,EAAE,CACF,QAAQ,EAAE,sBAAsB,EAAE,GAAG,IAAI,KACtC,sBAAsB,EAAE,GAAG,IAAI,KACjC,IAAI,CAAC;IACV,eAAe,EAAE,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI,KAAK,IAAI,CAAC;IAClE,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACvD,
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../../src/store.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,UAAU,aAAa;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,sBAAsB,EAAE,GAAG,IAAI,CAAC;IACtC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,GAAG,CAAC;IACZ,YAAY,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC5C,OAAO,EAAE,CACP,EAAE,EAAE,CACF,QAAQ,EAAE,sBAAsB,EAAE,GAAG,IAAI,KACtC,sBAAsB,EAAE,GAAG,IAAI,KACjC,IAAI,CAAC;IACV,eAAe,EAAE,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI,KAAK,IAAI,CAAC;IAClE,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACvD,WAAW,EAAE,CAAC,sBAAsB,EAAE,QAAQ,KAAK,IAAI,CAAC;IACxD,WAAW,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,CAAC;IAC9C,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,KAAK,IAAI,CAAC;IAC5C,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACjC,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACjC,oBAAoB,EAAE,CAAC,MAAM,EAAE;QAC7B,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;KACnB,KAAK,IAAI,CAAC;IACX,aAAa,EAAE,OAAO,CAAC;IACvB,OAAO,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;CACnC;AAgDD,eAAO,MAAM,WAAW;;;;;;;;;;EAqBvB,CAAC"}
|
|
@@ -2,21 +2,30 @@ export interface CustomParameter {
|
|
|
2
2
|
name: string;
|
|
3
3
|
value: string;
|
|
4
4
|
}
|
|
5
|
+
export interface OneSignalIntegrationParameters {
|
|
6
|
+
onesignal_id: string;
|
|
7
|
+
external_id: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IntegrationParameters {
|
|
10
|
+
onesignal?: OneSignalIntegrationParameters;
|
|
11
|
+
}
|
|
5
12
|
export interface CreateCustomerRequest {
|
|
6
|
-
name: string;
|
|
7
|
-
country: string;
|
|
8
|
-
language: string;
|
|
9
13
|
externalId: string;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
name?: string;
|
|
15
|
+
country?: string;
|
|
16
|
+
language?: string;
|
|
17
|
+
email?: string;
|
|
18
|
+
phone?: string;
|
|
19
|
+
ipAddress?: string;
|
|
13
20
|
customParameters?: CustomParameter[];
|
|
21
|
+
integrationParameters?: IntegrationParameters;
|
|
14
22
|
}
|
|
15
23
|
export interface Customer {
|
|
16
24
|
id: number;
|
|
17
25
|
project_id: number;
|
|
18
26
|
external_id: string;
|
|
19
27
|
name: string;
|
|
28
|
+
device: null | string;
|
|
20
29
|
country: string;
|
|
21
30
|
language: string;
|
|
22
31
|
email: string;
|
|
@@ -24,7 +33,8 @@ export interface Customer {
|
|
|
24
33
|
ip_address: string;
|
|
25
34
|
custom_parameters: string;
|
|
26
35
|
user_code: string;
|
|
27
|
-
updated_at: string;
|
|
28
36
|
created_at: string;
|
|
37
|
+
updated_at: string;
|
|
38
|
+
deleted_at: null | string;
|
|
29
39
|
}
|
|
30
40
|
//# sourceMappingURL=Customer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Customer.d.ts","sourceRoot":"","sources":["../../../../../src/types/Customer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAqB;IACpC,
|
|
1
|
+
{"version":3,"file":"Customer.d.ts","sourceRoot":"","sources":["../../../../../src/types/Customer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,8BAA8B;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,CAAC,EAAE,8BAA8B,CAAC;CAC5C;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;IACrC,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;CAC/C;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,IAAI,GAAG,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;CAC3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@developer_tribe/react-native-comnyx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "React Native chat component with integrated support panel, enabling real-time customer communication and efficient agent workflow management.",
|
|
5
5
|
"source": "./src/index.tsx",
|
|
6
6
|
"main": "./lib/commonjs/index.js",
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { CreateCustomerRequest } from './types/Customer';
|
|
2
|
+
|
|
3
|
+
const ACCUMULATOR_DEBOUNCE_TIME_IN_MS = 3000;
|
|
4
|
+
|
|
5
|
+
class Accumulator {
|
|
6
|
+
private registerData: CreateCustomerRequest | null = null;
|
|
7
|
+
private __select_time: NodeJS.Timeout | undefined = undefined;
|
|
8
|
+
private listener: ((data: CreateCustomerRequest) => Promise<void>) | null =
|
|
9
|
+
null;
|
|
10
|
+
private _isListenerCalledOnce: boolean = false;
|
|
11
|
+
constructor() {}
|
|
12
|
+
|
|
13
|
+
register(
|
|
14
|
+
externalId: string,
|
|
15
|
+
listener: (data: CreateCustomerRequest) => Promise<void>
|
|
16
|
+
) {
|
|
17
|
+
this.registerData = {
|
|
18
|
+
externalId,
|
|
19
|
+
customParameters: [],
|
|
20
|
+
integrationParameters: {},
|
|
21
|
+
};
|
|
22
|
+
this.listener = listener;
|
|
23
|
+
this.debounce();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
add(data: Partial<Omit<CreateCustomerRequest, 'externalId'>>) {
|
|
27
|
+
if (!this.registerData) {
|
|
28
|
+
throw new Error('Register data is not set');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// First, create a map of existing custom parameters by name
|
|
32
|
+
const customParamsMap = new Map<string, string>();
|
|
33
|
+
|
|
34
|
+
// Add existing parameters to the map
|
|
35
|
+
(this.registerData.customParameters || []).forEach((param) => {
|
|
36
|
+
customParamsMap.set(param.name, param.value);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Add or override with new parameters
|
|
40
|
+
(data.customParameters || []).forEach((param) => {
|
|
41
|
+
customParamsMap.set(param.name, param.value);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Convert map back to array of CustomParameter objects
|
|
45
|
+
const mergedCustomParameters = Array.from(customParamsMap.entries()).map(
|
|
46
|
+
([name, value]) => ({
|
|
47
|
+
name,
|
|
48
|
+
value,
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
this.registerData = {
|
|
53
|
+
...this.registerData,
|
|
54
|
+
...data,
|
|
55
|
+
integrationParameters: {
|
|
56
|
+
...(this.registerData.integrationParameters || {}),
|
|
57
|
+
...(data.integrationParameters || {}),
|
|
58
|
+
},
|
|
59
|
+
customParameters: mergedCustomParameters,
|
|
60
|
+
};
|
|
61
|
+
this.debounce();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async flush() {
|
|
65
|
+
if (!this.registerData) {
|
|
66
|
+
throw new Error('Register data is not set');
|
|
67
|
+
}
|
|
68
|
+
if (this.listener) {
|
|
69
|
+
await this.listener(this.registerData!);
|
|
70
|
+
this.registerData = {
|
|
71
|
+
...this.registerData,
|
|
72
|
+
customParameters: [],
|
|
73
|
+
};
|
|
74
|
+
this._isListenerCalledOnce = true;
|
|
75
|
+
}
|
|
76
|
+
this.reset();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
debounce() {
|
|
80
|
+
if (!this.registerData) {
|
|
81
|
+
throw new Error('Register data is not set');
|
|
82
|
+
}
|
|
83
|
+
this.reset();
|
|
84
|
+
this.__select_time = setTimeout(() => {
|
|
85
|
+
if (this.listener) {
|
|
86
|
+
this.listener(this.registerData!);
|
|
87
|
+
this.registerData = {
|
|
88
|
+
...this.registerData!,
|
|
89
|
+
customParameters: [],
|
|
90
|
+
};
|
|
91
|
+
this._isListenerCalledOnce = true;
|
|
92
|
+
}
|
|
93
|
+
}, ACCUMULATOR_DEBOUNCE_TIME_IN_MS);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
reset() {
|
|
97
|
+
if (this.__select_time) {
|
|
98
|
+
clearTimeout(this.__select_time);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get() {
|
|
103
|
+
return this.registerData;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
isListenerCalledOnce() {
|
|
107
|
+
return this._isListenerCalledOnce;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const accumulator = new Accumulator();
|
package/src/App.tsx
CHANGED
|
@@ -23,9 +23,9 @@ export function Comnyx({
|
|
|
23
23
|
onBack,
|
|
24
24
|
themes,
|
|
25
25
|
}: ComnyxProps) {
|
|
26
|
-
const {
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const { externalId, formSubmitted } = useAppStore((s) => ({
|
|
27
|
+
externalId: s.externalId,
|
|
28
|
+
formSubmitted: s.formSubmitted,
|
|
29
29
|
}));
|
|
30
30
|
const themeColors = useThemeColors();
|
|
31
31
|
usePolling();
|
|
@@ -38,7 +38,7 @@ export function Comnyx({
|
|
|
38
38
|
}
|
|
39
39
|
}, [language, theme, fake, themes]);
|
|
40
40
|
|
|
41
|
-
if (!
|
|
41
|
+
if (!externalId) {
|
|
42
42
|
return (
|
|
43
43
|
<View
|
|
44
44
|
style={[styles.container, { backgroundColor: themeColors.background }]}
|
|
@@ -46,7 +46,7 @@ export function Comnyx({
|
|
|
46
46
|
<AppText localization="app.initialization.required" />
|
|
47
47
|
</View>
|
|
48
48
|
);
|
|
49
|
-
} else if (!
|
|
49
|
+
} else if (!formSubmitted) {
|
|
50
50
|
return <CustomerForm onBack={onBack} />;
|
|
51
51
|
}
|
|
52
52
|
|
package/src/api/customers.ts
CHANGED
|
@@ -10,6 +10,7 @@ export function createCustomer(
|
|
|
10
10
|
if (options.fake) {
|
|
11
11
|
return Promise.resolve(getFakeCustomer(customerData));
|
|
12
12
|
}
|
|
13
|
+
console.info('[Comnyx] Adding customer info');
|
|
13
14
|
return axiosInstance
|
|
14
15
|
.post('/api/customers/create', customerData)
|
|
15
16
|
.then((res) => res.data);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { accumulator } from './Accumulator';
|
|
2
|
+
|
|
3
|
+
export function collectData(key: string, value: string) {
|
|
4
|
+
accumulator.add({
|
|
5
|
+
customParameters: [
|
|
6
|
+
{
|
|
7
|
+
name: key,
|
|
8
|
+
value,
|
|
9
|
+
},
|
|
10
|
+
],
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function registerOneSignalForComnyx(
|
|
15
|
+
onesignal_id: string,
|
|
16
|
+
external_id: string
|
|
17
|
+
) {
|
|
18
|
+
accumulator.add({
|
|
19
|
+
integrationParameters: {
|
|
20
|
+
onesignal: {
|
|
21
|
+
onesignal_id,
|
|
22
|
+
external_id,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
Image,
|
|
7
7
|
ScrollView,
|
|
8
8
|
StatusBar,
|
|
9
|
+
ActivityIndicator,
|
|
9
10
|
} from 'react-native';
|
|
10
11
|
import { useForm, Controller } from 'react-hook-form';
|
|
11
12
|
import { useAppStore } from '../store';
|
|
@@ -14,10 +15,11 @@ import { AppText } from './AppText';
|
|
|
14
15
|
import { useLocalize } from '../hooks/useLocalize';
|
|
15
16
|
import { useThemeColors } from '../hooks/useThemeColors';
|
|
16
17
|
import CustomPopup from './CustomAlert';
|
|
17
|
-
import { useState } from 'react';
|
|
18
|
+
import { useEffect, useState } from 'react';
|
|
18
19
|
import { ScaledSheet } from './ScaledSheet';
|
|
19
20
|
import type { LocalizationKeys } from '../types/LocalizationKeys';
|
|
20
21
|
import { activeOpacity } from '../constants/activeOpacity';
|
|
22
|
+
import { accumulator } from '../Accumulator';
|
|
21
23
|
|
|
22
24
|
interface CustomerFormData {
|
|
23
25
|
name: string;
|
|
@@ -40,6 +42,7 @@ export function CustomerForm({ onBack }: { onBack: () => void }) {
|
|
|
40
42
|
handleSubmit,
|
|
41
43
|
formState: { errors },
|
|
42
44
|
} = useForm<CustomerFormData>();
|
|
45
|
+
const [loading, setLoading] = useState(true);
|
|
43
46
|
const themeColors = useThemeColors();
|
|
44
47
|
const localize = useLocalize();
|
|
45
48
|
|
|
@@ -55,6 +58,16 @@ export function CustomerForm({ onBack }: { onBack: () => void }) {
|
|
|
55
58
|
description: 'null',
|
|
56
59
|
});
|
|
57
60
|
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (!accumulator.isListenerCalledOnce()) {
|
|
63
|
+
accumulator.flush().then(() => {
|
|
64
|
+
setTimeout(() => {
|
|
65
|
+
setLoading(false);
|
|
66
|
+
}, 100);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}, []);
|
|
70
|
+
|
|
58
71
|
const onSubmit = async (data: CustomerFormData) => {
|
|
59
72
|
try {
|
|
60
73
|
const customer = await createCustomer(
|
|
@@ -62,13 +75,12 @@ export function CustomerForm({ onBack }: { onBack: () => void }) {
|
|
|
62
75
|
...data,
|
|
63
76
|
language: 'en',
|
|
64
77
|
externalId: useAppStore.getState().externalId || '',
|
|
65
|
-
ipAddress: '192.168.1.1',
|
|
66
78
|
customParameters: [],
|
|
67
79
|
},
|
|
68
80
|
{ fake: useAppStore.getState().fake }
|
|
69
81
|
);
|
|
70
82
|
if (customer !== undefined) {
|
|
71
|
-
useAppStore.getState().
|
|
83
|
+
useAppStore.getState().setForm(customer);
|
|
72
84
|
}
|
|
73
85
|
} catch (error) {
|
|
74
86
|
console.error('Error creating customer:', error);
|
|
@@ -95,6 +107,19 @@ export function CustomerForm({ onBack }: { onBack: () => void }) {
|
|
|
95
107
|
);
|
|
96
108
|
};
|
|
97
109
|
|
|
110
|
+
if (loading) {
|
|
111
|
+
return (
|
|
112
|
+
<View
|
|
113
|
+
style={[
|
|
114
|
+
styles.loadingContainer,
|
|
115
|
+
{ backgroundColor: themeColors.background },
|
|
116
|
+
]}
|
|
117
|
+
>
|
|
118
|
+
<ActivityIndicator size="large" color={themeColors.light_text} />
|
|
119
|
+
</View>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
98
123
|
return (
|
|
99
124
|
<>
|
|
100
125
|
<StatusBar
|
|
@@ -401,4 +426,9 @@ const styles = ScaledSheet.create({
|
|
|
401
426
|
tintColor: 'red',
|
|
402
427
|
},
|
|
403
428
|
titleContainer: { marginHorizontal: '20@s', flex: 1 },
|
|
429
|
+
loadingContainer: {
|
|
430
|
+
flex: 1,
|
|
431
|
+
justifyContent: 'center',
|
|
432
|
+
alignItems: 'center',
|
|
433
|
+
},
|
|
404
434
|
});
|
|
@@ -5,15 +5,14 @@ export function getFakeCustomer(customerData: CreateCustomerRequest): Customer {
|
|
|
5
5
|
id: Math.floor(Math.random() * 1000),
|
|
6
6
|
project_id: 1,
|
|
7
7
|
external_id: customerData.externalId,
|
|
8
|
-
name: customerData.name
|
|
9
|
-
country: customerData.country
|
|
10
|
-
language: customerData.language
|
|
11
|
-
email: customerData.email
|
|
12
|
-
phone: customerData.phone
|
|
13
|
-
ip_address: customerData.ipAddress,
|
|
8
|
+
name: customerData.name!,
|
|
9
|
+
country: customerData.country!,
|
|
10
|
+
language: customerData.language!,
|
|
11
|
+
email: customerData.email!,
|
|
12
|
+
phone: customerData.phone!,
|
|
14
13
|
custom_parameters: JSON.stringify(customerData.customParameters || []),
|
|
15
14
|
user_code: Math.random().toString(36).substring(7),
|
|
16
15
|
updated_at: new Date().toISOString(),
|
|
17
16
|
created_at: new Date().toISOString(),
|
|
18
|
-
};
|
|
17
|
+
} as Customer;
|
|
19
18
|
}
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import './__dev__';
|
|
2
|
+
export {
|
|
3
|
+
collectData as collectDataForComnyx,
|
|
4
|
+
registerOneSignalForComnyx,
|
|
5
|
+
} from './collectData';
|
|
2
6
|
export { registerComnyx } from './register';
|
|
3
7
|
export type { CreateCustomerRequest } from './types/Customer';
|
|
4
8
|
export { Comnyx } from './App';
|
package/src/register.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { accumulator } from './Accumulator';
|
|
1
2
|
import { initApi } from './api/api';
|
|
2
3
|
import { useAppStore } from './store';
|
|
4
|
+
import { createCustomer } from './api/customers';
|
|
5
|
+
import type { CreateCustomerRequest } from './types/Customer';
|
|
3
6
|
|
|
4
7
|
export function registerComnyx(registerOptions: {
|
|
5
8
|
externalId: string;
|
|
@@ -14,4 +17,13 @@ export function registerComnyx(registerOptions: {
|
|
|
14
17
|
|
|
15
18
|
initApi(registerOptions.token);
|
|
16
19
|
useAppStore.getState().init({ externalId: registerOptions.externalId });
|
|
20
|
+
accumulator.register(
|
|
21
|
+
registerOptions.externalId,
|
|
22
|
+
async (accumulatedData: CreateCustomerRequest) => {
|
|
23
|
+
const customer = await createCustomer(accumulatedData, {
|
|
24
|
+
fake: false,
|
|
25
|
+
});
|
|
26
|
+
useAppStore.getState().setCustomer(customer);
|
|
27
|
+
}
|
|
28
|
+
);
|
|
17
29
|
}
|
package/src/store.ts
CHANGED
|
@@ -26,7 +26,7 @@ interface AppStoreState {
|
|
|
26
26
|
) => void;
|
|
27
27
|
setFirstMessage: (message: AppConversationMessage | null) => void;
|
|
28
28
|
init: ({ externalId }: { externalId: string }) => void;
|
|
29
|
-
|
|
29
|
+
setCustomer: (createCustomerResponse: Customer) => void;
|
|
30
30
|
setLanguage: (language: LanguageCode) => void;
|
|
31
31
|
setTheme: (theme: 'light' | 'dark') => void;
|
|
32
32
|
setFake: (fake: boolean) => void;
|
|
@@ -35,6 +35,8 @@ interface AppStoreState {
|
|
|
35
35
|
baseHeight: number;
|
|
36
36
|
baseWidth: number;
|
|
37
37
|
}) => void;
|
|
38
|
+
formSubmitted: boolean;
|
|
39
|
+
setForm: (form: Customer) => void;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
const storeCreator: StateCreator<AppStoreState> = (set, get) => ({
|
|
@@ -49,6 +51,7 @@ const storeCreator: StateCreator<AppStoreState> = (set, get) => ({
|
|
|
49
51
|
fake: false,
|
|
50
52
|
themes: {},
|
|
51
53
|
firstMessage: null,
|
|
54
|
+
formSubmitted: false,
|
|
52
55
|
setData: (cb) => {
|
|
53
56
|
const newData = cb(get().data);
|
|
54
57
|
set({ data: newData });
|
|
@@ -57,10 +60,10 @@ const storeCreator: StateCreator<AppStoreState> = (set, get) => ({
|
|
|
57
60
|
set({ firstMessage: message });
|
|
58
61
|
},
|
|
59
62
|
init: ({ externalId }: { externalId: string }) => {
|
|
60
|
-
set({ externalId: externalId
|
|
63
|
+
set({ externalId: externalId });
|
|
61
64
|
},
|
|
62
|
-
|
|
63
|
-
set({ customer: createCustomerResponse });
|
|
65
|
+
setCustomer: (createCustomerResponse: Customer) => {
|
|
66
|
+
set({ customer: createCustomerResponse, initialized: true });
|
|
64
67
|
},
|
|
65
68
|
setLanguage: (language: LanguageCode) => {
|
|
66
69
|
set({ language });
|
|
@@ -77,16 +80,21 @@ const storeCreator: StateCreator<AppStoreState> = (set, get) => ({
|
|
|
77
80
|
updateBaseDimensions: ({ baseWidth, baseHeight }) => {
|
|
78
81
|
set({ baseWidth, baseHeight });
|
|
79
82
|
},
|
|
83
|
+
setForm: (form: Customer) => {
|
|
84
|
+
set({ formSubmitted: true, customer: form });
|
|
85
|
+
},
|
|
80
86
|
});
|
|
81
87
|
|
|
82
88
|
export const useAppStore = createWithEqualityFn<AppStoreState>()(
|
|
83
89
|
persist(storeCreator, {
|
|
84
|
-
name: 'commonyx_appStore-
|
|
90
|
+
name: 'commonyx_appStore-12',
|
|
85
91
|
storage: createJSONStorage(() => AsyncStorage),
|
|
86
92
|
skipHydration: false,
|
|
87
93
|
partialize: (state) => ({
|
|
88
94
|
customer: state.customer,
|
|
89
95
|
externalId: state.externalId,
|
|
96
|
+
initialized: state.initialized,
|
|
97
|
+
formSubmitted: state.formSubmitted,
|
|
90
98
|
data: state.data
|
|
91
99
|
?.filter((message) => message.approved)
|
|
92
100
|
.map((message) => ({
|
package/src/types/Customer.ts
CHANGED
|
@@ -3,15 +3,25 @@ export interface CustomParameter {
|
|
|
3
3
|
value: string;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
export interface OneSignalIntegrationParameters {
|
|
7
|
+
onesignal_id: string;
|
|
8
|
+
external_id: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IntegrationParameters {
|
|
12
|
+
onesignal?: OneSignalIntegrationParameters;
|
|
13
|
+
}
|
|
14
|
+
|
|
6
15
|
export interface CreateCustomerRequest {
|
|
7
|
-
name: string;
|
|
8
|
-
country: string;
|
|
9
|
-
language: string;
|
|
10
16
|
externalId: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
name?: string;
|
|
18
|
+
country?: string;
|
|
19
|
+
language?: string;
|
|
20
|
+
email?: string;
|
|
21
|
+
phone?: string;
|
|
22
|
+
ipAddress?: string;
|
|
14
23
|
customParameters?: CustomParameter[];
|
|
24
|
+
integrationParameters?: IntegrationParameters;
|
|
15
25
|
}
|
|
16
26
|
|
|
17
27
|
export interface Customer {
|
|
@@ -19,6 +29,7 @@ export interface Customer {
|
|
|
19
29
|
project_id: number;
|
|
20
30
|
external_id: string;
|
|
21
31
|
name: string;
|
|
32
|
+
device: null | string;
|
|
22
33
|
country: string;
|
|
23
34
|
language: string;
|
|
24
35
|
email: string;
|
|
@@ -26,6 +37,7 @@ export interface Customer {
|
|
|
26
37
|
ip_address: string;
|
|
27
38
|
custom_parameters: string;
|
|
28
39
|
user_code: string;
|
|
29
|
-
updated_at: string;
|
|
30
40
|
created_at: string;
|
|
41
|
+
updated_at: string;
|
|
42
|
+
deleted_at: null | string;
|
|
31
43
|
}
|