@eohjsc/react-native-smart-city 0.2.45 → 0.2.49

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 (98) hide show
  1. package/README.md +9 -0
  2. package/index.js +6 -0
  3. package/package.json +23 -3
  4. package/src/Images/Common/logo.png +0 -0
  5. package/src/Images/Common/logo@2x.png +0 -0
  6. package/src/Images/Common/logo@3x.png +0 -0
  7. package/src/commons/ActionTemplate/index.js +40 -25
  8. package/src/commons/Automate/ItemAutomate.js +2 -2
  9. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +82 -0
  10. package/src/commons/Dashboard/MyPinnedSharedUnit/styles.js +78 -0
  11. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +60 -0
  12. package/src/commons/Dashboard/MyUnit/index.js +111 -0
  13. package/src/commons/Dashboard/MyUnit/styles.js +61 -0
  14. package/src/commons/Device/ConnectedViewHeader.js +4 -1
  15. package/src/commons/Form/TextInput.js +1 -1
  16. package/src/commons/MediaPlayer/index.js +6 -1
  17. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +3 -3
  18. package/src/{screens/Unit/components → commons}/SearchLocation/RowLocation.js +2 -2
  19. package/src/{screens/Unit/components → commons}/SearchLocation/RowLocationStyles.js +1 -1
  20. package/src/{screens/Unit/components → commons}/SearchLocation/SearchBarLocationStyles.js +1 -1
  21. package/src/{screens/Unit/components → commons}/SearchLocation/__test__/RowLocation.test.js +2 -2
  22. package/src/{screens/Unit/components → commons}/SearchLocation/index.js +2 -2
  23. package/src/commons/SubUnit/OneTap/ItemOneTap.js +3 -1
  24. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +2 -0
  25. package/src/commons/SubUnit/ShortDetail.js +1 -1
  26. package/src/commons/Unit/SharedUnit.js +2 -2
  27. package/src/configs/API.js +11 -4
  28. package/src/configs/Constants.js +19 -6
  29. package/src/configs/Images.js +1 -0
  30. package/src/iot/RemoteControl/Bluetooth.js +10 -1
  31. package/src/iot/RemoteControl/Internet.js +0 -2
  32. package/src/navigations/AddDeviceStack.js +5 -0
  33. package/src/navigations/AddUnitStack.js +2 -0
  34. package/src/navigations/UnitStack.js +8 -0
  35. package/src/screens/ActivityLog/FilterPopup.js +24 -17
  36. package/src/screens/ActivityLog/ItemLog.js +26 -22
  37. package/src/screens/ActivityLog/__test__/FilterPopup.test.js +1 -0
  38. package/src/screens/ActivityLog/__test__/ItemLog.test.js +0 -20
  39. package/src/screens/ActivityLog/__test__/index.test.js +3 -0
  40. package/src/screens/ActivityLog/hooks/__test__/index.test.js +8 -0
  41. package/src/screens/ActivityLog/hooks/index.js +5 -9
  42. package/src/screens/ActivityLog/index.js +4 -4
  43. package/src/screens/ActivityLog/styles/filterPopupStyles.js +3 -0
  44. package/src/screens/AddCommon/SelectSubUnit.js +10 -1
  45. package/src/screens/AddCommon/SelectUnit.js +11 -0
  46. package/src/screens/AddLocationMaps/index.js +124 -74
  47. package/src/screens/AddLocationMaps/indexStyle.js +58 -0
  48. package/src/screens/AddNewAction/SelectAction.js +59 -4
  49. package/src/screens/AddNewAction/SelectSensorDevices.js +27 -5
  50. package/src/screens/AddNewAction/SetupSensor.js +1 -6
  51. package/src/screens/AddNewAction/__test__/SelectAction.test.js +6 -4
  52. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +11 -1
  53. package/src/screens/AddNewAutoSmart/index.js +24 -13
  54. package/src/screens/AddNewDevice/ConnectingDevices.js +3 -0
  55. package/src/screens/AddNewGateway/ConnectingGatewayStyles.js +10 -1
  56. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +9 -1
  57. package/src/screens/AddNewOneTap/index.js +11 -6
  58. package/src/screens/Automate/MultiUnits.js +14 -53
  59. package/src/screens/Automate/__test__/MultiUnits.test.js +5 -246
  60. package/src/screens/Automate/__test__/index.test.js +1 -0
  61. package/src/screens/Automate/index.js +1 -0
  62. package/src/screens/Device/__test__/detail.test.js +14 -0
  63. package/src/screens/Device/components/DetailHistoryChart.js +63 -0
  64. package/src/screens/Device/components/EmergencyCountdown.js +29 -0
  65. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +57 -0
  66. package/src/screens/Device/components/SensorDisplayItem.js +127 -0
  67. package/src/screens/Device/detail.js +81 -294
  68. package/src/screens/Device/hooks/useDisconnectedDevice.js +63 -0
  69. package/src/screens/Device/styles.js +0 -10
  70. package/src/screens/GuestInfo/components/RecurringDetail.js +2 -2
  71. package/src/screens/Notification/components/NotificationItem.js +31 -14
  72. package/src/screens/Notification/styles/NotificationItemStyles.js +5 -0
  73. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +12 -3
  74. package/src/screens/ScanChipQR/components/QRScan/__test__/QRScan.test.js +11 -2
  75. package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +12 -3
  76. package/src/screens/ScriptDetail/__test__/index.test.js +83 -3
  77. package/src/screens/ScriptDetail/hooks/index.js +4 -0
  78. package/src/screens/ScriptDetail/index.js +65 -4
  79. package/src/screens/SetSchedule/__test__/SelectWeekday.test.js +2 -2
  80. package/src/screens/SetSchedule/__test__/index.test.js +8 -0
  81. package/src/screens/SetSchedule/components/SelectWeekday.js +13 -7
  82. package/src/screens/SetSchedule/index.js +28 -6
  83. package/src/screens/Sharing/Components/__test__/TitleCheckBox.test.js +38 -0
  84. package/src/screens/SubUnit/AddSubUnit.js +113 -29
  85. package/src/screens/SubUnit/AddSubUnitStyles.js +10 -0
  86. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +1 -0
  87. package/src/screens/TDSGuide/index.js +15 -19
  88. package/src/screens/Unit/MoreMenu.js +6 -1
  89. package/src/screens/Unit/SelectLocation.js +2 -3
  90. package/src/screens/Unit/SmartAccount.js +141 -0
  91. package/src/screens/Unit/SmartAccountItem.js +51 -0
  92. package/src/screens/Unit/SmartAccountStyles.js +46 -0
  93. package/src/screens/Unit/__test__/SmartAccount.test.js +58 -0
  94. package/src/screens/Unit/hook/useStateAlertRemove.js +36 -0
  95. package/src/utils/I18n/translations/en.json +26 -2
  96. package/src/utils/I18n/translations/vi.json +38 -14
  97. package/src/utils/Route/index.js +4 -0
  98. package/src/utils/Validation.js +3 -1
@@ -45,6 +45,9 @@ const AddCommonSelectUnit = ({ route }) => {
45
45
  setTitle(t('text_select_a_unit'));
46
46
  setSubTitle(t('first_select_a_unit'));
47
47
  break;
48
+ case 'AddHassioDevice':
49
+ setTitle(t('text_select_a_unit'));
50
+ break;
48
51
  default:
49
52
  setTitle(t('add_new_sub_unit'));
50
53
  setSubTitle(t('add_new_subunit_select_unit'));
@@ -91,6 +94,14 @@ const AddCommonSelectUnit = ({ route }) => {
91
94
  unit_id: units[selectedIndex].id,
92
95
  });
93
96
  break;
97
+ case 'AddHassioDevice':
98
+ navigation.navigate(Routes.SmartAccountConnecting, {
99
+ username: route.params.username,
100
+ password: route.params.password,
101
+ brand: route.params.brand,
102
+ unit_id: units[selectedIndex].id,
103
+ });
104
+ break;
94
105
  default:
95
106
  break;
96
107
  }
@@ -1,14 +1,20 @@
1
- import React, { memo, useState, useEffect, useCallback } from 'react';
2
- import { View, StyleSheet } from 'react-native';
3
- import MapView, { Marker, Circle, PROVIDER_GOOGLE } from 'react-native-maps';
4
- import { getStatusBarHeight } from 'react-native-iphone-x-helper';
1
+ import React, { memo, useState, useCallback, useRef } from 'react';
2
+ import { View, ScrollView } from 'react-native';
3
+ import MapView, { Marker, PROVIDER_GOOGLE } from 'react-native-maps';
5
4
  import { useNavigation } from '@react-navigation/native';
6
5
  import { useTranslations } from '../../hooks/Common/useTranslations';
7
6
 
8
7
  import { Colors } from '../../configs';
9
8
  import Text from '../../commons/Text';
10
9
  import { ViewButtonBottom } from '../../commons';
11
- import PinLocation from '../../../assets/images/AddLocationMaps/PinLocation.svg';
10
+ import SearchBarLocation from '../../commons/SearchLocation';
11
+ import RowLocation from '../../commons/SearchLocation/RowLocation';
12
+ import Point from '../../../assets/images/AddLocationMaps/Point.svg';
13
+ import { axiosGet } from '../../utils/Apis/axios';
14
+ import { API } from '../../configs';
15
+ import { SCConfig } from '../../configs';
16
+ import styles from './indexStyle';
17
+ import Routes from '../../utils/Route';
12
18
 
13
19
  export const initialRadius = 250;
14
20
  const initialRegion = {
@@ -16,21 +22,99 @@ const initialRegion = {
16
22
  longitudeDelta: 0.009221,
17
23
  };
18
24
 
25
+ const DEFAULT_LATITUDE = 10.7974046; // EoH center
26
+ const DEFAULT_LONGITUDE = 106.7035663;
27
+
19
28
  const AddLocationMaps = memo(() => {
20
29
  const t = useTranslations();
21
- const { goBack } = useNavigation();
22
- const [color, setColor] = useState(Colors.Black);
23
- useEffect(() => {
24
- setColor(Colors.DaybreakBlue);
25
- }, [setColor]);
30
+ const { goBack, navigate } = useNavigation();
31
+ const [input, setInput] = useState('');
32
+ const [searchData, setSearchData] = useState([]);
33
+ const [searchedLocation, setSearchedLocation] = useState(null);
26
34
 
27
- const selectedCoordinates = { latitude: 10.7993573, longitude: 106.7050793 };
35
+ const mapRef = useRef(null);
28
36
 
29
- const onDone = useCallback(() => {}, []);
37
+ const onDone = useCallback(() => {
38
+ navigate(Routes.AddSubUnit, {
39
+ location: input,
40
+ isAddUnit: true,
41
+ });
42
+ }, [input, navigate]);
30
43
  const onBack = useCallback(() => {
31
44
  goBack();
32
45
  }, [goBack]);
33
46
 
47
+ const onTextInput = useCallback(async (input) => {
48
+ setInput(input);
49
+ if (!input) {
50
+ setSearchData([]);
51
+ setSearchedLocation(null);
52
+ return;
53
+ }
54
+ try {
55
+ const config = {
56
+ params: {
57
+ input: input,
58
+ key: SCConfig.GOOGLE_MAP_API_KEY,
59
+ sessiontoken: 123456324,
60
+ strictBounds: false,
61
+ types: ['establishment'],
62
+ },
63
+ };
64
+
65
+ const { success, data } = await axiosGet(
66
+ API.EXTERNAL.GOOGLE_MAP.AUTO_COMPLETE,
67
+ config
68
+ );
69
+ if (success) {
70
+ setSearchData(data.predictions);
71
+ }
72
+ } catch (error) {}
73
+ }, []);
74
+
75
+ const animateToRegion = useCallback((lat, lng) => {
76
+ if (!mapRef || !mapRef.current) {
77
+ return;
78
+ }
79
+
80
+ mapRef.current.animateToRegion(
81
+ {
82
+ latitude: lat,
83
+ longitude: lng,
84
+ ...initialRegion,
85
+ },
86
+ 600
87
+ );
88
+ }, []);
89
+
90
+ const onPressRowLocation = useCallback(
91
+ async (item) => {
92
+ setInput(item.description);
93
+ setSearchData([]);
94
+ const body = {
95
+ params: {
96
+ place_id: item.place_id,
97
+ key: SCConfig.GOOGLE_MAP_API_KEY,
98
+ },
99
+ };
100
+
101
+ const { success, data } = await axiosGet(
102
+ API.EXTERNAL.GOOGLE_MAP.GET_LAT_LNG_BY_PLACE_ID,
103
+ body
104
+ );
105
+ if (success) {
106
+ const { location } = data.result.geometry;
107
+ animateToRegion(location.lat, location.lng);
108
+ setSearchedLocation({
109
+ description: item.description,
110
+ latitude: location.lat,
111
+ longitude: location.lng,
112
+ });
113
+ }
114
+ },
115
+ [animateToRegion]
116
+ );
117
+
34
118
  return (
35
119
  <View style={styles.container}>
36
120
  <Text color={Colors.Gray9} size={24} semibold style={styles.textHeader}>
@@ -40,35 +124,39 @@ const AddLocationMaps = memo(() => {
40
124
  <Text color={Colors.Gray8} size={12} style={styles.textExplain}>
41
125
  {t('text_explain_add_geolocation')}
42
126
  </Text>
43
- <Text color={Colors.Black} size={16} style={styles.textAddress}>
44
- 298/3 Điện Biên Phủ, phường 17, quận Bình Thạnh, Thành phố Hồ Chí
45
- Minh, Việt Nam
46
- </Text>
127
+ <View style={styles.searchLocation}>
128
+ <SearchBarLocation input={input} onTextInput={onTextInput} />
129
+ <ScrollView style={styles.searchData}>
130
+ {searchData.map((item) => (
131
+ <RowLocation item={item} onPress={onPressRowLocation} />
132
+ ))}
133
+ </ScrollView>
134
+ </View>
47
135
  <View style={styles.mapContainer}>
48
136
  <MapView
137
+ ref={mapRef}
49
138
  provider={PROVIDER_GOOGLE}
50
- region={{
51
- ...selectedCoordinates,
139
+ style={styles.mapView}
140
+ initialRegion={{
52
141
  ...initialRegion,
142
+ latitude: DEFAULT_LATITUDE,
143
+ longitude: DEFAULT_LONGITUDE,
53
144
  }}
54
- style={styles.mapView}
145
+ followUserLocation={true}
55
146
  >
56
- <Marker
57
- coordinate={selectedCoordinates}
58
- anchor={{ x: 0.5, y: 0.5 }}
59
- calloutOffset={{ x: 1, y: 1 }}
60
- tracksViewChanges={false}
61
- >
62
- <PinLocation />
63
- </Marker>
64
- <Circle
65
- center={selectedCoordinates}
66
- radius={initialRadius}
67
- strokeColor={Colors.Blue6}
68
- fillColor={color}
69
- zIndex={2}
70
- strokeWidth={1}
71
- />
147
+ {searchedLocation && (
148
+ <Marker
149
+ coordinate={{
150
+ latitude: searchedLocation.latitude,
151
+ longitude: searchedLocation.longitude,
152
+ }}
153
+ tracksViewChanges={false}
154
+ >
155
+ <View style={styles.pointCircle}>
156
+ <Point />
157
+ </View>
158
+ </Marker>
159
+ )}
72
160
  </MapView>
73
161
  </View>
74
162
  </View>
@@ -77,48 +165,10 @@ const AddLocationMaps = memo(() => {
77
165
  onLeftClick={onBack}
78
166
  rightTitle={t('done')}
79
167
  onRightClick={onDone}
168
+ rightDisabled={!input}
80
169
  />
81
170
  </View>
82
171
  );
83
172
  });
84
173
 
85
174
  export default AddLocationMaps;
86
-
87
- const styles = StyleSheet.create({
88
- container: {
89
- flex: 1,
90
- backgroundColor: Colors.Gray2,
91
- paddingTop: getStatusBarHeight() + 16,
92
- },
93
- textHeader: {
94
- marginHorizontal: 16,
95
- },
96
- content: {
97
- marginTop: 16,
98
- paddingTop: 16,
99
- borderTopLeftRadius: 20,
100
- borderTopRightRadius: 20,
101
- backgroundColor: Colors.White,
102
- borderWidth: 1,
103
- borderColor: Colors.Gray4,
104
- flex: 1,
105
- },
106
- textExplain: {
107
- lineHeight: 20,
108
- marginHorizontal: 16,
109
- },
110
- textAddress: {
111
- lineHeight: 24,
112
- margin: 16,
113
- },
114
- mapContainer: {
115
- flex: 1,
116
- },
117
- mapView: {
118
- position: 'absolute',
119
- top: 0,
120
- left: 0,
121
- right: 0,
122
- bottom: 0,
123
- },
124
- });
@@ -0,0 +1,58 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { getStatusBarHeight } from 'react-native-iphone-x-helper';
3
+
4
+ import { Colors } from '../../configs';
5
+
6
+ export default StyleSheet.create({
7
+ container: {
8
+ flex: 1,
9
+ backgroundColor: Colors.Gray2,
10
+ paddingTop: getStatusBarHeight() + 16,
11
+ },
12
+ textHeader: {
13
+ marginHorizontal: 16,
14
+ },
15
+ content: {
16
+ marginTop: 16,
17
+ paddingTop: 16,
18
+ borderTopLeftRadius: 20,
19
+ borderTopRightRadius: 20,
20
+ backgroundColor: Colors.White,
21
+ borderWidth: 1,
22
+ borderColor: Colors.Gray4,
23
+ flex: 1,
24
+ },
25
+ textExplain: {
26
+ lineHeight: 20,
27
+ marginHorizontal: 16,
28
+ },
29
+ mapContainer: {
30
+ flex: 1,
31
+ },
32
+ mapView: {
33
+ position: 'absolute',
34
+ top: 0,
35
+ left: 0,
36
+ right: 0,
37
+ bottom: 0,
38
+ },
39
+ pointCircle: {
40
+ flex: 1,
41
+ alignItems: 'center',
42
+ justifyContent: 'center',
43
+ width: 109,
44
+ height: 109,
45
+ borderRadius: 50,
46
+ backgroundColor: Colors.BlueTransparent5,
47
+ borderWidth: 1,
48
+ borderColor: Colors.Blue10,
49
+ },
50
+ searchLocation: {
51
+ paddingVertical: 8,
52
+ },
53
+ searchData: {
54
+ paddingHorizontal: 26,
55
+ width: '100%',
56
+ maxHeight: 100,
57
+ },
58
+ });
@@ -12,7 +12,7 @@ import OptionsDropdownActionTemplate from '../../commons/OneTapTemplate/OptionsD
12
12
  import StatesGridActionTemplate from '../../commons/OneTapTemplate/StatesGridActionTemplate';
13
13
  import { axiosGet, axiosPost } from '../../utils/Apis/axios';
14
14
  import { API, Images } from '../../configs';
15
- import { TESTID } from '../../configs/Constants';
15
+ import { CONDITION_TYPES, TESTID } from '../../configs/Constants';
16
16
  import Routes from '../../utils/Route';
17
17
  import styles from './Styles/SelectActionStyles';
18
18
  import moment from 'moment';
@@ -30,6 +30,7 @@ const SelectAction = memo(({ route }) => {
30
30
  unit,
31
31
  device,
32
32
  automateId,
33
+ automate = {},
33
34
  scriptName,
34
35
  isSelectSensor = false,
35
36
  type,
@@ -42,9 +43,11 @@ const SelectAction = memo(({ route }) => {
42
43
  const [sensorData, setSensorData] = useState([]);
43
44
  const [checkedItem, setCheckedItem] = useState({});
44
45
  const [isLoading, setIsLoading] = useState(false);
46
+ const [isfetched, setIsfetched] = useState(true);
45
47
 
46
48
  const fetchData = useCallback(async () => {
47
49
  isSelectSensor && setIsLoading(true);
50
+ setIsfetched(true);
48
51
  const { success, data } = await axiosGet(
49
52
  isSelectSensor
50
53
  ? API.AUTOMATE.GET_SENSOR_CONFIG(device.id)
@@ -53,13 +56,58 @@ const SelectAction = memo(({ route }) => {
53
56
  isSelectSensor && true
54
57
  );
55
58
  if (success) {
56
- isSelectSensor ? setSensorData(data) : setData(data);
59
+ if (isSelectSensor) {
60
+ if (automate?.config_id) {
61
+ const conditionType = [
62
+ {
63
+ title: `${t('is_below')} (<)`,
64
+ type: CONDITION_TYPES.IS_BELOW,
65
+ conditionValue: '<',
66
+ },
67
+ {
68
+ title: `${t('is')} (=)`,
69
+ type: CONDITION_TYPES.IS,
70
+ conditionValue: '=',
71
+ },
72
+ {
73
+ title: `${t('is_above')} (>)`,
74
+ type: CONDITION_TYPES.IS_ABOVE,
75
+ conditionValue: '>',
76
+ },
77
+ ];
78
+ const condition = conditionType.find((item) => {
79
+ return item.conditionValue === automate.condition;
80
+ });
81
+ const updateSensorData = data.map((obj) =>
82
+ obj.id === automate.config_id
83
+ ? { ...obj, value: automate.value, ...condition }
84
+ : obj
85
+ );
86
+ let selectSensor = data.find((config) => {
87
+ return config.id === automate.config_id;
88
+ });
89
+ setSensorData(updateSensorData);
90
+ setCheckedItem(selectSensor);
91
+ } else {
92
+ setSensorData(data);
93
+ }
94
+ } else {
95
+ setData(data);
96
+ }
57
97
  }
98
+ setIsfetched(false);
58
99
  const to = setTimeout(() => {
59
100
  setIsLoading(false);
60
101
  clearTimeout(to);
61
102
  }, 1000);
62
- }, [device.id, isSelectSensor]);
103
+ }, [
104
+ automate.condition,
105
+ automate.config_id,
106
+ automate.value,
107
+ device.id,
108
+ isSelectSensor,
109
+ t,
110
+ ]);
63
111
 
64
112
  const checkConditionToContinue = useCallback(() => {
65
113
  const itemTemp = sensorData?.find((i) => i.id === checkedItem?.id);
@@ -76,6 +124,13 @@ const SelectAction = memo(({ route }) => {
76
124
  isSelectSensor,
77
125
  isMultiUnits,
78
126
  automateId,
127
+ automate: {
128
+ ...automate,
129
+ condition: itemTemp?.conditionValue || '<',
130
+ value: itemTemp?.value,
131
+ config_id: itemTemp?.id,
132
+ config_name: itemTemp?.name,
133
+ },
79
134
  scriptName,
80
135
  });
81
136
  } else {
@@ -302,7 +357,7 @@ const SelectAction = memo(({ route }) => {
302
357
  testID={TESTID.ACTION_ITEM}
303
358
  />
304
359
  )}
305
- {data?.length === 0 && (
360
+ {data?.length === 0 && sensorData?.length === 0 && !isfetched && (
306
361
  <View style={styles.noneData}>
307
362
  <Text center>
308
363
  {t('you_do_not_have_the_device_or_have_share_control_device')}
@@ -21,6 +21,7 @@ const SelectSensorDevices = memo(({ route }) => {
21
21
  const {
22
22
  unit,
23
23
  automateId,
24
+ automate = {},
24
25
  title = AUTOMATE_SELECT.SELECT_DEVICE,
25
26
  type,
26
27
  scriptName,
@@ -59,13 +60,29 @@ const SelectSensorDevices = memo(({ route }) => {
59
60
  station: item,
60
61
  index: index,
61
62
  }));
63
+ if (isSelectSensor) {
64
+ if (automate.sensor_id) {
65
+ let selectSensor = {};
66
+ data.map((item) => {
67
+ item.sensors.map((sensor) => {
68
+ if (sensor.id === automate.sensor_id) {
69
+ selectSensor = sensor;
70
+ return;
71
+ } else if (selectSensor) {
72
+ return;
73
+ }
74
+ });
75
+ });
76
+ setSelectedDevice(selectSensor);
77
+ }
78
+ }
62
79
  setStation(data);
63
80
  setListMenuItem(listMenu);
64
81
  setListStation(listMenu.concat([{ text: '' }]));
65
82
  }
66
83
  }
67
84
  );
68
- }, [isSelectSensor, unit.id]);
85
+ }, [automate.sensor_id, isSelectSensor, unit]);
69
86
 
70
87
  useEffect(() => {
71
88
  fetchDetails();
@@ -84,6 +101,10 @@ const SelectSensorDevices = memo(({ route }) => {
84
101
  unit,
85
102
  device: selectedDevice,
86
103
  automateId: automateId,
104
+ automate: {
105
+ ...automate,
106
+ sensor_id: selectedDevice?.id ? selectedDevice.id : automate.sensor_id,
107
+ },
87
108
  stationName: station[indexStation]?.name,
88
109
  isSelectSensor,
89
110
  type,
@@ -93,18 +114,19 @@ const SelectSensorDevices = memo(({ route }) => {
93
114
  isMultiUnits,
94
115
  });
95
116
  }, [
117
+ navigate,
118
+ unit,
96
119
  selectedDevice,
97
120
  automateId,
121
+ automate,
98
122
  station,
99
123
  indexStation,
100
- navigate,
101
- unit,
102
- type,
103
124
  isSelectSensor,
125
+ type,
104
126
  scriptName,
105
- isMultiUnits,
106
127
  isAutomateTab,
107
128
  isCreateNewAction,
129
+ isMultiUnits,
108
130
  ]);
109
131
 
110
132
  const onPressClose = useCallback(() => {
@@ -13,12 +13,7 @@ import BottomButtonView from '../../commons/BottomButtonView';
13
13
  import { HorizontalPicker } from '../../commons';
14
14
  import { popAction } from '../../navigations/utils';
15
15
  import { useStatusBarPreview } from '../../hooks/Common/useStatusBar';
16
-
17
- const CONDITION_TYPES = {
18
- IS: 'IS',
19
- IS_BELOW: 'IS_BELOW',
20
- IS_ABOVE: 'IS_ABOVE',
21
- };
16
+ import { CONDITION_TYPES } from '../../configs/Constants';
22
17
 
23
18
  const SetUpSensor = () => {
24
19
  const t = useTranslations();
@@ -63,7 +63,7 @@ describe('Test SelectAction', () => {
63
63
  return response;
64
64
  });
65
65
  await act(async () => {
66
- tree = renderer.create(wrapComponent(route));
66
+ tree = await renderer.create(wrapComponent(route));
67
67
  });
68
68
  const instance = tree.root;
69
69
 
@@ -83,7 +83,7 @@ describe('Test SelectAction', () => {
83
83
  return response;
84
84
  });
85
85
  await act(async () => {
86
- tree = renderer.create(wrapComponent(route));
86
+ tree = await renderer.create(wrapComponent(route));
87
87
  });
88
88
  const instance = tree.root;
89
89
 
@@ -99,6 +99,7 @@ describe('Test SelectAction', () => {
99
99
  visibilityTime: 1000,
100
100
  });
101
101
  });
102
+
102
103
  test('test fetchData', async () => {
103
104
  const response = {
104
105
  status: 200,
@@ -113,7 +114,7 @@ describe('Test SelectAction', () => {
113
114
  return response;
114
115
  });
115
116
  await act(async () => {
116
- tree = renderer.create(wrapComponent(route));
117
+ tree = await renderer.create(wrapComponent(route));
117
118
  });
118
119
  expect(axios.get).toHaveBeenCalled();
119
120
  });
@@ -219,6 +220,7 @@ describe('Test SelectAction', () => {
219
220
  expect(optionsDropdownActionTemplate).toBeDefined();
220
221
  expect(statesGridActionTemplate).toBeDefined();
221
222
  });
223
+
222
224
  test('test onPress handleOnSelectAction', async () => {
223
225
  const response = {
224
226
  status: 200,
@@ -247,7 +249,7 @@ describe('Test SelectAction', () => {
247
249
  return response;
248
250
  });
249
251
  await act(async () => {
250
- tree = renderer.create(wrapComponent(route));
252
+ tree = await renderer.create(wrapComponent(route));
251
253
  });
252
254
  const instance = tree.root;
253
255
  const actionTemplate = instance.findByType(ActionTemplate);
@@ -39,6 +39,10 @@ describe('test AddNewAutoSmart', () => {
39
39
  },
40
40
  };
41
41
 
42
+ beforeEach(() => {
43
+ mockNavigate.mockClear();
44
+ });
45
+
42
46
  test('AddNewAutoSmart select sensor device', async () => {
43
47
  await act(async () => {
44
48
  tree = await create(wrapComponent(route));
@@ -62,8 +66,11 @@ describe('test AddNewAutoSmart', () => {
62
66
  });
63
67
 
64
68
  expect(mockNavigate).toBeCalledWith(Routes.SelectSensorDevices, {
69
+ automate: {},
70
+ automateId: undefined,
65
71
  title: 'select_sensor',
66
72
  type: 'value_change',
73
+ scriptName: undefined,
67
74
  unit: { id: 1 },
68
75
  isAutomateTab: undefined,
69
76
  isMultiUnits: undefined,
@@ -92,11 +99,14 @@ describe('test AddNewAutoSmart', () => {
92
99
  await bottomButton.props.onPress();
93
100
  });
94
101
  expect(mockNavigate).toHaveBeenCalledWith(Routes.SetSchedule, {
102
+ automate: {},
103
+ automateId: undefined,
95
104
  type: 'schedule',
105
+ routeName: 'SetSchedule',
106
+ scriptName: undefined,
96
107
  unit: route.params.unit,
97
108
  isAutomateTab: undefined,
98
109
  isMultiUnits: undefined,
99
- routeName: 'SetSchedule',
100
110
  });
101
111
  });
102
112
  });
@@ -17,8 +17,14 @@ import Routes from '../../utils/Route';
17
17
  const AddNewAutoSmart = memo(({ route }) => {
18
18
  const t = useTranslations();
19
19
  const { navigate, goBack } = useNavigation();
20
- const { type, unit, isAutomateTab, isMultiUnits, automateId, scriptName } =
21
- route.params;
20
+ const {
21
+ type,
22
+ unit,
23
+ isAutomateTab,
24
+ isMultiUnits,
25
+ automate = {},
26
+ scriptName,
27
+ } = route.params;
22
28
  const typeAutoSmart = {
23
29
  [AUTOMATE_TYPE.AUTOMATE]: [
24
30
  {
@@ -57,26 +63,31 @@ const AddNewAutoSmart = memo(({ route }) => {
57
63
  },
58
64
  ],
59
65
  };
60
- const [data] = useState(typeAutoSmart[type]);
61
- const [selectedIndex, setSelectedIndex] = useState(-1);
66
+ const [data] = useState(
67
+ automate?.id ? typeAutoSmart[AUTOMATE_TYPE.AUTOMATE] : typeAutoSmart[type]
68
+ );
69
+ const [selectedIndex, setSelectedIndex] = useState(
70
+ automate?.id ? data.findIndex((obj) => obj.type === type) : -1
71
+ );
62
72
 
63
73
  const handleOnContinue = useCallback(() => {
64
- const automate = data[selectedIndex];
74
+ const dataAutomate = data[selectedIndex];
65
75
  const params = {
66
- type: automate?.type,
76
+ type: dataAutomate?.type,
67
77
  unit: unit,
68
- ...(automate?.data || {}),
78
+ ...(dataAutomate?.data || {}),
69
79
  isAutomateTab,
70
80
  isMultiUnits,
71
- routeName: automate?.route,
72
- automateId,
81
+ automateId: automate?.id,
82
+ routeName: dataAutomate?.route,
83
+ automate,
73
84
  scriptName,
74
85
  };
75
86
 
76
- if (automate.type === AUTOMATE_TYPE.VALUE_CHANGE && isMultiUnits) {
87
+ if (dataAutomate.type === AUTOMATE_TYPE.VALUE_CHANGE && isMultiUnits) {
77
88
  navigate(Routes.SelectUnit, params);
78
89
  } else {
79
- navigate(automate.route, params);
90
+ navigate(dataAutomate.route, params);
80
91
  }
81
92
  }, [
82
93
  navigate,
@@ -85,7 +96,7 @@ const AddNewAutoSmart = memo(({ route }) => {
85
96
  unit,
86
97
  isAutomateTab,
87
98
  isMultiUnits,
88
- automateId,
99
+ automate,
89
100
  scriptName,
90
101
  ]);
91
102
 
@@ -107,7 +118,7 @@ const AddNewAutoSmart = memo(({ route }) => {
107
118
  <HeaderCustom isShowClose onClose={onClose} />
108
119
  <View style={styles.container}>
109
120
  <Text semibold type={'H2'} style={styles.titleCreate}>
110
- {automateId ? t('update_smart') : t('create_smart')}
121
+ {automate?.id ? t('update_smart') : t('create_smart')}
111
122
  </Text>
112
123
  <Text type={'Body'} style={styles.titleChoose}>
113
124
  {t('choose_the_automation_method_you_want')}