@eohjsc/react-native-smart-city 0.2.92 → 0.2.93

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 (73) hide show
  1. package/assets/images/Device/current-state.svg +3 -0
  2. package/assets/images/Device/door-state.svg +3 -0
  3. package/assets/images/Device/wind-strength.svg +12 -0
  4. package/package.json +1 -1
  5. package/src/commons/Action/ItemQuickAction.js +1 -0
  6. package/src/commons/Action/__test__/ItemQuickAction.test.js +49 -2
  7. package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplateStyle.js +2 -1
  8. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +31 -11
  9. package/src/commons/ActionGroup/OptionsDropdownActionTemplateStyle.js +5 -2
  10. package/src/commons/ActionGroup/TimerActionTemplate.js +14 -10
  11. package/src/commons/ActionGroup/TimerActionTemplateStyles.js +12 -0
  12. package/src/commons/ActionGroup/TwoButtonTemplate/TwoButtonTemplateStyles.js +55 -0
  13. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +170 -0
  14. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +1 -1
  15. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +112 -0
  16. package/src/commons/ActionGroup/index.js +3 -0
  17. package/src/commons/CameraDevice/index.js +6 -1
  18. package/src/commons/Device/HistoryChart.js +2 -2
  19. package/src/commons/Device/ItemDevice.js +3 -13
  20. package/src/commons/IconComponent/index.js +32 -26
  21. package/src/commons/MediaPlayerDetail/index.js +16 -4
  22. package/src/commons/SubUnit/Favorites/index.js +8 -7
  23. package/src/commons/SubUnit/__test__/Favorites.test.js +33 -35
  24. package/src/configs/API.js +4 -0
  25. package/src/configs/Constants.js +21 -0
  26. package/src/context/actionType.ts +17 -0
  27. package/src/context/mockStore.ts +18 -0
  28. package/src/context/reducer.ts +102 -0
  29. package/src/iot/RemoteControl/Bluetooth.js +2 -0
  30. package/src/iot/RemoteControl/GoogleHome.js +1 -0
  31. package/src/navigations/AutomateStack.js +16 -1
  32. package/src/navigations/UnitStack.js +27 -0
  33. package/src/screens/AddNewAction/Device/__test__/index.test.js +1 -1
  34. package/src/screens/AddNewAction/SelectAction.js +13 -15
  35. package/src/screens/AddNewAction/__test__/SelectAction.test.js +0 -7
  36. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +2 -0
  37. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +2 -0
  38. package/src/screens/AddNewGateway/PlugAndPlay/__test__/ConnectWifiWarning.test.js +9 -0
  39. package/src/screens/AddNewGateway/PlugAndPlay/__test__/GatewayWifiList.test.js +15 -0
  40. package/src/screens/AddNewGateway/SetupGatewayWifi.js +6 -1
  41. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +34 -0
  42. package/src/screens/AllCamera/index.js +1 -0
  43. package/src/screens/Automate/MultiUnits.js +9 -9
  44. package/src/screens/Automate/index.js +21 -20
  45. package/src/screens/Device/__test__/detail.test.js +119 -86
  46. package/src/screens/Device/detail.js +38 -51
  47. package/src/screens/Device/hooks/useFavoriteDevice.js +38 -0
  48. package/src/screens/EmergencyContacts/EmergencyContactsList.js +1 -1
  49. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +41 -44
  50. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +1 -0
  51. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +18 -19
  52. package/src/screens/Notification/__test__/NotificationItem.test.js +64 -53
  53. package/src/screens/Notification/components/NotificationItem.js +13 -4
  54. package/src/screens/ScriptDetail/__test__/index.test.js +15 -4
  55. package/src/screens/ScriptDetail/hooks/useStarredScript.js +32 -0
  56. package/src/screens/ScriptDetail/index.js +11 -20
  57. package/src/screens/SharedUnit/__test__/TabHeader.test.js +5 -0
  58. package/src/screens/Sharing/SelectUser.js +3 -23
  59. package/src/screens/Sharing/__test__/SelectUser.test.js +12 -80
  60. package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +33 -0
  61. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +2 -0
  62. package/src/screens/Unit/ChooseLocation.js +5 -0
  63. package/src/screens/Unit/Detail.js +33 -37
  64. package/src/screens/Unit/ManageUnit.js +21 -20
  65. package/src/screens/Unit/ManageUnitStyles.js +1 -0
  66. package/src/screens/Unit/SelectAddress.js +8 -2
  67. package/src/screens/Unit/Summaries.js +12 -15
  68. package/src/screens/Unit/__test__/Detail.test.js +25 -0
  69. package/src/screens/Unit/components/__test__/Header.test.js +32 -0
  70. package/src/screens/Unit/hook/useFavorites.js +28 -0
  71. package/src/utils/Apis/axios.js +7 -2
  72. package/src/utils/I18n/translations/en.json +1 -4
  73. package/src/utils/I18n/translations/vi.json +1 -4
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ScrollView } from 'react-native';
2
+ import { Alert, ScrollView } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
4
  import DeviceDetail from '../detail';
5
5
  import axios from 'axios';
@@ -69,12 +69,17 @@ const mockAxios = (
69
69
  });
70
70
  };
71
71
 
72
- const wrapComponent = (account, route) => (
73
- <SCProvider initState={mockSCStore({})}>
72
+ let store = mockSCStore({});
73
+
74
+ const wrapComponent = (store, account, route) => (
75
+ <SCProvider initState={store}>
74
76
  <DeviceDetail account={account} route={route} />
75
77
  </SCProvider>
76
78
  );
77
79
 
80
+ const mockAlertShow = jest.fn();
81
+ Alert.alert = mockAlertShow;
82
+
78
83
  describe('test DeviceDetail', () => {
79
84
  let tree;
80
85
  let route;
@@ -119,78 +124,79 @@ describe('test DeviceDetail', () => {
119
124
  mockedNavigate.mockClear();
120
125
  });
121
126
 
122
- test('render DeviceDetail render SensorDisplayItem', async () => {
123
- const responseDisplay = {
124
- status: 200,
125
- data: {
126
- items: [
127
- {
128
- configuration: {
129
- id: 2,
130
- name: 'EoH Gate',
131
- preview_uri:
132
- 'http://admin:admin123@203.205.32.86:10080/Streaming/Channels/2/picture',
133
- uri: 'rtsp://admin:admin123@203.205.32.86:10554/Streaming/Channels/1/',
127
+ let data_sensor_display = {
128
+ items: [
129
+ {
130
+ configuration: {
131
+ id: 2,
132
+ name: 'EoH Gate',
133
+ preview_uri:
134
+ 'http://admin:admin123@203.205.32.86:10080/Streaming/Channels/2/picture',
135
+ uri: 'rtsp://admin:admin123@203.205.32.86:10554/Streaming/Channels/1/',
136
+ },
137
+ id: 17,
138
+ order: 1,
139
+ template: 'camera',
140
+ type: 'camera',
141
+ },
142
+ {
143
+ configuration: {
144
+ id: 1,
145
+ template: 'three_button_action_template',
146
+ title: '',
147
+ configuration: {
148
+ action1: '2b949045-8e03-4c07-a855-7794ade2e69c',
149
+ action1_data: {
150
+ color: '#00979D',
151
+ command_prefer_over_bluetooth: false,
152
+ command_prefer_over_googlehome: false,
153
+ command_prefer_over_internet: true,
154
+ googlehome_actions: [],
155
+ icon: 'caret-up',
156
+ id: 9,
157
+ key: '2b949045-8e03-4c07-a855-7794ade2e69c',
134
158
  },
135
- id: 17,
136
- order: 1,
137
- template: 'camera',
138
- type: 'camera',
139
- },
140
- {
141
- configuration: {
142
- id: 1,
143
- template: 'three_button_action_template',
144
- title: '',
145
- configuration: {
146
- action1: '2b949045-8e03-4c07-a855-7794ade2e69c',
147
- action1_data: {
148
- color: '#00979D',
149
- command_prefer_over_bluetooth: false,
150
- command_prefer_over_googlehome: false,
151
- command_prefer_over_internet: true,
152
- googlehome_actions: [],
153
- icon: 'caret-up',
154
- id: 9,
155
- key: '2b949045-8e03-4c07-a855-7794ade2e69c',
156
- },
157
- action2: '38347d5e-4418-4ab0-978c-c82f4c034897',
158
- action2_data: {
159
- color: '#00979D',
160
- command_prefer_over_bluetooth: false,
161
- command_prefer_over_googlehome: false,
162
- command_prefer_over_internet: true,
163
- googlehome_actions: [],
164
- icon: 'stop',
165
- id: 11,
166
- key: '38347d5e-4418-4ab0-978c-c82f4c034897',
167
- },
168
- action3: 'a492e08c-8cb1-44ee-8ea0-46aaca4e5141',
169
- action3_data: {
170
- color: '#00979D',
171
- command_prefer_over_bluetooth: false,
172
- command_prefer_over_googlehome: false,
173
- command_prefer_over_internet: true,
174
- googlehome_actions: [],
175
- icon: 'caret-down',
176
- id: 10,
177
- key: 'a492e08c-8cb1-44ee-8ea0-46aaca4e5141',
178
- },
179
- icon1: 'caret-up',
180
- icon2: 'stop',
181
- icon3: 'caret-down',
182
- text1: 'UP',
183
- text2: 'STOP/UNLOCK',
184
- text3: 'DOWN',
185
- },
159
+ action2: '38347d5e-4418-4ab0-978c-c82f4c034897',
160
+ action2_data: {
161
+ color: '#00979D',
162
+ command_prefer_over_bluetooth: false,
163
+ command_prefer_over_googlehome: false,
164
+ command_prefer_over_internet: true,
165
+ googlehome_actions: [],
166
+ icon: 'stop',
167
+ id: 11,
168
+ key: '38347d5e-4418-4ab0-978c-c82f4c034897',
186
169
  },
187
- id: 18,
188
- order: 2,
189
- template: 'action',
190
- type: 'action',
170
+ action3: 'a492e08c-8cb1-44ee-8ea0-46aaca4e5141',
171
+ action3_data: {
172
+ color: '#00979D',
173
+ command_prefer_over_bluetooth: false,
174
+ command_prefer_over_googlehome: false,
175
+ command_prefer_over_internet: true,
176
+ googlehome_actions: [],
177
+ icon: 'caret-down',
178
+ id: 10,
179
+ key: 'a492e08c-8cb1-44ee-8ea0-46aaca4e5141',
180
+ },
181
+ icon1: 'caret-up',
182
+ icon2: 'stop',
183
+ icon3: 'caret-down',
184
+ text1: 'UP',
185
+ text2: 'STOP/UNLOCK',
186
+ text3: 'DOWN',
191
187
  },
192
- ],
188
+ },
189
+ id: 18,
190
+ order: 2,
191
+ template: 'action',
192
+ type: 'action',
193
193
  },
194
+ ],
195
+ };
196
+ test('render DeviceDetail render SensorDisplayItem', async () => {
197
+ const responseDisplay = {
198
+ status: 200,
199
+ data: data_sensor_display,
194
200
  };
195
201
 
196
202
  const responseRemoteControl = {
@@ -216,7 +222,7 @@ describe('test DeviceDetail', () => {
216
222
  mockAxios(responseDisplay, responseDisplayValueV2, responseRemoteControl);
217
223
 
218
224
  await act(async () => {
219
- tree = await create(wrapComponent(account, route));
225
+ tree = await create(wrapComponent(store, account, route));
220
226
  });
221
227
  const instance = tree.root;
222
228
  expect(axios.get).toHaveBeenCalledTimes(4);
@@ -277,7 +283,7 @@ describe('test DeviceDetail', () => {
277
283
 
278
284
  test('AlertSendConfirm onSendNowAlert', async () => {
279
285
  await act(async () => {
280
- tree = await create(wrapComponent(account, route));
286
+ tree = await create(wrapComponent(store, account, route));
281
287
  });
282
288
  const instance = tree.root;
283
289
  const alertSendConfirm = instance.findByType(AlertSendConfirm);
@@ -306,7 +312,7 @@ describe('test DeviceDetail', () => {
306
312
 
307
313
  test('ButtonPopup onClick', async () => {
308
314
  await act(async () => {
309
- tree = await create(wrapComponent(account, route));
315
+ tree = await create(wrapComponent(store, account, route));
310
316
  });
311
317
  const instance = tree.root;
312
318
  const buttonPopup = instance.find(
@@ -336,7 +342,7 @@ describe('test DeviceDetail', () => {
336
342
 
337
343
  test('ButtonPopup render', async () => {
338
344
  await act(async () => {
339
- tree = await create(wrapComponent(account, route));
345
+ tree = await create(wrapComponent(store, account, route));
340
346
  });
341
347
  const instance = tree.root;
342
348
  const buttonPopupTitle = instance.find(
@@ -359,7 +365,7 @@ describe('test DeviceDetail', () => {
359
365
 
360
366
  test('ScrollView onRefresh', async () => {
361
367
  await act(async () => {
362
- tree = await create(wrapComponent(account, route));
368
+ tree = await create(wrapComponent(store, account, route));
363
369
  });
364
370
  const instance = tree.root;
365
371
  const scrollView = instance.findByType(ScrollView);
@@ -499,7 +505,7 @@ describe('test DeviceDetail', () => {
499
505
  mockAxios(responseDisplay, responseDisplayValueV2);
500
506
 
501
507
  await act(async () => {
502
- tree = await create(wrapComponent(account, route));
508
+ tree = await create(wrapComponent(store, account, route));
503
509
  });
504
510
 
505
511
  const instance = tree.root;
@@ -563,7 +569,7 @@ describe('test DeviceDetail', () => {
563
569
  mockAxios(responseDisplay, responseDisplayValueV2);
564
570
 
565
571
  await act(async () => {
566
- tree = await create(wrapComponent(account, route));
572
+ tree = await create(wrapComponent(store, account, route));
567
573
  });
568
574
 
569
575
  const instance = tree.root;
@@ -611,7 +617,7 @@ describe('test DeviceDetail', () => {
611
617
  mockAxios(responseDisplay, responseDisplayValueV2);
612
618
 
613
619
  await act(async () => {
614
- tree = await create(wrapComponent(account, route));
620
+ tree = await create(wrapComponent(store, account, route));
615
621
  });
616
622
 
617
623
  const instance = tree.root;
@@ -628,7 +634,7 @@ describe('test DeviceDetail', () => {
628
634
  route.params.sensorData.is_managed_by_backend = false;
629
635
 
630
636
  await act(async () => {
631
- tree = await create(wrapComponent(account, route));
637
+ tree = await create(wrapComponent(store, account, route));
632
638
  });
633
639
 
634
640
  expect(axios.get).not.toBeCalledWith(API.SENSOR.DISPLAY_VALUES_V2(1));
@@ -675,7 +681,7 @@ describe('test DeviceDetail', () => {
675
681
  mockAxios(responseDisplay, responseDisplayValueV2);
676
682
 
677
683
  await act(async () => {
678
- tree = await create(wrapComponent(account, route));
684
+ tree = await create(wrapComponent(store, account, route));
679
685
  });
680
686
 
681
687
  const instance = tree.root;
@@ -689,7 +695,7 @@ describe('test DeviceDetail', () => {
689
695
 
690
696
  test('HeaderDevice button more onClick', async () => {
691
697
  await act(async () => {
692
- tree = await create(wrapComponent(account, route));
698
+ tree = await create(wrapComponent(store, account, route));
693
699
  });
694
700
  const instance = tree.root;
695
701
  const menu = instance.findByType(MenuActionMore);
@@ -711,7 +717,7 @@ describe('test DeviceDetail', () => {
711
717
  sensor.is_favourite = false;
712
718
 
713
719
  await act(async () => {
714
- tree = await create(wrapComponent(account, route));
720
+ tree = await create(wrapComponent(store, account, route));
715
721
  });
716
722
  const instance = tree.root;
717
723
 
@@ -736,10 +742,10 @@ describe('test DeviceDetail', () => {
736
742
  const unit_id = route.params.unitData.id;
737
743
  const station_id = route.params.station.id;
738
744
  const sensor = route.params.sensorData;
739
- sensor.is_favourite = true;
745
+ store.unit.favoriteDeviceIds = [sensor.id];
740
746
 
741
747
  await act(async () => {
742
- tree = await create(wrapComponent(account, route));
748
+ tree = await create(wrapComponent(store, account, route));
743
749
  });
744
750
  const instance = tree.root;
745
751
 
@@ -797,7 +803,7 @@ describe('test DeviceDetail', () => {
797
803
  mockAxios(responseDisplay, responseDisplayValueV2);
798
804
 
799
805
  await act(async () => {
800
- tree = await create(wrapComponent(account, route));
806
+ tree = await create(wrapComponent(store, account, route));
801
807
  });
802
808
  const instance = tree.root;
803
809
  const menu = instance.findByType(MenuActionMore);
@@ -816,4 +822,31 @@ describe('test DeviceDetail', () => {
816
822
  },
817
823
  });
818
824
  });
825
+
826
+ test('Open popup ble when server down', async () => {
827
+ store.app.isBluetoothEnabled = false;
828
+ data_sensor_display.items[1].configuration.configuration.action1_data.command_prefer_over_bluetooth = true;
829
+ const responseDisplay = {
830
+ status: 200,
831
+ data: data_sensor_display,
832
+ resp_status: 503,
833
+ };
834
+
835
+ const responseDisplayValueV2 = {
836
+ status: 503,
837
+ resp_status: 503,
838
+ data: {
839
+ configs: [],
840
+ is_connected: true,
841
+ last_updated: '2021-01-24T12:00:00.000Z',
842
+ },
843
+ };
844
+
845
+ mockAxios(responseDisplay, responseDisplayValueV2);
846
+
847
+ await act(async () => {
848
+ await create(wrapComponent(store, account, route));
849
+ });
850
+ expect(mockAlertShow).toBeCalled();
851
+ });
819
852
  });
@@ -16,7 +16,7 @@ import { Icon } from '@ant-design/react-native';
16
16
  import { useCountUp } from './hooks/useCountUp';
17
17
  import { getData as getLocalData } from '../../utils/Storage';
18
18
  import { API, Colors } from '../../configs';
19
- import { axiosGet, axiosPost } from '../../utils/Apis/axios';
19
+ import { axiosGet } from '../../utils/Apis/axios';
20
20
  import {
21
21
  isDeviceConnected,
22
22
  scanBluetoothDevices,
@@ -29,6 +29,7 @@ import {
29
29
  useAlertResolveEmergency,
30
30
  useEmergencyButton,
31
31
  } from './hooks/useEmergencyButton';
32
+ import { useFavoriteDevice } from './hooks/useFavoriteDevice';
32
33
  import BottomButtonView from '../../commons/BottomButtonView';
33
34
  import Text from '../../commons/Text';
34
35
  import { transformDatetime } from '../../utils/Converter/time';
@@ -69,7 +70,6 @@ const DeviceDetail = ({ route }) => {
69
70
  const [unit, setUnit] = useState(unitData || { id: unitId });
70
71
  const [sensor, setSensor] = useState(sensorData || { id: sensorId });
71
72
  const [station, setStation] = useState(sensor?.station);
72
- const [isFavourite, setIsFavourite] = useState(sensor?.is_favourite);
73
73
  const { isOwner } = useIsOwnerOfUnit(unit?.user_id);
74
74
  const [sensorName, setSensorName] = useState(sensor?.name);
75
75
  const [lockShowing, acquireLockShowing, releaseLockShowing] = useBoolean();
@@ -83,9 +83,9 @@ const DeviceDetail = ({ route }) => {
83
83
  const isNetworkConnected = useSCContextSelector(
84
84
  (state) => state.app.isNetworkConnected
85
85
  );
86
- const isBluetoothEnabled = useSCContextSelector(
87
- (state) => state.app.isBluetoothEnabled
88
- );
86
+ const isBluetoothEnabled = useSCContextSelector((state) => {
87
+ return state.app.isBluetoothEnabled;
88
+ });
89
89
 
90
90
  const isDeviceConnectedViaBle = useMemo(
91
91
  () =>
@@ -110,41 +110,28 @@ const DeviceDetail = ({ route }) => {
110
110
 
111
111
  useDisconnectedDevice(sensorName, isDeviceHasBle, serverDown);
112
112
 
113
- const isShowSetupEmergencyContact = useMemo(() => {
114
- display.items.filter(
115
- (item) =>
116
- item.type === 'emergency' && item.configuration.type === 'button'
117
- ).length > 0;
118
- }, [display.items]);
113
+ const isShowSetupEmergencyContact = useMemo(
114
+ () =>
115
+ display.items.filter(
116
+ (item) =>
117
+ item.type === 'emergency' && item.configuration.type === 'button'
118
+ ).length > 0,
119
+ [display.items]
120
+ );
119
121
 
120
- const isShowSetUpSmartLock = useMemo(() => {
121
- display.items.filter(
122
- (item) =>
123
- item.type === 'smartLock' && item.configuration.type === 'button'
124
- ).length > 0;
125
- }, [display.items]);
122
+ const isShowSetUpSmartLock = useMemo(
123
+ () =>
124
+ display.items.filter(
125
+ (item) =>
126
+ item.type === 'smartLock' && item.configuration.type === 'button'
127
+ ).length > 0,
128
+ [display.items]
129
+ );
126
130
 
127
- const addToFavorites = useCallback(async () => {
128
- const { success } = await axiosPost(
129
- API.SENSOR.ADD_TO_FAVOURITES(unit?.id, sensor?.station?.id, sensor?.id)
130
- );
131
- if (success) {
132
- setIsFavourite(true);
133
- }
134
- }, [unit, sensor]);
135
-
136
- const removeFromFavorites = useCallback(async () => {
137
- const { success } = await axiosPost(
138
- API.SENSOR.REMOVE_FROM_FAVOURITES(
139
- unit?.id,
140
- sensor?.station.id,
141
- sensor?.id
142
- )
143
- );
144
- if (success) {
145
- setIsFavourite(false);
146
- }
147
- }, [unit, sensor]);
131
+ const { isFavorite, addToFavorites, removeFromFavorites } = useFavoriteDevice(
132
+ unit,
133
+ sensor
134
+ );
148
135
 
149
136
  const currentUserId = useSelector((state) =>
150
137
  get(state, 'auth.account.user.id', 0)
@@ -162,10 +149,10 @@ const DeviceDetail = ({ route }) => {
162
149
  }, [unitId]);
163
150
 
164
151
  useEffect(() => {
165
- if (unitId) {
152
+ if (unitId && !unitData) {
166
153
  fetchUnitDetail();
167
154
  }
168
- }, [fetchUnitDetail, unitData, unitId]);
155
+ }, [fetchUnitDetail, unitId, unitData]);
169
156
 
170
157
  const fetchSensorDetail = useCallback(async () => {
171
158
  const { success, data } = await axiosGet(
@@ -179,10 +166,10 @@ const DeviceDetail = ({ route }) => {
179
166
  }, [sensorId]);
180
167
 
181
168
  useEffect(() => {
182
- if (sensorId) {
169
+ if (sensorId && !sensorData) {
183
170
  fetchSensorDetail();
184
171
  }
185
- }, [fetchSensorDetail, sensorData, sensorId]);
172
+ }, [fetchSensorDetail, sensorId, sensorData]);
186
173
 
187
174
  const fetchDataDeviceDetail = useCallback(async () => {
188
175
  if (!token) {
@@ -192,7 +179,7 @@ const DeviceDetail = ({ route }) => {
192
179
  return;
193
180
  }
194
181
 
195
- const { success, data, resp_status } = await axiosGet(
182
+ const { success, data } = await axiosGet(
196
183
  API.SENSOR.DISPLAY(sensor?.id),
197
184
  {},
198
185
  true
@@ -216,8 +203,6 @@ const DeviceDetail = ({ route }) => {
216
203
  }
217
204
  }
218
205
  }
219
- } else if (resp_status >= 500) {
220
- setServerDown(true);
221
206
  }
222
207
  setLoading((preState) => ({ ...preState, displayTemplate: false }));
223
208
 
@@ -347,7 +332,7 @@ const DeviceDetail = ({ route }) => {
347
332
  text: t('passcode_list'),
348
333
  });
349
334
  }
350
- if (!isFavourite) {
335
+ if (!isFavorite) {
351
336
  menuItems.unshift({
352
337
  doAction: addToFavorites,
353
338
  text: t('add_to_favorites'),
@@ -365,7 +350,7 @@ const DeviceDetail = ({ route }) => {
365
350
  isShowSetupEmergencyContact,
366
351
  isShowSetUpSmartLock,
367
352
  t,
368
- isFavourite,
353
+ isFavorite,
369
354
  sensor,
370
355
  unit,
371
356
  sensorName,
@@ -434,7 +419,7 @@ const DeviceDetail = ({ route }) => {
434
419
  });
435
420
 
436
421
  const fetchValues = async () => {
437
- const { success, data } = await axiosGet(
422
+ const { success, data, resp_status } = await axiosGet(
438
423
  API.SENSOR.DISPLAY_VALUES_V2(sensor?.id),
439
424
  {
440
425
  params: params,
@@ -445,6 +430,8 @@ const DeviceDetail = ({ route }) => {
445
430
  setConnected(data.is_connected);
446
431
  transformDatetime(data, ['last_updated']);
447
432
  setLastUpdated(data.last_updated);
433
+ } else if (resp_status >= 500) {
434
+ setServerDown(true);
448
435
  }
449
436
  setLoading((preState) => ({ ...preState, isConnected: false }));
450
437
  };
@@ -626,10 +613,10 @@ const DeviceDetail = ({ route }) => {
626
613
  <View style={styles.headerRight}>
627
614
  <TouchableOpacity
628
615
  style={styles.buttonStar}
629
- onPress={isFavourite ? removeFromFavorites : addToFavorites}
616
+ onPress={isFavorite ? removeFromFavorites : addToFavorites}
630
617
  testID={TESTID.HEADER_DEVICE_BUTTON_STAR}
631
618
  >
632
- {isFavourite ? (
619
+ {isFavorite ? (
633
620
  <IconFill name="star" size={25} color={Colors.Yellow6} />
634
621
  ) : (
635
622
  <IconOutline name="star" size={25} />
@@ -653,7 +640,7 @@ const DeviceDetail = ({ route }) => {
653
640
  </View>
654
641
  ),
655
642
  [
656
- isFavourite,
643
+ isFavorite,
657
644
  removeFromFavorites,
658
645
  addToFavorites,
659
646
  isShowSetupEmergencyContact,
@@ -0,0 +1,38 @@
1
+ import { useContext, useCallback } from 'react';
2
+ import { API } from '../../../configs';
3
+ import { SCContext, useSCContextSelector } from '../../../context';
4
+ import { Action } from '../../../context/actionType';
5
+ import { axiosPost } from '../../../utils/Apis/axios';
6
+
7
+ export const useFavoriteDevice = (unit, device) => {
8
+ const { setAction } = useContext(SCContext);
9
+ const favoriteDeviceIds = useSCContextSelector(
10
+ (state) => state.unit.favoriteDeviceIds
11
+ );
12
+
13
+ const isFavorite = favoriteDeviceIds.includes(device.id);
14
+
15
+ const addToFavorites = useCallback(async () => {
16
+ const { success } = await axiosPost(
17
+ API.SENSOR.ADD_TO_FAVOURITES(unit?.id, device?.station?.id, device?.id)
18
+ );
19
+ success && setAction(Action.ADD_DEVICE_TO_FAVORITES, device.id);
20
+ }, [unit, device, setAction]);
21
+
22
+ const removeFromFavorites = useCallback(async () => {
23
+ const { success } = await axiosPost(
24
+ API.SENSOR.REMOVE_FROM_FAVOURITES(
25
+ unit?.id,
26
+ device?.station?.id,
27
+ device?.id
28
+ )
29
+ );
30
+ success && setAction(Action.REMOVE_DEVICE_FROM_FAVORITES, device.id);
31
+ }, [unit, device, setAction]);
32
+
33
+ return {
34
+ isFavorite,
35
+ addToFavorites,
36
+ removeFromFavorites,
37
+ };
38
+ };
@@ -82,7 +82,7 @@ export const EmergencyContactsList = ({ route }) => {
82
82
  id: 2,
83
83
  text: t('select_unit_members'),
84
84
  route: Routes.EmergencyContactsSelectContacts,
85
- data: { unitId },
85
+ data: { unitId, group },
86
86
  },
87
87
  ];
88
88