ordering-ui-react-native 0.22.42 → 0.22.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.22.42",
3
+ "version": "0.22.43",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -1,5 +1,6 @@
1
1
  import React, { useEffect, useState } from 'react'
2
- import { Dimensions, StyleSheet, TouchableOpacity, View } from 'react-native';
2
+ import { Dimensions, SafeAreaView, StyleSheet, View } from 'react-native';
3
+ import SelectDropdown from 'react-native-select-dropdown'
3
4
  import { useLanguage } from 'ordering-components/native'
4
5
  import { useTheme } from 'styled-components/native'
5
6
  import { useForm, Controller } from 'react-hook-form';
@@ -17,7 +18,31 @@ import {
17
18
  } from './styles'
18
19
 
19
20
  import { Container } from '../../layouts/Container'
20
- import { OText, OInput, OIcon } from '../shared'
21
+ import { OText, OInput, OIcon, OButton } from '../shared'
22
+
23
+ const printerList = [
24
+ { nickname: 'mPOP', model: 'mPOP', emulation: 'StarPRNT', portName1: 'BT:mPOP', type: 1, ip: '', printMode: 'append' },
25
+ { nickname: 'FVP10', model: 'FVP10', emulation: 'StarLine', portName1: 'BT:FVP10', type: 1, ip: '', printMode: 'append' },
26
+ { nickname: 'TSP100', model: 'TSP100', emulation: 'StarGraphic', portName1: 'BT:TSP100', type: 1, ip: '', printMode: 'appendBitmapText' },
27
+ { nickname: 'TSP100IV', model: 'TSP100IV', emulation: 'StarLine', portName1: 'BT:TSP100iv', type: 1, ip: '', printMode: 'append' },
28
+ { nickname: 'TSP65011', model: 'TSP65011', emulation: 'StarLine', portName1: 'BT:TSP65011', type: 1, ip: '', printMode: 'append' },
29
+ { nickname: 'TSP7001', model: 'TSP7001', emulation: 'StarLine', portName1: 'BT:TSP7001', type: 1, ip: '', printMode: 'append' },
30
+ { nickname: 'TSP80011', model: 'TSP80011', emulation: 'StarLine', portName1: 'BT:TSP80011', type: 1, ip: '', printMode: 'append' },
31
+ { nickname: 'SP700', model: 'SP700', emulation: 'StarDotImpact', portName1: 'BT:SP700', type: 1, ip: '', printMode: 'append' },
32
+ { nickname: 'SM-S210i', model: 'SM-S210i', emulation: 'EscPosMobile', portName1: 'BT:SMS210i', type: 1, ip: '', printMode: 'append' },
33
+ { nickname: 'SM-S220i', model: 'SM-S220i', emulation: 'EscPosMobile', portName1: 'BT:SMS220i', type: 1, ip: '', printMode: 'append' },
34
+ { nickname: 'SM-S230i', model: 'SM-S230i', emulation: 'EscosMobile', portName1: 'BT:SMS230i', type: 1, ip: '', printMode: 'append' },
35
+ { nickname: 'SM-T300i/T300', model: 'SM-T300i/T300', emulation: 'EscPosMobile', portName1: 'BT:SMT300i/T300', type: 1, ip: '', printMode: 'append' },
36
+ { nickname: 'SM-T400i', model: 'SM-T400i', emulation: 'EscosMobile', portName1: 'BT:SMT400i', type: 1, ip: '', printMode: 'append' },
37
+ { nickname: 'SM-L200', model: 'SM-L200', emulation: 'StarPRNT', portName1: 'BT:SML200', type: 1, ip: '', printMode: 'append' },
38
+ { nickname: 'SM-L300', model: 'SM-L300', emulation: 'StarPRNT', portName1: 'BT:SML300', type: 1, ip: '', printMode: 'append' },
39
+ { nickname: 'BSC10', model: 'BSC10', emulation: 'EscPos', portName1: 'BT:BSC10', type: 1, ip: '', printMode: 'append' },
40
+ { nickname: 'SM-S210i StarPRNT', model: 'SM-S210i StarPRNT', emulation: 'StarPRNT', portName1: 'BT:SMS210i', type: 1, ip: '', printMode: 'append' },
41
+ { nickname: 'SM-S220i StarPRNT', model: 'SM-S220i StarPRNT', emulation: 'StarPRNT', portName1: 'BT:SMS220i', type: 1, ip: '', printMode: 'append' },
42
+ { nickname: 'SM-S230i StarPRNT', model: 'SM-S230i StarPRNT', emulation: 'StarPRNT', portName1: 'BT:SMS230i', type: 1, ip: '', printMode: 'append' },
43
+ { nickname: 'SM-T300i/T300 StarPRNT', model: 'SM-T300i/T300 StarPRNT', emulation: 'StarPRNT', portName1: 'BT:SMT300i', type: 1, ip: '', printMode: 'append' },
44
+ { nickname: 'SM-T400i StarPRNT', model: 'SM-T400i StarPRNT', emulation: 'StarPRNT', portName1: 'BT:SMT400i', type: 1, ip: '', printMode: 'append' },
45
+ ]
21
46
 
22
47
  export const PrinterEdition = (props: any) => {
23
48
  const {
@@ -25,13 +50,15 @@ export const PrinterEdition = (props: any) => {
25
50
  onClose
26
51
  } = props
27
52
 
28
- const WIDTH_SCREEN = Dimensions.get('window').width
53
+ const HEIGHT_SCREEN = Dimensions.get('window').height
29
54
  const [, t] = useLanguage()
30
55
  const theme = useTheme()
31
56
  const { handleSubmit, control, setValue, watch } = useForm();
32
57
 
33
58
  const watchIp = watch('ip')
59
+ const watchNickname = watch('nickname')
34
60
  const isErrorIp = !/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i.test(watchIp)
61
+ const isErrorNickname = watchNickname && !/^[a-zA-Z0-9\s]+$/i.test(watchNickname)
35
62
 
36
63
  const [currentPrinter, setCurrentPrinter] = useState(printer)
37
64
 
@@ -49,24 +76,36 @@ export const PrinterEdition = (props: any) => {
49
76
  height: 40,
50
77
  borderWidth: 1,
51
78
  borderRadius: 8,
79
+ },
80
+ savePrinterBtnText: {
81
+ color: theme.colors.white,
82
+ fontSize: 18,
83
+ },
84
+ savePrinterBtn: {
85
+ height: 44,
86
+ borderRadius: 8,
87
+ marginHorizontal: 20
52
88
  }
53
89
  })
54
90
 
55
91
  const handleChangePrinter = (values: any) => {
56
92
  props.handleChangePrinter({
57
93
  ...values,
58
- item: currentPrinter,
94
+ index: currentPrinter?.index ?? null,
95
+ type: currentPrinter?.type,
96
+ ip: currentPrinter?.ip,
97
+ item: currentPrinter
59
98
  })
60
99
  }
61
100
 
62
- const onSubmit = ({ ip }: any) => {
63
- handleChangePrinter({ type: 2, ip, edit: true })
101
+ const onSubmit = () => {
102
+ handleChangePrinter({ edit: !!printer, isAdd: !printer })
64
103
  onClose && onClose()
65
104
  }
66
105
 
67
106
  useEffect(() => {
68
- console.log(currentPrinter, isErrorIp)
69
107
  currentPrinter?.ip && setValue('ip', currentPrinter?.ip)
108
+ currentPrinter?.nickname && setValue('nickname', currentPrinter?.nickname)
70
109
  }, [currentPrinter?.type])
71
110
 
72
111
  useEffect(() => {
@@ -74,7 +113,8 @@ export const PrinterEdition = (props: any) => {
74
113
  }, [printer])
75
114
 
76
115
  return (
77
- <Container>
116
+ <SafeAreaView style={{ flex: 1, marginBottom: 20 }}>
117
+ <Container>
78
118
  <ContainerEdition>
79
119
  <BackArrowWrapper>
80
120
  <BackArrow activeOpacity={1} onPress={() => onClose()}>
@@ -99,120 +139,225 @@ export const PrinterEdition = (props: any) => {
99
139
  size={22}
100
140
  style={{ paddingTop: 0 }}
101
141
  >
102
- {printer.model}
142
+ {t('PRINTER_CONFIGURE', 'Printer Configure')}
103
143
  </OText>
104
144
  </WrapperHeader>
105
145
 
106
- <WrapperIcons>
107
- <OText
108
- size={20}
109
- style={{ paddingTop: 0, marginBottom: 10 }}
110
- >
111
- {`${t('CONNECTION_TYPE', 'Connection type')}:`}
112
- </OText>
113
- <WrapperIcon
114
- activeOpacity={1}
115
- style={{
116
- borderColor: currentPrinter?.type === 1 ? theme.colors.primary : theme.colors.textGray
117
- }}
118
- onPress={() => {
119
- setCurrentPrinter({ ...printer, type: 1 })
120
- handleChangePrinter({ type: 1, ip: null, edit: true })
121
- }}
122
- >
123
- <FAIcons
124
- name='bluetooth'
125
- size={22}
126
- {...(currentPrinter?.type === 1 ? { color: theme.colors.primary } : {})}
127
- style={styles.optionIcons}
128
- />
146
+ <SelectDropdown
147
+ data={printerList}
148
+ defaultValueByIndex={printerList.findIndex(p => p.model === currentPrinter?.model)}
149
+ dropdownOverlayColor='transparent'
150
+ defaultButtonText={t('SELECT_PRINTER', 'Select printer')}
151
+ buttonTextAfterSelection={item => item.model}
152
+ rowTextForSelection={item => item.model}
153
+ renderDropdownIcon={() => dropDownIcon()}
154
+ buttonStyle={{
155
+ width: '100%',
156
+ backgroundColor: theme.colors.primary,
157
+ borderRadius: 8,
158
+ flexDirection: 'row-reverse',
159
+ justifyContent: 'space-between',
160
+ alignItems: 'center',
161
+ height: 44,
162
+ marginTop: 20,
163
+ }}
164
+ buttonTextStyle={{
165
+ color: theme.colors.white,
166
+ fontSize: 18,
167
+ textAlign: 'left',
168
+ marginHorizontal: 0
169
+ }}
170
+ dropdownStyle={{
171
+ borderRadius: 8,
172
+ borderColor: theme.colors.primary,
173
+ maxHeight: HEIGHT_SCREEN * 0.3
174
+ }}
175
+ rowStyle={{
176
+ borderBottomColor: theme.colors.disabled,
177
+ backgroundColor: theme.colors.gray100,
178
+ height: 40,
179
+ flexDirection: 'column',
180
+ alignItems: 'flex-start',
181
+ paddingTop: 8,
182
+ paddingHorizontal: 14,
183
+ width: '100%'
184
+ }}
185
+ rowTextStyle={{
186
+ marginHorizontal: 0,
187
+ fontSize: 14,
188
+ }}
189
+ onSelect={item => setCurrentPrinter(item)}
190
+ />
191
+ {!!currentPrinter && (
192
+ <WrapperIcons>
129
193
  <OText
130
- size={18}
131
- style={{ paddingTop: 0 }}
194
+ size={20}
195
+ style={{ paddingTop: 0, marginBottom: 10 }}
132
196
  >
133
- {t('CONNECTION_VIA_BLUETOOTH', 'Via Bluetooth')}
197
+ {`${t('PRINTER_NICKNAME', 'Nickname')}:`}
134
198
  </OText>
135
- </WrapperIcon>
136
- <WrapperIcon
137
- activeOpacity={1}
138
- style={{
139
- borderColor: currentPrinter?.type === 2 ? theme.colors.primary : theme.colors.textGray
140
- }}
141
- onPress={() => setCurrentPrinter({ ...printer, type: 2 })}
142
- >
143
- <MCIcons
144
- name='access-point-network'
145
- size={22}
146
- {...(currentPrinter?.type === 2 ? { color: theme.colors.primary } : {})}
147
- style={styles.optionIcons}
199
+ <Controller
200
+ control={control}
201
+ name={'nickname'}
202
+ rules={{
203
+ pattern: {
204
+ value: /^[a-zA-Z0-9\s]+$/i,
205
+ message: t('INVALID_ERROR_PRINTER_NICKNAME', 'Invalid Nickname')
206
+ }
207
+ }}
208
+ defaultValue={currentPrinter?.ip ?? ''}
209
+ render={() => (
210
+ <OInput
211
+ placeholder={`${t('EXAMPLE_SHORT', 'Ex:')} ${t('NICKNAME_EXAMPLE_TEXT', 'Kitchen printer')}`}
212
+ placeholderTextColor={theme.colors.arrowColor}
213
+ style={{
214
+ ...styles.inputStyle,
215
+ borderColor: isErrorNickname ? theme.colors.danger500 : theme.colors.tabBar,
216
+ marginBottom: 10
217
+ }}
218
+ value={currentPrinter?.nickname ?? ''}
219
+ selectionColor={theme.colors.primary}
220
+ color={theme.colors.textGray}
221
+ onChange={(value: any) => {
222
+ setValue('nickname', value)
223
+ setCurrentPrinter({
224
+ ...currentPrinter,
225
+ nickname: value
226
+ })
227
+ }}
228
+ />
229
+ )}
148
230
  />
149
231
  <OText
150
- size={18}
151
- style={{ paddingTop: 0 }}
232
+ size={20}
233
+ style={{ paddingTop: 0, marginBottom: 10 }}
152
234
  >
153
- {t('CONNECTION_VIA_LAN', 'Via LAN')}
235
+ {`${t('CONNECTION_TYPE', 'Connection type')}:`}
154
236
  </OText>
155
- </WrapperIcon>
156
- {currentPrinter?.type === 2 && (
157
- <>
158
- <View style={{ flexDirection: 'row' }}>
159
- <Controller
160
- control={control}
161
- name={'ip'}
162
- rules={{
163
- required: t('VALIDATION_ERROR_IP_ADDRESS_REQUIRED', 'Ip address is required'),
164
- pattern: {
165
- value: /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i,
166
- message: t('INVALID_ERROR_IP_ADDRESS', 'Invalid ip address')
167
- }
168
- }}
169
- defaultValue={currentPrinter?.ip ?? ''}
170
- render={() => (
171
- <OInput
172
- placeholder={t('IP_ADDRESS', 'Ip address')}
173
- placeholderTextColor={theme.colors.arrowColor}
174
- style={{
175
- ...styles.inputStyle,
176
- borderColor: isErrorIp ? theme.colors.danger500 : theme.colors.tabBar
177
- }}
178
- value={currentPrinter?.ip ?? ''}
179
- selectionColor={theme.colors.primary}
180
- color={theme.colors.textGray}
181
- onChange={(value: any) => {
182
- setValue('ip', value)
183
- setCurrentPrinter({
184
- ...currentPrinter,
185
- ip: value
186
- })
187
- }}
188
- />
189
- )}
190
- />
191
- <TouchableOpacity
192
- activeOpacity={1}
193
- disabled={isErrorIp}
194
- onPress={handleSubmit(onSubmit)}
195
- style={{ width: 40 }}
196
- >
197
- <FeatherIcon
198
- name='save'
199
- size={20}
200
- color={isErrorIp ? theme.colors.tabBar : theme.colors.primary }
201
- style={{ ...styles.icons, paddingRight: 0 }}
202
- />
203
- </TouchableOpacity>
204
- </View>
237
+ <WrapperIcon
238
+ activeOpacity={1}
239
+ style={{
240
+ borderColor: currentPrinter?.type === 1 ? theme.colors.primary : theme.colors.textGray
241
+ }}
242
+ onPress={() => {
243
+ setCurrentPrinter({
244
+ ...currentPrinter,
245
+ type: 1,
246
+ ip: '',
247
+ portName: currentPrinter?.portName1
248
+ })
249
+ }}
250
+ >
251
+ <FAIcons
252
+ name='bluetooth'
253
+ size={22}
254
+ {...(currentPrinter?.type === 1 ? { color: theme.colors.primary } : {})}
255
+ style={styles.optionIcons}
256
+ />
257
+ <OText
258
+ size={18}
259
+ style={{ paddingTop: 0 }}
260
+ >
261
+ {t('CONNECTION_VIA_BLUETOOTH', 'Via Bluetooth')}
262
+ </OText>
263
+ </WrapperIcon>
264
+ <WrapperIcon
265
+ activeOpacity={1}
266
+ style={{
267
+ borderColor: currentPrinter?.type === 2 ? theme.colors.primary : theme.colors.textGray
268
+ }}
269
+ onPress={() => setCurrentPrinter({ ...currentPrinter, type: 2 })}
270
+ >
271
+ <MCIcons
272
+ name='access-point-network'
273
+ size={22}
274
+ {...(currentPrinter?.type === 2 ? { color: theme.colors.primary } : {})}
275
+ style={styles.optionIcons}
276
+ />
205
277
  <OText
206
- size={14}
207
- color={theme.colors.tabBar}
208
- style={{ paddingTop: 5, paddingLeft: 10 }}
278
+ size={18}
279
+ style={{ paddingTop: 0 }}
209
280
  >
210
- {`${t('EXAMPLE_SHORT', 'Ex:')} 8.8.8.8`}
281
+ {t('CONNECTION_VIA_LAN', 'Via LAN')}
211
282
  </OText>
212
- </>
213
- )}
214
- </WrapperIcons>
283
+ </WrapperIcon>
284
+ {currentPrinter?.type === 2 && (
285
+ <>
286
+ <View style={{ flexDirection: 'row' }}>
287
+ <Controller
288
+ control={control}
289
+ name={'ip'}
290
+ rules={{
291
+ required: t('VALIDATION_ERROR_IP_ADDRESS_REQUIRED', 'Ip address is required'),
292
+ pattern: {
293
+ value: /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i,
294
+ message: t('INVALID_ERROR_IP_ADDRESS', 'Invalid ip address')
295
+ }
296
+ }}
297
+ defaultValue={currentPrinter?.ip ?? ''}
298
+ render={() => (
299
+ <OInput
300
+ placeholder={t('IP_ADDRESS', 'Ip address')}
301
+ placeholderTextColor={theme.colors.arrowColor}
302
+ style={{
303
+ ...styles.inputStyle,
304
+ borderColor: isErrorIp ? theme.colors.danger500 : theme.colors.tabBar
305
+ }}
306
+ value={currentPrinter?.ip ?? ''}
307
+ selectionColor={theme.colors.primary}
308
+ color={theme.colors.textGray}
309
+ onChange={(value: any) => {
310
+ setValue('ip', value)
311
+ setCurrentPrinter({
312
+ ...currentPrinter,
313
+ ip: value
314
+ })
315
+ }}
316
+ />
317
+ )}
318
+ />
319
+ </View>
320
+ <OText
321
+ size={14}
322
+ color={theme.colors.tabBar}
323
+ style={{ paddingTop: 5, paddingLeft: 10 }}
324
+ >
325
+ {`${t('EXAMPLE_SHORT', 'Ex:')} 8.8.8.8`}
326
+ </OText>
327
+ </>
328
+ )}
329
+ </WrapperIcons>
330
+ )}
215
331
  </ContainerEdition>
216
332
  </Container>
333
+ <View>
334
+ <OButton
335
+ text={t('SAVE_PRINTER', 'Save Printer')}
336
+ imgRightSrc={null}
337
+ textStyle={styles.savePrinterBtnText}
338
+ style={styles.savePrinterBtn}
339
+ bgColor={theme.colors.primary}
340
+ borderColor={theme.colors.primary}
341
+ isDisabled={
342
+ isErrorNickname ||
343
+ !currentPrinter?.model ||
344
+ currentPrinter?.type === 2 && !currentPrinter?.ip
345
+ }
346
+ onClick={() => onSubmit()}
347
+ />
348
+ </View>
349
+ </SafeAreaView>
350
+ )
351
+ }
352
+
353
+ const dropDownIcon = () => {
354
+ const theme = useTheme()
355
+
356
+ return (
357
+ <FeatherIcon
358
+ name='chevron-down'
359
+ size={20}
360
+ color={theme.colors.white}
361
+ />
217
362
  )
218
363
  }
@@ -2,14 +2,13 @@ import React, { useEffect, useState } from 'react'
2
2
  import { StyleSheet, TouchableOpacity, View, Dimensions } from 'react-native'
3
3
  import SimpleLineIcons from 'react-native-vector-icons/SimpleLineIcons'
4
4
  import FeatherIcon from 'react-native-vector-icons/Feather'
5
- import MCIcons from 'react-native-vector-icons/MaterialCommunityIcons'
6
5
  import { useTheme } from 'styled-components/native'
7
6
  import ToggleSwitch from 'toggle-switch-react-native';
8
7
  import { useLanguage } from 'ordering-components/native'
9
8
 
10
9
  import { _setStoreData, _retrieveStoreData } from '../../providers/StoreUtil'
11
- import { Container, ContainerList, EnabledAutoPrint } from './styles'
12
- import { OText, OIcon, OModal } from '../shared'
10
+ import { Container, ContainerList, EnabledAutoPrint, NoPrintersContainer } from './styles'
11
+ import { OText, OIcon, OModal, OButton } from '../shared'
13
12
  import { PrinterEdition } from '../PrinterEdition'
14
13
 
15
14
  export const PrinterSettings = (props: any) => {
@@ -17,9 +16,10 @@ export const PrinterSettings = (props: any) => {
17
16
 
18
17
  const [printers, setPrinters] = useState<any>({ list: [] })
19
18
  const [autoPrintEnabled, setAutoPrintEnabled] = useState<boolean>(false)
20
- const [openModal, setOpenModal] = useState({ open: false, data: null })
19
+ const [openModal, setOpenModal] = useState<any>({ open: false, data: null })
21
20
 
22
21
  const WIDTH_SCREEN = Dimensions.get('window').width
22
+ const HEIGHT_SCREEN = Dimensions.get('window').height
23
23
 
24
24
  const [, t] = useLanguage()
25
25
  const theme = useTheme()
@@ -40,7 +40,7 @@ export const PrinterSettings = (props: any) => {
40
40
  wIconContainer: {
41
41
  flexDirection: 'row',
42
42
  alignItems: 'center',
43
- width: WIDTH_SCREEN - 60 - 10 - 26
43
+ width: WIDTH_SCREEN - 40 - 22 - 22 - 10, // screen - margin - icon - icon - marginIcon
44
44
  },
45
45
  wrapperContainer: {
46
46
  flexDirection: 'column',
@@ -55,9 +55,6 @@ export const PrinterSettings = (props: any) => {
55
55
  borderWidth: 1,
56
56
  borderRadius: 8,
57
57
  },
58
- label: {
59
- color: theme.colors.textGray
60
- },
61
58
  btnBackArrow: {
62
59
  borderWidth: 0,
63
60
  width: 32,
@@ -74,40 +71,28 @@ export const PrinterSettings = (props: any) => {
74
71
  flexDirection: 'row',
75
72
  minHeight: 33,
76
73
  },
74
+ addButtonText: {
75
+ color: theme.colors.inputTextColor,
76
+ fontSize: 16,
77
+ },
78
+ addButton: {
79
+ height: 40,
80
+ marginTop: 10,
81
+ borderRadius: 8,
82
+ marginRight: 10,
83
+ marginBottom: 10,
84
+ },
77
85
  })
78
86
 
79
- const printerList = [
80
- { model: 'mPOP', emulation: 'StarPRNT', portName1: 'BT:mPOP', type: 1, ip: '', printMode: 'append' },
81
- { model: 'FVP10', emulation: 'StarLine', portName1: 'BT:FVP10', type: 1, ip: '', printMode: 'append' },
82
- { model: 'TSP100', emulation: 'StarGraphic', portName1: 'BT:TSP100', type: 1, ip: '', printMode: 'appendBitmapText' },
83
- { model: 'TSP100IV', emulation: 'StarLine', portName1: 'BT:TSP100iv', type: 1, ip: '', printMode: 'append' },
84
- { model: 'TSP65011', emulation: 'StarLine', portName1: 'BT:TSP65011', type: 1, ip: '', printMode: 'append' },
85
- { model: 'TSP7001', emulation: 'StarLine', portName1: 'BT:TSP7001', type: 1, ip: '', printMode: 'append' },
86
- { model: 'TSP80011', emulation: 'StarLine', portName1: 'BT:TSP80011', type: 1, ip: '', printMode: 'append' },
87
- { model: 'SP700', emulation: 'StarDotImpact', portName1: 'BT:SP700', type: 1, ip: '', printMode: 'append' },
88
- { model: 'SM-S210i', emulation: 'EscPosMobile', portName1: 'BT:SMS210i', type: 1, ip: '', printMode: 'append' },
89
- { model: 'SM-S220i', emulation: 'EscPosMobile', portName1: 'BT:SMS220i', type: 1, ip: '', printMode: 'append' },
90
- { model: 'SM-S230i', emulation: 'EscosMobile', portName1: 'BT:SMS230i', type: 1, ip: '', printMode: 'append' },
91
- { model: 'SM-T300i/T300', emulation: 'EscPosMobile', portName1: 'BT:SMT300i/T300', type: 1, ip: '', printMode: 'append' },
92
- { model: 'SM-T400i', emulation: 'EscosMobile', portName1: 'BT:SMT400i', type: 1, ip: '', printMode: 'append' },
93
- { model: 'SM-L200', emulation: 'StarPRNT', portName1: 'BT:SML200', type: 1, ip: '', printMode: 'append' },
94
- { model: 'SM-L300', emulation: 'StarPRNT', portName1: 'BT:SML300', type: 1, ip: '', printMode: 'append' },
95
- { model: 'BSC10', emulation: 'EscPos', portName1: 'BT:BSC10', type: 1, ip: '', printMode: 'append' },
96
- { model: 'SM-S210i StarPRNT', emulation: 'StarPRNT', portName1: 'BT:SMS210i', type: 1, ip: '', printMode: 'append' },
97
- { model: 'SM-S220i StarPRNT', emulation: 'StarPRNT', portName1: 'BT:SMS220i', type: 1, ip: '', printMode: 'append' },
98
- { model: 'SM-S230i StarPRNT', emulation: 'StarPRNT', portName1: 'BT:SMS230i', type: 1, ip: '', printMode: 'append' },
99
- { model: 'SM-T300i/T300 StarPRNT', emulation: 'StarPRNT', portName1: 'BT:SMT300i', type: 1, ip: '', printMode: 'append' },
100
- { model: 'SM-T400i StarPRNT', emulation: 'StarPRNT', portName1: 'BT:SMT400i', type: 1, ip: '', printMode: 'append' },
101
- ]
102
-
103
87
  const goToBack = () => navigation?.canGoBack() && navigation.goBack()
104
88
 
105
- const handleClick = async ({ item, type, ip, edit }: any) => {
89
+ const handleClick = async ({ item, type, ip, edit, isAdd, index }: any) => {
106
90
  let _item = item
91
+ const action = edit || isAdd
107
92
  let _printers = printers.list
108
- const idx = _printers.findIndex((p: any) => p.model === _item.model)
93
+ const idx = index ?? _printers.findIndex((p: any) => p.model === _item.model)
109
94
 
110
- if (idx !== -1 && !edit) {
95
+ if (idx !== -1 && !action) {
111
96
  _printers.splice(idx, 1);
112
97
  } else {
113
98
  const _currentPrinter = _printers.find((p: any) => p.model === _item?.model)
@@ -154,43 +139,50 @@ export const PrinterSettings = (props: any) => {
154
139
  <OText size={24} style={{ paddingTop: 0 }}>
155
140
  {t('PRINTER_SETTINGS', 'Printer Settings')}
156
141
  </OText>
157
- <EnabledAutoPrint>
158
- <View style={{ flex: 1 }}>
159
- <OText
160
- numberOfLines={2}
161
- adjustsFontSizeToFit
162
- style={{ ...styles.label, paddingHorizontal: 0 }}>
163
- {t('AUTO_PRINT_AFTER_ACCEPTING_ORDER', 'Auto print after accepting order')}
164
- </OText>
165
- </View>
166
- <ToggleSwitch
167
- isOn={autoPrintEnabled}
168
- onColor={theme.colors.primary}
169
- offColor={theme.colors.offColor}
170
- size="small"
171
- onToggle={() => handleAutoPrint()}
172
- animationSpeed={200}
142
+ {!!printers.list.length && (
143
+ <EnabledAutoPrint>
144
+ <View style={{ flex: 1 }}>
145
+ <OText
146
+ numberOfLines={2}
147
+ adjustsFontSizeToFit
148
+ color={theme.colors.textGray}
149
+ style={{ paddingHorizontal: 0 }}>
150
+ {t('AUTO_PRINT_AFTER_ACCEPTING_ORDER', 'Auto print after accepting order')}
151
+ </OText>
152
+ </View>
153
+ <ToggleSwitch
154
+ isOn={autoPrintEnabled}
155
+ onColor={theme.colors.primary}
156
+ offColor={theme.colors.offColor}
157
+ size="small"
158
+ onToggle={() => handleAutoPrint()}
159
+ animationSpeed={200}
160
+ />
161
+ </EnabledAutoPrint>
162
+ )}
163
+ {!!printers.list.length && (
164
+ <OButton
165
+ text={t('ADD_PRINTER', 'Add printer')}
166
+ imgRightSrc={null}
167
+ textStyle={styles.addButtonText}
168
+ style={styles.addButton}
169
+ bgColor={theme.colors.primary}
170
+ borderColor={theme.colors.primary}
171
+ onClick={() => setOpenModal({ open: true, data: null })}
173
172
  />
174
- </EnabledAutoPrint>
173
+ )}
175
174
  <View>
176
- {printerList.map((item: any, i: number) => (
175
+ {printers.list.map((item: any, i: number) => (
177
176
  <ContainerList
178
177
  key={i}
179
178
  activeOpacity={1}
180
- onPress={() => handleClick({ item })}
181
179
  >
182
180
  <View style={styles.wrapperContainer}>
183
181
  <View style={{ flexDirection: 'row', alignItems: 'center' }}>
184
- <MCIcons
185
- name={printers.list.find((p: any) => p?.model === item.model) ? "checkbox-marked" : "checkbox-blank-outline"}
186
- size={26}
187
- color={theme.colors.primary}
188
- onPress={() => handleClick({ item })}
189
- />
190
182
  <TouchableOpacity
191
183
  activeOpacity={1}
192
184
  style={styles.wIconContainer}
193
- onPress={() => handleClick({ item })}
185
+ onPress={() => setOpenModal({ open: true, data: { ...item, index: i} })}
194
186
  >
195
187
  <SimpleLineIcons
196
188
  name='printer'
@@ -198,55 +190,74 @@ export const PrinterSettings = (props: any) => {
198
190
  size={18}
199
191
  style={{
200
192
  ...styles.icons,
201
- color: printers.list.find((p: any) => p?.model === item.model)
202
- ? theme.colors.primary
203
- : theme.colors.textGray
193
+ color: theme.colors.primary
204
194
  }}
205
195
  />
206
196
  <OText
207
197
  size={18}
208
- color={printers.list.find((p: any) => p?.model === item.model)
209
- ? theme.colors.primary
210
- : theme.colors.textGray
211
- }
198
+ color={theme.colors.primary}
212
199
  >
213
- {item.model}
200
+ {item?.nickname ?? item.model}
214
201
  </OText>
215
202
  </TouchableOpacity>
216
- {!!printers.list.find((p: any) => p?.model === item.model) && (
217
- <TouchableOpacity
218
- activeOpacity={1}
219
- onPress={() => setOpenModal({
220
- open: true,
221
- data: printers.list.find((p: any) => p?.model === item.model)
222
- })}
223
- style={{ width: 40 }}
224
- >
225
- <FeatherIcon
226
- name='edit'
227
- size={20}
228
- style={styles.icons}
229
- />
230
- </TouchableOpacity>
231
- )}
203
+ <TouchableOpacity
204
+ activeOpacity={1}
205
+ onPress={() => setOpenModal({ open: true, data: { ...item, index: i} })}
206
+ >
207
+ <FeatherIcon
208
+ name='edit'
209
+ size={22}
210
+ />
211
+ </TouchableOpacity>
212
+ <TouchableOpacity
213
+ activeOpacity={1}
214
+ onPress={() => handleClick({ item })}
215
+ style={{ marginLeft: 10 }}
216
+ >
217
+ <FeatherIcon
218
+ name='trash-2'
219
+ size={22}
220
+ color={theme.colors.danger500}
221
+ />
222
+ </TouchableOpacity>
232
223
  </View>
233
224
  </View>
234
225
  </ContainerList>
235
226
  ))}
227
+ {!printers.list.length && (
228
+ <NoPrintersContainer style={{ height: HEIGHT_SCREEN/2 }}>
229
+ <OText
230
+ size={20}
231
+ color={theme.colors.textGray}
232
+ numberOfLines={2}
233
+ adjustsFontSizeToFit
234
+ style={{ paddingHorizontal: 0, opacity: 0.4 }}
235
+ >
236
+ {t('NO_PRINTERS_CONFIGURED', 'No printers configured')}
237
+ </OText>
238
+ <OButton
239
+ text={t('ADD_PRINTER', 'Add printer')}
240
+ imgRightSrc={null}
241
+ textStyle={styles.addButtonText}
242
+ style={styles.addButton}
243
+ bgColor={theme.colors.primary}
244
+ borderColor={theme.colors.primary}
245
+ onClick={() => setOpenModal({ open: true, data: null })}
246
+ />
247
+ </NoPrintersContainer>
248
+ )}
236
249
  </View>
237
250
  <OModal
238
251
  hideIcons
239
252
  entireModal
240
253
  customClose
241
254
  open={openModal.open}
242
- style={{
243
- paddingTop: 0,
244
- marginTop: 0
245
- }}
255
+ style={{ paddingTop: 0, marginTop: 0 }}
246
256
  onClose={() => setOpenModal({ open: false, data: null })}
247
257
  >
248
258
  <PrinterEdition
249
259
  printer={openModal.data}
260
+ printersList={printers}
250
261
  handleChangePrinter={handleClick}
251
262
  onClose={() => setOpenModal({ open: false, data: null })}
252
263
  />
@@ -19,3 +19,12 @@ export const EnabledAutoPrint = styled.View`
19
19
  align-items: center;
20
20
  padding: 20px 0px 10px;
21
21
  `;
22
+
23
+ export const NoPrintersContainer = styled.View`
24
+ flex-direction: column;
25
+ align-items: center;
26
+ justify-content: center;
27
+ margin-top: 40px;
28
+ height: 100%;
29
+ flex: 1;
30
+ `