@eohjsc/react-native-smart-city 0.3.57 → 0.3.59

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 (80) hide show
  1. package/package.json +1 -1
  2. package/src/Images/Common/loading-circle.json +1 -1
  3. package/src/Images/DevMode/report.svg +3 -0
  4. package/src/commons/Header/HeaderCustom.js +5 -1
  5. package/src/commons/ModalPopupCT/__test__/ModalPopupCT.test.js +68 -0
  6. package/src/commons/ModalPopupCT/index.js +118 -0
  7. package/src/commons/ModalPopupCT/styles.js +95 -0
  8. package/src/commons/SubUnit/ShortDetail.js +1 -2
  9. package/src/commons/SubUnit/__test__/ShortDetail.test.js +1 -2
  10. package/src/configs/API.js +8 -3
  11. package/src/configs/AccessibilityLabel.js +2 -0
  12. package/src/configs/Colors.js +2 -0
  13. package/src/context/actionType.ts +1 -0
  14. package/src/context/reducer.ts +10 -0
  15. package/src/screens/AddCommon/SelectUnit.js +1 -2
  16. package/src/screens/AddCommon/__test__/SelectUnit.test.js +4 -2
  17. package/src/screens/AddNewGateway/ConnectingDevice.js +2 -2
  18. package/src/screens/AddNewGateway/ConnectingModbusDevice.js +4 -4
  19. package/src/screens/AddNewGateway/ConnectingWifiDevice.js +11 -9
  20. package/src/screens/AddNewGateway/ConnectingWifiGuide.js +3 -3
  21. package/src/screens/AddNewGateway/ConnectingZigbeeDevice.js +4 -4
  22. package/src/screens/AddNewGateway/RenameNewDevices.js +35 -27
  23. package/src/screens/AddNewGateway/ScanGatewayQR.js +3 -3
  24. package/src/screens/AddNewGateway/ScanModbusQR.js +3 -3
  25. package/src/screens/AddNewGateway/ScanWifiDeviceQR.js +3 -3
  26. package/src/screens/AddNewGateway/SelectDeviceSubUnit.js +10 -13
  27. package/src/screens/AddNewGateway/SelectDeviceType.js +6 -9
  28. package/src/screens/AddNewGateway/SelectDeviceUnit.js +1 -2
  29. package/src/screens/AddNewGateway/SelectModbusGateway.js +6 -7
  30. package/src/screens/AddNewGateway/SelectZigbeeGateway.js +4 -4
  31. package/src/screens/AddNewGateway/ShareWifiPassword.js +23 -27
  32. package/src/screens/AddNewGateway/__test__/ConnectingWifiGuide.test.js +6 -2
  33. package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +6 -2
  34. package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +129 -3
  35. package/src/screens/AddNewGateway/__test__/SelectDeviceSubUnit.test.js +25 -1
  36. package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +6 -2
  37. package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +6 -2
  38. package/src/screens/AddNewGateway/__test__/ShareWifiPassword.test.js +80 -1
  39. package/src/screens/Device/components/EmergencyCountdown.js +21 -3
  40. package/src/screens/Device/detail.js +15 -2
  41. package/src/screens/Device/hooks/useCountUp.js +0 -1
  42. package/src/screens/Gateway/DetailConfigActionModbus/index.js +12 -5
  43. package/src/screens/Gateway/DetailConfigActionModbus/styles.js +3 -0
  44. package/src/screens/Gateway/DetailConfigActionZigbee/__test__/index.test.js +2 -1
  45. package/src/screens/Gateway/DetailConfigActionZigbee/index.js +7 -2
  46. package/src/screens/Gateway/DeviceGatewayInfo/__test__/index.test.js +2 -1
  47. package/src/screens/Gateway/DeviceGatewayInfo/index.js +3 -1
  48. package/src/screens/Gateway/DeviceGatewayInfo/styles.js +3 -0
  49. package/src/screens/Gateway/DeviceModbusDetail/__test__/index.test.js +21 -10
  50. package/src/screens/Gateway/DeviceModbusDetail/index.js +52 -19
  51. package/src/screens/Gateway/DeviceZigbeeDetail/__test__/index.test.js +9 -10
  52. package/src/screens/Gateway/DeviceZigbeeDetail/index.js +40 -18
  53. package/src/screens/Gateway/GatewayConnectionMethods/__test__/index.test.js +2 -1
  54. package/src/screens/Gateway/GatewayConnectionMethods/index.js +1 -0
  55. package/src/screens/Gateway/GatewayDetail/__test__/index.test.js +15 -18
  56. package/src/screens/Gateway/GatewayDetail/index.js +68 -14
  57. package/src/screens/Gateway/GatewayInfo/__test__/index.test.js +4 -6
  58. package/src/screens/Gateway/GatewayInfo/index.js +64 -27
  59. package/src/screens/Gateway/GatewayInfo/styles.js +3 -0
  60. package/src/screens/Gateway/__test__/index.test.js +3 -2
  61. package/src/screens/Gateway/components/Detail/__test__/index.test.js +1 -0
  62. package/src/screens/Gateway/components/Detail/index.js +16 -1
  63. package/src/screens/Gateway/components/DetailActionModbus/__test__/index.test.js +2 -1
  64. package/src/screens/Gateway/components/DetailActionModbus/index.js +6 -1
  65. package/src/screens/Gateway/components/DetailActionModbus/styles.js +1 -0
  66. package/src/screens/Gateway/components/GatewayItem/__test__/index.test.js +1 -0
  67. package/src/screens/Gateway/components/Information/__test__/index.test.js +2 -1
  68. package/src/screens/Gateway/components/Information/index.js +6 -1
  69. package/src/screens/Gateway/components/RowItem/__test__/index.test.js +2 -1
  70. package/src/screens/Gateway/hooks/useGateway.js +18 -1
  71. package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +12 -0
  72. package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +1 -0
  73. package/src/screens/SubUnit/Detail.js +1 -2
  74. package/src/screens/Template/__test__/detail.test.js +39 -11
  75. package/src/screens/Template/__test__/index.test.js +2 -1
  76. package/src/screens/Template/detail.js +51 -4
  77. package/src/screens/Template/index.js +10 -7
  78. package/src/screens/Unit/AddMenu.js +1 -1
  79. package/src/utils/I18n/translations/en.json +7 -2
  80. package/src/utils/I18n/translations/vi.json +7 -2
@@ -3,7 +3,6 @@ import moment from 'moment';
3
3
 
4
4
  export const useCountUp = (eventTime) => {
5
5
  const [currentTime, setCurrentTime] = useState(moment());
6
-
7
6
  useEffect(() => {
8
7
  const intervalId =
9
8
  eventTime &&
@@ -1,12 +1,12 @@
1
1
  import React, { memo, useCallback, useMemo } from 'react';
2
2
  import { View } from 'react-native';
3
+ import { useRoute, useNavigation } from '@react-navigation/native';
3
4
 
4
- import styles from './styles';
5
5
  import DetailConfigAction from '../components/DetailConfigAction';
6
- import { useRoute, useNavigation } from '@react-navigation/native';
7
- import { calculateLength, calculateStartAddress } from '../utils';
8
6
  import DetailActionModbus from '../components/DetailActionModbus';
7
+ import { calculateLength, calculateStartAddress } from '../utils';
9
8
  import Routes from '../../../utils/Route';
9
+ import styles from './styles';
10
10
 
11
11
  const DetailConfigActionModbus = () => {
12
12
  const { params = {} } = useRoute();
@@ -17,6 +17,7 @@ const DetailConfigActionModbus = () => {
17
17
  isConfigWrite,
18
18
  isAction,
19
19
  isChildAction,
20
+ writeConfigs,
20
21
  } = params;
21
22
 
22
23
  const sa = useMemo(() => {
@@ -93,7 +94,9 @@ const DetailConfigActionModbus = () => {
93
94
  {
94
95
  id: 1,
95
96
  title: 'config_write',
96
- data: '--',
97
+ data:
98
+ writeConfigs?.find((item) => item?.id === itemActionConfig?.register)
99
+ ?.config?.name || '--',
97
100
  },
98
101
  {
99
102
  id: 2,
@@ -120,7 +123,9 @@ const DetailConfigActionModbus = () => {
120
123
  itemActionConfig?.delay,
121
124
  itemActionConfig?.ex,
122
125
  itemActionConfig?.index,
126
+ itemActionConfig?.register,
123
127
  len,
128
+ writeConfigs,
124
129
  ]
125
130
  );
126
131
 
@@ -146,9 +151,10 @@ const DetailConfigActionModbus = () => {
146
151
  navigate(Routes.DetailChildConfigActionModbus, {
147
152
  isChildAction: true,
148
153
  itemActionConfig: item,
154
+ writeConfigs: writeConfigs,
149
155
  });
150
156
  },
151
- [navigate]
157
+ [navigate, writeConfigs]
152
158
  );
153
159
  return (
154
160
  <View style={styles.wrap}>
@@ -170,6 +176,7 @@ const DetailConfigActionModbus = () => {
170
176
  listData={listAction}
171
177
  itemAction={itemActionConfig}
172
178
  onPressRow={onPressRow}
179
+ buttonBackStyles={styles.buttonBack}
173
180
  />
174
181
  )
175
182
  )}
@@ -6,4 +6,7 @@ export default StyleSheet.create({
6
6
  flex: 1,
7
7
  backgroundColor: Colors.White,
8
8
  },
9
+ buttonBack: {
10
+ marginRight: 12,
11
+ },
9
12
  });
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
+ import { useRoute } from '@react-navigation/native';
4
+
3
5
  import { SCProvider } from '../../../../context';
4
6
  import { mockSCStore } from '../../../../context/mockStore';
5
7
  import DetailConfigActionZigbee from '..';
6
- import { useRoute } from '@react-navigation/native';
7
8
  import DetailConfigAction from '../../components/DetailConfigAction';
8
9
 
9
10
  const wrapComponent = () => (
@@ -1,9 +1,9 @@
1
1
  import React, { memo, useMemo } from 'react';
2
2
  import { View } from 'react-native';
3
+ import { useRoute } from '@react-navigation/native';
3
4
 
4
5
  import styles from './styles';
5
6
  import DetailConfigAction from '../components/DetailConfigAction';
6
- import { useRoute } from '@react-navigation/native';
7
7
 
8
8
  const DetailConfigActionZigbee = () => {
9
9
  const { params = {} } = useRoute();
@@ -22,13 +22,18 @@ const DetailConfigActionZigbee = () => {
22
22
  {
23
23
  id: 2,
24
24
  title: (isConfig && 'key') || (isAction && 'control_payload') || '',
25
- data: '--',
25
+ data:
26
+ (isConfig && itemActionConfig?.config?.key) ||
27
+ (isAction && itemActionConfig?.action?.control_payload) ||
28
+ '--',
26
29
  },
27
30
  ],
28
31
  [
29
32
  isAction,
30
33
  isConfig,
34
+ itemActionConfig?.action?.control_payload,
31
35
  itemActionConfig?.action?.name,
36
+ itemActionConfig?.config?.key,
32
37
  itemActionConfig?.config?.name,
33
38
  ]
34
39
  );
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
+ import { useRoute } from '@react-navigation/native';
4
+
3
5
  import { SCProvider } from '../../../../context';
4
6
  import { mockSCStore } from '../../../../context/mockStore';
5
7
  import DeviceGatewayInfo from '..';
6
- import { useRoute } from '@react-navigation/native';
7
8
  import Information from '../../components/Information';
8
9
 
9
10
  const wrapComponent = () => (
@@ -1,7 +1,8 @@
1
1
  import React, { memo, useMemo } from 'react';
2
2
  import { View } from 'react-native';
3
- import t from '../../../hooks/Common/useTranslations';
4
3
  import { useRoute } from '@react-navigation/native';
4
+
5
+ import t from '../../../hooks/Common/useTranslations';
5
6
  import styles from './styles';
6
7
  import Information from '../components/Information';
7
8
 
@@ -78,6 +79,7 @@ const DeviceGatewayInfo = () => {
78
79
  return (
79
80
  <View style={styles.wrap}>
80
81
  <Information
82
+ buttonBackStyles={styles.buttonBack}
81
83
  listInformation={
82
84
  isZigbee
83
85
  ? deviceInformationZigbee
@@ -6,4 +6,7 @@ export default StyleSheet.create({
6
6
  flex: 1,
7
7
  backgroundColor: Colors.White,
8
8
  },
9
+ buttonBack: {
10
+ marginRight: 12,
11
+ },
9
12
  });
@@ -1,22 +1,23 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+ import { useRoute } from '@react-navigation/native';
5
+ import SegmentedControl from '@react-native-community/segmented-control';
6
+ import Toast from 'react-native-toast-message';
7
+
3
8
  import { SCProvider } from '../../../../context';
4
9
  import { mockSCStore } from '../../../../context/mockStore';
5
10
  import DeviceModbusDetail from '..';
6
- import { useRoute } from '@react-navigation/native';
7
11
  import { HeaderCustom } from '../../../../commons';
8
12
  import { AccessibilityLabel } from '../../../../configs/Constants';
9
13
  import Routes from '../../../../utils/Route';
10
14
  import TabPaneCT from '../../components/TabPaneCT';
11
15
  import MenuActionMore from '../../../../commons/MenuActionMore';
12
- import { Alert } from 'react-native';
13
- import Toast from 'react-native-toast-message';
14
- import SegmentedControl from '@react-native-community/segmented-control';
15
- import MockAdapter from 'axios-mock-adapter';
16
16
  import api from '../../../../utils/Apis/axios';
17
17
  import { API } from '../../../../configs';
18
18
  import { PERMISSION_TYPE } from '../../../../configs/Constants';
19
19
  import Detail from '../../components/Detail';
20
+ import ModalPopupCT from '../../../../commons/ModalPopupCT';
20
21
 
21
22
  const mock = new MockAdapter(api.axiosInstance);
22
23
 
@@ -127,13 +128,11 @@ describe('Test DeviceModbusDetail', () => {
127
128
  await act(async () => {
128
129
  menuActionMore.props.listMenuItem[1].doAction();
129
130
  });
130
- expect(Alert.alert.mock.calls[0][0]).toEqual(
131
- 'Are you sure you want to delete device "undefined" ?'
132
- );
133
- mock.onDelete(API.DEV_MODE.ZIGBEE.DEVICE_DETAIL(1, 1)).reply(200);
131
+ const modal = instance.findByType(ModalPopupCT);
134
132
  await act(async () => {
135
- await Alert.alert.mock.calls[0][2][1].onPress();
133
+ await modal.props.onPressConfirm();
136
134
  });
135
+ mock.onDelete(API.DEV_MODE.ZIGBEE.DEVICE_DETAIL(1, 1)).reply(200);
137
136
  expect(mockPop).toBeCalledWith(1);
138
137
  expect(Toast.show).toBeCalledWith({
139
138
  position: 'bottom',
@@ -257,6 +256,12 @@ describe('Test DeviceModbusDetail', () => {
257
256
  isConfigRead: false,
258
257
  isConfigWrite: true,
259
258
  itemActionConfig: 1,
259
+ writeConfigs: [
260
+ {
261
+ func: 6,
262
+ id: 2,
263
+ },
264
+ ],
260
265
  });
261
266
  });
262
267
 
@@ -290,6 +295,12 @@ describe('Test DeviceModbusDetail', () => {
290
295
  isConfigRead: true,
291
296
  isConfigWrite: false,
292
297
  itemActionConfig: 1,
298
+ writeConfigs: [
299
+ {
300
+ func: 6,
301
+ id: 2,
302
+ },
303
+ ],
293
304
  });
294
305
  });
295
306
 
@@ -1,11 +1,12 @@
1
1
  import React, { memo, useMemo, useEffect, useCallback } from 'react';
2
- import { View, Alert } from 'react-native';
2
+ import { View } from 'react-native';
3
3
  import t from '../../../hooks/Common/useTranslations';
4
4
  import {
5
5
  useRoute,
6
6
  useNavigation,
7
7
  useIsFocused,
8
8
  } from '@react-navigation/native';
9
+
9
10
  import { useGateway } from '../hooks/useGateway';
10
11
  import Routes from '../../../utils/Route';
11
12
  import { PERMISSION_TYPE } from '../../../configs/Constants';
@@ -21,6 +22,8 @@ const DeviceModbusDetail = () => {
21
22
  const {
22
23
  selectedIndex,
23
24
  detailDeviceModbus,
25
+ dataModalPopupCT,
26
+ setDataModalPopupCT,
24
27
  setSelectedIndex,
25
28
  deleteDeviceDetail,
26
29
  fetchRegistersModbus,
@@ -28,6 +31,7 @@ const DeviceModbusDetail = () => {
28
31
  setRefresh,
29
32
  refresh,
30
33
  } = useGateway();
34
+
31
35
  const listTabs = useMemo(
32
36
  () => [
33
37
  {
@@ -53,6 +57,40 @@ const DeviceModbusDetail = () => {
53
57
  ]
54
58
  );
55
59
 
60
+ const handleDeleteDevice = useCallback(() => {
61
+ setDataModalPopupCT((prev) => ({
62
+ ...prev,
63
+ title: `${t('delete_device', { name: device?.sensor?.name })}`,
64
+ subTitle: t('message_delete_device'),
65
+ type: 'device',
66
+ isVisible: true,
67
+ isShowUnderstand: false,
68
+ isShowAlert: false,
69
+ isChecked: false,
70
+ onPressConfirm: () => {
71
+ setDataModalPopupCT((prevData) => ({
72
+ ...prevData,
73
+ isVisible: false,
74
+ isChecked: false,
75
+ }));
76
+ deleteDeviceDetail(gatewayId, device?.id, false, isModbus);
77
+ },
78
+ onPressCancel: () =>
79
+ setDataModalPopupCT((prevData) => ({
80
+ ...prevData,
81
+ isVisible: false,
82
+ isChecked: false,
83
+ })),
84
+ }));
85
+ }, [
86
+ deleteDeviceDetail,
87
+ device?.id,
88
+ device?.sensor?.name,
89
+ gatewayId,
90
+ isModbus,
91
+ setDataModalPopupCT,
92
+ ]);
93
+
56
94
  const listMenuItem = useMemo(() => {
57
95
  const RouteGatewayInformation = {
58
96
  id: 1,
@@ -68,25 +106,10 @@ const DeviceModbusDetail = () => {
68
106
  id: 2,
69
107
  text: t('delete_device'),
70
108
  textStyle: styles.textColorRed,
71
- doAction: () =>
72
- Alert.alert(
73
- t('message_delete_device', { name: device?.sensor?.name }),
74
- '',
75
- [
76
- {
77
- text: t('cancel'),
78
- },
79
- {
80
- text: t('ok'),
81
- onPress: () =>
82
- deleteDeviceDetail(gatewayId, device?.id, false, isModbus),
83
- style: 'destructive',
84
- },
85
- ]
86
- ),
109
+ doAction: handleDeleteDevice,
87
110
  };
88
111
  return [RouteGatewayInformation, ListDeleteGateway];
89
- }, [deleteDeviceDetail, gatewayId, isModbus, device, navigate]);
112
+ }, [handleDeleteDevice, navigate, device, isModbus]);
90
113
 
91
114
  const isConfigRead = useMemo(() => {
92
115
  return listTabs[selectedIndex]?.title === PERMISSION_TYPE.CONFIG_READ;
@@ -131,9 +154,18 @@ const DeviceModbusDetail = () => {
131
154
  isConfigRead,
132
155
  isConfigWrite,
133
156
  isAction,
157
+ writeConfigs: detailDeviceModbus?.config_write,
134
158
  });
135
159
  },
136
- [device, gatewayId, isAction, isConfigRead, isConfigWrite, navigate]
160
+ [
161
+ detailDeviceModbus?.config_write,
162
+ device,
163
+ gatewayId,
164
+ isAction,
165
+ isConfigRead,
166
+ isConfigWrite,
167
+ navigate,
168
+ ]
137
169
  );
138
170
 
139
171
  const onRefresh = useCallback(() => {
@@ -168,6 +200,7 @@ const DeviceModbusDetail = () => {
168
200
  onPressRow={onPressRow}
169
201
  onRefresh={onRefresh}
170
202
  refresh={refresh}
203
+ dataModalPopupCT={dataModalPopupCT}
171
204
  />
172
205
  </View>
173
206
  );
@@ -1,22 +1,23 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+ import Toast from 'react-native-toast-message';
5
+ import SegmentedControl from '@react-native-community/segmented-control';
6
+ import { useRoute } from '@react-navigation/native';
7
+
3
8
  import { SCProvider } from '../../../../context';
4
9
  import { mockSCStore } from '../../../../context/mockStore';
5
10
  import DeviceZigbeeDetail from '..';
6
- import { useRoute } from '@react-navigation/native';
7
11
  import { HeaderCustom } from '../../../../commons';
8
12
  import { AccessibilityLabel } from '../../../../configs/Constants';
9
13
  import Routes from '../../../../utils/Route';
10
14
  import TabPaneCT from '../../components/TabPaneCT';
11
15
  import MenuActionMore from '../../../../commons/MenuActionMore';
12
- import { Alert } from 'react-native';
13
- import Toast from 'react-native-toast-message';
14
- import SegmentedControl from '@react-native-community/segmented-control';
15
- import MockAdapter from 'axios-mock-adapter';
16
16
  import api from '../../../../utils/Apis/axios';
17
17
  import { API } from '../../../../configs';
18
18
  import { PERMISSION_TYPE } from '../../../../configs/Constants';
19
19
  import Detail from '../../components/Detail';
20
+ import ModalPopupCT from '../../../../commons/ModalPopupCT';
20
21
 
21
22
  const mock = new MockAdapter(api.axiosInstance);
22
23
 
@@ -127,13 +128,11 @@ describe('Test DeviceZigbeeDetail', () => {
127
128
  await act(async () => {
128
129
  menuActionMore.props.listMenuItem[1].doAction();
129
130
  });
130
- expect(Alert.alert.mock.calls[0][0]).toEqual(
131
- 'Are you sure you want to delete device "undefined" ?'
132
- );
133
- mock.onDelete(API.DEV_MODE.ZIGBEE.DEVICE_DETAIL(1, 1)).reply(200);
131
+ const modal = instance.findByType(ModalPopupCT);
134
132
  await act(async () => {
135
- await Alert.alert.mock.calls[0][2][1].onPress();
133
+ await modal.props.onPressConfirm();
136
134
  });
135
+ mock.onDelete(API.DEV_MODE.ZIGBEE.DEVICE_DETAIL(1, 1)).reply(200);
137
136
  expect(mockPop).toBeCalledWith(1);
138
137
  expect(Toast.show).toBeCalledWith({
139
138
  position: 'bottom',
@@ -1,5 +1,5 @@
1
1
  import React, { memo, useMemo, useEffect, useCallback } from 'react';
2
- import { View, Alert } from 'react-native';
2
+ import { View } from 'react-native';
3
3
  import {
4
4
  useRoute,
5
5
  useNavigation,
@@ -22,6 +22,8 @@ const DeviceZigbeeDetail = () => {
22
22
  const {
23
23
  selectedIndex,
24
24
  setSelectedIndex,
25
+ setDataModalPopupCT,
26
+ dataModalPopupCT,
25
27
  fetchActionConfigDevice,
26
28
  deleteDeviceDetail,
27
29
  detailDeviceZigbee,
@@ -45,6 +47,40 @@ const DeviceZigbeeDetail = () => {
45
47
  [detailDeviceZigbee?.actions, detailDeviceZigbee?.configs]
46
48
  );
47
49
 
50
+ const handleDeleteDevice = useCallback(() => {
51
+ setDataModalPopupCT((prev) => ({
52
+ ...prev,
53
+ title: `${t('delete_device', { name: device?.sensor?.name })}`,
54
+ subTitle: t('message_delete_device'),
55
+ type: 'device',
56
+ isVisible: true,
57
+ isShowUnderstand: false,
58
+ isShowAlert: false,
59
+ isChecked: false,
60
+ onPressConfirm: () => {
61
+ setDataModalPopupCT((prevData) => ({
62
+ ...prevData,
63
+ isVisible: false,
64
+ isChecked: false,
65
+ }));
66
+ deleteDeviceDetail(gatewayId, device?.id, isZigbee, false);
67
+ },
68
+ onPressCancel: () =>
69
+ setDataModalPopupCT((prevData) => ({
70
+ ...prevData,
71
+ isVisible: false,
72
+ isChecked: false,
73
+ })),
74
+ }));
75
+ }, [
76
+ deleteDeviceDetail,
77
+ device?.id,
78
+ device?.sensor?.name,
79
+ gatewayId,
80
+ isZigbee,
81
+ setDataModalPopupCT,
82
+ ]);
83
+
48
84
  const listMenuItem = useMemo(() => {
49
85
  const RouteGatewayInformation = {
50
86
  id: 1,
@@ -61,25 +97,10 @@ const DeviceZigbeeDetail = () => {
61
97
  id: 2,
62
98
  text: t('delete_device'),
63
99
  textStyle: styles.textColorRed,
64
- doAction: () =>
65
- Alert.alert(
66
- t('message_delete_device', { name: device?.sensor?.name }),
67
- '',
68
- [
69
- {
70
- text: t('cancel'),
71
- },
72
- {
73
- text: t('ok'),
74
- onPress: () =>
75
- deleteDeviceDetail(gatewayId, device?.id, isZigbee, false),
76
- style: 'destructive',
77
- },
78
- ]
79
- ),
100
+ doAction: handleDeleteDevice,
80
101
  };
81
102
  return [RouteGatewayInformation, ListDeleteGateway];
82
- }, [deleteDeviceDetail, gatewayId, isZigbee, device, navigate]);
103
+ }, [handleDeleteDevice, navigate, device, isZigbee]);
83
104
 
84
105
  const isConfig = useMemo(() => {
85
106
  return listTabs[selectedIndex]?.title === PERMISSION_TYPE.CONFIG;
@@ -140,6 +161,7 @@ const DeviceZigbeeDetail = () => {
140
161
  onPressRow={onPressRow}
141
162
  refresh={refresh}
142
163
  onRefresh={onRefresh}
164
+ dataModalPopupCT={dataModalPopupCT}
143
165
  />
144
166
  </View>
145
167
  );
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
+ import { FlatList } from 'react-native';
2
3
  import { create, act } from 'react-test-renderer';
4
+
3
5
  import { SCProvider } from '../../../../context';
4
6
  import { mockSCStore } from '../../../../context/mockStore';
5
7
  import GatewayConnectionMethods from '..';
6
8
  import { HeaderCustom } from '../../../../commons';
7
- import { FlatList } from 'react-native';
8
9
  import { AccessibilityLabel } from '../../../../configs/Constants';
9
10
 
10
11
  const wrapComponent = () => (
@@ -1,5 +1,6 @@
1
1
  import React, { useCallback, memo, useMemo } from 'react';
2
2
  import { View, FlatList } from 'react-native';
3
+
3
4
  import { Colors } from '../../../configs';
4
5
  import t from '../../../hooks/Common/useTranslations';
5
6
  import { Text, HeaderCustom } from '../../../commons';
@@ -1,22 +1,23 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
+ import Toast from 'react-native-toast-message';
4
+ import SegmentedControl from '@react-native-community/segmented-control';
5
+ import { useRoute } from '@react-navigation/native';
6
+ import MockAdapter from 'axios-mock-adapter';
7
+
3
8
  import { SCProvider } from '../../../../context';
4
9
  import { mockSCStore } from '../../../../context/mockStore';
5
10
  import GatewayDetail from '..';
6
- import { useRoute } from '@react-navigation/native';
7
11
  import { HeaderCustom } from '../../../../commons';
8
12
  import { AccessibilityLabel } from '../../../../configs/Constants';
9
13
  import Routes from '../../../../utils/Route';
10
14
  import TabPaneCT from '../../components/TabPaneCT';
11
15
  import MenuActionMore from '../../../../commons/MenuActionMore';
12
- import { Alert } from 'react-native';
13
- import Toast from 'react-native-toast-message';
14
- import SegmentedControl from '@react-native-community/segmented-control';
15
- import MockAdapter from 'axios-mock-adapter';
16
16
  import api from '../../../../utils/Apis/axios';
17
17
  import { API } from '../../../../configs';
18
18
  import { DEVICE_TYPE } from '../../../../configs/Constants';
19
19
  import Detail from '../../components/Detail';
20
+ import ModalPopupCT from '../../../../commons/ModalPopupCT';
20
21
 
21
22
  const mock = new MockAdapter(api.axiosInstance);
22
23
 
@@ -127,7 +128,12 @@ describe('Test GatewayDetail', () => {
127
128
  await act(async () => {
128
129
  menuActionMore[0].props.listMenuItem[1].doAction();
129
130
  });
130
- expect(Alert.alert).toHaveBeenCalled();
131
+ const modal = instance.findByType(ModalPopupCT);
132
+ mock.onPost(API.DEV_MODE.GATEWAY.REBOOT(1)).reply(200);
133
+ await act(async () => {
134
+ await modal.props.onPressConfirm();
135
+ });
136
+ expect(mockPop).toBeCalledWith(1);
131
137
  });
132
138
 
133
139
  it('test render GatewayDetail onPress more and onPress Delete', async () => {
@@ -142,21 +148,12 @@ describe('Test GatewayDetail', () => {
142
148
  await act(async () => {
143
149
  menuActionMore.props.listMenuItem[2].doAction();
144
150
  });
145
- expect(Alert.alert.mock.calls[1][0]).toEqual(
146
- 'Are you sure you want to delete gateway "undefined" ?'
147
- );
148
- mock.onDelete(API.DEV_MODE.GATEWAY.DETAIL(1)).reply(200);
151
+ const modal = instance.findByType(ModalPopupCT);
149
152
  await act(async () => {
150
- await Alert.alert.mock.calls[1][2][1].onPress();
153
+ await modal.props.onPressConfirm();
151
154
  });
155
+ mock.onDelete(API.DEV_MODE.GATEWAY.DETAIL(1)).reply(200);
152
156
  expect(mockPop).toBeCalledWith(1);
153
- expect(Toast.show).toBeCalledWith({
154
- position: 'bottom',
155
- text1: 'Delete successfully!',
156
- text2: undefined,
157
- type: 'success',
158
- visibilityTime: 1000,
159
- });
160
157
  });
161
158
 
162
159
  it('test render GatewayDetail onPress TabPanel zigbee', async () => {