@developer_tribe/react-native-comnyx 0.3.14 → 0.4.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 (87) hide show
  1. package/lib/commonjs/Accumulator.js +73 -0
  2. package/lib/commonjs/Accumulator.js.map +1 -0
  3. package/lib/commonjs/App.js +6 -6
  4. package/lib/commonjs/App.js.map +1 -1
  5. package/lib/commonjs/api/customers.js +1 -0
  6. package/lib/commonjs/api/customers.js.map +1 -1
  7. package/lib/commonjs/collectData.js +27 -0
  8. package/lib/commonjs/collectData.js.map +1 -0
  9. package/lib/commonjs/components/ChatList.js +5 -3
  10. package/lib/commonjs/components/ChatList.js.map +1 -1
  11. package/lib/commonjs/components/CustomerForm.js +29 -3
  12. package/lib/commonjs/components/CustomerForm.js.map +1 -1
  13. package/lib/commonjs/components/EmptyList.js +4 -1
  14. package/lib/commonjs/components/EmptyList.js.map +1 -1
  15. package/lib/commonjs/data/fake/customers.js +0 -1
  16. package/lib/commonjs/data/fake/customers.js.map +1 -1
  17. package/lib/commonjs/index.js +13 -0
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/register.js +8 -0
  20. package/lib/commonjs/register.js.map +1 -1
  21. package/lib/commonjs/store.js +14 -5
  22. package/lib/commonjs/store.js.map +1 -1
  23. package/lib/module/Accumulator.js +69 -0
  24. package/lib/module/Accumulator.js.map +1 -0
  25. package/lib/module/App.js +6 -6
  26. package/lib/module/App.js.map +1 -1
  27. package/lib/module/api/customers.js +1 -0
  28. package/lib/module/api/customers.js.map +1 -1
  29. package/lib/module/collectData.js +22 -0
  30. package/lib/module/collectData.js.map +1 -0
  31. package/lib/module/components/ChatList.js +5 -3
  32. package/lib/module/components/ChatList.js.map +1 -1
  33. package/lib/module/components/CustomerForm.js +31 -5
  34. package/lib/module/components/CustomerForm.js.map +1 -1
  35. package/lib/module/components/EmptyList.js +4 -1
  36. package/lib/module/components/EmptyList.js.map +1 -1
  37. package/lib/module/data/fake/customers.js +0 -1
  38. package/lib/module/data/fake/customers.js.map +1 -1
  39. package/lib/module/index.js +1 -0
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/module/register.js +8 -0
  42. package/lib/module/register.js.map +1 -1
  43. package/lib/module/store.js +14 -5
  44. package/lib/module/store.js.map +1 -1
  45. package/lib/typescript/commonjs/src/Accumulator.d.ts +18 -0
  46. package/lib/typescript/commonjs/src/Accumulator.d.ts.map +1 -0
  47. package/lib/typescript/commonjs/src/api/customers.d.ts.map +1 -1
  48. package/lib/typescript/commonjs/src/collectData.d.ts +3 -0
  49. package/lib/typescript/commonjs/src/collectData.d.ts.map +1 -0
  50. package/lib/typescript/commonjs/src/components/ChatList.d.ts.map +1 -1
  51. package/lib/typescript/commonjs/src/components/CustomerForm.d.ts.map +1 -1
  52. package/lib/typescript/commonjs/src/data/fake/customers.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/src/index.d.ts +1 -0
  54. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  55. package/lib/typescript/commonjs/src/register.d.ts.map +1 -1
  56. package/lib/typescript/commonjs/src/store.d.ts +3 -1
  57. package/lib/typescript/commonjs/src/store.d.ts.map +1 -1
  58. package/lib/typescript/commonjs/src/types/Customer.d.ts +17 -7
  59. package/lib/typescript/commonjs/src/types/Customer.d.ts.map +1 -1
  60. package/lib/typescript/module/src/Accumulator.d.ts +18 -0
  61. package/lib/typescript/module/src/Accumulator.d.ts.map +1 -0
  62. package/lib/typescript/module/src/api/customers.d.ts.map +1 -1
  63. package/lib/typescript/module/src/collectData.d.ts +3 -0
  64. package/lib/typescript/module/src/collectData.d.ts.map +1 -0
  65. package/lib/typescript/module/src/components/ChatList.d.ts.map +1 -1
  66. package/lib/typescript/module/src/components/CustomerForm.d.ts.map +1 -1
  67. package/lib/typescript/module/src/data/fake/customers.d.ts.map +1 -1
  68. package/lib/typescript/module/src/index.d.ts +1 -0
  69. package/lib/typescript/module/src/index.d.ts.map +1 -1
  70. package/lib/typescript/module/src/register.d.ts.map +1 -1
  71. package/lib/typescript/module/src/store.d.ts +3 -1
  72. package/lib/typescript/module/src/store.d.ts.map +1 -1
  73. package/lib/typescript/module/src/types/Customer.d.ts +17 -7
  74. package/lib/typescript/module/src/types/Customer.d.ts.map +1 -1
  75. package/package.json +1 -1
  76. package/src/Accumulator.ts +84 -0
  77. package/src/App.tsx +5 -5
  78. package/src/api/customers.ts +1 -0
  79. package/src/collectData.ts +26 -0
  80. package/src/components/ChatList.tsx +4 -2
  81. package/src/components/CustomerForm.tsx +34 -4
  82. package/src/components/EmptyList.tsx +1 -0
  83. package/src/data/fake/customers.ts +6 -7
  84. package/src/index.tsx +4 -0
  85. package/src/register.ts +12 -0
  86. package/src/store.ts +13 -5
  87. package/src/types/Customer.ts +19 -7
@@ -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().initForm(customer);
83
+ useAppStore.getState().setForm(customer);
72
84
  }
73
85
  } catch (error) {
74
86
  console.error('Error creating customer:', error);
@@ -95,10 +107,23 @@ 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
101
- barStyle={'dark-content'}
126
+ barStyle={'light-content'}
102
127
  backgroundColor={themeColors.dark_background}
103
128
  animated={false}
104
129
  translucent
@@ -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
  });
@@ -37,6 +37,7 @@ const styles = ScaledSheet.create({
37
37
  paddingHorizontal: '20@s',
38
38
  paddingVertical: '20@vs',
39
39
  gap: 15,
40
+ transform: [{ scaleY: -1 }],
40
41
  },
41
42
  title: {
42
43
  fontSize: '18@vs',
@@ -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
- initForm: (createCustomerResponse: Customer) => void;
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, initialized: true });
63
+ set({ externalId: externalId });
61
64
  },
62
- initForm: (createCustomerResponse: Customer) => {
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-10',
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) => ({
@@ -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
- email: string;
12
- phone: string;
13
- ipAddress: string;
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
  }