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

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 (204) hide show
  1. package/package.json +1 -1
  2. package/src/Images/Common/reorder.svg +3 -0
  3. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/AutoLockStyles.js +1 -1
  4. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +3 -1
  5. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/index.js +3 -3
  6. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/index.test.js +3 -10
  7. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/index.js +1 -0
  8. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/SetupGeneratePasscodeStyles.js +1 -1
  9. package/src/commons/ActionGroup/OnOffTemplate/SwitchButtonTemplate.js +13 -5
  10. package/src/commons/ActionGroup/SliderRangeTemplate.js +100 -69
  11. package/src/commons/ActionGroup/SliderRangeTemplateStyles.js +27 -27
  12. package/src/commons/ActionGroup/StatesGridActionTemplate.js +4 -1
  13. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +4 -1
  14. package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +56 -0
  15. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +2 -2
  16. package/src/commons/ActionGroup/__test__/SwitchButtonTemplate.test.js +45 -8
  17. package/src/commons/ActionGroup/__test__/index.test.js +0 -19
  18. package/src/commons/ActionGroup/index.js +0 -3
  19. package/src/commons/ActionTemplate/CurtainAction.js +3 -3
  20. package/src/commons/ActionTemplate/CurtainActionStyles.js +1 -1
  21. package/src/commons/ActionTemplate/OnOffButtonAction.js +2 -2
  22. package/src/commons/ActionTemplate/OnOffButtonActionStyles.js +1 -1
  23. package/src/commons/ActionTemplate/OnOffSimpleAction.js +2 -2
  24. package/src/commons/ActionTemplate/OnOffSimpleActionStyles.js +1 -1
  25. package/src/commons/ActionTemplate/OnOffSmartLockAction.js +2 -2
  26. package/src/commons/ActionTemplate/OnOffSmartLockActionStyles.js +1 -1
  27. package/src/commons/ActionTemplate/OneButtonAction.js +1 -1
  28. package/src/commons/ActionTemplate/OneButtonActionStyles.js +1 -1
  29. package/src/commons/ActionTemplate/ThreeButtonAction.js +3 -3
  30. package/src/commons/ActionTemplate/ThreeButtonActionStyles.js +1 -1
  31. package/src/commons/Auth/AccountList.js +1 -1
  32. package/src/commons/Auth/__test__/OtpInputList.test.js +13 -17
  33. package/src/commons/Automate/ItemAutomate.js +10 -4
  34. package/src/commons/Automate/__test__/ItemAutomate.test.js +11 -11
  35. package/src/commons/Device/DeviceAlertStatus.js +2 -1
  36. package/src/commons/Device/ProgressBar/index.js +5 -11
  37. package/src/commons/Device/ProgressBar/styles.js +11 -3
  38. package/src/commons/Device/WindSpeed/Anemometer/index.js +2 -0
  39. package/src/commons/Device/WindSpeed/LinearChart/__test__/LinearChart.test.js +14 -1
  40. package/src/commons/Device/WindSpeed/LinearChart/index.js +4 -2
  41. package/src/commons/FlatListDnD/__test__/index.test.js +49 -0
  42. package/src/commons/FlatListDnD/index.js +37 -0
  43. package/src/commons/FlatListDnD/styles.js +12 -0
  44. package/src/commons/Form/__test__/TextInput.test.js +1 -1
  45. package/src/commons/Header/HeaderCustom.js +2 -1
  46. package/src/commons/HorizontalPicker/index.js +65 -38
  47. package/src/commons/IconComponent/index.js +3 -2
  48. package/src/commons/MediaPlayer/__test__/index.test.js +8 -3
  49. package/src/commons/MediaPlayer/index.js +11 -7
  50. package/src/commons/MenuActionMore/index.js +6 -4
  51. package/src/commons/Modal/ModalBottom.js +2 -3
  52. package/src/commons/Modal/ModalCustom.js +2 -3
  53. package/src/commons/NavBar/index.js +48 -50
  54. package/src/commons/OneTapTemplate/NumberUpDownActionTemplate.js +1 -1
  55. package/src/commons/OneTapTemplate/NumberUpDownActionTemplateStyles.js +1 -1
  56. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +1 -1
  57. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplateStyles.js +1 -1
  58. package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +1 -1
  59. package/src/commons/OneTapTemplate/StatesGridActionTemplateStyles.js +1 -1
  60. package/src/commons/PreventAccess/index.js +1 -1
  61. package/src/commons/Sharing/StationDevicePermissions.js +4 -4
  62. package/src/commons/Sharing/WrapHeaderScrollable.js +5 -5
  63. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +2 -2
  64. package/src/commons/SubUnit/OneTap/ItemOneTap.js +7 -11
  65. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +11 -6
  66. package/src/commons/SubUnit/OneTap/index.js +19 -6
  67. package/src/commons/UnitSummary/AirQuality/__test__/index.test.js +4 -0
  68. package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +1 -1
  69. package/src/configs/API.js +6 -0
  70. package/src/configs/AccessibilityLabel.js +1 -0
  71. package/src/configs/Colors.js +1 -1
  72. package/src/configs/Constants.js +12 -18
  73. package/src/hooks/Common/__test__/useStatusbar.test.js +5 -5
  74. package/src/hooks/Common/index.js +0 -2
  75. package/src/hooks/Common/useKeyboardShow.js +4 -4
  76. package/src/hooks/Common/useStatusBar.js +2 -2
  77. package/src/hooks/Common/useTitleHeader.js +5 -7
  78. package/src/hooks/IoT/__test__/useRemoteControl.test.js +11 -0
  79. package/src/hooks/IoT/useBluetoothConnection.js +6 -3
  80. package/src/hooks/index.js +1 -2
  81. package/src/navigations/UnitStack.js +33 -9
  82. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +8 -31
  83. package/src/screens/AddNewAutoSmart/index.js +24 -60
  84. package/src/screens/AddNewGateway/SelectDeviceSubUnit.js +1 -2
  85. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +5 -17
  86. package/src/screens/AddNewGateway/__test__/SelectDeviceSubUnit.test.js +5 -13
  87. package/src/screens/AddNewGateway/__test__/SelectDeviceUnit.test.js +9 -11
  88. package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +6 -14
  89. package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +6 -14
  90. package/src/screens/AddNewGateway/hooks/__Tests__/useWifiManage.test.js +3 -2
  91. package/src/screens/AddNewGateway/index.js +1 -1
  92. package/src/screens/AllCamera/index.js +2 -3
  93. package/src/screens/AllGateway/DetailConfigActionZigbee/__test__/index.test.js +0 -18
  94. package/src/screens/AllGateway/DetailConfigActionZigbee/index.js +1 -1
  95. package/src/screens/AllGateway/DeviceModbusDetail/__test__/index.test.js +5 -2
  96. package/src/screens/AllGateway/hooks/__test__/index.test.js +1 -1
  97. package/src/screens/{AddNewAction → Automate/AddNewAction}/ChooseAction.js +78 -119
  98. package/src/screens/{AddNewAction → Automate/AddNewAction}/ChooseConfig.js +45 -73
  99. package/src/screens/{AddNewAction → Automate/AddNewAction}/Components/LoadingSelectAction.js +1 -1
  100. package/src/screens/{AddNewAction → Automate/AddNewAction}/Components/SelectDevices.js +3 -3
  101. package/src/screens/{AddNewAction → Automate/AddNewAction}/Device/DeviceStyles.js +5 -1
  102. package/src/screens/{AddNewAction → Automate/AddNewAction}/Device/__test__/index.test.js +3 -3
  103. package/src/screens/{AddNewAction → Automate/AddNewAction}/Device/index.js +5 -4
  104. package/src/screens/{AddNewAction → Automate/AddNewAction}/NewActionWrapper.js +11 -10
  105. package/src/screens/{AddNewAction → Automate/AddNewAction}/SelectControlDevices.js +11 -49
  106. package/src/screens/{AddNewAction → Automate/AddNewAction}/SelectMonitorDevices.js +10 -42
  107. package/src/screens/{AddNewAction → Automate/AddNewAction}/SetupConfigCondition.js +52 -101
  108. package/src/screens/{AddNewAction → Automate/AddNewAction}/Styles/SelectActionStyles.js +1 -1
  109. package/src/screens/{AddNewAction → Automate/AddNewAction}/Styles/SelectSensorDevicesStyles.js +1 -1
  110. package/src/screens/{AddNewAction → Automate/AddNewAction}/Styles/SetupSensorStyles.js +4 -2
  111. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/ChooseAction.test.js +10 -11
  112. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/ChooseConfig.test.js +26 -27
  113. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/SelectControlDevices.test.js +9 -9
  114. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/SelectMonitorDevices.test.js +5 -5
  115. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/SetupSensor.test.js +43 -13
  116. package/src/screens/Automate/Components/InputName.js +64 -0
  117. package/src/screens/{AddNewOneTap/AddNewOneTapStyles.js → Automate/Components/InputNameStyles.js} +2 -2
  118. package/src/screens/{EditActionsList → Automate/EditActionsList}/Styles/indexStyles.js +5 -1
  119. package/src/screens/{EditActionsList → Automate/EditActionsList}/__tests__/index.test.js +6 -6
  120. package/src/screens/{EditActionsList → Automate/EditActionsList}/index.js +18 -19
  121. package/src/screens/Automate/MultiUnits.js +68 -66
  122. package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +134 -0
  123. package/src/screens/Automate/OneTap/index.js +16 -0
  124. package/src/screens/Automate/Scenario/ScenarioName.js +15 -0
  125. package/src/screens/{AddNewOneTap → Automate/Scenario}/__test__/AddNewOneTap.test.js +27 -45
  126. package/src/screens/Automate/ScriptDetail/Components/DeleteScript.js +45 -0
  127. package/src/screens/Automate/ScriptDetail/Components/RenameScript.js +58 -0
  128. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/Styles/indexStyles.js +1 -1
  129. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/__test__/index.test.js +69 -72
  130. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/__test__/useStarredScript.test.js +7 -6
  131. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/hooks/useStarredScript.js +4 -4
  132. package/src/screens/Automate/ScriptDetail/index.js +346 -0
  133. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/utils.js +32 -31
  134. package/src/screens/{SetSchedule → Automate/SetSchedule}/__test__/SelectWeekday.test.js +2 -2
  135. package/src/screens/{SetSchedule → Automate/SetSchedule}/__test__/index.test.js +21 -46
  136. package/src/screens/{SetSchedule → Automate/SetSchedule}/components/RepeatOptionsPopup.js +4 -4
  137. package/src/screens/{SetSchedule → Automate/SetSchedule}/components/RowItem.js +2 -2
  138. package/src/screens/{SetSchedule → Automate/SetSchedule}/components/SelectWeekday.js +3 -3
  139. package/src/screens/Automate/SetSchedule/index.js +140 -0
  140. package/src/screens/{SetSchedule → Automate/SetSchedule}/styles/RepeatOptionsPopupStyles.js +1 -1
  141. package/src/screens/{SetSchedule → Automate/SetSchedule}/styles/RowItemStyles.js +1 -1
  142. package/src/screens/{SetSchedule → Automate/SetSchedule}/styles/SelectWeekdayStyles.js +1 -1
  143. package/src/screens/{SetSchedule → Automate/SetSchedule}/styles/indexStyles.js +1 -1
  144. package/src/screens/Automate/ValueChange/ValueChangeName.js +16 -0
  145. package/src/screens/Automate/__test__/MultiUnits.test.js +76 -120
  146. package/src/screens/Automate/__test__/index.test.js +2 -9
  147. package/src/screens/Automate/constants.js +0 -0
  148. package/src/screens/Automate/index.js +11 -22
  149. package/src/screens/ChangePosition/__test__/index.test.js +75 -0
  150. package/src/screens/ChangePosition/index.js +112 -0
  151. package/src/screens/ChangePosition/styles.js +87 -0
  152. package/src/screens/Device/__test__/detail.test.js +202 -257
  153. package/src/screens/Device/__test__/sensorDisplayItem.test.js +4 -0
  154. package/src/screens/Device/components/SensorDisplayItem.js +2 -1
  155. package/src/screens/Device/components/VisualChart.js +55 -8
  156. package/src/screens/Device/detail.js +14 -0
  157. package/src/screens/Device/hooks/__test__/useEmergencyButton.test.js +35 -13
  158. package/src/screens/Device/hooks/useEvaluateValue.js +20 -2
  159. package/src/screens/Device/styles.js +7 -0
  160. package/src/screens/GuestInfo/components/__test__/AccessScheduleSheet.test.js +52 -0
  161. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +18 -13
  162. package/src/screens/Notification/__test__/Notification.test.js +1 -1
  163. package/src/screens/PlayBackCamera/index.js +2 -3
  164. package/src/screens/SharedUnit/index.js +5 -4
  165. package/src/screens/Sharing/SelectUser.js +2 -2
  166. package/src/screens/Sharing/__test__/MemberList.test.js +9 -15
  167. package/src/screens/Sharing/__test__/MemberList2.test.js +10 -16
  168. package/src/screens/Sharing/__test__/SelectUser.test.js +8 -4
  169. package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +1 -1
  170. package/src/screens/SmartAccount/index.js +1 -0
  171. package/src/screens/SubUnit/ManageSubUnit.js +4 -4
  172. package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +9 -28
  173. package/src/screens/TDSGuide/index.js +1 -1
  174. package/src/screens/Template/GatewayList.js +4 -1
  175. package/src/screens/Template/__test__/detail.test.js +14 -20
  176. package/src/screens/Template/detail.js +1 -0
  177. package/src/screens/UVIndexGuide/index.js +2 -2
  178. package/src/screens/Unit/Detail.js +6 -5
  179. package/src/screens/Unit/SelectAddToFavorites.js +1 -1
  180. package/src/screens/Unit/__test__/ChooseLocation.test.js +8 -13
  181. package/src/screens/Unit/__test__/Detail.test.js +3 -1
  182. package/src/screens/Unit/__test__/SelectAddToFavorites.test.js +1 -1
  183. package/src/screens/Unit/__test__/SmartAccount.test.js +8 -14
  184. package/src/screens/UnitSummary/components/UvIndex/__test__/index.test.js +4 -0
  185. package/src/screens/UnitSummary/components/WaterQuality/__test__/index.test.js +6 -11
  186. package/src/screens/WaterQualityGuide/index.js +10 -5
  187. package/src/utils/I18n/translations/en.json +23 -18
  188. package/src/utils/I18n/translations/vi.json +21 -18
  189. package/src/utils/Route/index.js +3 -0
  190. package/src/utils/Utils.js +29 -0
  191. package/src/utils/__test__/Utils.test.js +6 -0
  192. package/src/commons/ActionGroup/CurtainButtonTemplate.js +0 -130
  193. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +0 -109
  194. package/src/commons/Auth/SocialButton.js +0 -54
  195. package/src/commons/Auth/__test__/SocialButton.test.js +0 -46
  196. package/src/commons/Sharing/__test__/StationDevicePermission.test.js +0 -85
  197. package/src/hooks/__test__/useInitDeepLink.test.js +0 -28
  198. package/src/hooks/useInitDeepLink.js +0 -25
  199. package/src/screens/AddNewOneTap/index.js +0 -156
  200. package/src/screens/ScriptDetail/hooks/index.js +0 -136
  201. package/src/screens/ScriptDetail/index.js +0 -446
  202. package/src/screens/SetSchedule/index.js +0 -200
  203. /package/src/screens/{AddNewAction → Automate/AddNewAction}/Components/index.js +0 -0
  204. /package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/LoadingSelectAction.test.js +0 -0
@@ -3,35 +3,26 @@ import { Image, TouchableOpacity, View } from 'react-native';
3
3
  import { useNavigation, useRoute } from '@react-navigation/native';
4
4
 
5
5
  import styles from './Styles/SetupSensorStyles';
6
- import { Colors, Images } from '../../configs';
7
- import { useTranslations } from '../../hooks/Common/useTranslations';
8
- import { ModalCustom } from '../../commons/Modal';
9
- import Text from '../../commons/Text';
10
- import { HorizontalPicker } from '../../commons';
11
- import { useStatusBarPreview } from '../../hooks/Common/useStatusBar';
12
- import Routes from '../../utils/Route';
13
- import { getAutomationData } from '../ScriptDetail/utils';
6
+ import { Colors, Images } from '../../../configs';
7
+ import { useTranslations } from '../../../hooks/Common/useTranslations';
8
+ import { ModalCustom } from '../../../commons/Modal';
9
+ import Text from '../../../commons/Text';
10
+ import { HorizontalPicker } from '../../../commons';
11
+ import { setStatusBarPreview } from '../../../hooks/Common/useStatusBar';
12
+ import Routes from '../../../utils/Route';
14
13
  import NewActionWrapper from './NewActionWrapper';
14
+ import _TextInput from '../../../commons/Form/TextInput';
15
15
 
16
16
  const SetupConfigCondition = () => {
17
17
  const t = useTranslations();
18
18
 
19
19
  const { navigate } = useNavigation();
20
20
  const { params = {} } = useRoute();
21
- const { item, sensorData, type, automate } = params;
21
+ const { item, defaultCondition = {} } = params;
22
22
 
23
- const hasLimit = useMemo(() => !!item?.range_max, [item]);
24
23
  const [isShowModal, setIsShowModal] = useState(false);
25
- const [itemActiveModal, setItemActiveModal] = useState(null);
26
- const [value, setValue] = useState(null);
27
- const [minimum] = useState(hasLimit ? parseInt(item?.range_min, 10) : 0);
28
- const [maximum, setMaximum] = useState(
29
- value === 0
30
- ? 100
31
- : hasLimit
32
- ? (parseInt(item?.range_max, 10) - minimum) * 10 + minimum
33
- : (parseInt(item?.value, 10) + 20 - minimum) * 10 + minimum
34
- );
24
+ const [itemActiveModal, setItemActiveModal] = useState(defaultCondition);
25
+ const [value, setValue] = useState(defaultCondition?.value);
35
26
 
36
27
  const hasNoValueEvaluation = !item?.evaluate_configuration;
37
28
 
@@ -63,35 +54,6 @@ const SetupConfigCondition = () => {
63
54
  return [];
64
55
  }, [item.evaluate_configuration, item.id, t]);
65
56
 
66
- useEffect(() => {
67
- let defaultCondition = null;
68
- if (sensorData) {
69
- const index = sensorData.findIndex((i) => i?.id === item?.id);
70
- if (index !== -1 && sensorData[index].condition) {
71
- defaultCondition = sensorData[index];
72
- }
73
- }
74
-
75
- if (automate && !defaultCondition) {
76
- const automationData = getAutomationData(type, automate);
77
-
78
- const index = conditionOptions.findIndex(
79
- (i) =>
80
- i.condition === automationData?.condition &&
81
- i.value === automationData?.value
82
- );
83
- if (index !== -1) {
84
- defaultCondition = conditionOptions[index];
85
- }
86
- }
87
-
88
- if (!defaultCondition) {
89
- defaultCondition = conditionOptions[0];
90
- }
91
-
92
- setItemActiveModal(defaultCondition);
93
- }, [conditionOptions, item, sensorData, automate, type]);
94
-
95
57
  const onOpenModal = useCallback(() => {
96
58
  setIsShowModal(true);
97
59
  }, []);
@@ -101,67 +63,27 @@ const SetupConfigCondition = () => {
101
63
  }, []);
102
64
 
103
65
  const onChooseCondition = (selectedItem) => () => {
104
- setItemActiveModal(selectedItem);
66
+ setItemActiveModal((prev) => ({ ...prev, ...selectedItem }));
105
67
  onCloseModal();
106
68
  };
107
69
 
108
- const onChangeValue = useCallback(
109
- (newValue) => {
110
- setValue(
111
- (parseFloat(newValue / 128) + parseFloat(minimum)).toFixed(
112
- item?.decimal_behind || 1
113
- )
114
- );
115
- },
116
- // eslint-disable-next-line react-hooks/exhaustive-deps
117
- [value]
118
- );
119
-
120
70
  const onSave = useCallback(() => {
121
- const dataTemp = [...sensorData];
122
- const index = dataTemp.findIndex((i) => i?.id === item?.id);
123
- dataTemp.splice(index, 1, { ...item, ...itemActiveModal });
124
71
  navigate({
125
72
  name: Routes.ChooseConfig,
126
73
  merge: true,
127
74
  params: {
128
- newSensorData: dataTemp,
75
+ newCondition: {
76
+ ...itemActiveModal,
77
+ config: item.id,
78
+ },
129
79
  },
130
80
  });
131
- }, [sensorData, item, itemActiveModal, navigate]);
132
-
133
- const renderScroll = useMemo(() => {
134
- return (
135
- <HorizontalPicker
136
- minimum={minimum}
137
- maximum={maximum}
138
- segmentSpacing={8}
139
- segmentWidth={8}
140
- step={10}
141
- normalHeight={4}
142
- normalWidth={4}
143
- stepHeight={12}
144
- stepWidth={12}
145
- stepColor={Colors.Gray6}
146
- normalColor={Colors.Gray6}
147
- onChangeValue={onChangeValue}
148
- value={value - minimum}
149
- />
150
- );
151
- // eslint-disable-next-line react-hooks/exhaustive-deps
152
- }, [minimum, maximum, value]);
81
+ }, [item.id, itemActiveModal, navigate]);
153
82
 
154
83
  useEffect(() => {
155
84
  !hasNoValueEvaluation && setValue(1);
156
85
  }, [hasNoValueEvaluation]);
157
86
 
158
- useEffect(() => {
159
- if (!hasLimit && maximum - 150 <= value * 10) {
160
- setMaximum(maximum + 200);
161
- }
162
- // eslint-disable-next-line react-hooks/exhaustive-deps
163
- }, [value]);
164
-
165
87
  useEffect(() => {
166
88
  if (item?.title) {
167
89
  const itemTemp = conditionOptions.find((i) => i.title === item.title);
@@ -171,19 +93,26 @@ const SetupConfigCondition = () => {
171
93
  }, [item]);
172
94
 
173
95
  useEffect(() => {
174
- // eslint-disable-next-line react-hooks/rules-of-hooks
175
- useStatusBarPreview(
96
+ setStatusBarPreview(
176
97
  isShowModal ? Colors.BlackTransparent4 : Colors.TextTransparent
177
98
  );
178
99
  }, [isShowModal]);
179
100
 
101
+ const onChangeValue = useCallback((v) => {
102
+ const newValue = parseInt(v, 10);
103
+ if (!isNaN(newValue)) {
104
+ setValue(newValue);
105
+ setItemActiveModal((prev) => ({ ...prev, value: newValue }));
106
+ }
107
+ }, []);
108
+
180
109
  return (
181
110
  <>
182
111
  <NewActionWrapper
183
112
  name={t('set_up {name}', { name: item?.name })}
184
113
  nextTitle={t('save')}
185
114
  onNext={onSave}
186
- canNext={true}
115
+ canNext={itemActiveModal?.condition}
187
116
  >
188
117
  <TouchableOpacity
189
118
  onPress={onOpenModal}
@@ -204,14 +133,36 @@ const SetupConfigCondition = () => {
204
133
  </Text>
205
134
  <View style={[styles.flexRow, styles.center]}>
206
135
  <View>
207
- <Text style={styles.value}>{value}</Text>
208
- <View style={styles.underline} />
136
+ <_TextInput
137
+ textInputStyle={styles.value}
138
+ wrapStyle={styles.wrapValue}
139
+ value={value?.toString()}
140
+ onChange={onChangeValue}
141
+ />
209
142
  </View>
210
143
  <Text type="H2" style={styles.unit}>
211
144
  {item?.unit}
212
145
  </Text>
213
146
  </View>
214
- {renderScroll}
147
+ <HorizontalPicker
148
+ minimum={item?.range_min}
149
+ maximum={item?.range_max}
150
+ segmentSpacing={8}
151
+ segmentWidth={8}
152
+ step={
153
+ item?.decimal_behind
154
+ ? 1 / Math.pow(10, item?.decimal_behind)
155
+ : 1
156
+ }
157
+ normalHeight={4}
158
+ normalWidth={4}
159
+ stepHeight={12}
160
+ stepWidth={12}
161
+ stepColor={Colors.Gray6}
162
+ normalColor={Colors.Gray6}
163
+ onChangeValue={onChangeValue}
164
+ value={value}
165
+ />
215
166
  </>
216
167
  )}
217
168
  </NewActionWrapper>
@@ -1,6 +1,6 @@
1
1
  import { StyleSheet } from 'react-native';
2
2
  import { getBottomSpace } from 'react-native-iphone-x-helper';
3
- import { Colors, Constants, Theme } from '../../../configs';
3
+ import { Colors, Constants, Theme } from '../../../../configs';
4
4
 
5
5
  export default StyleSheet.create({
6
6
  ...Theme,
@@ -1,6 +1,6 @@
1
1
  import { StyleSheet } from 'react-native';
2
2
  import { getBottomSpace } from 'react-native-iphone-x-helper';
3
- import { Colors, Constants } from '../../../configs';
3
+ import { Colors, Constants } from '../../../../configs';
4
4
 
5
5
  export default StyleSheet.create({
6
6
  wrap: {
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet } from 'react-native';
2
- import { Theme, Colors } from '../../../configs';
2
+ import { Theme, Colors } from '../../../../configs';
3
3
 
4
4
  export default StyleSheet.create({
5
5
  ...Theme,
@@ -46,8 +46,10 @@ export default StyleSheet.create({
46
46
  fontSize: 48,
47
47
  fontWeight: 'bold',
48
48
  textAlign: 'center',
49
- marginLeft: 15,
49
+ borderBottomWidth: 1,
50
+ borderBottomColor: Colors.Black,
50
51
  },
52
+ wrapValue: { marginTop: 0, margin: 0 },
51
53
  unit: {
52
54
  marginTop: -30,
53
55
  },
@@ -3,14 +3,14 @@ import renderer, { act } from 'react-test-renderer';
3
3
  import MockAdapter from 'axios-mock-adapter';
4
4
 
5
5
  import ChooseAction from '../ChooseAction';
6
- import { SCProvider } from '../../../context';
7
- import { mockSCStore } from '../../../context/mockStore';
8
- import BottomButtonView from '../../../commons/BottomButtonView';
9
- import { AccessibilityLabel, DEVICE_TYPE } from '../../../configs/Constants';
10
- import api from '../../../utils/Apis/axios';
11
- import { API } from '../../../configs';
6
+ import { SCProvider } from '../../../../context';
7
+ import { mockSCStore } from '../../../../context/mockStore';
8
+ import BottomButtonView from '../../../../commons/BottomButtonView';
9
+ import { AccessibilityLabel, DEVICE_TYPE } from '../../../../configs/Constants';
10
+ import api from '../../../../utils/Apis/axios';
11
+ import { API } from '../../../../configs';
12
12
  import { TouchableOpacity } from 'react-native';
13
- import SelectActionCard from '../../../commons/SelectActionCard';
13
+ import SelectActionCard from '../../../../commons/SelectActionCard';
14
14
  import { useNavigation } from '@react-navigation/native';
15
15
 
16
16
  const mock = new MockAdapter(api.axiosInstance);
@@ -68,9 +68,9 @@ describe('Test ChooseAction', () => {
68
68
 
69
69
  it('test fetchData', async () => {
70
70
  const response = [
71
- { template: 'on_off_button_action_template' },
72
- { template: 'one_button_action_template' },
73
- { template: 'three_button_action_template' },
71
+ { template: 'on_off_button_action_template', id: 1, configuration: {} },
72
+ { template: 'one_button_action_template', id: 2, configuration: {} },
73
+ { template: 'three_button_action_template', id: 3, configuration: {} },
74
74
  ];
75
75
  mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
76
76
  await act(async () => {
@@ -291,7 +291,6 @@ describe('Test ChooseAction', () => {
291
291
  data: { config_id: config5, config_value: 1 },
292
292
  },
293
293
  ],
294
- unit: 1,
295
294
  })
296
295
  );
297
296
  });
@@ -3,18 +3,18 @@ import renderer, { act } from 'react-test-renderer';
3
3
  import MockAdapter from 'axios-mock-adapter';
4
4
 
5
5
  import ChooseConfig from '../ChooseConfig';
6
- import { SCProvider } from '../../../context';
7
- import { mockSCStore } from '../../../context/mockStore';
8
- import { DEVICE_TYPE } from '../../../configs/Constants';
9
- import api from '../../../utils/Apis/axios';
10
- import { API } from '../../../configs';
11
- import TitleCheckBox from '../../Sharing/Components/TitleCheckBox';
12
- import Text from '../../../commons/Text';
13
- import t from '../../../hooks/Common/useTranslations';
14
- import Routes from '../../../utils/Route';
15
- import CheckBoxCustom from '../../Sharing/Components/CheckBoxCustom';
16
- import BottomButtonView from '../../../commons/BottomButtonView';
17
- import { ToastBottomHelper } from '../../../utils/Utils';
6
+ import { SCProvider } from '../../../../context';
7
+ import { mockSCStore } from '../../../../context/mockStore';
8
+ import { DEVICE_TYPE } from '../../../../configs/Constants';
9
+ import api from '../../../../utils/Apis/axios';
10
+ import { API } from '../../../../configs';
11
+ import TitleCheckBox from '../../../Sharing/Components/TitleCheckBox';
12
+ import Text from '../../../../commons/Text';
13
+ import t from '../../../../hooks/Common/useTranslations';
14
+ import Routes from '../../../../utils/Route';
15
+ import CheckBoxCustom from '../../../Sharing/Components/CheckBoxCustom';
16
+ import BottomButtonView from '../../../../commons/BottomButtonView';
17
+ import { ToastBottomHelper } from '../../../../utils/Utils';
18
18
  import { useNavigation } from '@react-navigation/native';
19
19
 
20
20
  const mock = new MockAdapter(api.axiosInstance);
@@ -138,22 +138,27 @@ describe('Test ChooseConfig', () => {
138
138
  });
139
139
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.SetupConfigCondition, {
140
140
  item: { id: 1 },
141
- sensorData: [{ id: 1 }],
142
- isAutomateTab: undefined,
143
- type: undefined,
144
- automate: {},
141
+ closeScreen: undefined,
142
+ defaultCondition: undefined,
145
143
  });
146
144
  });
147
145
 
148
146
  it('render condition from setup', async () => {
149
- mock.onGet(API.AUTOMATE.DISPLAY_CONFIGS(1)).reply(400); // hack test to fail api data
147
+ mock.onGet(API.AUTOMATE.DISPLAY_CONFIGS(1)).reply(200, [
148
+ {
149
+ id: 1,
150
+ },
151
+ {
152
+ id: 2,
153
+ },
154
+ ]);
150
155
  await act(async () => {
151
156
  tree = await renderer.create(
152
157
  wrapComponent({
153
158
  ...route,
154
159
  params: {
155
160
  ...route.params,
156
- newSensorData: [{ id: 1 }, { id: 2, value: 1 }],
161
+ newCondition: { config: 2, value: 1 }, // condition from setup
157
162
  },
158
163
  })
159
164
  );
@@ -197,15 +202,9 @@ describe('Test ChooseConfig', () => {
197
202
  await act(async () => {
198
203
  await button.props.onPressMain();
199
204
  });
200
- expect(mockedNavigate).toHaveBeenCalledWith(Routes.AddNewOneTap, {
201
- automate: { config_id: 1, id: 1, value: 1 },
202
- automateData: { id: 1, value: 1 },
203
- automateId: undefined,
204
- isAutomateTab: undefined,
205
- isMultiUnits: undefined,
206
- scriptName: undefined,
207
- type: undefined,
208
- unit: route.params.unit,
205
+ expect(mockedNavigate).toHaveBeenCalledWith(Routes.ValueChangeName, {
206
+ automate: { config_id: 1 },
207
+ closeScreen: undefined,
209
208
  });
210
209
  });
211
210
  });
@@ -1,16 +1,16 @@
1
1
  import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
3
  import MockAdapter from 'axios-mock-adapter';
4
- import { SCProvider } from '../../../context';
5
- import { mockSCStore } from '../../../context/mockStore';
4
+ import { SCProvider } from '../../../../context';
5
+ import { mockSCStore } from '../../../../context/mockStore';
6
6
  import Device from '../Device';
7
- import BottomButtonView from '../../../commons/BottomButtonView';
8
- import NavBar from '../../../commons/NavBar';
9
- import API from '../../../configs/API';
10
- import { AccessibilityLabel } from '../../../configs/Constants';
7
+ import BottomButtonView from '../../../../commons/BottomButtonView';
8
+ import NavBar from '../../../../commons/NavBar';
9
+ import API from '../../../../configs/API';
10
+ import { AccessibilityLabel } from '../../../../configs/Constants';
11
11
  import { TouchableOpacity } from 'react-native';
12
- import Routes from '../../../utils/Route';
13
- import api from '../../../utils/Apis/axios';
12
+ import Routes from '../../../../utils/Route';
13
+ import api from '../../../../utils/Apis/axios';
14
14
  import SelectControlDevices from '../SelectControlDevices';
15
15
  import { useNavigation, useRoute } from '@react-navigation/native';
16
16
 
@@ -28,7 +28,7 @@ describe('Test SelectMonitorDevices', () => {
28
28
  let tree;
29
29
  const route = {
30
30
  params: {
31
- unit: { id: 1, name: 'Unit test' },
31
+ unitId: 1,
32
32
  automateId: 1,
33
33
  scriptName: 'scriptName test',
34
34
  automate: {
@@ -3,12 +3,12 @@ import renderer, { act } from 'react-test-renderer';
3
3
  import MockAdapter from 'axios-mock-adapter';
4
4
 
5
5
  import SelectMonitorDevices from '../SelectMonitorDevices';
6
- import { SCProvider } from '../../../context';
7
- import { mockSCStore } from '../../../context/mockStore';
8
- import API from '../../../configs/API';
9
- import { AccessibilityLabel } from '../../../configs/Constants';
6
+ import { SCProvider } from '../../../../context';
7
+ import { mockSCStore } from '../../../../context/mockStore';
8
+ import API from '../../../../configs/API';
9
+ import { AccessibilityLabel } from '../../../../configs/Constants';
10
10
  import { TouchableOpacity } from 'react-native';
11
- import api from '../../../utils/Apis/axios';
11
+ import api from '../../../../utils/Apis/axios';
12
12
  import { useRoute } from '@react-navigation/native';
13
13
 
14
14
  const mock = new MockAdapter(api.axiosInstance);
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
- import { TouchableOpacity } from 'react-native';
2
+ import { Animated, TouchableOpacity, View } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
- import { HorizontalPicker } from '../../../commons';
5
- import { SCProvider } from '../../../context';
6
- import { mockSCStore } from '../../../context/mockStore';
7
- import BottomButtonView from '../../../commons/BottomButtonView';
4
+ import { HorizontalPicker } from '../../../../commons';
5
+ import { SCProvider } from '../../../../context';
6
+ import { mockSCStore } from '../../../../context/mockStore';
7
+ import BottomButtonView from '../../../../commons/BottomButtonView';
8
8
  import SetupConfigCondition from '../SetupConfigCondition';
9
9
  import { useNavigation, useRoute } from '@react-navigation/native';
10
10
 
@@ -38,8 +38,8 @@ describe('Test SetupConfigCondition', () => {
38
38
  id: 1,
39
39
  value: 10,
40
40
  range_min: 0,
41
- range_max: 100,
42
- decimal_behind: 2,
41
+ range_max: 10,
42
+ decimal_behind: 0,
43
43
  title: 'is below (<)',
44
44
  sensor_type: 'air_quality',
45
45
  },
@@ -77,25 +77,55 @@ describe('Test SetupConfigCondition', () => {
77
77
  expect(mockGoBack).toBeCalled();
78
78
  });
79
79
 
80
- it('Test change value and item', async () => {
80
+ it('Test render when have no maximum', async () => {
81
81
  useRoute.mockReturnValue({
82
82
  params: {
83
83
  item: {
84
84
  id: 1,
85
- value: 10,
86
85
  range_min: 0,
87
- decimal_behind: 2,
86
+ range_max: 0,
87
+ decimal_behind: 0,
88
88
  title: 'is below (<)',
89
89
  sensor_type: 'air_quality',
90
90
  },
91
- sensorData: [],
92
91
  },
93
92
  });
94
93
  await act(async () => {
95
94
  tree = await create(wrapComponent());
96
95
  });
97
96
  const instance = tree.root;
98
- const HorizontalPickers = instance.findAllByType(HorizontalPicker);
99
- expect(HorizontalPickers).toHaveLength(1);
97
+ const picker = instance.findByType(HorizontalPicker);
98
+ const scroll = picker.findByType(Animated.ScrollView);
99
+ const views = scroll.findByType(View).findAll((el) => {
100
+ return el.type === View && el.props.accessibilityLabel?.includes('x-');
101
+ });
102
+ expect(views).toHaveLength(10 + 1);
103
+ });
104
+ it('Test render when have no maximum and value is near maximum', async () => {
105
+ useRoute.mockReturnValue({
106
+ params: {
107
+ item: {
108
+ id: 1,
109
+ range_min: 0,
110
+ range_max: 0,
111
+ decimal_behind: 1,
112
+ title: 'is below (<)',
113
+ sensor_type: 'air_quality',
114
+ },
115
+ defaultCondition: {
116
+ value: 0.9,
117
+ },
118
+ },
119
+ });
120
+ await act(async () => {
121
+ tree = await create(wrapComponent());
122
+ });
123
+ const instance = tree.root;
124
+ const picker = instance.findByType(HorizontalPicker);
125
+ const scroll = picker.findByType(Animated.ScrollView);
126
+ const views = scroll.findByType(View).findAll((el) => {
127
+ return el.type === View && el.props.accessibilityLabel?.includes('x-');
128
+ });
129
+ expect(views).toHaveLength(20 - 1); // I don't know why
100
130
  });
101
131
  });
@@ -0,0 +1,64 @@
1
+ import React, { useCallback, useState } from 'react';
2
+ import { Keyboard, ScrollView } from 'react-native';
3
+ import { useNavigation, useRoute } from '@react-navigation/native';
4
+
5
+ import { API } from '../../../configs';
6
+ import { AccessibilityLabel } from '../../../configs/Constants';
7
+ import _TextInput from '../../../commons/Form/TextInput';
8
+ import styles from './InputNameStyles';
9
+ import { useTranslations } from '../../../hooks/Common/useTranslations';
10
+ import { axiosPost, axiosPut } from '../../../utils/Apis/axios';
11
+ import NewActionWrapper from '../../Automate/AddNewAction/NewActionWrapper';
12
+
13
+ const InputName = ({ title, placeholder }) => {
14
+ const { automate, closeScreen } = useRoute().params;
15
+ const t = useTranslations();
16
+ const { navigate } = useNavigation();
17
+ const [name, setName] = useState(automate?.name);
18
+
19
+ const handleContinue = useCallback(async () => {
20
+ Keyboard.dismiss();
21
+
22
+ const params = {
23
+ ...automate,
24
+ name: name,
25
+ };
26
+
27
+ const { success, data } = automate?.id
28
+ ? await axiosPut(API.AUTOMATE.UPDATE_AUTOMATE(automate?.id), params)
29
+ : await axiosPost(API.AUTOMATE.CREATE_AUTOMATE(), params);
30
+
31
+ if (success) {
32
+ navigate({
33
+ name: closeScreen,
34
+ merge: true,
35
+ params: {
36
+ newAutomate: data,
37
+ },
38
+ });
39
+ }
40
+ }, [automate, name, navigate, closeScreen]);
41
+
42
+ return (
43
+ <NewActionWrapper
44
+ canNext={name}
45
+ onNext={handleContinue}
46
+ nextTitle={t('save')}
47
+ name={title}
48
+ >
49
+ <ScrollView scrollIndicatorInsets={{ right: 1 }}>
50
+ <_TextInput
51
+ placeholder={placeholder}
52
+ wrapStyle={styles.noMarginTop}
53
+ onChange={setName}
54
+ textInputStyle={styles.textInput}
55
+ value={name}
56
+ accessibilityLabel={AccessibilityLabel.NAME_YOUR_BUTTON}
57
+ autoFocus
58
+ />
59
+ </ScrollView>
60
+ </NewActionWrapper>
61
+ );
62
+ };
63
+
64
+ export default InputName;
@@ -1,6 +1,6 @@
1
1
  import { StyleSheet } from 'react-native';
2
2
  import { getBottomSpace } from 'react-native-iphone-x-helper';
3
- import { Colors } from '../../configs';
3
+ import { Colors } from '../../../configs';
4
4
 
5
5
  export default StyleSheet.create({
6
6
  wrap: {
@@ -29,7 +29,7 @@ export default StyleSheet.create({
29
29
  bottom: 0,
30
30
  left: 0,
31
31
  right: 0,
32
- paddingBottom: getBottomSpace() > 0 ? getBottomSpace() : 32,
32
+ paddingBottom: getBottomSpace() || 32,
33
33
  paddingTop: 24,
34
34
  backgroundColor: Colors.White,
35
35
  borderColor: Colors.ShadownTransparent,
@@ -1,4 +1,4 @@
1
- import { Colors } from '../../../configs';
1
+ import { Colors } from '../../../../configs';
2
2
  import { StyleSheet } from 'react-native';
3
3
 
4
4
  export default StyleSheet.create({
@@ -18,6 +18,10 @@ export default StyleSheet.create({
18
18
  height: 100,
19
19
  marginBottom: 16,
20
20
  },
21
+ isDragging: {
22
+ borderBottomWidth: 1,
23
+ borderColor: Colors.Red,
24
+ },
21
25
  leftItem: {
22
26
  width: 41,
23
27
  height: '100%',
@@ -1,16 +1,16 @@
1
1
  import React from 'react';
2
2
  import DraggableFlatList from 'react-native-draggable-flatlist';
3
3
  import { create, act } from 'react-test-renderer';
4
- import { SCProvider } from '../../../context';
5
- import { mockSCStore } from '../../../context/mockStore';
4
+ import { SCProvider } from '../../../../context';
5
+ import { mockSCStore } from '../../../../context/mockStore';
6
6
  import EditActionsList from '../index';
7
- import { AccessibilityLabel } from '../../../configs/Constants';
7
+ import { AccessibilityLabel } from '../../../../configs/Constants';
8
8
  import { TouchableOpacity } from 'react-native';
9
- import api from '../../../utils/Apis/axios';
9
+ import api from '../../../../utils/Apis/axios';
10
10
  import MockAdapter from 'axios-mock-adapter';
11
- import API from '../../../configs/API';
11
+ import API from '../../../../configs/API';
12
12
 
13
- import { ModalBottom } from '../../../commons/Modal';
13
+ import { ModalBottom } from '../../../../commons/Modal';
14
14
 
15
15
  const mockSetdata = jest.fn();
16
16
  const mockedNavigate = jest.fn();