@developer_tribe/react-native-comnyx 0.1.1 → 0.2.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.
Files changed (310) hide show
  1. package/lib/commonjs/App.js +59 -0
  2. package/lib/commonjs/App.js.map +1 -0
  3. package/lib/commonjs/__dev__.js +29 -0
  4. package/lib/commonjs/__dev__.js.map +1 -0
  5. package/lib/commonjs/api/api.js +22 -0
  6. package/lib/commonjs/api/api.js.map +1 -0
  7. package/lib/commonjs/api/conversations.js +37 -0
  8. package/lib/commonjs/api/conversations.js.map +1 -0
  9. package/lib/commonjs/api/customers.js +15 -0
  10. package/lib/commonjs/api/customers.js.map +1 -0
  11. package/lib/commonjs/api/index.js +33 -0
  12. package/lib/commonjs/api/index.js.map +1 -0
  13. package/lib/commonjs/api/messages.js +27 -0
  14. package/lib/commonjs/api/messages.js.map +1 -0
  15. package/lib/commonjs/assets/clock.png +0 -0
  16. package/lib/commonjs/assets/double-check.png +0 -0
  17. package/lib/commonjs/assets/down.png +0 -0
  18. package/lib/commonjs/assets/send.png +0 -0
  19. package/lib/commonjs/components/AppText.js +38 -0
  20. package/lib/commonjs/components/AppText.js.map +1 -0
  21. package/lib/commonjs/components/ChatList.js +268 -0
  22. package/lib/commonjs/components/ChatList.js.map +1 -0
  23. package/lib/commonjs/components/CustomerForm.js +279 -0
  24. package/lib/commonjs/components/CustomerForm.js.map +1 -0
  25. package/lib/commonjs/components/EmptyList.js +40 -0
  26. package/lib/commonjs/components/EmptyList.js.map +1 -0
  27. package/lib/commonjs/components/InitFailed.js +51 -0
  28. package/lib/commonjs/components/InitFailed.js.map +1 -0
  29. package/lib/commonjs/components/MessageInput.js +119 -0
  30. package/lib/commonjs/components/MessageInput.js.map +1 -0
  31. package/lib/commonjs/components/MessageItem.js +117 -0
  32. package/lib/commonjs/components/MessageItem.js.map +1 -0
  33. package/lib/commonjs/constants/countries.js +587 -0
  34. package/lib/commonjs/constants/countries.js.map +1 -0
  35. package/lib/commonjs/constants/translations.js +219 -0
  36. package/lib/commonjs/constants/translations.js.map +1 -0
  37. package/lib/commonjs/data/fake/conversations.js +95 -0
  38. package/lib/commonjs/data/fake/conversations.js.map +1 -0
  39. package/lib/commonjs/data/fake/customers.js +24 -0
  40. package/lib/commonjs/data/fake/customers.js.map +1 -0
  41. package/lib/commonjs/data/fake/messages.js +67 -0
  42. package/lib/commonjs/data/fake/messages.js.map +1 -0
  43. package/lib/commonjs/hooks/useLocalize.js +20 -0
  44. package/lib/commonjs/hooks/useLocalize.js.map +1 -0
  45. package/lib/commonjs/hooks/usePolling.js +50 -0
  46. package/lib/commonjs/hooks/usePolling.js.map +1 -0
  47. package/lib/commonjs/hooks/useThemeColors.js +17 -0
  48. package/lib/commonjs/hooks/useThemeColors.js.map +1 -0
  49. package/lib/commonjs/index.js +15 -6
  50. package/lib/commonjs/index.js.map +1 -1
  51. package/lib/commonjs/register.js +21 -0
  52. package/lib/commonjs/register.js.map +1 -0
  53. package/lib/commonjs/store.js +79 -0
  54. package/lib/commonjs/store.js.map +1 -0
  55. package/lib/commonjs/types/ApiOptions.js +2 -0
  56. package/lib/commonjs/types/ApiOptions.js.map +1 -0
  57. package/lib/commonjs/types/Conversation.js +2 -0
  58. package/lib/commonjs/types/Conversation.js.map +1 -0
  59. package/lib/commonjs/types/Customer.js +2 -0
  60. package/lib/commonjs/types/Customer.js.map +1 -0
  61. package/lib/commonjs/types/Language.js +2 -0
  62. package/lib/commonjs/types/Language.js.map +1 -0
  63. package/lib/commonjs/types/LocalizationKeys.js +2 -0
  64. package/lib/commonjs/types/LocalizationKeys.js.map +1 -0
  65. package/lib/commonjs/types/MessageResponse.js +2 -0
  66. package/lib/commonjs/types/MessageResponse.js.map +1 -0
  67. package/lib/commonjs/types/Theme.js +29 -0
  68. package/lib/commonjs/types/Theme.js.map +1 -0
  69. package/lib/commonjs/utils/date.js +17 -0
  70. package/lib/commonjs/utils/date.js.map +1 -0
  71. package/lib/module/App.js +55 -0
  72. package/lib/module/App.js.map +1 -0
  73. package/lib/module/__dev__.js +29 -0
  74. package/lib/module/__dev__.js.map +1 -0
  75. package/lib/module/api/api.js +17 -0
  76. package/lib/module/api/api.js.map +1 -0
  77. package/lib/module/api/conversations.js +32 -0
  78. package/lib/module/api/conversations.js.map +1 -0
  79. package/lib/module/api/customers.js +11 -0
  80. package/lib/module/api/customers.js.map +1 -0
  81. package/lib/module/api/index.js +6 -0
  82. package/lib/module/api/index.js.map +1 -0
  83. package/lib/module/api/messages.js +23 -0
  84. package/lib/module/api/messages.js.map +1 -0
  85. package/lib/module/assets/clock.png +0 -0
  86. package/lib/module/assets/double-check.png +0 -0
  87. package/lib/module/assets/down.png +0 -0
  88. package/lib/module/assets/send.png +0 -0
  89. package/lib/module/components/AppText.js +34 -0
  90. package/lib/module/components/AppText.js.map +1 -0
  91. package/lib/module/components/ChatList.js +265 -0
  92. package/lib/module/components/ChatList.js.map +1 -0
  93. package/lib/module/components/CustomerForm.js +275 -0
  94. package/lib/module/components/CustomerForm.js.map +1 -0
  95. package/lib/module/components/EmptyList.js +36 -0
  96. package/lib/module/components/EmptyList.js.map +1 -0
  97. package/lib/module/components/InitFailed.js +47 -0
  98. package/lib/module/components/InitFailed.js.map +1 -0
  99. package/lib/module/components/MessageInput.js +115 -0
  100. package/lib/module/components/MessageInput.js.map +1 -0
  101. package/lib/module/components/MessageItem.js +114 -0
  102. package/lib/module/components/MessageItem.js.map +1 -0
  103. package/lib/module/constants/countries.js +583 -0
  104. package/lib/module/constants/countries.js.map +1 -0
  105. package/lib/module/constants/translations.js +215 -0
  106. package/lib/module/constants/translations.js.map +1 -0
  107. package/lib/module/data/fake/conversations.js +88 -0
  108. package/lib/module/data/fake/conversations.js.map +1 -0
  109. package/lib/module/data/fake/customers.js +20 -0
  110. package/lib/module/data/fake/customers.js.map +1 -0
  111. package/lib/module/data/fake/messages.js +63 -0
  112. package/lib/module/data/fake/messages.js.map +1 -0
  113. package/lib/module/hooks/useLocalize.js +16 -0
  114. package/lib/module/hooks/useLocalize.js.map +1 -0
  115. package/lib/module/hooks/usePolling.js +46 -0
  116. package/lib/module/hooks/usePolling.js.map +1 -0
  117. package/lib/module/hooks/useThemeColors.js +13 -0
  118. package/lib/module/hooks/useThemeColors.js.map +1 -0
  119. package/lib/module/index.js +3 -4
  120. package/lib/module/index.js.map +1 -1
  121. package/lib/module/register.js +17 -0
  122. package/lib/module/register.js.map +1 -0
  123. package/lib/module/store.js +74 -0
  124. package/lib/module/store.js.map +1 -0
  125. package/lib/module/types/ApiOptions.js +2 -0
  126. package/lib/module/types/ApiOptions.js.map +1 -0
  127. package/lib/module/types/Conversation.js +2 -0
  128. package/lib/module/types/Conversation.js.map +1 -0
  129. package/lib/module/types/Customer.js +2 -0
  130. package/lib/module/types/Customer.js.map +1 -0
  131. package/lib/module/types/Language.js +2 -0
  132. package/lib/module/types/Language.js.map +1 -0
  133. package/lib/module/types/LocalizationKeys.js +2 -0
  134. package/lib/module/types/LocalizationKeys.js.map +1 -0
  135. package/lib/module/types/MessageResponse.js +2 -0
  136. package/lib/module/types/MessageResponse.js.map +1 -0
  137. package/lib/module/types/Theme.js +25 -0
  138. package/lib/module/types/Theme.js.map +1 -0
  139. package/lib/module/utils/date.js +12 -0
  140. package/lib/module/utils/date.js.map +1 -0
  141. package/lib/typescript/commonjs/src/App.d.ts +9 -0
  142. package/lib/typescript/commonjs/src/App.d.ts.map +1 -0
  143. package/lib/typescript/commonjs/src/__dev__.d.ts +2 -0
  144. package/lib/typescript/commonjs/src/__dev__.d.ts.map +1 -0
  145. package/lib/typescript/commonjs/src/api/api.d.ts +4 -0
  146. package/lib/typescript/commonjs/src/api/api.d.ts.map +1 -0
  147. package/lib/typescript/commonjs/src/api/conversations.d.ts +7 -0
  148. package/lib/typescript/commonjs/src/api/conversations.d.ts.map +1 -0
  149. package/lib/typescript/commonjs/src/api/customers.d.ts +4 -0
  150. package/lib/typescript/commonjs/src/api/customers.d.ts.map +1 -0
  151. package/lib/typescript/commonjs/src/api/index.d.ts +4 -0
  152. package/lib/typescript/commonjs/src/api/index.d.ts.map +1 -0
  153. package/lib/typescript/commonjs/src/api/messages.d.ts +4 -0
  154. package/lib/typescript/commonjs/src/api/messages.d.ts.map +1 -0
  155. package/lib/typescript/commonjs/src/components/AppText.d.ts +10 -0
  156. package/lib/typescript/commonjs/src/components/AppText.d.ts.map +1 -0
  157. package/lib/typescript/commonjs/src/components/ChatList.d.ts +2 -0
  158. package/lib/typescript/commonjs/src/components/ChatList.d.ts.map +1 -0
  159. package/lib/typescript/commonjs/src/components/CustomerForm.d.ts +2 -0
  160. package/lib/typescript/commonjs/src/components/CustomerForm.d.ts.map +1 -0
  161. package/lib/typescript/commonjs/src/components/EmptyList.d.ts +2 -0
  162. package/lib/typescript/commonjs/src/components/EmptyList.d.ts.map +1 -0
  163. package/lib/typescript/commonjs/src/components/InitFailed.d.ts +6 -0
  164. package/lib/typescript/commonjs/src/components/InitFailed.d.ts.map +1 -0
  165. package/lib/typescript/commonjs/src/components/MessageInput.d.ts +4 -0
  166. package/lib/typescript/commonjs/src/components/MessageInput.d.ts.map +1 -0
  167. package/lib/typescript/commonjs/src/components/MessageItem.d.ts +5 -0
  168. package/lib/typescript/commonjs/src/components/MessageItem.d.ts.map +1 -0
  169. package/lib/typescript/commonjs/src/constants/countries.d.ts +6 -0
  170. package/lib/typescript/commonjs/src/constants/countries.d.ts.map +1 -0
  171. package/lib/typescript/commonjs/src/constants/translations.d.ts +4 -0
  172. package/lib/typescript/commonjs/src/constants/translations.d.ts.map +1 -0
  173. package/lib/typescript/commonjs/src/data/fake/conversations.d.ts +5 -0
  174. package/lib/typescript/commonjs/src/data/fake/conversations.d.ts.map +1 -0
  175. package/lib/typescript/commonjs/src/data/fake/customers.d.ts +3 -0
  176. package/lib/typescript/commonjs/src/data/fake/customers.d.ts.map +1 -0
  177. package/lib/typescript/commonjs/src/data/fake/messages.d.ts +3 -0
  178. package/lib/typescript/commonjs/src/data/fake/messages.d.ts.map +1 -0
  179. package/lib/typescript/commonjs/src/hooks/useLocalize.d.ts +3 -0
  180. package/lib/typescript/commonjs/src/hooks/useLocalize.d.ts.map +1 -0
  181. package/lib/typescript/commonjs/src/hooks/usePolling.d.ts +2 -0
  182. package/lib/typescript/commonjs/src/hooks/usePolling.d.ts.map +1 -0
  183. package/lib/typescript/commonjs/src/hooks/useThemeColors.d.ts +3 -0
  184. package/lib/typescript/commonjs/src/hooks/useThemeColors.d.ts.map +1 -0
  185. package/lib/typescript/commonjs/src/index.d.ts +4 -1
  186. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  187. package/lib/typescript/commonjs/src/register.d.ts +5 -0
  188. package/lib/typescript/commonjs/src/register.d.ts.map +1 -0
  189. package/lib/typescript/commonjs/src/store.d.ts +35 -0
  190. package/lib/typescript/commonjs/src/store.d.ts.map +1 -0
  191. package/lib/typescript/commonjs/src/types/ApiOptions.d.ts +4 -0
  192. package/lib/typescript/commonjs/src/types/ApiOptions.d.ts.map +1 -0
  193. package/lib/typescript/commonjs/src/types/Conversation.d.ts +26 -0
  194. package/lib/typescript/commonjs/src/types/Conversation.d.ts.map +1 -0
  195. package/lib/typescript/commonjs/src/types/Customer.d.ts +30 -0
  196. package/lib/typescript/commonjs/src/types/Customer.d.ts.map +1 -0
  197. package/lib/typescript/commonjs/src/types/Language.d.ts +2 -0
  198. package/lib/typescript/commonjs/src/types/Language.d.ts.map +1 -0
  199. package/lib/typescript/commonjs/src/types/LocalizationKeys.d.ts +22 -0
  200. package/lib/typescript/commonjs/src/types/LocalizationKeys.d.ts.map +1 -0
  201. package/lib/typescript/commonjs/src/types/MessageResponse.d.ts +59 -0
  202. package/lib/typescript/commonjs/src/types/MessageResponse.d.ts.map +1 -0
  203. package/lib/typescript/commonjs/src/types/Theme.d.ts +18 -0
  204. package/lib/typescript/commonjs/src/types/Theme.d.ts.map +1 -0
  205. package/lib/typescript/commonjs/src/utils/date.d.ts +7 -0
  206. package/lib/typescript/commonjs/src/utils/date.d.ts.map +1 -0
  207. package/lib/typescript/module/src/App.d.ts +9 -0
  208. package/lib/typescript/module/src/App.d.ts.map +1 -0
  209. package/lib/typescript/module/src/__dev__.d.ts +2 -0
  210. package/lib/typescript/module/src/__dev__.d.ts.map +1 -0
  211. package/lib/typescript/module/src/api/api.d.ts +4 -0
  212. package/lib/typescript/module/src/api/api.d.ts.map +1 -0
  213. package/lib/typescript/module/src/api/conversations.d.ts +7 -0
  214. package/lib/typescript/module/src/api/conversations.d.ts.map +1 -0
  215. package/lib/typescript/module/src/api/customers.d.ts +4 -0
  216. package/lib/typescript/module/src/api/customers.d.ts.map +1 -0
  217. package/lib/typescript/module/src/api/index.d.ts +4 -0
  218. package/lib/typescript/module/src/api/index.d.ts.map +1 -0
  219. package/lib/typescript/module/src/api/messages.d.ts +4 -0
  220. package/lib/typescript/module/src/api/messages.d.ts.map +1 -0
  221. package/lib/typescript/module/src/components/AppText.d.ts +10 -0
  222. package/lib/typescript/module/src/components/AppText.d.ts.map +1 -0
  223. package/lib/typescript/module/src/components/ChatList.d.ts +2 -0
  224. package/lib/typescript/module/src/components/ChatList.d.ts.map +1 -0
  225. package/lib/typescript/module/src/components/CustomerForm.d.ts +2 -0
  226. package/lib/typescript/module/src/components/CustomerForm.d.ts.map +1 -0
  227. package/lib/typescript/module/src/components/EmptyList.d.ts +2 -0
  228. package/lib/typescript/module/src/components/EmptyList.d.ts.map +1 -0
  229. package/lib/typescript/module/src/components/InitFailed.d.ts +6 -0
  230. package/lib/typescript/module/src/components/InitFailed.d.ts.map +1 -0
  231. package/lib/typescript/module/src/components/MessageInput.d.ts +4 -0
  232. package/lib/typescript/module/src/components/MessageInput.d.ts.map +1 -0
  233. package/lib/typescript/module/src/components/MessageItem.d.ts +5 -0
  234. package/lib/typescript/module/src/components/MessageItem.d.ts.map +1 -0
  235. package/lib/typescript/module/src/constants/countries.d.ts +6 -0
  236. package/lib/typescript/module/src/constants/countries.d.ts.map +1 -0
  237. package/lib/typescript/module/src/constants/translations.d.ts +4 -0
  238. package/lib/typescript/module/src/constants/translations.d.ts.map +1 -0
  239. package/lib/typescript/module/src/data/fake/conversations.d.ts +5 -0
  240. package/lib/typescript/module/src/data/fake/conversations.d.ts.map +1 -0
  241. package/lib/typescript/module/src/data/fake/customers.d.ts +3 -0
  242. package/lib/typescript/module/src/data/fake/customers.d.ts.map +1 -0
  243. package/lib/typescript/module/src/data/fake/messages.d.ts +3 -0
  244. package/lib/typescript/module/src/data/fake/messages.d.ts.map +1 -0
  245. package/lib/typescript/module/src/hooks/useLocalize.d.ts +3 -0
  246. package/lib/typescript/module/src/hooks/useLocalize.d.ts.map +1 -0
  247. package/lib/typescript/module/src/hooks/usePolling.d.ts +2 -0
  248. package/lib/typescript/module/src/hooks/usePolling.d.ts.map +1 -0
  249. package/lib/typescript/module/src/hooks/useThemeColors.d.ts +3 -0
  250. package/lib/typescript/module/src/hooks/useThemeColors.d.ts.map +1 -0
  251. package/lib/typescript/module/src/index.d.ts +4 -1
  252. package/lib/typescript/module/src/index.d.ts.map +1 -1
  253. package/lib/typescript/module/src/register.d.ts +5 -0
  254. package/lib/typescript/module/src/register.d.ts.map +1 -0
  255. package/lib/typescript/module/src/store.d.ts +35 -0
  256. package/lib/typescript/module/src/store.d.ts.map +1 -0
  257. package/lib/typescript/module/src/types/ApiOptions.d.ts +4 -0
  258. package/lib/typescript/module/src/types/ApiOptions.d.ts.map +1 -0
  259. package/lib/typescript/module/src/types/Conversation.d.ts +26 -0
  260. package/lib/typescript/module/src/types/Conversation.d.ts.map +1 -0
  261. package/lib/typescript/module/src/types/Customer.d.ts +30 -0
  262. package/lib/typescript/module/src/types/Customer.d.ts.map +1 -0
  263. package/lib/typescript/module/src/types/Language.d.ts +2 -0
  264. package/lib/typescript/module/src/types/Language.d.ts.map +1 -0
  265. package/lib/typescript/module/src/types/LocalizationKeys.d.ts +22 -0
  266. package/lib/typescript/module/src/types/LocalizationKeys.d.ts.map +1 -0
  267. package/lib/typescript/module/src/types/MessageResponse.d.ts +59 -0
  268. package/lib/typescript/module/src/types/MessageResponse.d.ts.map +1 -0
  269. package/lib/typescript/module/src/types/Theme.d.ts +18 -0
  270. package/lib/typescript/module/src/types/Theme.d.ts.map +1 -0
  271. package/lib/typescript/module/src/utils/date.d.ts +7 -0
  272. package/lib/typescript/module/src/utils/date.d.ts.map +1 -0
  273. package/package.json +10 -2
  274. package/src/App.tsx +59 -0
  275. package/src/__dev__.ts +22 -0
  276. package/src/api/api.ts +16 -0
  277. package/src/api/conversations.ts +53 -0
  278. package/src/api/customers.ts +16 -0
  279. package/src/api/index.ts +6 -0
  280. package/src/api/messages.ts +33 -0
  281. package/src/assets/clock.png +0 -0
  282. package/src/assets/double-check.png +0 -0
  283. package/src/assets/down.png +0 -0
  284. package/src/assets/send.png +0 -0
  285. package/src/components/AppText.tsx +43 -0
  286. package/src/components/ChatList.tsx +299 -0
  287. package/src/components/CustomerForm.tsx +300 -0
  288. package/src/components/EmptyList.tsx +32 -0
  289. package/src/components/InitFailed.tsx +46 -0
  290. package/src/components/MessageInput.tsx +133 -0
  291. package/src/components/MessageItem.tsx +141 -0
  292. package/src/constants/countries.ts +200 -0
  293. package/src/constants/translations.ts +232 -0
  294. package/src/data/fake/conversations.ts +558 -0
  295. package/src/data/fake/customers.ts +19 -0
  296. package/src/data/fake/messages.ts +64 -0
  297. package/src/hooks/useLocalize.ts +18 -0
  298. package/src/hooks/usePolling.ts +46 -0
  299. package/src/hooks/useThemeColors.ts +10 -0
  300. package/src/index.tsx +4 -5
  301. package/src/register.ts +17 -0
  302. package/src/store.ts +85 -0
  303. package/src/types/ApiOptions.ts +4 -0
  304. package/src/types/Conversation.ts +29 -0
  305. package/src/types/Customer.ts +31 -0
  306. package/src/types/Language.ts +11 -0
  307. package/src/types/LocalizationKeys.ts +21 -0
  308. package/src/types/MessageResponse.ts +58 -0
  309. package/src/types/Theme.ts +40 -0
  310. package/src/utils/date.ts +11 -0
@@ -0,0 +1,300 @@
1
+ import {
2
+ View,
3
+ TextInput,
4
+ StyleSheet,
5
+ TouchableOpacity,
6
+ Modal,
7
+ FlatList,
8
+ Pressable,
9
+ } from 'react-native';
10
+ import { useForm, Controller } from 'react-hook-form';
11
+ import { useAppStore } from '../store';
12
+ import { createCustomer } from '../api';
13
+ import { AppText } from './AppText';
14
+ import { useLocalize } from '../hooks/useLocalize';
15
+ import { useThemeColors } from '../hooks/useThemeColors';
16
+ import { countries } from '../constants/countries';
17
+ import { useState } from 'react';
18
+
19
+ interface CustomerFormData {
20
+ name: string;
21
+ country: string;
22
+ email: string;
23
+ phone: string;
24
+ }
25
+
26
+ export function CustomerForm() {
27
+ const {
28
+ control,
29
+ handleSubmit,
30
+ formState: { errors },
31
+ } = useForm<CustomerFormData>();
32
+ const themeColors = useThemeColors();
33
+ const localize = useLocalize();
34
+ const [isCountryModalVisible, setIsCountryModalVisible] = useState(false);
35
+
36
+ const inputStyle = {
37
+ ...styles.input,
38
+ color: themeColors.text,
39
+ borderColor: themeColors.border,
40
+ backgroundColor: themeColors.background,
41
+ };
42
+
43
+ const onSubmit = async (data: CustomerFormData) => {
44
+ try {
45
+ const customer = await createCustomer(
46
+ {
47
+ ...data,
48
+ language: 'en',
49
+ externalId: useAppStore.getState().externalId || '',
50
+ ipAddress: '192.168.1.1',
51
+ customParameters: [],
52
+ },
53
+ { fake: useAppStore.getState().fake }
54
+ );
55
+ if (customer !== undefined) {
56
+ useAppStore.getState().initForm(customer);
57
+ }
58
+ } catch (error) {
59
+ console.error('Error creating customer:', error);
60
+ }
61
+ };
62
+
63
+ return (
64
+ <View
65
+ style={[styles.container, { backgroundColor: themeColors.background }]}
66
+ >
67
+ <View style={styles.headerContainer}>
68
+ <AppText
69
+ localization="customer.form.title"
70
+ style={[styles.headerText, { color: themeColors.text }]}
71
+ />
72
+ <AppText
73
+ localization="customer.form.instructions"
74
+ style={[styles.headerText, { color: themeColors.text }]}
75
+ />
76
+ </View>
77
+ <Controller
78
+ control={control}
79
+ rules={{ required: true }}
80
+ render={({ field: { onChange, value } }) => (
81
+ <TextInput
82
+ style={inputStyle}
83
+ placeholder={localize('customer.form.placeholder.name')}
84
+ placeholderTextColor="#6C757D"
85
+ value={value}
86
+ onChangeText={onChange}
87
+ />
88
+ )}
89
+ name="name"
90
+ />
91
+ {errors.name && (
92
+ <AppText
93
+ localization="customer.form.error"
94
+ style={[styles.error, { color: themeColors.error }]}
95
+ />
96
+ )}
97
+
98
+ <Controller
99
+ control={control}
100
+ rules={{ required: true }}
101
+ render={({ field: { onChange, value } }) => (
102
+ <>
103
+ <Pressable
104
+ style={[
105
+ styles.input,
106
+ {
107
+ borderColor: themeColors.border,
108
+ backgroundColor: themeColors.background,
109
+ justifyContent: 'center',
110
+ },
111
+ ]}
112
+ onPress={() => setIsCountryModalVisible(true)}
113
+ >
114
+ <AppText style={{ color: value ? themeColors.text : '#6C757D' }}>
115
+ {value
116
+ ? countries.find((c) => c.code === value)?.name
117
+ : localize('customer.form.placeholder.country')}
118
+ </AppText>
119
+ </Pressable>
120
+
121
+ <Modal
122
+ visible={isCountryModalVisible}
123
+ transparent={true}
124
+ animationType="slide"
125
+ onRequestClose={() => setIsCountryModalVisible(false)}
126
+ >
127
+ <View
128
+ style={[
129
+ styles.modalContainer,
130
+ { backgroundColor: 'rgba(0, 0, 0, 0.5)' },
131
+ ]}
132
+ >
133
+ <View
134
+ style={[
135
+ styles.modalContent,
136
+ { backgroundColor: themeColors.background },
137
+ ]}
138
+ >
139
+ <FlatList
140
+ data={countries}
141
+ keyExtractor={(item) => item.code}
142
+ initialScrollIndex={countries.findIndex(
143
+ (c) => c.code === value
144
+ )}
145
+ renderItem={({ item }) => (
146
+ <Pressable
147
+ style={[
148
+ styles.countryItem,
149
+ {
150
+ backgroundColor:
151
+ value === item.code
152
+ ? themeColors.primary
153
+ : themeColors.background,
154
+ borderBottomColor: themeColors.border,
155
+ },
156
+ ]}
157
+ onPress={() => {
158
+ onChange(item.code);
159
+ setIsCountryModalVisible(false);
160
+ }}
161
+ >
162
+ <AppText
163
+ style={{
164
+ color:
165
+ value === item.code
166
+ ? themeColors.background
167
+ : themeColors.text,
168
+ fontSize: 16,
169
+ }}
170
+ >
171
+ {item.name}
172
+ </AppText>
173
+ </Pressable>
174
+ )}
175
+ />
176
+ </View>
177
+ </View>
178
+ </Modal>
179
+ </>
180
+ )}
181
+ name="country"
182
+ />
183
+ {errors.country && (
184
+ <AppText
185
+ localization="customer.form.error.country"
186
+ style={[styles.error, { color: themeColors.error }]}
187
+ />
188
+ )}
189
+
190
+ <Controller
191
+ control={control}
192
+ rules={{ required: true, pattern: /^\S+@\S+$/i }}
193
+ render={({ field: { onChange, value } }) => (
194
+ <TextInput
195
+ style={inputStyle}
196
+ placeholder={localize('customer.form.placeholder.email')}
197
+ placeholderTextColor="#6C757D"
198
+ value={value}
199
+ onChangeText={onChange}
200
+ keyboardType="email-address"
201
+ />
202
+ )}
203
+ name="email"
204
+ />
205
+ {errors.email && (
206
+ <AppText
207
+ localization="customer.form.error.email"
208
+ style={[styles.error, { color: themeColors.error }]}
209
+ />
210
+ )}
211
+
212
+ <Controller
213
+ control={control}
214
+ rules={{ required: true }}
215
+ render={({ field: { onChange, value } }) => (
216
+ <TextInput
217
+ style={inputStyle}
218
+ placeholder={localize('customer.form.placeholder.phone')}
219
+ placeholderTextColor="#6C757D"
220
+ value={value}
221
+ onChangeText={onChange}
222
+ keyboardType="phone-pad"
223
+ />
224
+ )}
225
+ name="phone"
226
+ />
227
+ {errors.phone && (
228
+ <AppText
229
+ localization="customer.form.error.phone"
230
+ style={[styles.error, { color: themeColors.error }]}
231
+ />
232
+ )}
233
+ <TouchableOpacity
234
+ style={[styles.button, { backgroundColor: themeColors.primary }]}
235
+ onPress={handleSubmit(onSubmit)}
236
+ >
237
+ <AppText
238
+ localization="customer.form.submit"
239
+ style={styles.buttonText}
240
+ />
241
+ </TouchableOpacity>
242
+ </View>
243
+ );
244
+ }
245
+
246
+ const styles = StyleSheet.create({
247
+ container: {
248
+ padding: 24,
249
+ flex: 1,
250
+ justifyContent: 'center',
251
+ },
252
+ headerContainer: {
253
+ marginBottom: 24,
254
+ },
255
+ headerText: {
256
+ fontSize: 15,
257
+ fontWeight: '600',
258
+ textAlign: 'center',
259
+ },
260
+ input: {
261
+ height: 56,
262
+ borderWidth: 1,
263
+ borderRadius: 12,
264
+ paddingHorizontal: 16,
265
+ fontSize: 16,
266
+ backgroundColor: 'white',
267
+ marginBottom: 16,
268
+ },
269
+ button: {
270
+ padding: 16,
271
+ borderRadius: 12,
272
+ alignItems: 'center',
273
+ marginTop: 24,
274
+ },
275
+ buttonText: {
276
+ color: 'white',
277
+ fontSize: 16,
278
+ fontWeight: '600',
279
+ },
280
+ error: {
281
+ fontSize: 14,
282
+ marginLeft: 16,
283
+ top: -16,
284
+ },
285
+ modalContainer: {
286
+ flex: 1,
287
+ justifyContent: 'center',
288
+ alignItems: 'center',
289
+ },
290
+ modalContent: {
291
+ width: '90%',
292
+ height: '70%',
293
+ borderRadius: 12,
294
+ overflow: 'hidden',
295
+ },
296
+ countryItem: {
297
+ padding: 16,
298
+ borderBottomWidth: 1,
299
+ },
300
+ });
@@ -0,0 +1,32 @@
1
+ import { View, StyleSheet } from 'react-native';
2
+ import { useThemeColors } from '../hooks/useThemeColors';
3
+ import { AppText } from './AppText';
4
+
5
+ export function EmptyList() {
6
+ const themeColors = useThemeColors();
7
+
8
+ return (
9
+ <View
10
+ style={[styles.container, { backgroundColor: themeColors.background }]}
11
+ >
12
+ <AppText
13
+ localization="chat.empty"
14
+ style={[styles.text, { color: themeColors.text }]}
15
+ />
16
+ </View>
17
+ );
18
+ }
19
+
20
+ const styles = StyleSheet.create({
21
+ container: {
22
+ flex: 1,
23
+ alignItems: 'center',
24
+ justifyContent: 'center',
25
+ padding: 20,
26
+ transform: [{ rotate: '180deg' }], //TODO: inverted list
27
+ },
28
+ text: {
29
+ fontSize: 16,
30
+ textAlign: 'center',
31
+ },
32
+ });
@@ -0,0 +1,46 @@
1
+ import { TouchableOpacity, View, StyleSheet } from 'react-native';
2
+ import { useThemeColors } from '../hooks/useThemeColors';
3
+ import { AppText } from './AppText';
4
+
5
+ interface InitFailedProps {
6
+ setInitFailed: (value: boolean) => void;
7
+ }
8
+
9
+ export function InitFailed({ setInitFailed }: InitFailedProps) {
10
+ const themeColors = useThemeColors();
11
+
12
+ return (
13
+ <View
14
+ style={[styles.container, { backgroundColor: themeColors.background }]}
15
+ >
16
+ <TouchableOpacity
17
+ style={[styles.retryButton, { backgroundColor: themeColors.primary }]}
18
+ onPress={() => setInitFailed(false)}
19
+ >
20
+ <AppText
21
+ localization="chat.init.error"
22
+ style={[styles.retryText, { color: themeColors.background }]}
23
+ />
24
+ </TouchableOpacity>
25
+ </View>
26
+ );
27
+ }
28
+
29
+ const styles = StyleSheet.create({
30
+ container: {
31
+ flex: 1,
32
+ alignItems: 'center',
33
+ justifyContent: 'center',
34
+ padding: 20,
35
+ },
36
+ retryButton: {
37
+ padding: 15,
38
+ borderRadius: 8,
39
+ alignItems: 'center',
40
+ justifyContent: 'center',
41
+ },
42
+ retryText: {
43
+ fontSize: 16,
44
+ fontWeight: '500',
45
+ },
46
+ });
@@ -0,0 +1,133 @@
1
+ import {
2
+ StyleSheet,
3
+ TextInput,
4
+ View,
5
+ Image,
6
+ TouchableOpacity,
7
+ } from 'react-native';
8
+ import { useAppStore } from '../store';
9
+ import { useState } from 'react';
10
+ import { sendCustomerMessage } from '../api';
11
+ import { useThemeColors } from '../hooks/useThemeColors';
12
+
13
+ const sendDark = require('../assets/send.png');
14
+
15
+ export function MessageInput({
16
+ scrollToBottom,
17
+ }: {
18
+ scrollToBottom: (animated: boolean) => void;
19
+ }) {
20
+ const [value, setValue] = useState('');
21
+ const customer = useAppStore((s) => s.customer!);
22
+ const themeColors = useThemeColors();
23
+
24
+ const sendMessage = () => {
25
+ if (value.trim()) {
26
+ const date = new Date();
27
+ useAppStore.getState().setData((data) => [
28
+ {
29
+ id: null,
30
+ approved: false,
31
+ content: value,
32
+ created_at: date,
33
+ user: {
34
+ name: customer.name,
35
+ profile_photo_url: null,
36
+ },
37
+ },
38
+ ...(data ?? []),
39
+ ]);
40
+ sendCustomerMessage(customer.external_id, value, {
41
+ fake: useAppStore.getState().fake,
42
+ }).then((res) => {
43
+ const data = useAppStore.getState().data;
44
+ if (data) {
45
+ const itemIndex = data.findIndex(
46
+ (item) =>
47
+ item.id === null &&
48
+ new Date(item.created_at).getTime() === date.getTime()
49
+ );
50
+ if (itemIndex === -1) {
51
+ //TODO:??
52
+ } else {
53
+ const alteredData = [...data];
54
+ alteredData[itemIndex] = {
55
+ id: res.message.id,
56
+ content: res.message.content,
57
+ user: res.message.user ?? alteredData[itemIndex]?.user,
58
+ created_at: new Date(res.message.created_at),
59
+ approved: true,
60
+ };
61
+ useAppStore.setState({
62
+ data: alteredData,
63
+ });
64
+ scrollToBottom(false);
65
+ }
66
+ } else {
67
+ //TODO: ??
68
+ }
69
+ });
70
+ setValue('');
71
+ }
72
+ };
73
+
74
+ return (
75
+ <View
76
+ style={[styles.container, { backgroundColor: themeColors.background }]}
77
+ >
78
+ <TextInput
79
+ value={value}
80
+ onChangeText={(newValue) => setValue(newValue)}
81
+ onSubmitEditing={sendMessage}
82
+ returnKeyType="send"
83
+ style={[
84
+ styles.textInput,
85
+ {
86
+ backgroundColor: themeColors.background,
87
+ color: themeColors.text,
88
+ borderColor: themeColors.border,
89
+ },
90
+ ]}
91
+ placeholder="Type a message..."
92
+ placeholderTextColor={themeColors.text + '80'}
93
+ />
94
+ <TouchableOpacity
95
+ style={[styles.sendButton, { backgroundColor: themeColors.primary }]}
96
+ onPress={sendMessage}
97
+ >
98
+ <Image
99
+ style={[styles.sendIcon, { tintColor: themeColors.text }]}
100
+ source={sendDark}
101
+ />
102
+ </TouchableOpacity>
103
+ </View>
104
+ );
105
+ }
106
+
107
+ const styles = StyleSheet.create({
108
+ container: {
109
+ flexDirection: 'row',
110
+ padding: 10,
111
+ borderTopWidth: 1,
112
+ },
113
+ textInput: {
114
+ flex: 1,
115
+ borderWidth: 1,
116
+ borderRadius: 20,
117
+ paddingHorizontal: 15,
118
+ paddingVertical: 8,
119
+ marginRight: 10,
120
+ fontSize: 16,
121
+ },
122
+ sendButton: {
123
+ width: 40,
124
+ height: 40,
125
+ borderRadius: 20,
126
+ justifyContent: 'center',
127
+ alignItems: 'center',
128
+ },
129
+ sendIcon: {
130
+ width: 20,
131
+ height: 20,
132
+ },
133
+ });
@@ -0,0 +1,141 @@
1
+ import { View, Image } from 'react-native';
2
+ import { AppText } from './AppText';
3
+ import type { AppConversationMessage } from '../types/Conversation';
4
+ import { StyleSheet } from 'react-native';
5
+ import { useThemeColors } from '../hooks/useThemeColors';
6
+
7
+ const clockIcon = require('../assets/clock.png');
8
+ const doubleCheckIcon = require('../assets/double-check.png');
9
+
10
+ export function MessageItem({ item }: { item: AppConversationMessage }) {
11
+ const themeColors = useThemeColors();
12
+ const isDeviceOwner = !!item.user;
13
+ const formattedDate = new Date(item.created_at).toLocaleTimeString([], {
14
+ hour: '2-digit',
15
+ minute: '2-digit',
16
+ });
17
+
18
+ return (
19
+ <View
20
+ key={item.id}
21
+ style={[
22
+ styles.messageItem,
23
+ isDeviceOwner ? styles.rightMessage : styles.leftMessage,
24
+ ]}
25
+ >
26
+ <View
27
+ style={[
28
+ styles.messageBubble,
29
+ isDeviceOwner
30
+ ? [styles.rightBubble, { backgroundColor: themeColors.primary }]
31
+ : [styles.leftBubble, { backgroundColor: themeColors.border }],
32
+ ]}
33
+ >
34
+ <AppText
35
+ style={[
36
+ styles.messageText,
37
+ isDeviceOwner
38
+ ? styles.rightMessageText
39
+ : [styles.leftMessageText, { color: themeColors.text }],
40
+ ]}
41
+ >
42
+ {item.content}
43
+ </AppText>
44
+ <View style={styles.footer}>
45
+ <AppText
46
+ style={[
47
+ styles.timestamp,
48
+ isDeviceOwner
49
+ ? styles.rightTimestamp
50
+ : [styles.leftTimestamp, { color: themeColors.text }],
51
+ ]}
52
+ >
53
+ {formattedDate}
54
+ </AppText>
55
+ {!item.approved ? (
56
+ <Image
57
+ source={clockIcon}
58
+ style={[
59
+ styles.clockIcon,
60
+ isDeviceOwner
61
+ ? styles.rightClockIcon
62
+ : [styles.leftClockIcon, { tintColor: themeColors.text }],
63
+ ]}
64
+ />
65
+ ) : (
66
+ <Image
67
+ source={doubleCheckIcon}
68
+ style={[
69
+ styles.clockIcon,
70
+ isDeviceOwner
71
+ ? styles.rightClockIcon
72
+ : [styles.leftClockIcon, { tintColor: themeColors.text }],
73
+ ]}
74
+ />
75
+ )}
76
+ </View>
77
+ </View>
78
+ </View>
79
+ );
80
+ }
81
+
82
+ const styles = StyleSheet.create({
83
+ messageItem: {
84
+ marginVertical: 5,
85
+ maxWidth: '80%',
86
+ minHeight: 60,
87
+ minWidth: 100,
88
+ },
89
+ leftMessage: {
90
+ alignSelf: 'flex-start',
91
+ },
92
+ rightMessage: {
93
+ alignSelf: 'flex-end',
94
+ },
95
+ messageBubble: {
96
+ padding: 12,
97
+ borderRadius: 20,
98
+ },
99
+ leftBubble: {
100
+ borderTopLeftRadius: 4,
101
+ },
102
+ rightBubble: {
103
+ borderTopRightRadius: 4,
104
+ },
105
+ messageText: {
106
+ fontSize: 16,
107
+ },
108
+ leftMessageText: {
109
+ color: '#000000',
110
+ },
111
+ rightMessageText: {
112
+ color: '#FFFFFF',
113
+ },
114
+ footer: {
115
+ flexDirection: 'row',
116
+ justifyContent: 'space-between',
117
+ alignItems: 'center',
118
+ marginTop: 4,
119
+ },
120
+ timestamp: {
121
+ fontSize: 12,
122
+ opacity: 0.7,
123
+ },
124
+ leftTimestamp: {
125
+ color: '#666666',
126
+ },
127
+ rightTimestamp: {
128
+ color: '#FFFFFF',
129
+ },
130
+ clockIcon: {
131
+ width: 12,
132
+ height: 12,
133
+ marginLeft: 4,
134
+ },
135
+ leftClockIcon: {
136
+ tintColor: '#666666',
137
+ },
138
+ rightClockIcon: {
139
+ tintColor: '#FFFFFF',
140
+ },
141
+ });