@eohjsc/react-native-smart-city 0.3.49 → 0.3.51

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 (49) hide show
  1. package/package.json +1 -1
  2. package/src/commons/ActionGroup/OnOffTemplate/index.js +6 -8
  3. package/src/commons/ActionGroup/SliderRangeTemplate.js +7 -2
  4. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +98 -0
  5. package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +27 -3
  6. package/src/commons/ActionTemplate/__test__/CurtainAction.test.js +64 -0
  7. package/src/commons/ActionTemplate/__test__/OnOffSmartLockAction.test.js +54 -0
  8. package/src/commons/Device/HorizontalBarChart.js +0 -1
  9. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +3 -1
  10. package/src/commons/Processing/styles.js +0 -2
  11. package/src/commons/Sharing/WrapHeaderScrollable.js +5 -4
  12. package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +9 -2
  13. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +41 -39
  14. package/src/configs/Constants.js +2 -0
  15. package/src/configs/SCConfig.js +3 -0
  16. package/src/navigations/AddDeviceStack.js +0 -5
  17. package/src/navigations/UnitStack.js +5 -4
  18. package/src/screens/AQIGuide/index.js +2 -2
  19. package/src/screens/ActivityLog/styles/itemLogStyles.js +1 -0
  20. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +1 -1
  21. package/src/screens/AddNewGateway/ConnectingDevice.js +25 -3
  22. package/src/screens/AddNewGateway/ConnectingWifiGuide.js +1 -1
  23. package/src/screens/AddNewGateway/ConnectingWifiGuideStyles.js +10 -0
  24. package/src/screens/AddNewGateway/ConnectingZigbeeDevice.js +3 -17
  25. package/src/screens/AddNewGateway/ShareWifiPassword.js +2 -1
  26. package/src/screens/AddNewGateway/__test__/ConnectingWifiDevice.test.js +2 -1
  27. package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +27 -1
  28. package/src/screens/Device/detail.js +1 -3
  29. package/src/screens/Gateway/components/Information/styles.js +0 -1
  30. package/src/screens/Notification/__test__/NotificationItem.test.js +1 -0
  31. package/src/screens/Notification/components/NotificationItem.js +16 -1
  32. package/src/screens/Notification/index.js +1 -0
  33. package/src/screens/Notification/styles/indexStyles.js +3 -0
  34. package/src/screens/Sharing/SelectPermission.js +2 -2
  35. package/src/screens/SmartAccount/SuccessfullyConnected/__test__/SuccessfullyConnected.test.js +26 -7
  36. package/src/screens/SmartAccount/SuccessfullyConnected/index.js +29 -11
  37. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +1 -1
  38. package/src/screens/Template/__test__/GatewayList.test.js +1 -1
  39. package/src/screens/Template/__test__/Information.test.js +1 -1
  40. package/src/screens/Unit/Detail.js +24 -18
  41. package/src/screens/Unit/__test__/Detail.test.js +62 -18
  42. package/src/utils/Apis/axios.js +52 -36
  43. package/src/utils/I18n/translations/en.json +4 -0
  44. package/src/utils/I18n/translations/vi.json +5 -1
  45. package/src/utils/Storage.js +0 -4
  46. package/src/utils/Utils.js +1 -1
  47. package/src/utils/__test__/Utils.test.js +27 -3
  48. package/src/screens/AddNewDevice/ConnectingDevices.js +0 -62
  49. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +0 -110
@@ -55,7 +55,7 @@ import InfoMemberUnit from '../screens/Sharing/InfoMemberUnit';
55
55
  import EnterPassword from '../screens/EnterPassword';
56
56
  import SelectAddToFavorites from '../screens/Unit/SelectAddToFavorites';
57
57
  import { HanetCameraStack } from './HanetCameraStack';
58
- import { axiosGet } from '../utils/Apis/axios';
58
+ import { axiosGet, fetchWithCache } from '../utils/Apis/axios';
59
59
  import { API } from '../configs';
60
60
  import SideMenuDetail from '../screens/SideMenuDetail';
61
61
  import { styles } from './UnitStackStyles';
@@ -117,12 +117,13 @@ export const UnitStack = memo((props) => {
117
117
  if (!id) {
118
118
  return;
119
119
  }
120
- const { success, data } = await axiosGet(
120
+ await fetchWithCache(
121
121
  API.UNIT.FAVOURITE_DEVICES(id),
122
122
  {},
123
- true
123
+ ({ success, data }) => {
124
+ success && setAction(Action.SET_FAVORITE_DEVICES, data);
125
+ }
124
126
  );
125
- success && setAction(Action.SET_FAVORITE_DEVICES, data);
126
127
  };
127
128
  fetchFavoriteDevices();
128
129
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1,6 +1,6 @@
1
1
  import React, { memo, useMemo } from 'react';
2
2
  import { View, ScrollView, StyleSheet, TouchableOpacity } from 'react-native';
3
- import { getStatusBarHeight } from 'react-native-iphone-x-helper';
3
+ import { getBottomSpace } from 'react-native-iphone-x-helper';
4
4
 
5
5
  import { useTranslations } from '../../hooks/Common/useTranslations';
6
6
  import { Colors, Theme } from '../../configs';
@@ -146,7 +146,7 @@ const styles = StyleSheet.create({
146
146
  container: {
147
147
  flex: 1,
148
148
  backgroundColor: Theme.color.backgroundColor,
149
- paddingTop: getStatusBarHeight() + 10,
149
+ paddingBottom: getBottomSpace(),
150
150
  },
151
151
  titles: {
152
152
  marginHorizontal: 16,
@@ -31,6 +31,7 @@ export default StyleSheet.create({
31
31
  },
32
32
  name: {
33
33
  fontWeight: 'bold',
34
+ lineHeight: 22,
34
35
  },
35
36
  wrapText: {
36
37
  flexShrink: 1,
@@ -97,7 +97,7 @@ describe('Test AddNewDevice', () => {
97
97
  });
98
98
 
99
99
  it('fetchDetails fail', async () => {
100
- mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(400);
100
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(500);
101
101
  await act(async () => {
102
102
  tree = await create(wrapComponent(route));
103
103
  });
@@ -1,8 +1,12 @@
1
- import { useNavigation } from '@react-navigation/native';
2
1
  import React, { useCallback, useEffect, useState } from 'react';
2
+ import { useNavigation } from '@react-navigation/native';
3
+ import { Alert } from 'react-native';
4
+
3
5
  import Processing from '../../commons/Processing';
4
6
  import Routes from '../../utils/Route';
7
+ import { useTranslations } from '../../hooks/Common/useTranslations';
5
8
 
9
+ let timeout;
6
10
  const ConnectingDevice = ({
7
11
  title,
8
12
  fail,
@@ -13,13 +17,13 @@ const ConnectingDevice = ({
13
17
  chipId,
14
18
  sensorId,
15
19
  addDeviceType,
16
- goBack,
17
20
  showPopupTurnOnGuide,
18
21
  setHidePopupTurnOnGuide,
19
22
  setIsRecallChipScan,
20
23
  isChangeAddressSuccess,
21
24
  }) => {
22
- const { navigate } = useNavigation();
25
+ const t = useTranslations();
26
+ const { navigate, goBack } = useNavigation();
23
27
 
24
28
  const [renameParams, setRenameParams] = useState({
25
29
  unitId,
@@ -31,11 +35,29 @@ const ConnectingDevice = ({
31
35
 
32
36
  const complete = useCallback(
33
37
  (deviceInfo) => {
38
+ timeout && clearTimeout(timeout);
34
39
  navigate(Routes.RenameNewDevices, renameParams);
35
40
  },
36
41
  [navigate, renameParams]
37
42
  );
38
43
 
44
+ useEffect(() => {
45
+ timeout = setTimeout(() => {
46
+ Alert.alert(t('continue_to_wait'), t('it_has_been_5_minutes'), [
47
+ {
48
+ text: t('back'),
49
+ onPress: goBack,
50
+ },
51
+ {
52
+ text: t('continue'),
53
+ },
54
+ ]);
55
+ }, 300 * 1000); // when test, it takes more than 3 min
56
+ return () => {
57
+ clearTimeout(timeout);
58
+ };
59
+ }, [fail, goBack, t]);
60
+
39
61
  const onMessage = useCallback(
40
62
  (data) => {
41
63
  setRenameParams((oldParams) => {
@@ -99,7 +99,7 @@ const ConnectingWifiGuide = ({ route }) => {
99
99
  setWifiList(data.wifi);
100
100
  setCurrentState(0);
101
101
  clearInterval(intervalSend);
102
- socket.close();
102
+ socket?.close();
103
103
  socket = null;
104
104
  }
105
105
  });
@@ -1,4 +1,6 @@
1
+ import { Platform } from 'react-native';
1
2
  import { Dimensions, StyleSheet } from 'react-native';
3
+ import { getBottomSpace } from 'react-native-iphone-x-helper';
2
4
  import { Colors } from '../../configs';
3
5
 
4
6
  const customWidth = (Dimensions.get('window').width - 32 - 15) / 2; // set gap between flex item is 15px
@@ -55,4 +57,12 @@ export default StyleSheet.create({
55
57
  textAlign: 'center',
56
58
  lineHeight: 24,
57
59
  },
60
+ bottomButtonView: {
61
+ marginBottom:
62
+ getBottomSpace() +
63
+ Platform.select({
64
+ android: 10,
65
+ ios: -10,
66
+ }),
67
+ },
58
68
  });
@@ -1,6 +1,7 @@
1
1
  import { useNavigation } from '@react-navigation/native';
2
- import React, { useCallback, useEffect, useState } from 'react';
2
+ import React, { useCallback } from 'react';
3
3
  import { Alert } from 'react-native';
4
+
4
5
  import API from '../../configs/API';
5
6
  import { useTranslations } from '../../hooks/Common/useTranslations';
6
7
  import { axiosPost } from '../../utils/Apis/axios';
@@ -10,7 +11,6 @@ const ConnectingZigbeeDevice = ({ route }) => {
10
11
  const t = useTranslations();
11
12
  const { goBack } = useNavigation();
12
13
  const { unitId, subUnit, chipId } = route?.params || {};
13
- const [sensorId, setSensorId] = useState(null);
14
14
 
15
15
  const fail = useCallback(
16
16
  (message) => {
@@ -43,20 +43,6 @@ const ConnectingZigbeeDevice = ({ route }) => {
43
43
  [chipId, fail, subUnit?.id, unitId]
44
44
  );
45
45
 
46
- useEffect(() => {
47
- const timeOut = setTimeout(() => {
48
- setSensorId((value) => {
49
- if (!value) {
50
- fail(t('no_zigbee_device_join_timeout'));
51
- }
52
- return value;
53
- });
54
- }, 120 * 1000); // when test, it takes more than 1 min
55
- return () => {
56
- clearTimeout(timeOut);
57
- };
58
- }, [fail, t]);
59
-
60
46
  return (
61
47
  <ConnectingDevice
62
48
  title={t('connect_device')}
@@ -66,7 +52,7 @@ const ConnectingZigbeeDevice = ({ route }) => {
66
52
  unitId={unitId}
67
53
  subUnit={subUnit}
68
54
  chipId={chipId}
69
- sensorId={sensorId}
55
+ sensorId={null}
70
56
  />
71
57
  );
72
58
  };
@@ -105,6 +105,7 @@ const ShareWifiPassword = ({ route }) => {
105
105
  }
106
106
  if (ssid !== currentSsid) {
107
107
  clearInterval(checkWifiInterval);
108
+ setIsShowPopupPassword(false);
108
109
  navigation.navigate(Routes.ConnectingWifiDevice, {
109
110
  unitId,
110
111
  subUnit,
@@ -149,7 +150,7 @@ const ShareWifiPassword = ({ route }) => {
149
150
 
150
151
  socket.on('message', (msg, rinfo) => {
151
152
  if (handleSocketOnMsg(currentSsid, msg)) {
152
- socket.close();
153
+ socket?.close();
153
154
  socket = null;
154
155
  }
155
156
  });
@@ -60,7 +60,8 @@ describe('Test connecting wifi device', () => {
60
60
  });
61
61
  const instance = tree.root;
62
62
  expect(instance.findAllByType(Processing)).toHaveLength(1);
63
- jest.runAllTimers();
63
+ jest.runOnlyPendingTimers();
64
+
64
65
  expect(mock.history.post).toHaveLength(0);
65
66
  const connectingDevice = instance.findByType(ConnectingDevice);
66
67
  await act(async () => {
@@ -8,6 +8,7 @@ import { SCProvider } from '../../../context';
8
8
  import { mockSCStore } from '../../../context/mockStore';
9
9
  import api from '../../../utils/Apis/axios';
10
10
  import Processing from '../../../commons/Processing';
11
+ import { Alert } from 'react-native';
11
12
 
12
13
  const wrapComponent = (route) => (
13
14
  <SCProvider initState={mockSCStore({})}>
@@ -17,9 +18,21 @@ const wrapComponent = (route) => (
17
18
 
18
19
  const mock = new MockAdapter(api.axiosInstance);
19
20
 
21
+ jest.mock('react-native', () => {
22
+ const RN = jest.requireActual('react-native');
23
+ return Object.setPrototypeOf(
24
+ {
25
+ Alert: {
26
+ ...RN.Alert,
27
+ alert: jest.fn(),
28
+ },
29
+ },
30
+ RN
31
+ );
32
+ });
33
+
20
34
  const mockedNavigate = jest.fn();
21
35
  const mockedGoBack = jest.fn();
22
-
23
36
  jest.mock('@react-navigation/native', () => {
24
37
  return {
25
38
  ...jest.requireActual('@react-navigation/native'),
@@ -62,6 +75,19 @@ describe('Test connecting modbus device', () => {
62
75
  expect(mock.history.post).toHaveLength(1);
63
76
  });
64
77
 
78
+ it('timeout', async () => {
79
+ jest.useFakeTimers();
80
+
81
+ await act(async () => {
82
+ tree = await create(wrapComponent(route));
83
+ });
84
+
85
+ await act(async () => {
86
+ jest.runOnlyPendingTimers();
87
+ });
88
+ expect(Alert.alert).toBeCalled();
89
+ });
90
+
65
91
  it('receive sensor-id from channel then rename sensor-id', async () => {
66
92
  mock.onPost().reply(200, {});
67
93
  await act(async () => {
@@ -165,9 +165,7 @@ const DeviceDetail = ({ route }) => {
165
165
  }, [currentUserId, unit]);
166
166
 
167
167
  const fetchUnitDetail = useCallback(async () => {
168
- const { success, data } = await axiosGet(API.UNIT.UNIT_DETAIL(unitId), {
169
- headers: { 'Cache-Control': 'no-cache' },
170
- });
168
+ const { success, data } = await axiosGet(API.UNIT.UNIT_DETAIL(unitId));
171
169
  if (success) {
172
170
  setUnit(data);
173
171
  }
@@ -21,7 +21,6 @@ export default StyleSheet.create({
21
21
  flexDirection: 'row',
22
22
  alignItems: 'flex-start',
23
23
  padding: 16,
24
- gap: 16,
25
24
  backgroundColor: Colors.Blue14,
26
25
  borderColor: Colors.Blue15,
27
26
  borderWidth: 1,
@@ -165,6 +165,7 @@ describe('test NotificationItem', () => {
165
165
  NOTIFICATION_TYPES.FIRE,
166
166
  NOTIFICATION_TYPES.SOS,
167
167
  NOTIFICATION_TYPES.FILTER_WATER,
168
+ NOTIFICATION_TYPES.LOW_BATTERY,
168
169
  ];
169
170
  for (const content_code of listSensorType2) {
170
171
  test(`create ItemNotification ${content_code}`, async () => {
@@ -187,6 +187,21 @@ const NotificationItem = memo(({ item }) => {
187
187
  }),
188
188
  iconContent: <Image source={Images.logo} style={styles.logo} />,
189
189
  };
190
+ case NOTIFICATION_TYPES.LOW_BATTERY:
191
+ return {
192
+ content: customColorText(t('text_notification_content_low_battery')),
193
+ redirect: () =>
194
+ navigation.navigate(Routes.UnitStack, {
195
+ screen: Routes.DeviceDetail,
196
+ params: {
197
+ unitId,
198
+ sensorId,
199
+ },
200
+ }),
201
+ iconContent: (
202
+ <IconComponent iconKit={icon} style={styles.iconNotification} />
203
+ ),
204
+ };
190
205
  case NOTIFICATION_TYPES.NOTIFY_REMOVE_UNIT:
191
206
  return {
192
207
  content: customColorText(
@@ -342,7 +357,7 @@ const NotificationItem = memo(({ item }) => {
342
357
  default:
343
358
  return null;
344
359
  }
345
- }, [content_code, customColorText, navigation, params, t]);
360
+ }, [content_code, customColorText, icon, navigation, params, t]);
346
361
 
347
362
  const { content, redirect, iconContent } = renderItem() || {};
348
363
 
@@ -96,6 +96,7 @@ const Notification = memo(() => {
96
96
  onLoadMore={handleOnLoadMore}
97
97
  onRefresh={onRefresh}
98
98
  disableLoadMore={page >= maxPageNotification}
99
+ styleScrollView={styles.styleScrollView}
99
100
  >
100
101
  {notifications.map((item, index) => (
101
102
  <NotificationItem item={item} key={index} />
@@ -16,4 +16,7 @@ export default StyleSheet.create({
16
16
  iconPlus: {
17
17
  marginRight: 22,
18
18
  },
19
+ styleScrollView: {
20
+ marginTop: -10,
21
+ },
19
22
  });
@@ -8,7 +8,7 @@ import Text from '../../commons/Text';
8
8
  import { DeviceItem, TitleCheckBox } from './Components';
9
9
  import styles from './Styles/SelectPermissionStyles';
10
10
  import { axiosGet, axiosPost } from '../../utils/Apis/axios';
11
- import { object_Ids } from '../../utils/Utils';
11
+ import { objectIds } from '../../utils/Utils';
12
12
  import Routes from '../../utils/Route';
13
13
  import { API, Colors } from '../../configs';
14
14
  import { AccessibilityLabel } from '../../configs/Constants';
@@ -174,7 +174,7 @@ const SelectPermission = ({ route }) => {
174
174
  if (isUpdateSharedDevice) {
175
175
  if (hasDataChecked) {
176
176
  const { stationIds, deviceIds, actionIds, configIds } =
177
- object_Ids(dataDeviceShared);
177
+ objectIds(dataDeviceShared);
178
178
  for (let station in dataStations) {
179
179
  for (let item in dataStations[station].devices) {
180
180
  const itemTemp = dataStations[station].devices[item];
@@ -13,12 +13,13 @@ import Routes from '../../../../utils/Route';
13
13
 
14
14
  const mock = new MockAdapter(api.axiosInstance);
15
15
  const mockedNavigate = jest.fn();
16
+ const mockedDispatch = jest.fn();
16
17
  jest.mock('@react-navigation/native', () => {
17
18
  return {
18
19
  ...jest.requireActual('@react-navigation/native'),
19
20
  useNavigation: () => ({
20
21
  navigate: mockedNavigate,
21
- dispatch: jest.fn(),
22
+ dispatch: mockedDispatch,
22
23
  }),
23
24
  useIsFocused: () => true,
24
25
  };
@@ -128,13 +129,31 @@ describe('Test SuccessfullyConnected', () => {
128
129
  await act(async () => {
129
130
  handleFinish.props.onPress();
130
131
  });
131
- expect(mockedNavigate).toBeCalledWith(Routes.UnitStack, {
132
- screen: Routes.UnitDetail,
133
- params: {
134
- unitId: 1,
135
- stationId: 2,
136
- isSuccessfullyConnected: true,
132
+ expect(mockedDispatch).toBeCalledWith({
133
+ payload: {
134
+ index: 0,
135
+ routes: [
136
+ {
137
+ name: 'Main',
138
+ params: {
139
+ params: { screen: 'Dashboard' },
140
+ screen: 'DashboardStack',
141
+ },
142
+ },
143
+ {
144
+ name: 'UnitStack',
145
+ params: {
146
+ params: {
147
+ isSuccessfullyConnected: true,
148
+ stationId: 2,
149
+ unitId: 1,
150
+ },
151
+ screen: 'UnitDetail',
152
+ },
153
+ },
154
+ ],
137
155
  },
156
+ type: 'RESET',
138
157
  });
139
158
  });
140
159
  });
@@ -1,6 +1,6 @@
1
1
  import React, { memo, useCallback, useEffect, useState } from 'react';
2
2
  import { View, ScrollView } from 'react-native';
3
- import { useNavigation } from '@react-navigation/native';
3
+ import { useNavigation, CommonActions } from '@react-navigation/native';
4
4
  import { IconOutline } from '@ant-design/icons-react-native';
5
5
  import { ActivityIndicator } from '@ant-design/react-native';
6
6
 
@@ -28,7 +28,7 @@ const SuccessfullyConnected = memo(({ route }) => {
28
28
  chipId,
29
29
  } = route.params;
30
30
  const t = useTranslations();
31
- const { navigate } = useNavigation();
31
+ const { navigate, dispatch } = useNavigation();
32
32
  const [info, setInfo] = useState({});
33
33
  const [loadingFilterInfo, setLoadingFilterInfo] = useState(false);
34
34
  const [loading, setLoading] = useState(true);
@@ -55,15 +55,33 @@ const SuccessfullyConnected = memo(({ route }) => {
55
55
 
56
56
  const handleFinish = useCallback(async () => {
57
57
  await axiosPost(API.CHIP.RENAME_DEVICES(info.id), info);
58
- navigate(Routes.UnitStack, {
59
- screen: Routes.UnitDetail,
60
- params: {
61
- unitId: unit_id,
62
- stationId,
63
- isSuccessfullyConnected: true,
64
- },
58
+ const resetAction = CommonActions.reset({
59
+ index: 0,
60
+ routes: [
61
+ {
62
+ name: Routes.Main,
63
+ params: {
64
+ screen: Routes.DashboardStack,
65
+ params: {
66
+ screen: Routes.Dashboard,
67
+ },
68
+ },
69
+ },
70
+ {
71
+ name: Routes.UnitStack,
72
+ params: {
73
+ screen: Routes.UnitDetail,
74
+ params: {
75
+ unitId: unit_id,
76
+ stationId,
77
+ isSuccessfullyConnected: true,
78
+ },
79
+ },
80
+ },
81
+ ],
65
82
  });
66
- }, [info, navigate, stationId, unit_id]);
83
+ dispatch(resetAction);
84
+ }, [dispatch, info, stationId, unit_id]);
67
85
 
68
86
  const handleFilterNewInfo = useCallback(async () => {
69
87
  let newInfo = [];
@@ -125,7 +143,7 @@ const SuccessfullyConnected = memo(({ route }) => {
125
143
  {!loading && info?.sensors?.length !== 0 ? (
126
144
  <View>
127
145
  {info?.sensors?.map((sensor, sensor_index) => (
128
- <View style={styles.wrapItem}>
146
+ <View style={styles.wrapItem} key={`${sensor?.id}`}>
129
147
  {sensor?.end_devices?.length &&
130
148
  sensor?.end_devices?.map(
131
149
  (end_device, end_device_index) => (
@@ -98,7 +98,7 @@ describe('Test Add LG Device', () => {
98
98
  });
99
99
 
100
100
  it('fetchDetails fail', async () => {
101
- mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(400);
101
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(500);
102
102
  await act(async () => {
103
103
  tree = await create(wrapComponent(route));
104
104
  });
@@ -21,6 +21,6 @@ describe('Test GatewayList', () => {
21
21
  });
22
22
  const instance = tree.root;
23
23
  const Views = instance.findAllByType(View);
24
- expect(Views).toHaveLength(13);
24
+ expect(Views).toHaveLength(12);
25
25
  });
26
26
  });
@@ -11,6 +11,6 @@ describe('Test Information', () => {
11
11
  });
12
12
  const instance = tree.root;
13
13
  const Views = instance.findAllByType(View);
14
- expect(Views).toHaveLength(14);
14
+ expect(Views).toHaveLength(13);
15
15
  });
16
16
  });
@@ -26,7 +26,7 @@ import {
26
26
  import { useFavorites } from './hook/useFavorites';
27
27
  import { useUnitConnectRemoteDevices } from './hook/useUnitConnectRemoteDevices';
28
28
  import { useValueEvaluations } from '../../hooks/IoT';
29
- import { fetchWithCache, axiosGet } from '../../utils/Apis/axios';
29
+ import { fetchWithCache } from '../../utils/Apis/axios';
30
30
  import ShortDetailSubUnit from '../../commons/SubUnit/ShortDetail';
31
31
  import NavBar from '../../commons/NavBar';
32
32
  import WrapParallaxScrollView from '../../commons/WrapParallaxScrollView';
@@ -119,21 +119,6 @@ const UnitDetail = ({ route }) => {
119
119
  [t]
120
120
  );
121
121
 
122
- const fetchDetails = useCallback(async () => {
123
- getAutomates();
124
- const { success, data, resp_status } = await axiosGet(
125
- API.UNIT.UNIT_DETAIL(unitId),
126
- { headers: { 'Cache-Control': 'no-cache' } },
127
- true
128
- );
129
- if (success) {
130
- prepareData(data);
131
- setUnit(data);
132
- } else if (resp_status === 404) {
133
- setShowPreventAccess();
134
- }
135
- }, [getAutomates, unitId, prepareData, setShowPreventAccess]);
136
-
137
122
  const getAutomates = useCallback(async () => {
138
123
  await fetchWithCache(
139
124
  API.UNIT.AUTOMATE(unitId),
@@ -160,6 +145,26 @@ const UnitDetail = ({ route }) => {
160
145
  );
161
146
  }, [t, unitId]);
162
147
 
148
+ const fetchUnitDetail = useCallback(async () => {
149
+ await fetchWithCache(
150
+ API.UNIT.UNIT_DETAIL(unitId),
151
+ {},
152
+ ({ success, data, resp_status }) => {
153
+ if (success) {
154
+ prepareData(data);
155
+ setUnit(data);
156
+ } else if (resp_status === 404) {
157
+ setShowPreventAccess();
158
+ }
159
+ }
160
+ );
161
+ }, [prepareData, setShowPreventAccess, unitId]);
162
+
163
+ const fetchDetails = useCallback(async () => {
164
+ getAutomates();
165
+ await fetchUnitDetail();
166
+ }, [getAutomates, fetchUnitDetail]);
167
+
163
168
  const onRefresh = useCallback(
164
169
  (data = { content_code: NOTIFICATION_TYPES.NOTIFY_RENAME_UNIT }) => {
165
170
  data.content_code === NOTIFICATION_TYPES.NOTIFY_RENAME_UNIT &&
@@ -169,7 +174,7 @@ const UnitDetail = ({ route }) => {
169
174
  );
170
175
 
171
176
  useEffect(() => {
172
- const subscription = AppState.addEventListener('change', (nextAppState) => {
177
+ const handler = (nextAppState) => {
173
178
  if (
174
179
  appState.current.match(/inactive|background/) &&
175
180
  nextAppState === 'active'
@@ -177,7 +182,8 @@ const UnitDetail = ({ route }) => {
177
182
  fetchDetails();
178
183
  }
179
184
  appState.current = nextAppState;
180
- });
185
+ };
186
+ const subscription = AppState.addEventListener('change', handler);
181
187
 
182
188
  return () => {
183
189
  subscription?.remove();