@eohjsc/react-native-smart-city 0.2.59 → 0.2.63

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 (101) hide show
  1. package/README.md +115 -68
  2. package/assets/images/Map/MarkerGeolocation.svg +4 -0
  3. package/package.json +3 -3
  4. package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -2
  5. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +1 -1
  6. package/src/commons/ActionGroup/__test__/MenuActionAddSchedule.test.js +71 -0
  7. package/src/commons/ActionGroup/hooks/AccessScheduleDetailStyles.js +41 -0
  8. package/src/commons/ActionGroup/hooks/MenuActionAddSchedule.js +110 -0
  9. package/src/commons/ActionGroup/hooks/MenuActionAddScheduleStyle.js +69 -0
  10. package/src/commons/ActionGroup/hooks/RecurringDetail.js +97 -0
  11. package/src/commons/DateTimeRangeChange/DateTimeButton.js +7 -2
  12. package/src/commons/Device/HistoryChart.js +80 -81
  13. package/src/commons/Device/HorizontalBarChart.js +48 -31
  14. package/src/commons/Device/LinearChart.js +28 -1
  15. package/src/commons/Form/CurrencyInput.js +1 -0
  16. package/src/commons/FourButtonFilterHistory/__test__/FourButtonFilterHistory.test.js +48 -0
  17. package/src/commons/FourButtonFilterHistory/index.js +72 -0
  18. package/src/commons/FourButtonFilterHistory/styles.js +22 -0
  19. package/src/commons/ImagePicker/index.js +27 -33
  20. package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +11 -1
  21. package/src/commons/MediaPlayerDetail/index.js +14 -5
  22. package/src/commons/SubUnit/OneTap/OneTapStyles.js +20 -1
  23. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +151 -40
  24. package/src/commons/SubUnit/OneTap/index.js +64 -12
  25. package/src/commons/UnitSummary/AirQuality/index.js +9 -7
  26. package/src/commons/UnitSummary/ConfigHistoryChart.js +2 -1
  27. package/src/configs/API.js +3 -0
  28. package/src/configs/Constants.js +15 -0
  29. package/src/iot/RemoteControl/Bluetooth.js +6 -3
  30. package/src/iot/RemoteControl/GoogleHome.js +6 -3
  31. package/src/iot/RemoteControl/Internet.js +1 -0
  32. package/src/iot/RemoteControl/LG.js +2 -1
  33. package/src/iot/RemoteControl/index.js +13 -6
  34. package/src/navigations/SharedStack.js +11 -9
  35. package/src/navigations/UnitStack.js +26 -2
  36. package/src/screens/ActivityLog/ItemLog.js +3 -3
  37. package/src/screens/ActivityLog/__test__/ItemLog.test.js +5 -2
  38. package/src/screens/ActivityLog/hooks/index.js +2 -1
  39. package/src/screens/ActivityLog/index.js +0 -1
  40. package/src/screens/AddLocationMaps/index.js +4 -2
  41. package/src/screens/AddNewAction/SelectSensorDevices.js +18 -11
  42. package/src/screens/AddNewAction/Styles/SelectSensorDevicesStyles.js +5 -1
  43. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +6 -1
  44. package/src/screens/Automate/MultiUnits.js +7 -4
  45. package/src/screens/Automate/__test__/MultiUnits.test.js +1 -1
  46. package/src/screens/Automate/__test__/index.test.js +12 -0
  47. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +61 -0
  48. package/src/screens/ConfirmUnitDeletion/index.js +64 -0
  49. package/src/screens/ConfirmUnitDeletion/styles.js +37 -0
  50. package/src/screens/Device/__test__/detail.test.js +3 -2
  51. package/src/screens/Device/detail.js +48 -15
  52. package/src/screens/Device/hooks/useDisconnectedDevice.js +2 -1
  53. package/src/screens/Device/styles.js +3 -3
  54. package/src/screens/EmergencySetting/__test__/DropDownItem.test.js +59 -0
  55. package/src/screens/EmergencySetting/__test__/index.test.js +27 -0
  56. package/src/screens/EmergencySetting/components/DropDownItem.js +54 -0
  57. package/src/screens/EmergencySetting/index.js +92 -0
  58. package/src/screens/EmergencySetting/styles/DropDownItem.js +38 -0
  59. package/src/screens/EmergencySetting/styles.js +25 -0
  60. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +126 -0
  61. package/src/screens/MoveToAnotherSubUnit/index.js +88 -0
  62. package/src/screens/MoveToAnotherSubUnit/styles/MoveToAnotherSubUnitStyles.js +50 -0
  63. package/src/screens/ScriptDetail/Styles/indexStyles.js +0 -1
  64. package/src/screens/ScriptDetail/index.js +1 -0
  65. package/src/screens/SubUnit/AddSubUnit.js +3 -3
  66. package/src/screens/SubUnit/AddSubUnitStyles.js +0 -2
  67. package/src/screens/SubUnit/EditSubUnit.js +16 -7
  68. package/src/screens/SubUnit/EditSubUnitStyles.js +2 -3
  69. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +2 -2
  70. package/src/screens/TDSGuide/index.js +1 -1
  71. package/src/screens/Unit/ChooseLocation.js +3 -7
  72. package/src/screens/Unit/ChooseLocationStyles.js +5 -8
  73. package/src/screens/Unit/Detail.js +16 -6
  74. package/src/screens/Unit/ManageUnit.js +20 -26
  75. package/src/screens/Unit/SmartAccount.js +25 -41
  76. package/src/screens/Unit/SmartAccountItem.js +2 -1
  77. package/src/screens/Unit/SmartAccountStyles.js +0 -1
  78. package/src/screens/Unit/__test__/ManageUnit.test.js +0 -6
  79. package/src/screens/Unit/__test__/SmartAccount.test.js +24 -0
  80. package/src/screens/Unit/__test__/SmartAccountItem.test.js +72 -0
  81. package/src/screens/UnitSummary/components/3PPowerConsumption/index.js +58 -59
  82. package/src/screens/UnitSummary/components/PowerConsumption/index.js +26 -22
  83. package/src/screens/UnitSummary/components/Temperature/ItemTemperature/index.js +2 -2
  84. package/src/screens/UnitSummary/components/Temperature/index.js +15 -14
  85. package/src/screens/UnitSummary/components/UvIndex/index.js +6 -5
  86. package/src/screens/UnitSummary/components/WaterQuality/index.js +9 -7
  87. package/src/screens/UnitSummary/index.js +11 -7
  88. package/src/screens/WaterQualityGuide/index.js +1 -0
  89. package/src/utils/Apis/axios.js +4 -4
  90. package/src/utils/I18n/translations/en.json +20 -2
  91. package/src/utils/I18n/translations/vi.json +21 -2
  92. package/src/utils/Route/index.js +3 -0
  93. package/src/utils/Utils.js +4 -0
  94. package/src/commons/ThreeButtonHistory/CalendarHeader.js +0 -35
  95. package/src/commons/ThreeButtonHistory/CalendarHeaderStyles.js +0 -17
  96. package/src/commons/ThreeButtonHistory/SelectMonth.js +0 -53
  97. package/src/commons/ThreeButtonHistory/SelectMonthStyles.js +0 -29
  98. package/src/commons/ThreeButtonHistory/__test__/SelectMonth.test.js +0 -37
  99. package/src/commons/ThreeButtonHistory/__test__/ThreeButtonHistory.test.js +0 -240
  100. package/src/commons/ThreeButtonHistory/index.js +0 -310
  101. package/src/commons/ThreeButtonHistory/styles.js +0 -65
@@ -10,18 +10,24 @@ import { sendCommandOverLGThinq } from './LG';
10
10
 
11
11
  export const sendRemoteCommand = async (sensor, action, data) => {
12
12
  // No action, raise not authorized
13
+ let result = false;
13
14
  if (!action) {
14
15
  ToastBottomHelper.error(
15
16
  t('your_account_has_not_been_authorized_to_control')
16
17
  );
17
- return;
18
+ return result;
18
19
  }
19
20
  if (action.command_prefer_over_bluetooth) {
20
21
  try {
21
- await sendCommandOverBluetooth(sensor, action, data);
22
+ result = await sendCommandOverBluetooth(sensor, action, data);
22
23
  } catch (err) {
23
24
  if (err === SEND_COMMAND_OVER_BLUETOOTH_FAIL) {
24
- await sendCommandOverInternet(sensor, action, data, 'bluetooth');
25
+ result = await sendCommandOverInternet(
26
+ sensor,
27
+ action,
28
+ data,
29
+ 'bluetooth'
30
+ );
25
31
  } else {
26
32
  throw err;
27
33
  }
@@ -29,14 +35,15 @@ export const sendRemoteCommand = async (sensor, action, data) => {
29
35
  }
30
36
 
31
37
  if (action.command_prefer_over_internet) {
32
- await sendCommandOverInternet(sensor, action, data, 'internet');
38
+ result = await sendCommandOverInternet(sensor, action, data, 'internet');
33
39
  }
34
40
 
35
41
  if (action.command_prefer_over_googlehome) {
36
- await sendCommandOverGoogleHome(sensor, action, data);
42
+ result = await sendCommandOverGoogleHome(sensor, action, data);
37
43
  }
38
44
 
39
45
  if (action.command_prefer_over_lg) {
40
- await sendCommandOverLGThinq(sensor, action, data);
46
+ result = await sendCommandOverLGThinq(sensor, action, data);
41
47
  }
48
+ return result;
42
49
  };
@@ -1,7 +1,7 @@
1
1
  import React, { memo } from 'react';
2
2
  import { createStackNavigator } from '@react-navigation/stack';
3
3
  import { TouchableOpacity, StyleSheet } from 'react-native';
4
- import { useNavigation } from '@react-navigation/native';
4
+ import { useNavigation, useRoute } from '@react-navigation/native';
5
5
  import { Icon } from '@ant-design/react-native';
6
6
  import { useTranslations } from '../hooks/Common/useTranslations';
7
7
 
@@ -13,6 +13,7 @@ const Stack = createStackNavigator();
13
13
  const SharedStack = memo(() => {
14
14
  const t = useTranslations();
15
15
  const navigation = useNavigation();
16
+ const { params } = useRoute();
16
17
  return (
17
18
  <Stack.Navigator>
18
19
  <Stack.Screen
@@ -20,14 +21,15 @@ const SharedStack = memo(() => {
20
21
  component={Shared}
21
22
  options={{
22
23
  title: t('text_shared_with_me'),
23
- headerLeft: () => (
24
- <TouchableOpacity
25
- style={styles.btnMenu}
26
- onPress={() => navigation.toggleDrawer()}
27
- >
28
- <Icon name={'menu'} color={Colors.Black} />
29
- </TouchableOpacity>
30
- ),
24
+ headerLeft: () =>
25
+ params?.isMainSource && (
26
+ <TouchableOpacity
27
+ style={styles.btnMenu}
28
+ onPress={() => navigation.toggleDrawer()}
29
+ >
30
+ <Icon name={'menu'} color={Colors.Black} />
31
+ </TouchableOpacity>
32
+ ),
31
33
  headerTitleAlign: 'left',
32
34
  headerStyle: {
33
35
  backgroundColor: Colors.Gray2,
@@ -31,6 +31,7 @@ import AddNewAutoSmart from '../screens/AddNewAutoSmart';
31
31
  import PlaybackCamera from '../screens/PlayBackCamera';
32
32
  import AllCamera from '../screens/AllCamera';
33
33
  import ManageAccessScreen from '../screens/ManageAccess';
34
+ import MoveToAnotherSubUnit from '../screens/MoveToAnotherSubUnit';
34
35
  import GuestInfo from '../screens/GuestInfo';
35
36
  import ScriptDetail from '../screens/ScriptDetail';
36
37
  import EditActionsList from '../screens/EditActionsList';
@@ -41,6 +42,8 @@ import SelectAction from '../screens/AddNewAction/SelectAction';
41
42
  import EditSubUnit from '../screens/SubUnit/EditSubUnit';
42
43
  import SetUpSensor from '../screens/AddNewAction/SetupSensor';
43
44
  import EditDevice from '../screens/Device/EditDevice/index';
45
+ import EmergencySetting from '../screens/EmergencySetting';
46
+ import ConfirmUnitDeletion from '../screens/ConfirmUnitDeletion';
44
47
 
45
48
  const Stack = createStackNavigator();
46
49
 
@@ -156,7 +159,7 @@ export const UnitStack = memo((props) => {
156
159
  component={DeviceDetail}
157
160
  options={{
158
161
  headerShown: false,
159
- animationEnabled: false,
162
+ animationEnabled: Platform.OS === 'ios',
160
163
  }}
161
164
  />
162
165
  <Stack.Screen
@@ -170,7 +173,7 @@ export const UnitStack = memo((props) => {
170
173
  name={Route.TDSGuide}
171
174
  component={TDSGuide}
172
175
  options={{
173
- title: t('tds_infomation'),
176
+ title: t('tds_information'),
174
177
  }}
175
178
  />
176
179
  <Stack.Screen
@@ -229,6 +232,13 @@ export const UnitStack = memo((props) => {
229
232
  headerShown: false,
230
233
  }}
231
234
  />
235
+ <Stack.Screen
236
+ name={Route.MoveToAnotherSubUnit}
237
+ component={MoveToAnotherSubUnit}
238
+ options={{
239
+ headerShown: false,
240
+ }}
241
+ />
232
242
  <Stack.Screen
233
243
  name={Route.GuestInfo}
234
244
  component={GuestInfo}
@@ -291,6 +301,20 @@ export const UnitStack = memo((props) => {
291
301
  headerShown: false,
292
302
  }}
293
303
  />
304
+ <Stack.Screen
305
+ name={Route.EmergencySetting}
306
+ component={EmergencySetting}
307
+ options={{
308
+ headerShown: false,
309
+ }}
310
+ />
311
+ <Stack.Screen
312
+ name={Route.ConfirmUnitDeletion}
313
+ component={ConfirmUnitDeletion}
314
+ options={{
315
+ headerShown: false,
316
+ }}
317
+ />
294
318
  </Stack.Navigator>
295
319
  );
296
320
  });
@@ -29,14 +29,14 @@ const DetailLog = ({ item }) => {
29
29
  {item.action_name
30
30
  ? `${item.action_name} ${t('by')} `
31
31
  : `${t('activated_by')} `}
32
- <Text style={styles.name}>{item.name || item.params?.username}</Text>
32
+ <Text style={styles.name}>{item.name || item.username}</Text>
33
33
  </Text>
34
34
  );
35
35
  case ACTIVITY_LOG_TYPES.SCRIPT_UPDATED_BY:
36
36
  return (
37
37
  <Text style={styles.text}>
38
38
  {`${t('script_updated_by')} `}
39
- <Text style={styles.name}>{item.name || item.params?.username}</Text>
39
+ <Text style={styles.name}>{item.name || item.username}</Text>
40
40
  </Text>
41
41
  );
42
42
  default:
@@ -45,7 +45,7 @@ const DetailLog = ({ item }) => {
45
45
  {item.action_name
46
46
  ? `${item.action_name} ${t('by')} `
47
47
  : `${t('activated_by')} `}
48
- <Text style={styles.name}>{item.name || item.params?.username}</Text>
48
+ <Text style={styles.name}>{item.name || item.username}</Text>
49
49
  </Text>
50
50
  );
51
51
  }
@@ -46,6 +46,7 @@ test('test ItemLog one tap', () => {
46
46
  params: {
47
47
  username: 'username',
48
48
  },
49
+ username: 'username',
49
50
  created_at: '2021-07-02T15:48:24.917932Z',
50
51
  },
51
52
  type: `automate.${AUTOMATE_TYPE.ONE_TAP}`,
@@ -68,6 +69,7 @@ test('test ItemLog script update', () => {
68
69
  params: {
69
70
  username: 'username',
70
71
  },
72
+ username: 'username',
71
73
  created_at: '2021-07-02T15:48:24.917932Z',
72
74
  },
73
75
  type: 'automate',
@@ -79,7 +81,7 @@ test('test ItemLog script update', () => {
79
81
  });
80
82
  const instance = tree.root;
81
83
  const texts = instance.findAllByType(Text);
82
- expect(texts[2].props.children).toBe(props.item.params.username);
84
+ expect(texts[2].props.children).toBe(props.item.username);
83
85
  });
84
86
 
85
87
  test('test ItemLog no content_code', () => {
@@ -91,6 +93,7 @@ test('test ItemLog no content_code', () => {
91
93
  },
92
94
  created_at: '2021-07-02T15:48:24.917932Z',
93
95
  },
96
+ username: 'username',
94
97
  type: 'action',
95
98
  length: 2,
96
99
  index: 1,
@@ -100,7 +103,7 @@ test('test ItemLog no content_code', () => {
100
103
  });
101
104
  const instance = tree.root;
102
105
  const texts = instance.findAllByType(Text);
103
- expect(texts[2].props.children).toBe(props.item.params.username);
106
+ expect(texts[2].props.children).toBe(props.item.username);
104
107
  });
105
108
 
106
109
  describe('test ItemLog emergency event', () => {
@@ -12,6 +12,7 @@ const apiMaps = {
12
12
  url: () => API.SENSOR.ACTIVITY_LOG(),
13
13
  params: (id) => ({ id: id }),
14
14
  standardizeData: getDataForList,
15
+ memberUrl: (id) => API.SHARE.UNITS_MEMBERS(id),
15
16
  },
16
17
  ['emergency_event']: {
17
18
  url: () => API.EMERGENCY_BUTTON.ACTIVITY_LOG(),
@@ -58,7 +59,7 @@ export default ({ id, type, share, filterEnabled }) => {
58
59
  if (page === 1) {
59
60
  setIsRefreshing(true);
60
61
  } else {
61
- if (!isCanLoadMore) {
62
+ if (!isCanLoadMore || isLoading) {
62
63
  return;
63
64
  }
64
65
  setIsLoading(true);
@@ -66,7 +66,6 @@ const ActivityLogScreen = ({ route }) => {
66
66
  {getTitleFromTime(data[0].created_at, new Date())}
67
67
  </Text>
68
68
  );
69
-
70
69
  useEffect(() => {
71
70
  onRefresh();
72
71
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -24,6 +24,8 @@ const initialRegion = {
24
24
  const DEFAULT_LATITUDE = 10.7974046; // EoH center
25
25
  const DEFAULT_LONGITUDE = 106.7035663;
26
26
 
27
+ navigator.geolocation = require('@react-native-community/geolocation');
28
+
27
29
  const AddLocationMaps = memo(() => {
28
30
  const t = useTranslations();
29
31
  const { goBack, navigate } = useNavigation();
@@ -135,7 +137,7 @@ const AddLocationMaps = memo(() => {
135
137
  }
136
138
  },
137
139
  (error) => {},
138
- { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
140
+ {}
139
141
  );
140
142
  }, []);
141
143
 
@@ -231,7 +233,7 @@ const AddLocationMaps = memo(() => {
231
233
  latitude: searchedLocation.latitude,
232
234
  longitude: searchedLocation.longitude,
233
235
  }}
234
- radius={1000}
236
+ radius={300}
235
237
  fillColor={Colors.BlueTransparent5}
236
238
  strokeColor={Colors.Blue10}
237
239
  />
@@ -55,7 +55,8 @@ const SelectSensorDevices = memo(({ route }) => {
55
55
  (response) => {
56
56
  const { success, data } = response;
57
57
  if (success) {
58
- const listMenu = data.map((item, index) => ({
58
+ const newData = data.filter((item) => item.sensors.length > 0);
59
+ const listMenu = newData.map((item, index) => ({
59
60
  text: item.name,
60
61
  station: item,
61
62
  index: index,
@@ -63,7 +64,7 @@ const SelectSensorDevices = memo(({ route }) => {
63
64
  if (isSelectSensor) {
64
65
  if (automate.sensor_id) {
65
66
  let selectSensor = {};
66
- data.map((item) => {
67
+ newData.map((item) => {
67
68
  item.sensors.map((sensor) => {
68
69
  if (sensor.id === automate.sensor_id) {
69
70
  selectSensor = sensor;
@@ -76,9 +77,9 @@ const SelectSensorDevices = memo(({ route }) => {
76
77
  setSelectedDevice(selectSensor);
77
78
  }
78
79
  }
79
- setStation(data);
80
+ setStation(newData);
80
81
  setListMenuItem(listMenu);
81
- setListStation(listMenu.concat([{ text: '' }]));
82
+ setListStation(listMenu);
82
83
  }
83
84
  }
84
85
  );
@@ -174,13 +175,19 @@ const SelectSensorDevices = memo(({ route }) => {
174
175
  {t(title)}
175
176
  </Text>
176
177
 
177
- <NavBar
178
- listStation={listStation}
179
- listMenuItem={listMenuItem}
180
- onSnapToItem={onSnapToItem}
181
- indexStation={indexStation}
182
- style={styles.navbar}
183
- />
178
+ {!!listStation.length > 0 ? (
179
+ <NavBar
180
+ listStation={listStation}
181
+ listMenuItem={listMenuItem}
182
+ onSnapToItem={onSnapToItem}
183
+ indexStation={indexStation}
184
+ style={styles.navbar}
185
+ />
186
+ ) : (
187
+ <View style={styles.noneData}>
188
+ <Text center>{t('text_sub_unit_not_have_device')}</Text>
189
+ </View>
190
+ )}
184
191
 
185
192
  <View style={styles.boxDevices}>
186
193
  {station[indexStation]?.sensors &&
@@ -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, Constants } from '../../../configs';
4
4
 
5
5
  export default StyleSheet.create({
6
6
  wrap: {
@@ -33,4 +33,8 @@ export default StyleSheet.create({
33
33
  borderColor: Colors.ShadownTransparent,
34
34
  borderTopWidth: 1,
35
35
  },
36
+ noneData: {
37
+ paddingHorizontal: 16,
38
+ marginTop: Constants.height * 0.3,
39
+ },
36
40
  });
@@ -175,8 +175,13 @@ describe('Test SelectSensorDevices', () => {
175
175
  ],
176
176
  },
177
177
  ];
178
+ const listMenu = data.map((item, index) => ({
179
+ text: item.name,
180
+ station: item,
181
+ index: index,
182
+ }));
178
183
  const mockSetIndexStation = jest.fn();
179
- useState.mockImplementationOnce((init) => [init, mockSetState]);
184
+ useState.mockImplementationOnce((init) => [listMenu, mockSetState]);
180
185
  useState.mockImplementationOnce((init) => [init, mockSetState]);
181
186
  useState.mockImplementationOnce((init) => [init, mockSetIndexStation]);
182
187
  useState.mockImplementationOnce((init) => [data, mockSetState]);
@@ -26,8 +26,11 @@ const MultiUnits = () => {
26
26
  const { params = {} } = useRoute();
27
27
  const { isMultiUnits = false, unitName = '', unit, isOwner } = params;
28
28
  const [data, setData] = useState([]);
29
- // eslint-disable-next-line react-hooks/exhaustive-deps
30
- const tabName = useMemo(() => [t('smart'), t('automation')], []);
29
+ const tabName = useMemo(
30
+ () => [t(AUTOMATE_TYPE.SCENARIO), t(AUTOMATE_TYPE.AUTOMATION)],
31
+ // eslint-disable-next-line react-hooks/exhaustive-deps
32
+ []
33
+ );
31
34
  const [tabActive, setTabActive] = useState(tabName[0]);
32
35
 
33
36
  const getData = useCallback(
@@ -72,7 +75,7 @@ const MultiUnits = () => {
72
75
  screen: Routes.AddNewAutoSmart,
73
76
  params: {
74
77
  type:
75
- tabActive === t('smart')
78
+ tabActive === t(AUTOMATE_TYPE.SCENARIO)
76
79
  ? AUTOMATE_TYPE.ONE_TAP_ONLY
77
80
  : AUTOMATE_TYPE.VALUE_CHANGE,
78
81
  unit: { id: unit?.id },
@@ -109,7 +112,7 @@ const MultiUnits = () => {
109
112
 
110
113
  const renderContent = useMemo(() => {
111
114
  const listItems = data.filter((item) =>
112
- tabActive === t('smart')
115
+ tabActive === t(AUTOMATE_TYPE.SCENARIO)
113
116
  ? item?.type === AUTOMATE_TYPE.ONE_TAP
114
117
  : item?.type !== AUTOMATE_TYPE.ONE_TAP
115
118
  );
@@ -201,7 +201,7 @@ describe('Test MultiUnits', () => {
201
201
  });
202
202
  useState.mockImplementationOnce(() => [response.data, mockSetState]);
203
203
  useState.mockImplementationOnce(() => [
204
- getTranslate('en', 'smart'),
204
+ getTranslate('en', 'Scenario'),
205
205
  mockSetState,
206
206
  ]);
207
207
  await act(() => {
@@ -70,6 +70,18 @@ describe('Test Automate', () => {
70
70
  icon_kit: undefined,
71
71
  },
72
72
  },
73
+ {
74
+ id: 2,
75
+ user: 2,
76
+ type: 'one_tap',
77
+ activate_at: '2021-09-17T05:30:00Z',
78
+ script: {
79
+ id: 1,
80
+ name: 'script2',
81
+ icon: undefined,
82
+ icon_kit: undefined,
83
+ },
84
+ },
73
85
  ],
74
86
  },
75
87
  ],
@@ -0,0 +1,61 @@
1
+ import React from 'react';
2
+ import renderer, { act } from 'react-test-renderer';
3
+ import axios from 'axios';
4
+
5
+ import { SCProvider } from '../../../context';
6
+ import { mockSCStore } from '../../../context/mockStore';
7
+ import ConfirmUnitDeletion from '../index';
8
+ import _TextInput from '../../../commons/Form/TextInput';
9
+
10
+ const wrapComponent = (route, navigation) => (
11
+ <SCProvider initState={mockSCStore({})}>
12
+ <ConfirmUnitDeletion route={route} />
13
+ </SCProvider>
14
+ );
15
+
16
+ const mockedNavigate = jest.fn();
17
+
18
+ jest.mock('@react-navigation/native', () => {
19
+ return {
20
+ ...jest.requireActual('@react-navigation/native'),
21
+ useNavigation: () => ({
22
+ goBack: mockedNavigate,
23
+ }),
24
+ };
25
+ });
26
+
27
+ jest.mock('react', () => {
28
+ return {
29
+ ...jest.requireActual('react'),
30
+ memo: (x) => x,
31
+ };
32
+ });
33
+
34
+ jest.mock('axios');
35
+ describe('Test ConfirmUnitDeletion', () => {
36
+ let tree;
37
+ let route;
38
+
39
+ beforeAll(() => {
40
+ axios.get.mockClear();
41
+ route = {
42
+ params: {
43
+ unit: {
44
+ id: 10,
45
+ },
46
+ },
47
+ };
48
+ });
49
+
50
+ test('test render ConfirmUnitDeletion', async () => {
51
+ await act(async () => {
52
+ tree = await renderer.create(wrapComponent(route));
53
+ });
54
+ const instance = tree.root;
55
+
56
+ const textInput = instance.findByType(_TextInput);
57
+ await act(async () => {
58
+ textInput.props.onChange('new_name');
59
+ });
60
+ });
61
+ });
@@ -0,0 +1,64 @@
1
+ import React, { useCallback, useState } from 'react';
2
+ import { View } from 'react-native';
3
+ import { useNavigation } from '@react-navigation/native';
4
+
5
+ import { useTranslations } from '../../hooks/Common/useTranslations';
6
+ import styles from './styles';
7
+ import WrapHeaderScrollable from '../../commons/Sharing/WrapHeaderScrollable';
8
+ import Text from '../../commons/Text';
9
+ import { API, Colors } from '../../configs';
10
+ import _TextInput from '../../commons/Form/TextInput';
11
+ import { Button } from '../../commons';
12
+ import Routes from '../../utils/Route';
13
+ import { axiosDelete } from '../../utils/Apis/axios';
14
+ import { ToastBottomHelper } from '../../utils/Utils';
15
+
16
+ const ConfirmUnitDeletion = ({ route }) => {
17
+ const t = useTranslations();
18
+ const { unit } = route.params;
19
+ const navigation = useNavigation();
20
+ const [confirm, setConfrim] = useState('');
21
+ const [errorText, setErrorText] = useState();
22
+
23
+ const onChangePassword = useCallback((value) => {
24
+ setConfrim(value);
25
+ }, []);
26
+
27
+ const onSendPress = useCallback(async () => {
28
+ if (confirm === 'YES') {
29
+ const { success } = await axiosDelete(API.UNIT.MANAGE_UNIT(unit.id));
30
+ if (success) {
31
+ navigation.navigate(Routes.Dashboard);
32
+ ToastBottomHelper.success(t('unit_deleted_successfully'));
33
+ }
34
+ } else {
35
+ setErrorText(t('please_enter_correct'));
36
+ }
37
+ }, [confirm, navigation, t, unit.id]);
38
+
39
+ return (
40
+ <WrapHeaderScrollable
41
+ styleScrollView={styles.scrollView}
42
+ headerAniStyle={styles.headerAniStyle}
43
+ >
44
+ <Text semibold style={styles.txtForgot}>
45
+ {t('confirmation')}
46
+ </Text>
47
+ <Text type="H4" color={Colors.Gray9} style={styles.txtForgotHint}>
48
+ {t('enter_yes_to_perform')}
49
+ </Text>
50
+ <_TextInput
51
+ placeholder={t('text_password')}
52
+ onChange={onChangePassword}
53
+ errorText={errorText}
54
+ wrapStyle={styles.noMarginTop}
55
+ textInputStyle={styles.textInput}
56
+ />
57
+ <View style={styles.buttonWrap}>
58
+ <Button type="auth" title={t('done')} onPress={onSendPress} />
59
+ </View>
60
+ </WrapHeaderScrollable>
61
+ );
62
+ };
63
+
64
+ export default ConfirmUnitDeletion;
@@ -0,0 +1,37 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { Colors } from '../../configs';
3
+
4
+ export default StyleSheet.create({
5
+ scrollView: {
6
+ backgroundColor: Colors.White,
7
+ },
8
+ headerAniStyle: { borderBottomWidth: 0 },
9
+ txtForgot: {
10
+ color: Colors.Black,
11
+ fontSize: 24,
12
+ marginLeft: 16,
13
+ marginTop: 0,
14
+ fontWeight: 'bold',
15
+ },
16
+ txtForgotHint: {
17
+ marginLeft: 16,
18
+ marginTop: 30,
19
+ },
20
+ noMarginTop: {
21
+ margin: 16,
22
+ backgroundColor: Colors.White,
23
+ },
24
+ textInput: {
25
+ marginTop: 0,
26
+ borderWidth: 0,
27
+ borderBottomWidth: 1,
28
+ borderBottomColor: Colors.Gray4,
29
+ paddingLeft: 0,
30
+ backgroundColor: Colors.White,
31
+ },
32
+ buttonWrap: {
33
+ flexDirection: 'row',
34
+ marginTop: 24,
35
+ marginHorizontal: 16,
36
+ },
37
+ });
@@ -812,9 +812,10 @@ describe('test DeviceDetail', () => {
812
812
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.ActivityLog, {
813
813
  id: route.params.sensor.id,
814
814
  type: 'action',
815
+ share: route.params.unit,
815
816
  filterEnabled: {
816
- date: false,
817
- user: false,
817
+ date: true,
818
+ user: Boolean(route.params.unit.id),
818
819
  },
819
820
  });
820
821
  });