@developer_tribe/react-native-comnyx 0.2.0 → 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 (34) hide show
  1. package/lib/commonjs/components/ChatList.js +3 -3
  2. package/lib/commonjs/components/ChatList.js.map +1 -1
  3. package/lib/commonjs/components/CustomerForm.js +72 -6
  4. package/lib/commonjs/components/CustomerForm.js.map +1 -1
  5. package/lib/commonjs/components/MessageInput.js +2 -2
  6. package/lib/commonjs/components/MessageInput.js.map +1 -1
  7. package/lib/commonjs/constants/countries.js +587 -0
  8. package/lib/commonjs/constants/countries.js.map +1 -0
  9. package/lib/commonjs/store.js +1 -1
  10. package/lib/commonjs/store.js.map +1 -1
  11. package/lib/module/components/ChatList.js +3 -3
  12. package/lib/module/components/ChatList.js.map +1 -1
  13. package/lib/module/components/CustomerForm.js +74 -8
  14. package/lib/module/components/CustomerForm.js.map +1 -1
  15. package/lib/module/components/MessageInput.js +2 -2
  16. package/lib/module/components/MessageInput.js.map +1 -1
  17. package/lib/module/constants/countries.js +583 -0
  18. package/lib/module/constants/countries.js.map +1 -0
  19. package/lib/module/store.js +1 -1
  20. package/lib/module/store.js.map +1 -1
  21. package/lib/typescript/commonjs/src/components/ChatList.d.ts.map +1 -1
  22. package/lib/typescript/commonjs/src/components/CustomerForm.d.ts.map +1 -1
  23. package/lib/typescript/commonjs/src/constants/countries.d.ts +6 -0
  24. package/lib/typescript/commonjs/src/constants/countries.d.ts.map +1 -0
  25. package/lib/typescript/module/src/components/ChatList.d.ts.map +1 -1
  26. package/lib/typescript/module/src/components/CustomerForm.d.ts.map +1 -1
  27. package/lib/typescript/module/src/constants/countries.d.ts +6 -0
  28. package/lib/typescript/module/src/constants/countries.d.ts.map +1 -0
  29. package/package.json +1 -1
  30. package/src/components/ChatList.tsx +3 -9
  31. package/src/components/CustomerForm.tsx +105 -8
  32. package/src/components/MessageInput.tsx +1 -1
  33. package/src/constants/countries.ts +200 -0
  34. package/src/store.ts +1 -1
@@ -55,6 +55,7 @@ export function ChatList() {
55
55
  if (nextPageStatus.current) {
56
56
  return;
57
57
  }
58
+ console.log('next');
58
59
  nextPageStatus.current = 'loading';
59
60
  if (customer?.external_id) {
60
61
  const newPage = page + 1;
@@ -111,7 +112,7 @@ export function ChatList() {
111
112
  const currentScrollY = event.nativeEvent.contentOffset.y;
112
113
  const contentHeight = event.nativeEvent.contentSize.height;
113
114
  const scrollViewHeight = event.nativeEvent.layoutMeasurement.height;
114
- setIsScrollingUp(currentScrollY < 100);
115
+ setIsScrollingUp(currentScrollY > 100);
115
116
 
116
117
  if (currentScrollY >= contentHeight - scrollViewHeight - 200) {
117
118
  nextPage();
@@ -158,20 +159,13 @@ export function ChatList() {
158
159
  }
159
160
  return processedMessages;
160
161
  });
161
- scrollToBottom(false);
162
162
  })
163
163
  .catch((e) => {
164
164
  setInitFailed(true);
165
165
  console.error(e);
166
166
  });
167
167
  }
168
- }, [
169
- MESSAGES_PER_PAGE,
170
- customer?.external_id,
171
- initFailed,
172
- scrollToBottom,
173
- setData,
174
- ]);
168
+ }, [MESSAGES_PER_PAGE, customer?.external_id, initFailed, setData]);
175
169
 
176
170
  if (nexPageFailed) {
177
171
  return (
@@ -1,10 +1,20 @@
1
- import { View, TextInput, StyleSheet, TouchableOpacity } from 'react-native';
1
+ import {
2
+ View,
3
+ TextInput,
4
+ StyleSheet,
5
+ TouchableOpacity,
6
+ Modal,
7
+ FlatList,
8
+ Pressable,
9
+ } from 'react-native';
2
10
  import { useForm, Controller } from 'react-hook-form';
3
11
  import { useAppStore } from '../store';
4
12
  import { createCustomer } from '../api';
5
13
  import { AppText } from './AppText';
6
14
  import { useLocalize } from '../hooks/useLocalize';
7
15
  import { useThemeColors } from '../hooks/useThemeColors';
16
+ import { countries } from '../constants/countries';
17
+ import { useState } from 'react';
8
18
 
9
19
  interface CustomerFormData {
10
20
  name: string;
@@ -21,6 +31,7 @@ export function CustomerForm() {
21
31
  } = useForm<CustomerFormData>();
22
32
  const themeColors = useThemeColors();
23
33
  const localize = useLocalize();
34
+ const [isCountryModalVisible, setIsCountryModalVisible] = useState(false);
24
35
 
25
36
  const inputStyle = {
26
37
  ...styles.input,
@@ -88,13 +99,84 @@ export function CustomerForm() {
88
99
  control={control}
89
100
  rules={{ required: true }}
90
101
  render={({ field: { onChange, value } }) => (
91
- <TextInput
92
- style={inputStyle}
93
- placeholder={localize('customer.form.placeholder.country')}
94
- placeholderTextColor="#6C757D"
95
- value={value}
96
- onChangeText={onChange}
97
- />
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
+ </>
98
180
  )}
99
181
  name="country"
100
182
  />
@@ -200,4 +282,19 @@ const styles = StyleSheet.create({
200
282
  marginLeft: 16,
201
283
  top: -16,
202
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
+ },
203
300
  });
@@ -25,7 +25,6 @@ export function MessageInput({
25
25
  if (value.trim()) {
26
26
  const date = new Date();
27
27
  useAppStore.getState().setData((data) => [
28
- ...(data ?? []),
29
28
  {
30
29
  id: null,
31
30
  approved: false,
@@ -36,6 +35,7 @@ export function MessageInput({
36
35
  profile_photo_url: null,
37
36
  },
38
37
  },
38
+ ...(data ?? []),
39
39
  ]);
40
40
  sendCustomerMessage(customer.external_id, value, {
41
41
  fake: useAppStore.getState().fake,
@@ -0,0 +1,200 @@
1
+ export interface Country {
2
+ name: string;
3
+ code: string;
4
+ }
5
+
6
+ export const countries: Country[] = [
7
+ { name: 'Turkey', code: 'TR' },
8
+ { name: 'United States of America', code: 'US' },
9
+ { name: 'Afghanistan', code: 'AF' },
10
+ { name: 'Albania', code: 'AL' },
11
+ { name: 'Algeria', code: 'DZ' },
12
+ { name: 'Andorra', code: 'AD' },
13
+ { name: 'Angola', code: 'AO' },
14
+ { name: 'Antigua and Barbuda', code: 'AG' },
15
+ { name: 'Argentina', code: 'AR' },
16
+ { name: 'Armenia', code: 'AM' },
17
+ { name: 'Australia', code: 'AU' },
18
+ { name: 'Austria', code: 'AT' },
19
+ { name: 'Azerbaijan', code: 'AZ' },
20
+ { name: 'Bahamas', code: 'BS' },
21
+ { name: 'Bahrain', code: 'BH' },
22
+ { name: 'Bangladesh', code: 'BD' },
23
+ { name: 'Barbados', code: 'BB' },
24
+ { name: 'Belarus', code: 'BY' },
25
+ { name: 'Belgium', code: 'BE' },
26
+ { name: 'Belize', code: 'BZ' },
27
+ { name: 'Benin', code: 'BJ' },
28
+ { name: 'Bhutan', code: 'BT' },
29
+ { name: 'Bolivia', code: 'BO' },
30
+ { name: 'Bosnia and Herzegovina', code: 'BA' },
31
+ { name: 'Botswana', code: 'BW' },
32
+ { name: 'Brazil', code: 'BR' },
33
+ { name: 'Brunei', code: 'BN' },
34
+ { name: 'Bulgaria', code: 'BG' },
35
+ { name: 'Burkina Faso', code: 'BF' },
36
+ { name: 'Burundi', code: 'BI' },
37
+ { name: 'Cabo Verde', code: 'CV' },
38
+ { name: 'Cambodia', code: 'KH' },
39
+ { name: 'Cameroon', code: 'CM' },
40
+ { name: 'Canada', code: 'CA' },
41
+ { name: 'Central African Republic', code: 'CF' },
42
+ { name: 'Chad', code: 'TD' },
43
+ { name: 'Chile', code: 'CL' },
44
+ { name: 'China', code: 'CN' },
45
+ { name: 'Colombia', code: 'CO' },
46
+ { name: 'Comoros', code: 'KM' },
47
+ { name: 'Congo', code: 'CG' },
48
+ { name: 'Costa Rica', code: 'CR' },
49
+ { name: 'Croatia', code: 'HR' },
50
+ { name: 'Cuba', code: 'CU' },
51
+ { name: 'Cyprus', code: 'CY' },
52
+ { name: 'Czech Republic', code: 'CZ' },
53
+ { name: 'Denmark', code: 'DK' },
54
+ { name: 'Djibouti', code: 'DJ' },
55
+ { name: 'Dominica', code: 'DM' },
56
+ { name: 'Dominican Republic', code: 'DO' },
57
+ { name: 'Ecuador', code: 'EC' },
58
+ { name: 'Egypt', code: 'EG' },
59
+ { name: 'El Salvador', code: 'SV' },
60
+ { name: 'Equatorial Guinea', code: 'GQ' },
61
+ { name: 'Eritrea', code: 'ER' },
62
+ { name: 'Estonia', code: 'EE' },
63
+ { name: 'Eswatini', code: 'SZ' },
64
+ { name: 'Ethiopia', code: 'ET' },
65
+ { name: 'Fiji', code: 'FJ' },
66
+ { name: 'Finland', code: 'FI' },
67
+ { name: 'France', code: 'FR' },
68
+ { name: 'Gabon', code: 'GA' },
69
+ { name: 'Gambia', code: 'GM' },
70
+ { name: 'Georgia', code: 'GE' },
71
+ { name: 'Germany', code: 'DE' },
72
+ { name: 'Ghana', code: 'GH' },
73
+ { name: 'Greece', code: 'GR' },
74
+ { name: 'Grenada', code: 'GD' },
75
+ { name: 'Guatemala', code: 'GT' },
76
+ { name: 'Guinea', code: 'GN' },
77
+ { name: 'Guinea-Bissau', code: 'GW' },
78
+ { name: 'Guyana', code: 'GY' },
79
+ { name: 'Haiti', code: 'HT' },
80
+ { name: 'Honduras', code: 'HN' },
81
+ { name: 'Hungary', code: 'HU' },
82
+ { name: 'Iceland', code: 'IS' },
83
+ { name: 'India', code: 'IN' },
84
+ { name: 'Indonesia', code: 'ID' },
85
+ { name: 'Iran', code: 'IR' },
86
+ { name: 'Iraq', code: 'IQ' },
87
+ { name: 'Ireland', code: 'IE' },
88
+ { name: 'Israel', code: 'IL' },
89
+ { name: 'Italy', code: 'IT' },
90
+ { name: 'Jamaica', code: 'JM' },
91
+ { name: 'Japan', code: 'JP' },
92
+ { name: 'Jordan', code: 'JO' },
93
+ { name: 'Kazakhstan', code: 'KZ' },
94
+ { name: 'Kenya', code: 'KE' },
95
+ { name: 'Kiribati', code: 'KI' },
96
+ { name: 'Kuwait', code: 'KW' },
97
+ { name: 'Kyrgyzstan', code: 'KG' },
98
+ { name: 'Laos', code: 'LA' },
99
+ { name: 'Latvia', code: 'LV' },
100
+ { name: 'Lebanon', code: 'LB' },
101
+ { name: 'Lesotho', code: 'LS' },
102
+ { name: 'Liberia', code: 'LR' },
103
+ { name: 'Libya', code: 'LY' },
104
+ { name: 'Liechtenstein', code: 'LI' },
105
+ { name: 'Lithuania', code: 'LT' },
106
+ { name: 'Luxembourg', code: 'LU' },
107
+ { name: 'Madagascar', code: 'MG' },
108
+ { name: 'Malawi', code: 'MW' },
109
+ { name: 'Malaysia', code: 'MY' },
110
+ { name: 'Maldives', code: 'MV' },
111
+ { name: 'Mali', code: 'ML' },
112
+ { name: 'Malta', code: 'MT' },
113
+ { name: 'Marshall Islands', code: 'MH' },
114
+ { name: 'Mauritania', code: 'MR' },
115
+ { name: 'Mauritius', code: 'MU' },
116
+ { name: 'Mexico', code: 'MX' },
117
+ { name: 'Micronesia', code: 'FM' },
118
+ { name: 'Moldova', code: 'MD' },
119
+ { name: 'Monaco', code: 'MC' },
120
+ { name: 'Mongolia', code: 'MN' },
121
+ { name: 'Montenegro', code: 'ME' },
122
+ { name: 'Morocco', code: 'MA' },
123
+ { name: 'Mozambique', code: 'MZ' },
124
+ { name: 'Myanmar', code: 'MM' },
125
+ { name: 'Namibia', code: 'NA' },
126
+ { name: 'Nauru', code: 'NR' },
127
+ { name: 'Nepal', code: 'NP' },
128
+ { name: 'Netherlands', code: 'NL' },
129
+ { name: 'New Zealand', code: 'NZ' },
130
+ { name: 'Nicaragua', code: 'NI' },
131
+ { name: 'Niger', code: 'NE' },
132
+ { name: 'Nigeria', code: 'NG' },
133
+ { name: 'North Korea', code: 'KP' },
134
+ { name: 'North Macedonia', code: 'MK' },
135
+ { name: 'Norway', code: 'NO' },
136
+ { name: 'Oman', code: 'OM' },
137
+ { name: 'Pakistan', code: 'PK' },
138
+ { name: 'Palau', code: 'PW' },
139
+ { name: 'Panama', code: 'PA' },
140
+ { name: 'Papua New Guinea', code: 'PG' },
141
+ { name: 'Paraguay', code: 'PY' },
142
+ { name: 'Peru', code: 'PE' },
143
+ { name: 'Philippines', code: 'PH' },
144
+ { name: 'Poland', code: 'PL' },
145
+ { name: 'Portugal', code: 'PT' },
146
+ { name: 'Qatar', code: 'QA' },
147
+ { name: 'Romania', code: 'RO' },
148
+ { name: 'Russia', code: 'RU' },
149
+ { name: 'Rwanda', code: 'RW' },
150
+ { name: 'Saint Kitts and Nevis', code: 'KN' },
151
+ { name: 'Saint Lucia', code: 'LC' },
152
+ { name: 'Saint Vincent and the Grenadines', code: 'VC' },
153
+ { name: 'Samoa', code: 'WS' },
154
+ { name: 'San Marino', code: 'SM' },
155
+ { name: 'Sao Tome and Principe', code: 'ST' },
156
+ { name: 'Saudi Arabia', code: 'SA' },
157
+ { name: 'Senegal', code: 'SN' },
158
+ { name: 'Serbia', code: 'RS' },
159
+ { name: 'Seychelles', code: 'SC' },
160
+ { name: 'Sierra Leone', code: 'SL' },
161
+ { name: 'Singapore', code: 'SG' },
162
+ { name: 'Slovakia', code: 'SK' },
163
+ { name: 'Slovenia', code: 'SI' },
164
+ { name: 'Solomon Islands', code: 'SB' },
165
+ { name: 'Somalia', code: 'SO' },
166
+ { name: 'South Africa', code: 'ZA' },
167
+ { name: 'South Korea', code: 'KR' },
168
+ { name: 'South Sudan', code: 'SS' },
169
+ { name: 'Spain', code: 'ES' },
170
+ { name: 'Sri Lanka', code: 'LK' },
171
+ { name: 'Sudan', code: 'SD' },
172
+ { name: 'Suriname', code: 'SR' },
173
+ { name: 'Sweden', code: 'SE' },
174
+ { name: 'Switzerland', code: 'CH' },
175
+ { name: 'Syria', code: 'SY' },
176
+ { name: 'Taiwan', code: 'TW' },
177
+ { name: 'Tajikistan', code: 'TJ' },
178
+ { name: 'Tanzania', code: 'TZ' },
179
+ { name: 'Thailand', code: 'TH' },
180
+ { name: 'Timor-Leste', code: 'TL' },
181
+ { name: 'Togo', code: 'TG' },
182
+ { name: 'Tonga', code: 'TO' },
183
+ { name: 'Trinidad and Tobago', code: 'TT' },
184
+ { name: 'Tunisia', code: 'TN' },
185
+ { name: 'Turkmenistan', code: 'TM' },
186
+ { name: 'Tuvalu', code: 'TV' },
187
+ { name: 'Uganda', code: 'UG' },
188
+ { name: 'Ukraine', code: 'UA' },
189
+ { name: 'United Arab Emirates', code: 'AE' },
190
+ { name: 'United Kingdom', code: 'GB' },
191
+ { name: 'Uruguay', code: 'UY' },
192
+ { name: 'Uzbekistan', code: 'UZ' },
193
+ { name: 'Vanuatu', code: 'VU' },
194
+ { name: 'Vatican City', code: 'VA' },
195
+ { name: 'Venezuela', code: 'VE' },
196
+ { name: 'Vietnam', code: 'VN' },
197
+ { name: 'Yemen', code: 'YE' },
198
+ { name: 'Zambia', code: 'ZM' },
199
+ { name: 'Zimbabwe', code: 'ZW' }
200
+ ];
package/src/store.ts CHANGED
@@ -64,7 +64,7 @@ const storeCreator: StateCreator<AppStoreState> = (set, get) => ({
64
64
 
65
65
  export const useAppStore = createWithEqualityFn<AppStoreState>()(
66
66
  persist(storeCreator, {
67
- name: 'appStore-9',
67
+ name: 'commonyx_appStore-10',
68
68
  storage: createJSONStorage(() => AsyncStorage),
69
69
  skipHydration: false,
70
70
  partialize: (state) => ({