@eohjsc/react-native-smart-city 0.3.61 → 0.3.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 (81) hide show
  1. package/index.js +4 -2
  2. package/package.json +1 -1
  3. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +10 -0
  4. package/src/commons/Dashboard/MyUnit/index.js +9 -3
  5. package/src/commons/Device/HorizontalBarChart.js +3 -3
  6. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +2 -1
  7. package/src/commons/Header/HeaderCustom.js +4 -1
  8. package/src/configs/API.js +14 -0
  9. package/src/configs/Constants.js +1 -0
  10. package/src/context/actionType.ts +1 -0
  11. package/src/context/reducer.ts +10 -0
  12. package/src/navigations/AllGatewayStack.js +68 -0
  13. package/src/navigations/Main.js +197 -197
  14. package/src/navigations/UnitStack.js +8 -0
  15. package/src/screens/AllGateway/DetailConfigActionInternal/__test__/index.test.js +104 -0
  16. package/src/screens/AllGateway/DetailConfigActionInternal/index.js +97 -0
  17. package/src/screens/{Gateway/DetailConfigActionModbus → AllGateway/DetailConfigActionInternal}/styles.js +0 -0
  18. package/src/screens/{Gateway → AllGateway}/DetailConfigActionModbus/__test__/index.test.js +0 -0
  19. package/src/screens/{Gateway → AllGateway}/DetailConfigActionModbus/index.js +0 -0
  20. package/src/screens/{Gateway/DeviceGatewayInfo → AllGateway/DetailConfigActionModbus}/styles.js +0 -0
  21. package/src/screens/{Gateway → AllGateway}/DetailConfigActionZigbee/__test__/index.test.js +0 -0
  22. package/src/screens/{Gateway → AllGateway}/DetailConfigActionZigbee/index.js +0 -0
  23. package/src/screens/{Gateway → AllGateway}/DetailConfigActionZigbee/styles.js +0 -0
  24. package/src/screens/{Gateway → AllGateway}/DeviceGatewayInfo/__test__/index.test.js +0 -0
  25. package/src/screens/{Gateway → AllGateway}/DeviceGatewayInfo/index.js +26 -2
  26. package/src/screens/{Gateway/GatewayInfo → AllGateway/DeviceGatewayInfo}/styles.js +0 -0
  27. package/src/screens/AllGateway/DeviceInternalDetail/__test__/index.test.js +387 -0
  28. package/src/screens/AllGateway/DeviceInternalDetail/index.js +188 -0
  29. package/src/screens/{Gateway/DeviceModbusDetail → AllGateway/DeviceInternalDetail}/styles.js +0 -0
  30. package/src/screens/{Gateway → AllGateway}/DeviceModbusDetail/__test__/index.test.js +0 -0
  31. package/src/screens/{Gateway → AllGateway}/DeviceModbusDetail/index.js +9 -17
  32. package/src/screens/{Gateway/DeviceZigbeeDetail → AllGateway/DeviceModbusDetail}/styles.js +0 -0
  33. package/src/screens/{Gateway → AllGateway}/DeviceZigbeeDetail/__test__/index.test.js +0 -0
  34. package/src/screens/{Gateway → AllGateway}/DeviceZigbeeDetail/index.js +9 -17
  35. package/src/screens/{Gateway/GatewayDetail → AllGateway/DeviceZigbeeDetail}/styles.js +0 -0
  36. package/src/screens/{Gateway → AllGateway}/GatewayConnectionMethods/__test__/index.test.js +0 -0
  37. package/src/screens/{Gateway → AllGateway}/GatewayConnectionMethods/index.js +0 -0
  38. package/src/screens/{Gateway → AllGateway}/GatewayConnectionMethods/styles.js +0 -0
  39. package/src/screens/{Gateway → AllGateway}/GatewayDetail/__test__/index.test.js +71 -31
  40. package/src/screens/{Gateway → AllGateway}/GatewayDetail/index.js +62 -42
  41. package/src/screens/AllGateway/GatewayDetail/styles.js +12 -0
  42. package/src/screens/{Gateway → AllGateway}/GatewayInfo/__test__/index.test.js +0 -0
  43. package/src/screens/{Gateway → AllGateway}/GatewayInfo/index.js +14 -17
  44. package/src/screens/AllGateway/GatewayInfo/styles.js +12 -0
  45. package/src/screens/{Gateway → AllGateway}/__test__/index.test.js +8 -2
  46. package/src/screens/{Gateway → AllGateway}/components/Detail/__test__/index.test.js +0 -0
  47. package/src/screens/{Gateway → AllGateway}/components/Detail/index.js +0 -0
  48. package/src/screens/{Gateway → AllGateway}/components/Detail/styles.js +0 -0
  49. package/src/screens/{Gateway → AllGateway}/components/DetailActionModbus/__test__/index.test.js +0 -0
  50. package/src/screens/{Gateway → AllGateway}/components/DetailActionModbus/index.js +0 -0
  51. package/src/screens/{Gateway → AllGateway}/components/DetailActionModbus/styles.js +0 -0
  52. package/src/screens/{Gateway → AllGateway}/components/DetailConfigAction/__test__/index.test.js +0 -0
  53. package/src/screens/{Gateway → AllGateway}/components/DetailConfigAction/index.js +0 -0
  54. package/src/screens/{Gateway → AllGateway}/components/DetailConfigAction/styles.js +0 -0
  55. package/src/screens/{Gateway → AllGateway}/components/GatewayItem/__test__/index.test.js +0 -0
  56. package/src/screens/{Gateway → AllGateway}/components/GatewayItem/index.js +0 -0
  57. package/src/screens/{Gateway → AllGateway}/components/GatewayItem/styles.js +0 -0
  58. package/src/screens/{Gateway → AllGateway}/components/Information/__test__/index.test.js +0 -0
  59. package/src/screens/{Gateway → AllGateway}/components/Information/index.js +0 -0
  60. package/src/screens/{Gateway → AllGateway}/components/Information/styles.js +0 -0
  61. package/src/screens/{Gateway → AllGateway}/components/RowItem/__test__/index.test.js +0 -0
  62. package/src/screens/{Gateway → AllGateway}/components/RowItem/index.js +0 -0
  63. package/src/screens/{Gateway → AllGateway}/components/RowItem/styles.js +0 -0
  64. package/src/screens/{Gateway → AllGateway}/components/TabPaneCT/__test__/index.test.js +0 -0
  65. package/src/screens/{Gateway → AllGateway}/components/TabPaneCT/index.js +0 -0
  66. package/src/screens/{Gateway → AllGateway}/components/TabPaneCT/styles.js +0 -0
  67. package/src/screens/{Gateway → AllGateway}/hooks/__test__/index.test.js +15 -2
  68. package/src/screens/{Gateway → AllGateway}/hooks/useGateway.js +91 -11
  69. package/src/screens/{Gateway → AllGateway}/index.js +38 -26
  70. package/src/screens/{Gateway → AllGateway}/styles.js +9 -1
  71. package/src/screens/{Gateway → AllGateway}/utils/index.js +0 -0
  72. package/src/screens/Unit/MoreMenu.js +12 -1
  73. package/src/screens/WaterQualityGuide/__test__/index.test.js +8 -8
  74. package/src/screens/WaterQualityGuide/index.js +32 -53
  75. package/src/utils/Apis/axios.js +1 -1
  76. package/src/utils/Functions/preloadImages.js +39 -0
  77. package/src/utils/I18n/translations/en.json +22 -16
  78. package/src/utils/I18n/translations/vi.json +22 -19
  79. package/src/utils/Route/index.js +4 -0
  80. package/src/utils/Storage.js +6 -0
  81. package/src/utils/Utils.js +7 -0
@@ -22,13 +22,14 @@ const DeviceZigbeeDetail = () => {
22
22
  const {
23
23
  selectedIndex,
24
24
  setSelectedIndex,
25
- setDataModalPopupCT,
26
25
  dataModalPopupCT,
27
26
  fetchActionConfigDevice,
28
27
  deleteDeviceDetail,
29
28
  detailDeviceZigbee,
30
29
  setRefresh,
31
30
  refresh,
31
+ saveDataModalPopupCT,
32
+ hideModalPopupCT,
32
33
  } = useGateway();
33
34
 
34
35
  const listTabs = useMemo(
@@ -48,8 +49,7 @@ const DeviceZigbeeDetail = () => {
48
49
  );
49
50
 
50
51
  const handleDeleteDevice = useCallback(() => {
51
- setDataModalPopupCT((prev) => ({
52
- ...prev,
52
+ saveDataModalPopupCT({
53
53
  title: `${t('delete_device', { name: device?.sensor?.name })}`,
54
54
  subTitle: t('message_delete_device'),
55
55
  type: 'device',
@@ -58,27 +58,19 @@ const DeviceZigbeeDetail = () => {
58
58
  isShowAlert: false,
59
59
  isChecked: false,
60
60
  onPressConfirm: () => {
61
- setDataModalPopupCT((prevData) => ({
62
- ...prevData,
63
- isVisible: false,
64
- isChecked: false,
65
- }));
66
- deleteDeviceDetail(gatewayId, device?.id, isZigbee, false);
61
+ hideModalPopupCT();
62
+ deleteDeviceDetail(gatewayId, device?.id, false, isZigbee, false);
67
63
  },
68
- onPressCancel: () =>
69
- setDataModalPopupCT((prevData) => ({
70
- ...prevData,
71
- isVisible: false,
72
- isChecked: false,
73
- })),
74
- }));
64
+ onPressCancel: () => hideModalPopupCT(),
65
+ });
75
66
  }, [
76
67
  deleteDeviceDetail,
77
68
  device?.id,
78
69
  device?.sensor?.name,
79
70
  gatewayId,
80
71
  isZigbee,
81
- setDataModalPopupCT,
72
+ saveDataModalPopupCT,
73
+ hideModalPopupCT,
82
74
  ]);
83
75
 
84
76
  const listMenuItem = useMemo(() => {
@@ -66,11 +66,22 @@ const headerCustomOnPressMore = async (instance) => {
66
66
 
67
67
  describe('Test GatewayDetail', () => {
68
68
  let tree;
69
+
70
+ const onChangeTab = async (tabPaneCT, index) => {
71
+ const segmentedControl = tabPaneCT.findByType(SegmentedControl);
72
+ await act(async () => {
73
+ await segmentedControl.props.onChange({
74
+ nativeEvent: { selectedSegmentIndex: index },
75
+ });
76
+ });
77
+ };
78
+
69
79
  beforeEach(() => {
70
80
  useRoute.mockReturnValue({
71
81
  params: {
72
82
  item: {
73
83
  id: 1,
84
+ arduino_gateway: 1,
74
85
  modbus_gateway: 1,
75
86
  zigbee_gateway: 1,
76
87
  },
@@ -156,9 +167,9 @@ describe('Test GatewayDetail', () => {
156
167
  expect(mockPop).toBeCalledWith(1);
157
168
  });
158
169
 
159
- it('test render GatewayDetail onPress TabPanel zigbee', async () => {
170
+ it('test render GatewayDetail onPress TabPanel internal', async () => {
160
171
  mock
161
- .onGet(API.DEV_MODE.ZIGBEE.DEVICE(1))
172
+ .onGet(API.DEV_MODE.ARDUINO.DEVICE(1))
162
173
  .reply(200, [{ id: 1, name: 'device 1' }]);
163
174
  await act(async () => {
164
175
  tree = await create(wrapComponent());
@@ -166,16 +177,28 @@ describe('Test GatewayDetail', () => {
166
177
  const instance = tree.root;
167
178
  const detail = instance?.findByType(Detail);
168
179
  const tabPaneCT = detail.findByType(TabPaneCT);
169
- const segmentedControl = tabPaneCT.findByType(SegmentedControl);
180
+ await onChangeTab(tabPaneCT, 0);
181
+ expect(tabPaneCT.props.listTabs[0].data).toEqual([
182
+ { id: 1, name: 'device 1' },
183
+ ]);
184
+ expect(tabPaneCT.props.listTabs[0].title).toEqual(DEVICE_TYPE.INTERNAL);
185
+ });
186
+
187
+ it('test render GatewayDetail onPress TabPanel zigbee', async () => {
188
+ mock
189
+ .onGet(API.DEV_MODE.ZIGBEE.DEVICE(1))
190
+ .reply(200, [{ id: 1, name: 'device 1' }]);
170
191
  await act(async () => {
171
- await segmentedControl.props.onChange({
172
- nativeEvent: { selectedSegmentIndex: 0 },
173
- });
192
+ tree = await create(wrapComponent());
174
193
  });
175
- expect(tabPaneCT.props.listTabs[0].data).toEqual([
194
+ const instance = tree.root;
195
+ const detail = instance?.findByType(Detail);
196
+ const tabPaneCT = detail.findByType(TabPaneCT);
197
+ await onChangeTab(tabPaneCT, 1);
198
+ expect(tabPaneCT.props.listTabs[1].data).toEqual([
176
199
  { id: 1, name: 'device 1' },
177
200
  ]);
178
- expect(tabPaneCT.props.listTabs[0].title).toEqual(DEVICE_TYPE.ZIGBEE);
201
+ expect(tabPaneCT.props.listTabs[1].title).toEqual(DEVICE_TYPE.ZIGBEE);
179
202
  });
180
203
 
181
204
  it('test render GatewayDetail onPress TabPanel modbus', async () => {
@@ -188,16 +211,35 @@ describe('Test GatewayDetail', () => {
188
211
  const instance = tree.root;
189
212
  const detail = instance?.findByType(Detail);
190
213
  const tabPaneCT = detail.findByType(TabPaneCT);
191
- const segmentedControl = tabPaneCT.findByType(SegmentedControl);
192
- await act(async () => {
193
- await segmentedControl.props.onChange({
194
- nativeEvent: { selectedSegmentIndex: 1 },
195
- });
196
- });
197
- expect(tabPaneCT.props.listTabs[1].data).toEqual([
214
+ await onChangeTab(tabPaneCT, 2);
215
+ expect(tabPaneCT.props.listTabs[2].data).toEqual([
198
216
  { id: 1, name: 'device 1' },
199
217
  ]);
200
- expect(tabPaneCT.props.listTabs[1].title).toEqual(DEVICE_TYPE.MODBUS);
218
+ expect(tabPaneCT.props.listTabs[2].title).toEqual(DEVICE_TYPE.MODBUS);
219
+ });
220
+
221
+ it('test render GatewayDetail onPress TabPanel internal onPressRow', async () => {
222
+ mock
223
+ .onGet(API.DEV_MODE.ARDUINO.DEVICE(1))
224
+ .reply(200, [{ id: 1, name: 'device 1' }]);
225
+ await act(async () => {
226
+ tree = await create(wrapComponent());
227
+ });
228
+ const instance = tree.root;
229
+ const detail = instance?.findByType(Detail);
230
+ const tabPaneCT = detail.findByType(TabPaneCT);
231
+ await onChangeTab(tabPaneCT, 0);
232
+
233
+ await act(async () => {
234
+ await detail.props.onPressRow(1);
235
+ });
236
+ expect(mockNavigate).toBeCalledWith(Routes.DeviceInternalDetail, {
237
+ device: 1,
238
+ gatewayId: 1,
239
+ isInternal: true,
240
+ isModbus: false,
241
+ isZigbee: false,
242
+ });
201
243
  });
202
244
 
203
245
  it('test render GatewayDetail onPress TabPanel zigbee onPressRow', async () => {
@@ -209,12 +251,15 @@ describe('Test GatewayDetail', () => {
209
251
  });
210
252
  const instance = tree.root;
211
253
  const detail = instance?.findByType(Detail);
254
+ const tabPaneCT = detail.findByType(TabPaneCT);
255
+ await onChangeTab(tabPaneCT, 1);
212
256
  await act(async () => {
213
257
  await detail.props.onPressRow(1);
214
258
  });
215
259
  expect(mockNavigate).toBeCalledWith(Routes.DeviceZigbeeDetail, {
216
260
  device: 1,
217
261
  gatewayId: 1,
262
+ isInternal: false,
218
263
  isModbus: false,
219
264
  isZigbee: true,
220
265
  });
@@ -230,18 +275,15 @@ describe('Test GatewayDetail', () => {
230
275
  const instance = tree.root;
231
276
  const detail = instance?.findByType(Detail);
232
277
  const tabPaneCT = detail.findByType(TabPaneCT);
233
- const segmentedControl = tabPaneCT.findByType(SegmentedControl);
234
- await act(async () => {
235
- await segmentedControl.props.onChange({
236
- nativeEvent: { selectedSegmentIndex: 1 },
237
- });
238
- });
278
+ await onChangeTab(tabPaneCT, 2);
279
+
239
280
  await act(async () => {
240
281
  await detail.props.onPressRow(1);
241
282
  });
242
283
  expect(mockNavigate).toBeCalledWith(Routes.DeviceModbusDetail, {
243
284
  device: 1,
244
285
  gatewayId: 1,
286
+ isInternal: false,
245
287
  isModbus: true,
246
288
  isZigbee: false,
247
289
  });
@@ -257,24 +299,21 @@ describe('Test GatewayDetail', () => {
257
299
  const instance = tree.root;
258
300
  const detail = instance?.findByType(Detail);
259
301
  const tabPaneCT = detail.findByType(TabPaneCT);
260
- const segmentedControl = tabPaneCT.findByType(SegmentedControl);
261
- await act(async () => {
262
- await segmentedControl.props.onChange({
263
- nativeEvent: { selectedSegmentIndex: -1 },
264
- });
265
- });
302
+ await onChangeTab(tabPaneCT, -1);
303
+
266
304
  await act(async () => {
267
305
  await detail.props.onPressRow(1);
268
306
  });
269
307
  expect(mockNavigate).toBeCalledWith('', {
270
308
  device: 1,
271
309
  gatewayId: null,
310
+ isInternal: false,
272
311
  isModbus: false,
273
312
  isZigbee: false,
274
313
  });
275
314
  });
276
315
 
277
- it('test render GatewayDetail onPress TabPanel modbus onRefresh', async () => {
316
+ it('test render GatewayDetail onPress TabPanel zigbee onRefresh', async () => {
278
317
  mock
279
318
  .onGet(API.DEV_MODE.ZIGBEE.DEVICE(1))
280
319
  .reply(200, [{ id: 1, name: 'device 1' }]);
@@ -284,12 +323,13 @@ describe('Test GatewayDetail', () => {
284
323
  const instance = tree.root;
285
324
  const detail = instance?.findByType(Detail);
286
325
  const tabPaneCT = detail.findByType(TabPaneCT);
326
+ await onChangeTab(tabPaneCT, 1);
287
327
  await act(async () => {
288
328
  await detail.props.onRefresh();
289
329
  });
290
- expect(tabPaneCT.props.listTabs[0].data).toEqual([
330
+ expect(tabPaneCT.props.listTabs[1].data).toEqual([
291
331
  { id: 1, name: 'device 1' },
292
332
  ]);
293
- expect(tabPaneCT.props.listTabs[0].title).toEqual(DEVICE_TYPE.ZIGBEE);
333
+ expect(tabPaneCT.props.listTabs[1].title).toEqual(DEVICE_TYPE.ZIGBEE);
294
334
  });
295
335
  });
@@ -23,34 +23,39 @@ const GatewayDetail = () => {
23
23
  selectedIndex,
24
24
  setSelectedIndex,
25
25
  dataModalPopupCT,
26
- setDataModalPopupCT,
27
26
  fetchDevicesGateway,
28
27
  deleteGatewayDetail,
29
28
  rebootGatewayDetail,
30
29
  setRefresh,
31
30
  refresh,
32
31
  gatewayDevices,
32
+ saveDataModalPopupCT,
33
+ hideModalPopupCT,
33
34
  } = useGateway();
34
35
 
35
36
  const listTabs = useMemo(
36
37
  () => [
37
38
  {
38
39
  id: 1,
40
+ title: DEVICE_TYPE.INTERNAL,
41
+ data: gatewayDevices?.internal,
42
+ },
43
+ {
44
+ id: 2,
39
45
  title: DEVICE_TYPE.ZIGBEE,
40
46
  data: gatewayDevices?.zigbee,
41
47
  },
42
48
  {
43
- id: 2,
49
+ id: 3,
44
50
  title: DEVICE_TYPE.MODBUS,
45
51
  data: gatewayDevices?.modbus,
46
52
  },
47
53
  ],
48
- [gatewayDevices?.modbus, gatewayDevices?.zigbee]
54
+ [gatewayDevices?.internal, gatewayDevices?.modbus, gatewayDevices?.zigbee]
49
55
  );
50
56
 
51
57
  const handleRebootGateway = useCallback(() => {
52
- setDataModalPopupCT((prev) => ({
53
- ...prev,
58
+ saveDataModalPopupCT({
54
59
  title: `${t('reboot')} ${item?.name} gateway`,
55
60
  subTitle: t('message_reboot_gateway'),
56
61
  type: 'reboot',
@@ -59,48 +64,41 @@ const GatewayDetail = () => {
59
64
  isShowAlert: false,
60
65
  isChecked: false,
61
66
  onPressConfirm: () => {
62
- setDataModalPopupCT((prevData) => ({
63
- ...prevData,
64
- isVisible: false,
65
- isChecked: false,
66
- }));
67
+ hideModalPopupCT();
67
68
  rebootGatewayDetail(item?.id);
68
69
  },
69
- onPressCancel: () =>
70
- setDataModalPopupCT((prevData) => ({
71
- ...prevData,
72
- isVisible: false,
73
- isChecked: false,
74
- })),
75
- }));
76
- }, [item?.id, item?.name, rebootGatewayDetail, setDataModalPopupCT]);
70
+ onPressCancel: () => hideModalPopupCT(),
71
+ });
72
+ }, [
73
+ item?.id,
74
+ item?.name,
75
+ rebootGatewayDetail,
76
+ saveDataModalPopupCT,
77
+ hideModalPopupCT,
78
+ ]);
77
79
 
78
80
  const handleDeleteGateway = useCallback(() => {
79
- setDataModalPopupCT((prev) => ({
80
- ...prev,
81
+ saveDataModalPopupCT({
81
82
  title: `${t('delete')} ${item?.name} gateway`,
82
83
  subTitle: t('message_delete_gateway'),
83
84
  type: 'delete',
84
85
  isVisible: true,
85
- isChecked: false,
86
86
  isShowUnderstand: true,
87
87
  isShowAlert: true,
88
+ isChecked: false,
88
89
  onPressConfirm: () => {
89
- setDataModalPopupCT((prevData) => ({
90
- ...prevData,
91
- isVisible: false,
92
- isChecked: false,
93
- }));
90
+ hideModalPopupCT();
94
91
  deleteGatewayDetail(item?.id);
95
92
  },
96
- onPressCancel: () =>
97
- setDataModalPopupCT((prevData) => ({
98
- ...prevData,
99
- isVisible: false,
100
- isChecked: false,
101
- })),
102
- }));
103
- }, [deleteGatewayDetail, item?.id, item?.name, setDataModalPopupCT]);
93
+ onPressCancel: () => hideModalPopupCT(),
94
+ });
95
+ }, [
96
+ deleteGatewayDetail,
97
+ item?.id,
98
+ item?.name,
99
+ saveDataModalPopupCT,
100
+ hideModalPopupCT,
101
+ ]);
104
102
 
105
103
  const listMenuItem = useMemo(() => {
106
104
  const RouteGatewayInformation = {
@@ -133,6 +131,10 @@ const GatewayDetail = () => {
133
131
  navigate,
134
132
  ]);
135
133
 
134
+ const isInternal = useMemo(() => {
135
+ return listTabs[selectedIndex]?.title === DEVICE_TYPE.INTERNAL;
136
+ }, [listTabs, selectedIndex]);
137
+
136
138
  const isModbus = useMemo(() => {
137
139
  return listTabs[selectedIndex]?.title === DEVICE_TYPE.MODBUS;
138
140
  }, [listTabs, selectedIndex]);
@@ -142,34 +144,45 @@ const GatewayDetail = () => {
142
144
  }, [listTabs, selectedIndex]);
143
145
 
144
146
  const gatewayId = useMemo(() => {
145
- return isModbus
147
+ return isInternal
148
+ ? item?.arduino_gateway
149
+ : isModbus
146
150
  ? item?.modbus_gateway
147
151
  : isZigbee
148
152
  ? item?.zigbee_gateway
149
153
  : null;
150
- }, [isModbus, isZigbee, item?.modbus_gateway, item?.zigbee_gateway]);
154
+ }, [isInternal, isModbus, isZigbee, item]);
151
155
 
152
156
  useEffect(() => {
153
157
  if (isFocused) {
154
- fetchDevicesGateway(gatewayId, isModbus, isZigbee);
158
+ fetchDevicesGateway(gatewayId, isInternal, isModbus, isZigbee);
155
159
  }
156
- }, [fetchDevicesGateway, gatewayId, isModbus, isZigbee, isFocused]);
160
+ }, [
161
+ fetchDevicesGateway,
162
+ gatewayId,
163
+ isInternal,
164
+ isModbus,
165
+ isZigbee,
166
+ isFocused,
167
+ ]);
157
168
 
158
169
  const onPressRow = useCallback(
159
170
  (device) => {
160
171
  navigate(
161
- (isZigbee && Routes.DeviceZigbeeDetail) ||
172
+ (isInternal && Routes.DeviceInternalDetail) ||
173
+ (isZigbee && Routes.DeviceZigbeeDetail) ||
162
174
  (isModbus && Routes.DeviceModbusDetail) ||
163
175
  '',
164
176
  {
165
177
  device: device,
166
178
  gatewayId,
179
+ isInternal,
167
180
  isZigbee,
168
181
  isModbus,
169
182
  }
170
183
  );
171
184
  },
172
- [isModbus, isZigbee, gatewayId, navigate]
185
+ [isModbus, isZigbee, gatewayId, isInternal, navigate]
173
186
  );
174
187
 
175
188
  const title = useMemo(() => {
@@ -178,9 +191,16 @@ const GatewayDetail = () => {
178
191
 
179
192
  const onRefresh = useCallback(() => {
180
193
  setRefresh(true);
181
- fetchDevicesGateway(gatewayId, isModbus, isZigbee);
194
+ fetchDevicesGateway(gatewayId, isInternal, isModbus, isZigbee);
182
195
  setRefresh(false);
183
- }, [fetchDevicesGateway, isModbus, isZigbee, gatewayId, setRefresh]);
196
+ }, [
197
+ fetchDevicesGateway,
198
+ isModbus,
199
+ isInternal,
200
+ isZigbee,
201
+ gatewayId,
202
+ setRefresh,
203
+ ]);
184
204
 
185
205
  return (
186
206
  <View style={styles.wrap}>
@@ -0,0 +1,12 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { Colors } from '../../../configs';
3
+
4
+ export default StyleSheet.create({
5
+ wrap: {
6
+ flex: 1,
7
+ backgroundColor: Colors.White,
8
+ },
9
+ textColorRed: {
10
+ color: Colors.Red,
11
+ },
12
+ });
@@ -24,8 +24,9 @@ const GatewayInfo = () => {
24
24
  fetchDataDetailGateway,
25
25
  gatewayDetail,
26
26
  deleteGatewayDetail,
27
- setDataModalPopupCT,
28
27
  dataModalPopupCT,
28
+ saveDataModalPopupCT,
29
+ hideModalPopupCT,
29
30
  } = useGateway();
30
31
 
31
32
  const {
@@ -92,31 +93,27 @@ const GatewayInfo = () => {
92
93
  );
93
94
 
94
95
  const handleDeleteGateway = useCallback(() => {
95
- setDataModalPopupCT((prev) => ({
96
- ...prev,
96
+ saveDataModalPopupCT({
97
97
  title: `${t('delete')} ${gatewayName} gateway`,
98
- subTitle: t('message_reboot_gateway'),
98
+ subTitle: t('message_delete_gateway'),
99
99
  type: 'delete',
100
100
  isVisible: true,
101
101
  isShowUnderstand: true,
102
102
  isShowAlert: true,
103
103
  isChecked: false,
104
104
  onPressConfirm: () => {
105
- setDataModalPopupCT((prevData) => ({
106
- ...prevData,
107
- isVisible: false,
108
- isChecked: false,
109
- }));
105
+ hideModalPopupCT();
110
106
  deleteGatewayDetail(chipId, 2);
111
107
  },
112
- onPressCancel: () =>
113
- setDataModalPopupCT((prevData) => ({
114
- ...prevData,
115
- isVisible: false,
116
- isChecked: false,
117
- })),
118
- }));
119
- }, [chipId, deleteGatewayDetail, gatewayName, setDataModalPopupCT]);
108
+ onPressCancel: () => hideModalPopupCT(),
109
+ });
110
+ }, [
111
+ chipId,
112
+ deleteGatewayDetail,
113
+ gatewayName,
114
+ saveDataModalPopupCT,
115
+ hideModalPopupCT,
116
+ ]);
120
117
 
121
118
  const handleConnectionMethods = useCallback(() => {
122
119
  navigate(Routes.GatewayConnectionMethods);
@@ -0,0 +1,12 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { Colors } from '../../../configs';
3
+
4
+ export default StyleSheet.create({
5
+ wrap: {
6
+ flex: 1,
7
+ backgroundColor: Colors.White,
8
+ },
9
+ buttonBack: {
10
+ marginRight: 12,
11
+ },
12
+ });
@@ -65,8 +65,14 @@ describe('Test Gateway screen', () => {
65
65
  await act(async () => {
66
66
  await gatewayItems[0].props.onPress();
67
67
  });
68
- expect(mockNavigate).toBeCalledWith(Routes.GatewayDetail, {
69
- item: { id: 1, name: 'device 1' },
68
+ expect(mockNavigate).toBeCalledWith(Routes.AllGatewayStack, {
69
+ params: {
70
+ item: {
71
+ id: 1,
72
+ name: 'device 1',
73
+ },
74
+ },
75
+ screen: 'GatewayDetail',
70
76
  });
71
77
  });
72
78
 
@@ -51,13 +51,26 @@ describe('Test useGateway', () => {
51
51
  expect(hook.result.current.gateways).toEqual([{ id: 1, name: 'chip 1' }]);
52
52
  });
53
53
 
54
+ it('test useGateway fetchDevicesGateway isInterval', async () => {
55
+ mock
56
+ .onGet(API.DEV_MODE.ARDUINO.DEVICE(1))
57
+ .reply(200, [{ id: 1, name: 'device 1' }]);
58
+ await act(async () => {
59
+ await hook.result.current.fetchDevicesGateway(1, true, false, false);
60
+ });
61
+
62
+ expect(hook.result.current.gatewayDevices?.internal).toEqual([
63
+ { id: 1, name: 'device 1' },
64
+ ]);
65
+ });
66
+
54
67
  it('test useGateway fetchDevicesGateway isModbus', async () => {
55
68
  mock
56
69
  .onGet(API.DEV_MODE.MODBUS.DEVICE(1))
57
70
  .reply(200, [{ id: 1, name: 'device 1' }]);
58
71
 
59
72
  await act(async () => {
60
- await hook.result.current.fetchDevicesGateway(1, true, false);
73
+ await hook.result.current.fetchDevicesGateway(1, false, true, false);
61
74
  });
62
75
  expect(hook.result.current.gatewayDevices?.modbus).toEqual([
63
76
  { id: 1, name: 'device 1' },
@@ -70,7 +83,7 @@ describe('Test useGateway', () => {
70
83
  .reply(200, [{ id: 1, name: 'device 1' }]);
71
84
 
72
85
  await act(async () => {
73
- await hook.result.current.fetchDevicesGateway(1, false, true);
86
+ await hook.result.current.fetchDevicesGateway(1, false, false, true);
74
87
  });
75
88
  expect(hook.result.current.gatewayDevices?.zigbee).toEqual([
76
89
  { id: 1, name: 'device 1' },