@eohjsc/react-native-smart-city 0.3.89 → 0.3.91

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 (166) hide show
  1. package/package.json +1 -1
  2. package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +1 -1
  3. package/src/commons/ActionTemplate/CurtainAction.js +2 -2
  4. package/src/commons/ActionTemplate/OnOffButtonAction.js +2 -2
  5. package/src/commons/ActionTemplate/OnOffSimpleAction.js +2 -2
  6. package/src/commons/ActionTemplate/OnOffSmartLockAction.js +2 -2
  7. package/src/commons/ActionTemplate/OneButtonAction.js +2 -2
  8. package/src/commons/ActionTemplate/ThreeButtonAction.js +2 -2
  9. package/src/commons/ActionTemplate/__test__/CurtainAction.test.js +1 -1
  10. package/src/commons/ActionTemplate/__test__/OnOffButtonAction.test.js +1 -1
  11. package/src/commons/ActionTemplate/__test__/OnOffSimpleAction.test.js +1 -1
  12. package/src/commons/ActionTemplate/__test__/OnOffSmartLockAction.test.js +1 -1
  13. package/src/commons/ActionTemplate/__test__/OneButtonAction.test.js +1 -1
  14. package/src/commons/ActionTemplate/__test__/ThreeButtonAction.test.js +1 -1
  15. package/src/commons/ActionTemplate/__test__/index.test.js +21 -70
  16. package/src/commons/ActionTemplate/index.js +19 -55
  17. package/src/commons/Alert/__test__/Alert.test.js +1 -1
  18. package/src/commons/Auth/__test__/OtpInputList.test.js +4 -2
  19. package/src/commons/Auth/__test__/SocialButton.test.js +4 -2
  20. package/src/commons/BackDefault/__test__/BackDefault.test.js +1 -1
  21. package/src/commons/Button/__test__/Button.test.js +1 -1
  22. package/src/commons/ButtonPopup/__test__/ButtonPopup.test.js +1 -1
  23. package/src/commons/Calendar/__test__/Calendar.test.js +1 -1
  24. package/src/commons/ChartLoading/__test__/ChartLoading.test.js +1 -1
  25. package/src/commons/CircleButton/__test__/CircleButton.test.js +1 -1
  26. package/src/commons/CircleView/__test__/CircleView.test.js +1 -1
  27. package/src/commons/DateTimeRangeChange/__test__/DateTimeButton.test.js +4 -2
  28. package/src/commons/DateTimeRangeChange/index.js +31 -48
  29. package/src/commons/Device/Emergency/__test__/EmergencyButton.test.js +2 -2
  30. package/src/commons/Device/Emergency/__test__/EmergencyDetail.test.js +1 -1
  31. package/src/commons/Device/FlatListItems.js +1 -1
  32. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +2 -2
  33. package/src/commons/Device/HistoryChart.js +6 -49
  34. package/src/commons/Device/LinearChart/LinearChart.test.js +1 -1
  35. package/src/commons/Device/ProgressBar/__test__/ProgressBar.test.js +3 -4
  36. package/src/commons/Device/ProgressBar/index.js +6 -4
  37. package/src/commons/Device/ProgressBar/styles.js +9 -6
  38. package/src/commons/Device/RainningSensor/__test__/CurrentRainSensor.test.js +5 -5
  39. package/src/commons/Device/SonosSpeaker/__test__/SonosSpeaker.test.js +3 -3
  40. package/src/commons/Device/WindDirection/Compass/Compass.test.js +2 -2
  41. package/src/commons/Device/WindSpeed/LinearChart/index.js +1 -1
  42. package/src/commons/Device/__test__/DeviceAlertStatus.test.js +3 -3
  43. package/src/commons/Device/__test__/DisconnectedView.test.js +2 -2
  44. package/src/commons/Device/__test__/FlatListItems.test.js +1 -1
  45. package/src/commons/Device/__test__/SensorConnectedStatus.test.js +1 -1
  46. package/src/commons/DisplayChecking/__test__/DisplayChecking.test.js +1 -1
  47. package/src/commons/Form/__test__/CurrencyInput.test.js +2 -2
  48. package/src/commons/Form/__test__/TextInput.test.js +2 -2
  49. package/src/commons/Form/__test__/TextInputPassword.test.js +2 -2
  50. package/src/commons/FullLoading/__test__/index.test.js +2 -2
  51. package/src/commons/ImageButton/__test__/ImageButton.test.js +1 -1
  52. package/src/commons/OneTapTemplate/NumberUpDownActionTemplate.js +2 -2
  53. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +4 -4
  54. package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +4 -4
  55. package/src/commons/OneTapTemplate/__test__/NumberUpDownActionTemplate.test.js +2 -2
  56. package/src/commons/OneTapTemplate/__test__/OptionsDropdownActionTemplate.test.js +1 -1
  57. package/src/commons/OneTapTemplate/__test__/StatesGridActionTemplate.test.js +2 -2
  58. package/src/commons/RowItem/__test__/RowItem.test.js +1 -1
  59. package/src/commons/RowUser/__test__/RowUser.test.js +1 -1
  60. package/src/commons/Section/Section.test.js +2 -2
  61. package/src/commons/SelectSubUnit/__test__/SelectSubUnit.test.js +1 -1
  62. package/src/commons/SelectUnit/__test__/SelectUnit.test.js +3 -3
  63. package/src/commons/Sharing/__test__/ButtonRemoveMember.test.js +1 -1
  64. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +1 -1
  65. package/src/commons/Sharing/__test__/MemberList.test.js +6 -4
  66. package/src/commons/Sharing/__test__/RowMember.test.js +2 -2
  67. package/src/commons/Sharing/__test__/StationDevicePermission.test.js +3 -3
  68. package/src/commons/Sharing/__test__/WrapHeaderScrollable.test.js +4 -2
  69. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +2 -10
  70. package/src/commons/SubUnit/OneTap/index.js +3 -1
  71. package/src/commons/TextButton/__test__/TextButton.test.js +2 -2
  72. package/src/commons/Today/__test__/Today.test.js +1 -1
  73. package/src/commons/TouchableScale/__test__/TouchableScale.test.js +1 -1
  74. package/src/commons/UnitSummary/AirQuality/index.js +2 -2
  75. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +0 -6
  76. package/src/commons/UnitSummary/__test__/TotalPowerBox.test.js +1 -1
  77. package/src/commons/UnitSummary/__test__/TotalPowerConsumption.test.js +1 -1
  78. package/src/commons/ViewButtonBottom/__test__/ViewButtonBottom.test.js +1 -1
  79. package/src/configs/API.js +9 -32
  80. package/src/configs/Constants.js +2 -30
  81. package/src/context/reducer.ts +3 -1
  82. package/src/hoc/__test__/withRemoteControl.test.js +1 -1
  83. package/src/navigations/UnitStack.js +23 -13
  84. package/src/screens/ActivityLog/FilterPopup.js +4 -4
  85. package/src/screens/ActivityLog/__test__/FilterPopup.test.js +2 -2
  86. package/src/screens/ActivityLog/__test__/index.test.js +2 -2
  87. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +3 -3
  88. package/src/screens/AddCommon/__test__/SelectUnit.test.js +5 -5
  89. package/src/screens/AddNewAction/ChooseAction.js +180 -0
  90. package/src/screens/AddNewAction/ChooseConfig.js +207 -0
  91. package/src/screens/AddNewAction/Components/SelectDevices.js +75 -0
  92. package/src/screens/AddNewAction/Device/__test__/index.test.js +1 -1
  93. package/src/screens/AddNewAction/NewActionWrapper.js +55 -0
  94. package/src/screens/AddNewAction/SelectControlDevices.js +107 -0
  95. package/src/screens/AddNewAction/SelectMonitorDevices.js +142 -0
  96. package/src/screens/AddNewAction/SetupConfigCondition.js +245 -0
  97. package/src/screens/AddNewAction/Styles/SetupSensorStyles.js +1 -1
  98. package/src/screens/AddNewAction/__test__/{SelectAction.test.js → ChooseAction.test.js} +94 -114
  99. package/src/screens/AddNewAction/__test__/ChooseConfig.test.js +211 -0
  100. package/src/screens/AddNewAction/__test__/{SelectSensorDevices.test.js → SelectControlDevices.test.js} +32 -83
  101. package/src/screens/AddNewAction/__test__/SelectMonitorDevices.test.js +92 -0
  102. package/src/screens/AddNewAction/__test__/SetupSensor.test.js +9 -22
  103. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +2 -3
  104. package/src/screens/AddNewAutoSmart/index.js +13 -33
  105. package/src/screens/AddNewGateway/PlugAndPlay/__test__/ConnectRouterGuide.test.js +1 -1
  106. package/src/screens/AddNewGateway/PlugAndPlay/__test__/FirstWarning.test.js +1 -1
  107. package/src/screens/AddNewGateway/PlugAndPlay/__test__/ZigbeeDeviceConnectGuide.test.js +1 -1
  108. package/src/screens/AddNewGateway/__test__/ConnectingWifiGuide.test.js +1 -1
  109. package/src/screens/AddNewGateway/__test__/ScanGatewayQR.test.js +2 -2
  110. package/src/screens/AddNewGateway/__test__/ScanModbusQR.test.js +3 -3
  111. package/src/screens/AddNewGateway/__test__/ScanWifiDeviceQR.test.js +2 -2
  112. package/src/screens/AddNewGateway/__test__/SelectDeviceSubUnit.test.js +3 -3
  113. package/src/screens/AddNewGateway/__test__/SelectDeviceUnit.test.js +1 -1
  114. package/src/screens/AddNewGateway/__test__/ShareWifiPassword.test.js +1 -1
  115. package/src/screens/AddNewOneTap/index.js +16 -7
  116. package/src/screens/AllCamera/__test__/index.test.js +18 -57
  117. package/src/screens/AllCamera/index.js +98 -30
  118. package/src/screens/Automate/MultiUnits.js +2 -2
  119. package/src/screens/Automate/__test__/MultiUnits.test.js +2 -2
  120. package/src/screens/Automate/__test__/index.test.js +19 -38
  121. package/src/screens/Automate/index.js +8 -3
  122. package/src/screens/Device/__test__/DetailHistoryChart.test.js +2 -2
  123. package/src/screens/Device/__test__/EmergencyCountdown.test.js +4 -2
  124. package/src/screens/Device/__test__/sensorDisplayItem.test.js +10 -10
  125. package/src/screens/Device/components/ChartWrapper.js +3 -3
  126. package/src/screens/Device/components/VisualChart.js +1 -1
  127. package/src/screens/Device/components/__test__/VisualChart.test.js +1 -1
  128. package/src/screens/Device/hooks/useEvaluateValue.js +8 -0
  129. package/src/screens/DeviceInfo/__test__/index.test.js +16 -18
  130. package/src/screens/DeviceInfo/index.js +6 -5
  131. package/src/screens/EditActionsList/__tests__/index.test.js +14 -6
  132. package/src/screens/Notification/__test__/Notification.test.js +65 -74
  133. package/src/screens/Notification/index.js +14 -14
  134. package/src/screens/ScriptDetail/__test__/index.test.js +2 -8
  135. package/src/screens/ScriptDetail/index.js +9 -88
  136. package/src/screens/ScriptDetail/utils.js +112 -0
  137. package/src/screens/SelectUnit/__test__/index.test.js +0 -5
  138. package/src/screens/SelectUnit/index.js +1 -2
  139. package/src/screens/Sharing/Components/TitleCheckBox.js +2 -2
  140. package/src/screens/SmartAccount/SuccessfullyConnected/__test__/SuccessfullyConnected.test.js +3 -3
  141. package/src/screens/SmartAccount/__test__/Connecting.test.js +1 -1
  142. package/src/screens/SmartAccount/__test__/SmartAccount.test.js +3 -3
  143. package/src/screens/SmartIr/__test__/ButtonsBottom.test.js +1 -1
  144. package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +5 -5
  145. package/src/screens/SmartIr/__test__/SelectBrand.test.js +2 -2
  146. package/src/screens/SmartIr/__test__/SelectDeviceType.test.js +2 -2
  147. package/src/screens/SmartIr/__test__/SmartIr.test.js +2 -2
  148. package/src/screens/Template/__test__/detail.test.js +10 -2
  149. package/src/screens/Unit/__test__/Detail.test.js +7 -13
  150. package/src/screens/Unit/components/__test__/Header.test.js +4 -4
  151. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +1 -1
  152. package/src/screens/UnitSummary/components/3PPowerConsumption/index.js +14 -6
  153. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +1 -1
  154. package/src/screens/UnitSummary/components/Temperature/index.js +2 -2
  155. package/src/screens/UnitSummary/components/UvIndex/index.js +2 -2
  156. package/src/screens/UnitSummary/components/WaterQuality/index.js +2 -2
  157. package/src/screens/UnitSummary/components/__test__/TotalPowerBox.test.js +1 -1
  158. package/src/screens/UnitSummary/components/__test__/TotalPowerConsumption.test.js +1 -1
  159. package/src/screens/UnitSummary/components/__test__/index.test.js +2 -2
  160. package/src/utils/Apis/axios.js +3 -0
  161. package/src/utils/I18n/translations/en.json +1 -0
  162. package/src/utils/I18n/translations/vi.json +1 -0
  163. package/src/utils/Route/index.js +6 -3
  164. package/src/screens/AddNewAction/SelectAction.js +0 -570
  165. package/src/screens/AddNewAction/SelectSensorDevices.js +0 -236
  166. package/src/screens/AddNewAction/SetupSensor.js +0 -263
@@ -1,236 +0,0 @@
1
- import React, { memo, useState, useEffect, useCallback, useMemo } from 'react';
2
- import { ScrollView, TouchableOpacity, View } from 'react-native';
3
- import { useNavigation } from '@react-navigation/native';
4
-
5
- import { useTranslations } from '../../hooks/Common/useTranslations';
6
- import Text from '../../commons/Text';
7
- import NavBar from '../../commons/NavBar';
8
- import { fetchWithCache } from '../../utils/Apis/axios';
9
- import { API, Colors } from '../../configs';
10
- import Device from './Device';
11
- import BottomButtonView from '../../commons/BottomButtonView';
12
- import { HeaderCustom } from '../../commons/Header';
13
- import Routes from '../../utils/Route';
14
- import styles from './Styles/SelectSensorDevicesStyles';
15
- import { AUTOMATE_SELECT, AccessibilityLabel } from '../../configs/Constants';
16
- import { popAction } from '../../navigations/utils';
17
- import { Icon } from '@ant-design/react-native';
18
-
19
- const SelectSensorDevices = memo(({ route }) => {
20
- const t = useTranslations();
21
- const {
22
- unit,
23
- automateId,
24
- automate = {},
25
- title = AUTOMATE_SELECT.SELECT_DEVICE,
26
- type,
27
- scriptName,
28
- isAutomateTab,
29
- isCreateNewAction,
30
- isMultiUnits,
31
- oldType,
32
- isSetupEvent,
33
- } = route?.params || {};
34
-
35
- const [listStation, setListStation] = useState([]);
36
- const [listMenuItem, setListMenuItem] = useState([]);
37
- const [indexStation, setIndexStation] = useState(0);
38
- const [station, setStation] = useState([]);
39
- const [selectedDevice, setSelectedDevice] = useState();
40
- const { navigate, dispatch, goBack } = useNavigation();
41
- const isSelectSensor = title === AUTOMATE_SELECT.SELECT_SENSOR;
42
- const [loading, setLoading] = useState(true);
43
-
44
- const onSnapToItem = useCallback(
45
- (item, index) => {
46
- setIndexStation(index);
47
- },
48
- // eslint-disable-next-line react-hooks/exhaustive-deps
49
- [unit.id, indexStation]
50
- );
51
-
52
- const fetchDetails = useCallback(async () => {
53
- await fetchWithCache(
54
- isSelectSensor
55
- ? API.UNIT.DEVICE_SENSOR(unit.id)
56
- : API.UNIT.DEVICE_CONTROL(unit.id),
57
- {},
58
- (response) => {
59
- const { success, data } = response;
60
- if (success) {
61
- const newData = data.filter((item) => item.sensors.length > 0);
62
- const listMenu = newData.map((item, index) => ({
63
- text: item.name,
64
- station: item,
65
- index: index,
66
- }));
67
- if (isSelectSensor) {
68
- if (automate.sensor_id) {
69
- let selectSensor = {};
70
- newData.map((item) => {
71
- item.sensors.map((sensor) => {
72
- if (sensor.id === automate.sensor_id) {
73
- selectSensor = sensor;
74
- return;
75
- } else if (selectSensor) {
76
- return;
77
- }
78
- });
79
- });
80
- setSelectedDevice(selectSensor);
81
- }
82
- }
83
- setStation(newData);
84
- setListMenuItem(listMenu);
85
- setListStation(listMenu);
86
- }
87
- }
88
- );
89
- setLoading(false);
90
- }, [automate.sensor_id, isSelectSensor, unit]);
91
-
92
- useEffect(() => {
93
- fetchDetails();
94
- }, [fetchDetails]);
95
-
96
- const onPressDevice = (sensor) => {
97
- if (selectedDevice && selectedDevice.id === sensor.id) {
98
- setSelectedDevice(false);
99
- } else {
100
- setSelectedDevice(sensor);
101
- }
102
- };
103
-
104
- const onPressContinue = useCallback(() => {
105
- navigate(Routes.SelectAction, {
106
- unit,
107
- device: selectedDevice,
108
- automateId: automateId,
109
- automate: {
110
- ...automate,
111
- sensor_id: selectedDevice?.id ? selectedDevice.id : automate.sensor_id,
112
- },
113
- stationName: station[indexStation]?.name,
114
- isSelectSensor,
115
- type,
116
- scriptName,
117
- isAutomateTab,
118
- isCreateNewAction,
119
- isMultiUnits,
120
- oldType,
121
- isSetupEvent,
122
- });
123
- }, [
124
- navigate,
125
- unit,
126
- selectedDevice,
127
- automateId,
128
- automate,
129
- station,
130
- indexStation,
131
- isSelectSensor,
132
- type,
133
- scriptName,
134
- isAutomateTab,
135
- isCreateNewAction,
136
- isMultiUnits,
137
- oldType,
138
- isSetupEvent,
139
- ]);
140
-
141
- const onPressClose = useCallback(() => {
142
- if (automateId) {
143
- navigate(Routes.ScriptDetail, {
144
- id: automateId,
145
- name: scriptName,
146
- type: oldType,
147
- havePermission: true,
148
- unit,
149
- isMultiUnits,
150
- isCreateNewAction,
151
- isAutomateTab,
152
- });
153
- } else {
154
- dispatch(popAction(2));
155
- isAutomateTab && goBack();
156
- }
157
- // eslint-disable-next-line react-hooks/exhaustive-deps
158
- }, [route.params]);
159
-
160
- const rightComponent = useMemo(
161
- () => (
162
- <TouchableOpacity
163
- style={styles.buttonClose}
164
- onPress={onPressClose}
165
- accessibilityLabel={AccessibilityLabel.ICON_CLOSE}
166
- >
167
- <Icon name={'close'} size={24} color={Colors.Black} />
168
- </TouchableOpacity>
169
- ),
170
- // eslint-disable-next-line react-hooks/exhaustive-deps
171
- [route.params]
172
- );
173
- if (loading) {
174
- return null;
175
- }
176
-
177
- return (
178
- <View style={styles.wrap}>
179
- <HeaderCustom rightComponent={rightComponent} />
180
-
181
- <ScrollView
182
- style={styles.wrap}
183
- contentContainerStyle={styles.contentContainerStyle}
184
- scrollIndicatorInsets={{ right: 1 }}
185
- >
186
- <Text bold type="H2" style={styles.title}>
187
- {t(title)}
188
- </Text>
189
-
190
- {listStation.length ? (
191
- <NavBar
192
- listStation={listStation}
193
- listMenuItem={listMenuItem}
194
- onSnapToItem={onSnapToItem}
195
- indexStation={indexStation}
196
- style={styles.navbar}
197
- />
198
- ) : (
199
- <View style={styles.noneData}>
200
- <Text center>
201
- {t('you_do_not_have_the_device_or_have_share_control_device')}
202
- </Text>
203
- </View>
204
- )}
205
-
206
- <View style={styles.boxDevices}>
207
- {station[indexStation]?.sensors &&
208
- station[indexStation].sensors.map((sensor) => (
209
- <Device
210
- svgMain={sensor.icon || 'sensor'}
211
- title={sensor.name}
212
- sensor={sensor}
213
- isSelectDevice={
214
- selectedDevice && selectedDevice.id === sensor.id
215
- }
216
- onPress={onPressDevice}
217
- />
218
- ))}
219
- </View>
220
- </ScrollView>
221
-
222
- <BottomButtonView
223
- style={styles.bottomButtonView}
224
- mainTitle={t('continue')}
225
- onPressMain={onPressContinue}
226
- typeMain={
227
- Object.keys(selectedDevice || {}).length === 0
228
- ? 'disabled'
229
- : 'primary'
230
- }
231
- />
232
- </View>
233
- );
234
- });
235
-
236
- export default SelectSensorDevices;
@@ -1,263 +0,0 @@
1
- import React, { useMemo, useCallback, useState, useEffect } from 'react';
2
- import { View, TouchableOpacity, Image } from 'react-native';
3
- import { Icon } from '@ant-design/react-native';
4
- import { useNavigation, useRoute } from '@react-navigation/native';
5
-
6
- import styles from './Styles/SetupSensorStyles';
7
- import WrapHeaderScrollable from '../../commons/Sharing/WrapHeaderScrollable';
8
- import { Colors, Images } from '../../configs';
9
- import { useTranslations } from '../../hooks/Common/useTranslations';
10
- import { ModalCustom } from '../../commons/Modal';
11
- import Text from '../../commons/Text';
12
- import BottomButtonView from '../../commons/BottomButtonView';
13
- import { HorizontalPicker } from '../../commons';
14
- import { popAction } from '../../navigations/utils';
15
- import { useStatusBarPreview } from '../../hooks/Common/useStatusBar';
16
- import {
17
- CONDITION_TYPES,
18
- STATE_VALUE_SENSOR_TYPES,
19
- } from '../../configs/Constants';
20
-
21
- const SetUpSensor = () => {
22
- const t = useTranslations();
23
-
24
- const modalNumberConditionData = useMemo(
25
- () => [
26
- {
27
- title: `${t('is_below')} (<)`,
28
- type: CONDITION_TYPES.IS_BELOW,
29
- conditionValue: '<',
30
- },
31
- {
32
- title: `${t('is')} (=)`,
33
- type: CONDITION_TYPES.IS,
34
- conditionValue: '=',
35
- },
36
- {
37
- title: `${t('is_above')} (>)`,
38
- type: CONDITION_TYPES.IS_ABOVE,
39
- conditionValue: '>',
40
- },
41
- ],
42
- [t]
43
- );
44
-
45
- const { goBack, dispatch } = useNavigation();
46
- const { params = {} } = useRoute();
47
- const { item, sensorData, setSensorData, isAutomateTab } = params;
48
-
49
- const modalStateConditionData = useMemo(() => {
50
- return STATE_VALUE_SENSOR_TYPES.find((i) => i.type === item?.sensor_type);
51
- }, [item?.sensor_type]);
52
-
53
- const isHasLimit = useMemo(() => !!item?.range_max, [item]);
54
- const [isShowModal, setIsShowModal] = useState(false);
55
- const [itemActiveModal, setItemActiveModal] = useState(
56
- modalNumberConditionData[0]
57
- );
58
- const [itemActiveStateModal, setItemActiveStateModal] = useState(
59
- modalStateConditionData?.stateValue[1]
60
- );
61
- const [value, setValue] = useState(parseFloat(item?.value || 0));
62
- const [minimum] = useState(isHasLimit ? parseInt(item?.range_min, 10) : 0);
63
- const [maximum, setMaximum] = useState(
64
- value === 0
65
- ? 100
66
- : isHasLimit
67
- ? (parseInt(item?.range_max, 10) - minimum) * 10 + minimum
68
- : (parseInt(item?.value, 10) + 20 - minimum) * 10 + minimum
69
- );
70
-
71
- const isNumberValue = useMemo(() => {
72
- return !(modalStateConditionData?.type === item?.sensor_type);
73
- }, [item?.sensor_type, modalStateConditionData?.type]);
74
-
75
- const onOpenModal = useCallback(() => {
76
- setIsShowModal(true);
77
- }, []);
78
-
79
- const onCloseModal = useCallback(() => {
80
- setIsShowModal(false);
81
- }, []);
82
-
83
- const onChooseCondition = (selectedItem) => () => {
84
- if (isNumberValue) {
85
- setItemActiveModal(selectedItem);
86
- } else {
87
- setItemActiveStateModal(selectedItem);
88
- setItemActiveModal(modalNumberConditionData[1]);
89
- setValue(modalStateConditionData?.stateValue[0] === selectedItem ? 0 : 1);
90
- }
91
- onCloseModal();
92
- };
93
-
94
- useEffect(() => {
95
- if (!isNumberValue) {
96
- setItemActiveModal(modalNumberConditionData[1]);
97
- }
98
- }, [isNumberValue, modalNumberConditionData]);
99
-
100
- const handleClose = useCallback(() => {
101
- dispatch(popAction(4));
102
- isAutomateTab && goBack();
103
- // eslint-disable-next-line react-hooks/exhaustive-deps
104
- }, []);
105
-
106
- const onChangeValue = useCallback(
107
- (newValue) => {
108
- setValue(
109
- (parseFloat(newValue / 128) + parseFloat(minimum)).toFixed(
110
- item?.decimal_behind || 1
111
- )
112
- );
113
- },
114
- // eslint-disable-next-line react-hooks/exhaustive-deps
115
- [value]
116
- );
117
-
118
- const onSave = useCallback(() => {
119
- const dataTemp = [...sensorData];
120
- const index = dataTemp.findIndex((i) => i?.id === item?.id);
121
- dataTemp.splice(index, 1, { ...item, ...itemActiveModal, value });
122
- setSensorData(dataTemp);
123
- goBack();
124
- // eslint-disable-next-line react-hooks/exhaustive-deps
125
- }, [itemActiveModal, value, item, sensorData]);
126
-
127
- const rightComponent = useMemo(
128
- () => (
129
- <TouchableOpacity style={styles.closeButton} onPress={handleClose}>
130
- <Icon name={'close'} size={24} color={Colors.Black} />
131
- </TouchableOpacity>
132
- ),
133
- // eslint-disable-next-line react-hooks/exhaustive-deps
134
- []
135
- );
136
-
137
- const renderScroll = useMemo(() => {
138
- return (
139
- <HorizontalPicker
140
- minimum={minimum}
141
- maximum={maximum}
142
- segmentSpacing={8}
143
- segmentWidth={8}
144
- step={10}
145
- normalHeight={4}
146
- normalWidth={4}
147
- stepHeight={12}
148
- stepWidth={12}
149
- stepColor={Colors.Gray6}
150
- normalColor={Colors.Gray6}
151
- onChangeValue={onChangeValue}
152
- value={value - minimum}
153
- />
154
- );
155
- // eslint-disable-next-line react-hooks/exhaustive-deps
156
- }, [minimum, maximum, value]);
157
-
158
- useEffect(() => {
159
- !isNumberValue && setValue(1);
160
- }, [isNumberValue]);
161
-
162
- useEffect(() => {
163
- if (!isHasLimit && maximum - 150 <= value * 10) {
164
- setMaximum(maximum + 200);
165
- }
166
- // eslint-disable-next-line react-hooks/exhaustive-deps
167
- }, [value]);
168
-
169
- useEffect(() => {
170
- if (item?.title) {
171
- const itemTemp = modalNumberConditionData.find(
172
- (i) => i.title === item.title
173
- );
174
- itemTemp && setItemActiveModal(itemTemp);
175
- }
176
- // eslint-disable-next-line react-hooks/exhaustive-deps
177
- }, [item]);
178
-
179
- useEffect(() => {
180
- // eslint-disable-next-line react-hooks/rules-of-hooks
181
- useStatusBarPreview(
182
- isShowModal ? Colors.BlackTransparent4 : Colors.TextTransparent
183
- );
184
- }, [isShowModal]);
185
-
186
- return (
187
- <View style={styles.wrap}>
188
- <WrapHeaderScrollable
189
- title={t('set_up {name}', { name: item?.name })}
190
- headerAniStyle={styles.headerAniStyle}
191
- rightComponent={rightComponent}
192
- >
193
- <TouchableOpacity
194
- onPress={onOpenModal}
195
- style={[styles.itemCondition, styles.shadowView]}
196
- >
197
- <Text type="Body" color={Colors.Gray7}>
198
- {t('condition')}
199
- </Text>
200
- <Text type="H4" semibold style={styles.desciption}>
201
- {isNumberValue
202
- ? `${item?.name} ${itemActiveModal.title}`
203
- : t(itemActiveStateModal)}
204
- </Text>
205
- <Image source={Images.arrowBack} style={styles.arrowRight} />
206
- </TouchableOpacity>
207
- {isNumberValue && (
208
- <>
209
- <Text type="Body" color={Colors.Gray7} style={styles.setANumber}>
210
- {t('set_a_number')}
211
- </Text>
212
- <View style={[styles.flexRow, styles.center]}>
213
- <View>
214
- <Text style={styles.value}>{value}</Text>
215
- <View style={styles.underline} />
216
- </View>
217
- <Text type="H2" style={styles.unit}>
218
- {item?.unit}
219
- </Text>
220
- </View>
221
- {renderScroll}
222
- </>
223
- )}
224
- </WrapHeaderScrollable>
225
- <BottomButtonView
226
- style={styles.bottomButtonView}
227
- mainTitle={t('save')}
228
- onPressMain={onSave}
229
- typeMain={'primary'}
230
- />
231
- <ModalCustom
232
- onBackdropPress={onCloseModal}
233
- isVisible={isShowModal}
234
- style={styles.modal}
235
- >
236
- <View style={styles.modalContent}>
237
- {(isNumberValue
238
- ? modalNumberConditionData
239
- : /* Huy Disable picking not_active/not_detect option -> temporally remove not_active option */
240
- modalStateConditionData?.stateValue.slice(1)
241
- ).map((i, index) => (
242
- <React.Fragment key={index}>
243
- <TouchableOpacity
244
- onPress={onChooseCondition(i)}
245
- key={index}
246
- style={styles.itemModal}
247
- >
248
- <Text type="H4">
249
- {isNumberValue ? `${item?.name} ${i.title}` : t(i)}
250
- </Text>
251
- </TouchableOpacity>
252
- {index !== modalNumberConditionData.length - 1 && (
253
- <View style={styles.separated} />
254
- )}
255
- </React.Fragment>
256
- ))}
257
- </View>
258
- </ModalCustom>
259
- </View>
260
- );
261
- };
262
-
263
- export default SetUpSensor;