@developer_tribe/react-native-comnyx 0.4.4 → 0.4.6

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 (80) hide show
  1. package/lib/commonjs/App.js +13 -3
  2. package/lib/commonjs/App.js.map +1 -1
  3. package/lib/commonjs/api/api.js +2 -1
  4. package/lib/commonjs/api/api.js.map +1 -1
  5. package/lib/commonjs/api/customers.js +3 -1
  6. package/lib/commonjs/api/customers.js.map +1 -1
  7. package/lib/commonjs/components/ChatList.js +12 -12
  8. package/lib/commonjs/components/ChatList.js.map +1 -1
  9. package/lib/commonjs/components/CustomerForm.js +8 -4
  10. package/lib/commonjs/components/CustomerForm.js.map +1 -1
  11. package/lib/commonjs/components/MessageInput.js +1 -2
  12. package/lib/commonjs/components/MessageInput.js.map +1 -1
  13. package/lib/commonjs/constants/translations.js +10 -0
  14. package/lib/commonjs/constants/translations.js.map +1 -1
  15. package/lib/commonjs/hooks/usePolling.js +5 -5
  16. package/lib/commonjs/hooks/usePolling.js.map +1 -1
  17. package/lib/commonjs/register.js +4 -7
  18. package/lib/commonjs/register.js.map +1 -1
  19. package/lib/commonjs/store.js +1 -11
  20. package/lib/commonjs/store.js.map +1 -1
  21. package/lib/module/App.js +13 -3
  22. package/lib/module/App.js.map +1 -1
  23. package/lib/module/api/api.js +2 -1
  24. package/lib/module/api/api.js.map +1 -1
  25. package/lib/module/api/customers.js +3 -1
  26. package/lib/module/api/customers.js.map +1 -1
  27. package/lib/module/components/ChatList.js +12 -12
  28. package/lib/module/components/ChatList.js.map +1 -1
  29. package/lib/module/components/CustomerForm.js +8 -4
  30. package/lib/module/components/CustomerForm.js.map +1 -1
  31. package/lib/module/components/MessageInput.js +1 -2
  32. package/lib/module/components/MessageInput.js.map +1 -1
  33. package/lib/module/constants/translations.js +10 -0
  34. package/lib/module/constants/translations.js.map +1 -1
  35. package/lib/module/hooks/usePolling.js +5 -5
  36. package/lib/module/hooks/usePolling.js.map +1 -1
  37. package/lib/module/register.js +4 -7
  38. package/lib/module/register.js.map +1 -1
  39. package/lib/module/store.js +1 -11
  40. package/lib/module/store.js.map +1 -1
  41. package/lib/typescript/commonjs/src/App.d.ts.map +1 -1
  42. package/lib/typescript/commonjs/src/api/api.d.ts +1 -1
  43. package/lib/typescript/commonjs/src/api/api.d.ts.map +1 -1
  44. package/lib/typescript/commonjs/src/api/customers.d.ts +3 -1
  45. package/lib/typescript/commonjs/src/api/customers.d.ts.map +1 -1
  46. package/lib/typescript/commonjs/src/components/ChatList.d.ts.map +1 -1
  47. package/lib/typescript/commonjs/src/components/CustomerForm.d.ts.map +1 -1
  48. package/lib/typescript/commonjs/src/components/MessageInput.d.ts.map +1 -1
  49. package/lib/typescript/commonjs/src/constants/translations.d.ts.map +1 -1
  50. package/lib/typescript/commonjs/src/register.d.ts.map +1 -1
  51. package/lib/typescript/commonjs/src/store.d.ts +0 -5
  52. package/lib/typescript/commonjs/src/store.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/src/types/LocalizationKeys.d.ts +1 -0
  54. package/lib/typescript/commonjs/src/types/LocalizationKeys.d.ts.map +1 -1
  55. package/lib/typescript/module/src/App.d.ts.map +1 -1
  56. package/lib/typescript/module/src/api/api.d.ts +1 -1
  57. package/lib/typescript/module/src/api/api.d.ts.map +1 -1
  58. package/lib/typescript/module/src/api/customers.d.ts +3 -1
  59. package/lib/typescript/module/src/api/customers.d.ts.map +1 -1
  60. package/lib/typescript/module/src/components/ChatList.d.ts.map +1 -1
  61. package/lib/typescript/module/src/components/CustomerForm.d.ts.map +1 -1
  62. package/lib/typescript/module/src/components/MessageInput.d.ts.map +1 -1
  63. package/lib/typescript/module/src/constants/translations.d.ts.map +1 -1
  64. package/lib/typescript/module/src/register.d.ts.map +1 -1
  65. package/lib/typescript/module/src/store.d.ts +0 -5
  66. package/lib/typescript/module/src/store.d.ts.map +1 -1
  67. package/lib/typescript/module/src/types/LocalizationKeys.d.ts +1 -0
  68. package/lib/typescript/module/src/types/LocalizationKeys.d.ts.map +1 -1
  69. package/package.json +1 -1
  70. package/src/App.tsx +13 -4
  71. package/src/api/api.ts +2 -1
  72. package/src/api/customers.ts +2 -2
  73. package/src/components/ChatList.tsx +20 -15
  74. package/src/components/CustomerForm.tsx +8 -4
  75. package/src/components/MessageInput.tsx +1 -2
  76. package/src/constants/translations.ts +10 -0
  77. package/src/hooks/usePolling.ts +5 -5
  78. package/src/register.ts +4 -5
  79. package/src/store.ts +4 -10
  80. package/src/types/LocalizationKeys.ts +1 -0
@@ -47,10 +47,10 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
47
47
  (windowHeight - FLATLIST_PADDING) / MESSAGE_MIN_HEIGHT
48
48
  );
49
49
  const [loading, setLoading] = useState(true);
50
- const { data, setData, externalId } = useAppStore((s) => ({
50
+ const { data, setData, customer } = useAppStore((s) => ({
51
51
  data: s.data,
52
52
  setData: s.setData,
53
- externalId: s.externalId,
53
+ customer: s.customer,
54
54
  }));
55
55
  const ref = useRef<SectionList<AppConversationMessage>>(null);
56
56
  const [page, setPage] = useState(1);
@@ -131,7 +131,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
131
131
  }, [data]);
132
132
 
133
133
  const resendMessage = useCallback(() => {
134
- if (selectedMessage && externalId) {
134
+ if (selectedMessage && customer?.external_id) {
135
135
  const currentMessage = useAppStore.getState().data || [];
136
136
  const messageIndex = currentMessage.findIndex(
137
137
  (msg) => msg.content === selectedMessage
@@ -155,7 +155,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
155
155
  data: updatedValue,
156
156
  });
157
157
 
158
- sendCustomerMessage(externalId, selectedMessage, {
158
+ sendCustomerMessage(customer.external_id, selectedMessage, {
159
159
  fake: useAppStore.getState().fake,
160
160
  })
161
161
  .then((res: any) => {
@@ -214,21 +214,26 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
214
214
  });
215
215
  }
216
216
  }
217
- }, [selectedMessage, externalId]);
217
+ }, [selectedMessage, customer]);
218
218
 
219
219
  const nextPage = useCallback(() => {
220
220
  if (nextPageStatus.current) {
221
221
  return;
222
222
  }
223
223
  nextPageStatus.current = 'loading';
224
- if (externalId) {
224
+ if (customer?.external_id) {
225
225
  const newPage = page + 1;
226
226
  setPage(newPage);
227
227
  const firstMessage = useAppStore.getState().firstMessage;
228
- getCustomerConversation(externalId, firstMessage?.created_at, newPage, {
229
- fake: useAppStore.getState().fake,
230
- per_page: MESSAGES_PER_PAGE,
231
- })
228
+ getCustomerConversation(
229
+ customer.external_id,
230
+ firstMessage?.created_at,
231
+ newPage,
232
+ {
233
+ fake: useAppStore.getState().fake,
234
+ per_page: MESSAGES_PER_PAGE,
235
+ }
236
+ )
232
237
  .then((newData) => {
233
238
  listChangedRef.current = true;
234
239
  setData((prevData) => {
@@ -277,7 +282,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
277
282
  setLoading(false);
278
283
  });
279
284
  }
280
- }, [MESSAGES_PER_PAGE, externalId, page, setData]);
285
+ }, [MESSAGES_PER_PAGE, customer, page, setData]);
281
286
 
282
287
  const renderItem = useCallback(
283
288
  ({ item }: { item: AppConversationMessage }) => {
@@ -412,8 +417,8 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
412
417
  );
413
418
 
414
419
  useEffect(() => {
415
- if (externalId && !initFailed) {
416
- getCustomerConversation(externalId, new Date(), 1, {
420
+ if (customer?.external_id && !initFailed) {
421
+ getCustomerConversation(customer?.external_id, new Date(), 1, {
417
422
  fake: useAppStore.getState().fake,
418
423
  per_page: MESSAGES_PER_PAGE,
419
424
  })
@@ -437,7 +442,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
437
442
  if (processedMessages.length === 0) {
438
443
  setLoading(false);
439
444
  }
440
- return [...prevData, ...processedMessages];
445
+ return [...processedMessages];
441
446
  } else {
442
447
  // Handle the case where there's no previous data
443
448
  const processedMessages = newMessages.map((u) => ({
@@ -463,7 +468,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
463
468
  setLoading(false);
464
469
  });
465
470
  }
466
- }, [MESSAGES_PER_PAGE, externalId, initFailed, setData]);
471
+ }, [MESSAGES_PER_PAGE, customer?.external_id, initFailed, setData]);
467
472
 
468
473
  // Initialize the current section when sections are loaded
469
474
  useEffect(() => {
@@ -72,17 +72,17 @@ export function CustomerForm({ onBack }: { onBack: () => void }) {
72
72
 
73
73
  const onSubmit = async (data: CustomerFormData) => {
74
74
  try {
75
- const customer = await createCustomer(
75
+ const res = await createCustomer(
76
76
  {
77
77
  ...data,
78
78
  language: 'en',
79
79
  customParameters: [],
80
80
  },
81
81
  { fake: useAppStore.getState().fake },
82
- useAppStore.getState().externalId || ''
82
+ useAppStore.getState().customer?.external_id ?? ''
83
83
  );
84
- if (customer !== undefined) {
85
- useAppStore.getState().setForm(customer);
84
+ if (res) {
85
+ useAppStore.getState().setForm(res.customer);
86
86
  }
87
87
  } catch (error) {
88
88
  console.error('Error creating customer:', error);
@@ -190,6 +190,10 @@ export function CustomerForm({ onBack }: { onBack: () => void }) {
190
190
  <Controller
191
191
  control={control}
192
192
  rules={{
193
+ required: {
194
+ value: true,
195
+ message: localize('customer.form.validation.name.required'),
196
+ },
193
197
  maxLength: {
194
198
  value: 30,
195
199
  message: localize(
@@ -17,7 +17,6 @@ export function MessageInput({
17
17
  }) {
18
18
  const [value, setValue] = useState('');
19
19
  const customer = useAppStore((s) => s.customer!);
20
- const externalId = useAppStore((s) => s.externalId);
21
20
  const themeColors = useThemeColors();
22
21
  const localize = useLocalize();
23
22
 
@@ -37,7 +36,7 @@ export function MessageInput({
37
36
  },
38
37
  ...(data ?? []),
39
38
  ]);
40
- sendCustomerMessage(externalId as string, value, {
39
+ sendCustomerMessage(customer.external_id as string, value, {
41
40
  fake: useAppStore.getState().fake,
42
41
  })
43
42
  .then((res) => {
@@ -14,6 +14,7 @@ export const LocalizationList: Record<LanguageCode, LocalizationKeys> = {
14
14
  'customer.form.error.country': 'Country is required',
15
15
  'customer.form.error.email': 'Valid email is required',
16
16
  'customer.form.error.phone': 'Phone is required',
17
+ 'customer.form.validation.name.required': 'Name is required',
17
18
  'customer.form.placeholder.name': 'Enter your name',
18
19
  'customer.form.placeholder.country': 'Enter your country',
19
20
  'customer.form.placeholder.email': 'Enter your email',
@@ -60,6 +61,7 @@ export const LocalizationList: Record<LanguageCode, LocalizationKeys> = {
60
61
  'customer.form.error.country': 'Ülke zorunludur',
61
62
  'customer.form.error.email': 'Geçerli bir e-posta adresi gerekli',
62
63
  'customer.form.error.phone': 'Telefon alanı zorunludur',
64
+ 'customer.form.validation.name.required': 'İsim zorunludur',
63
65
  'customer.form.placeholder.name': 'Adınızı girin',
64
66
  'customer.form.placeholder.country': 'Ülkenizi girin',
65
67
  'customer.form.placeholder.email': 'E-posta adresinizi girin',
@@ -106,6 +108,7 @@ export const LocalizationList: Record<LanguageCode, LocalizationKeys> = {
106
108
  'customer.form.error.country': 'País es obligatorio',
107
109
  'customer.form.error.email': 'Se requiere un correo electrónico válido',
108
110
  'customer.form.error.phone': 'El teléfono es requerido',
111
+ 'customer.form.validation.name.required': 'El nombre es requerido',
109
112
  'customer.form.placeholder.name': 'Ingrese su nombre',
110
113
  'customer.form.placeholder.country': 'Ingrese su país',
111
114
  'customer.form.placeholder.email': 'Ingrese su correo electrónico',
@@ -154,6 +157,7 @@ export const LocalizationList: Record<LanguageCode, LocalizationKeys> = {
154
157
  'customer.form.error.country': 'Le pays est obligatoire',
155
158
  'customer.form.error.email': 'Un email valide est requis',
156
159
  'customer.form.error.phone': 'Le téléphone est requis',
160
+ 'customer.form.validation.name.required': 'Le nom est requis',
157
161
  'customer.form.placeholder.name': 'Entrez votre nom',
158
162
  'customer.form.placeholder.country': 'Entrez votre pays',
159
163
  'customer.form.placeholder.email': 'Entrez votre email',
@@ -203,6 +207,7 @@ export const LocalizationList: Record<LanguageCode, LocalizationKeys> = {
203
207
  'customer.form.error.country': 'Land ist erforderlich',
204
208
  'customer.form.error.email': 'Eine gültige E-Mail-Adresse ist erforderlich',
205
209
  'customer.form.error.phone': 'Telefon ist erforderlich',
210
+ 'customer.form.validation.name.required': 'Name ist erforderlich',
206
211
  'customer.form.placeholder.name': 'Geben Sie Ihren Namen ein',
207
212
  'customer.form.placeholder.country': 'Geben Sie Ihr Land ein',
208
213
  'customer.form.placeholder.email': 'Geben Sie Ihre E-Mail-Adresse ein',
@@ -253,6 +258,7 @@ export const LocalizationList: Record<LanguageCode, LocalizationKeys> = {
253
258
  'customer.form.error.country': 'Il paese è obbligatorio',
254
259
  'customer.form.error.email': "È richiesta un'email valida",
255
260
  'customer.form.error.phone': 'Il telefono è obbligatorio',
261
+ 'customer.form.validation.name.required': 'Il nome è obbligatorio',
256
262
  'customer.form.placeholder.name': 'Inserisci il tuo nome',
257
263
  'customer.form.placeholder.country': 'Inserisci il tuo paese',
258
264
  'customer.form.placeholder.email': 'Inserisci la tua email',
@@ -300,6 +306,7 @@ export const LocalizationList: Record<LanguageCode, LocalizationKeys> = {
300
306
  'customer.form.error.country': 'País é obrigatório',
301
307
  'customer.form.error.email': 'Um email válido é obrigatório',
302
308
  'customer.form.error.phone': 'O telefone é obrigatório',
309
+ 'customer.form.validation.name.required': 'O nome é obrigatório',
303
310
  'customer.form.placeholder.name': 'Digite seu nome',
304
311
  'customer.form.placeholder.country': 'Digite seu país',
305
312
  'customer.form.placeholder.email': 'Digite seu email',
@@ -349,6 +356,7 @@ export const LocalizationList: Record<LanguageCode, LocalizationKeys> = {
349
356
  'customer.form.error.country': 'Страна обязательна',
350
357
  'customer.form.error.email': 'Требуется действительный email',
351
358
  'customer.form.error.phone': 'Телефон обязателен',
359
+ 'customer.form.validation.name.required': 'Имя обязательно',
352
360
  'customer.form.placeholder.name': 'Введите ваше имя',
353
361
  'customer.form.placeholder.country': 'Введите вашу страну',
354
362
  'customer.form.placeholder.email': 'Введите ваш email',
@@ -398,6 +406,7 @@ export const LocalizationList: Record<LanguageCode, LocalizationKeys> = {
398
406
  'customer.form.error.country': '国は必須です',
399
407
  'customer.form.error.email': '有効なメールアドレスが必要です',
400
408
  'customer.form.error.phone': '電話番号は必須です',
409
+ 'customer.form.validation.name.required': '名前は必須です',
401
410
  'customer.form.placeholder.name': 'お名前を入力してください',
402
411
  'customer.form.placeholder.country': '国を入力してください',
403
412
  'customer.form.placeholder.email': 'メールアドレスを入力してください',
@@ -444,6 +453,7 @@ export const LocalizationList: Record<LanguageCode, LocalizationKeys> = {
444
453
  'customer.form.error.country': '国家为必填项',
445
454
  'customer.form.error.email': '需要有效的电子邮件',
446
455
  'customer.form.error.phone': '电话为必填项',
456
+ 'customer.form.validation.name.required': '姓名为必填项',
447
457
  'customer.form.placeholder.name': '请输入您的姓名',
448
458
  'customer.form.placeholder.country': '请输入您的国家',
449
459
  'customer.form.placeholder.email': '请输入您的电子邮件',
@@ -5,18 +5,18 @@ import { getNewCustomerConversation } from '../api';
5
5
  const NEW_MESSAGES_CHECK_INTERVAL = 10000;
6
6
 
7
7
  export function usePolling() {
8
- const { data, setData, externalId } = useAppStore((s) => ({
8
+ const { data, setData, customer } = useAppStore((s) => ({
9
9
  data: s.data,
10
10
  setData: s.setData,
11
- externalId: s.externalId,
11
+ customer: s.customer,
12
12
  }));
13
13
  const lastMessage = data ? data[data.length - 1] : null;
14
14
  useEffect(() => {
15
15
  const created_at = lastMessage?.created_at;
16
16
  let interval: NodeJS.Timeout | null = null;
17
- if (externalId && created_at) {
17
+ if (customer && created_at) {
18
18
  interval = setInterval(() => {
19
- getNewCustomerConversation(externalId, created_at, {
19
+ getNewCustomerConversation(customer?.external_id, created_at, {
20
20
  fake: useAppStore.getState().fake,
21
21
  }).then((newData) => {
22
22
  setData((prevData) => {
@@ -42,5 +42,5 @@ export function usePolling() {
42
42
  clearInterval(interval);
43
43
  }
44
44
  };
45
- }, [externalId, lastMessage?.created_at, setData]);
45
+ }, [customer, lastMessage?.created_at, setData]);
46
46
  }
package/src/register.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { accumulator } from './Accumulator';
2
2
  import { initApi } from './api/api';
3
3
  import { useAppStore } from './store';
4
- import { createCustomer } from './api/customers';
4
+ import { createCustomer } from './api';
5
5
  import type { CreateCustomerRequest } from './types/Customer';
6
6
 
7
7
  export function registerComnyx(registerOptions: {
@@ -15,16 +15,15 @@ export function registerComnyx(registerOptions: {
15
15
  throw new Error('Authentication token is required');
16
16
  }
17
17
 
18
- initApi(registerOptions.token);
19
- useAppStore.getState().init({ externalId: registerOptions.externalId });
18
+ initApi(registerOptions.token, registerOptions.externalId);
20
19
  accumulator.register(async (accumulatedData: CreateCustomerRequest) => {
21
- const customer = await createCustomer(
20
+ const data = await createCustomer(
22
21
  accumulatedData,
23
22
  {
24
23
  fake: false,
25
24
  },
26
25
  registerOptions.externalId
27
26
  );
28
- useAppStore.getState().setCustomer(customer);
27
+ useAppStore.getState().setCustomer(data.customer);
29
28
  });
30
29
  }
package/src/store.ts CHANGED
@@ -10,10 +10,8 @@ import type { LanguageCode } from './types/Language';
10
10
  interface AppStoreState {
11
11
  baseHeight: number;
12
12
  baseWidth: number;
13
- initialized: boolean;
14
13
  customer: Customer | null;
15
14
  data: AppConversationMessage[] | null;
16
- externalId: string | null;
17
15
  language: LanguageCode;
18
16
  theme: 'light' | 'dark';
19
17
  fake: boolean;
@@ -25,7 +23,6 @@ interface AppStoreState {
25
23
  ) => AppConversationMessage[] | null
26
24
  ) => void;
27
25
  setFirstMessage: (message: AppConversationMessage | null) => void;
28
- init: ({ externalId }: { externalId: string }) => void;
29
26
  setCustomer: (createCustomerResponse: Customer) => void;
30
27
  setLanguage: (language: LanguageCode) => void;
31
28
  setTheme: (theme: 'light' | 'dark') => void;
@@ -45,7 +42,6 @@ const storeCreator: StateCreator<AppStoreState> = (set, get) => ({
45
42
  initialized: false,
46
43
  customer: null,
47
44
  data: null,
48
- externalId: null,
49
45
  language: 'en',
50
46
  theme: 'light',
51
47
  fake: false,
@@ -59,11 +55,11 @@ const storeCreator: StateCreator<AppStoreState> = (set, get) => ({
59
55
  setFirstMessage: (message) => {
60
56
  set({ firstMessage: message });
61
57
  },
62
- init: ({ externalId }: { externalId: string }) => {
63
- set({ externalId: externalId });
64
- },
65
58
  setCustomer: (createCustomerResponse: Customer) => {
66
- set({ customer: createCustomerResponse, initialized: true });
59
+ set({
60
+ customer: createCustomerResponse,
61
+ formSubmitted: !!createCustomerResponse.name,
62
+ });
67
63
  },
68
64
  setLanguage: (language: LanguageCode) => {
69
65
  set({ language });
@@ -92,8 +88,6 @@ export const useAppStore = createWithEqualityFn<AppStoreState>()(
92
88
  skipHydration: false,
93
89
  partialize: (state) => ({
94
90
  customer: state.customer,
95
- externalId: state.externalId,
96
- initialized: state.initialized,
97
91
  formSubmitted: state.formSubmitted,
98
92
  data: state.data
99
93
  ?.filter((message) => message.approved)
@@ -17,6 +17,7 @@ export type LocalizationKeys = {
17
17
  'customer.form.validation.phone.invalid': string;
18
18
  'customer.form.validation.country.maxLength': string;
19
19
  'customer.form.validation.name.maxLength': string;
20
+ 'customer.form.validation.name.required': string;
20
21
  'chat.messageInput.placeholder': string;
21
22
  'app.initialization.required': string;
22
23
  'chat.load.error': string;