@eohjsc/react-native-smart-city 0.2.84 → 0.2.87

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 (128) hide show
  1. package/assets/images/Device/button-lock.svg +3 -0
  2. package/assets/images/Device/button-unlock.svg +3 -0
  3. package/assets/images/brightness.svg +12 -0
  4. package/assets/images/brightnessBlack.svg +12 -0
  5. package/index.js +4 -0
  6. package/package.json +3 -1
  7. package/src/Images/Common/SuccessfullyConnected.svg +4 -0
  8. package/src/Images/Common/eye-closed.png +0 -0
  9. package/src/Images/Common/eye-closed@2x.png +0 -0
  10. package/src/Images/Common/eye-closed@3x.png +0 -0
  11. package/src/Images/Common/eye.png +0 -0
  12. package/src/Images/Common/eye@2x.png +0 -0
  13. package/src/Images/Common/eye@3x.png +0 -0
  14. package/src/Images/SmartIr/AC.svg +14 -0
  15. package/src/Images/SmartIr/DIY.svg +3 -0
  16. package/src/Images/SmartIr/Fan.svg +10 -0
  17. package/src/Images/SmartIr/Fridge.svg +5 -0
  18. package/src/Images/SmartIr/TV.svg +10 -0
  19. package/src/Images/SmartIr/WM.svg +11 -0
  20. package/src/Images/SmartIr/index.js +7 -0
  21. package/src/commons/ActionGroup/LightActionTemplate.js +103 -0
  22. package/src/commons/ActionGroup/LightActionTemplateStyles.js +57 -0
  23. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/AutoLockStyles.js +40 -0
  24. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/ButtonWrapper.js +65 -0
  25. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/ButtonWrapperStyles.js +43 -0
  26. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +48 -0
  27. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/index.js +57 -0
  28. package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +48 -0
  29. package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLockStyle.js +51 -0
  30. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +48 -0
  31. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscodeStyles.js +42 -0
  32. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/PasscodeListStyles.js +49 -0
  33. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/index.js +66 -0
  34. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/ButtonWrapper.js +96 -0
  35. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/SetupGeneratePasscodeStyles.js +98 -0
  36. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +62 -0
  37. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/index.js +249 -0
  38. package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +33 -31
  39. package/src/commons/ActionGroup/OnOffTemplate/index.js +4 -2
  40. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +2 -1
  41. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +188 -186
  42. package/src/commons/ActionGroup/StatesGridActionTemplate.js +2 -1
  43. package/src/commons/ActionGroup/__test__/LightActionTemplate.test.js +59 -0
  44. package/src/commons/ActionGroup/index.js +6 -0
  45. package/src/commons/CardShadow/index.js +5 -2
  46. package/src/commons/CardShadow/styles.js +2 -3
  47. package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +16 -0
  48. package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +42 -0
  49. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +27 -0
  50. package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +18 -0
  51. package/src/commons/ConnectingProcess/index.js +205 -0
  52. package/src/commons/ConnectingProcess/styles.js +69 -0
  53. package/src/commons/Device/DisconnectedView.js +7 -1
  54. package/src/commons/Device/ItemDevice.js +8 -3
  55. package/src/commons/Device/LinearChart.js +3 -39
  56. package/src/commons/Device/__test__/DisconnectedView.test.js +13 -2
  57. package/src/commons/Form/TextInputPassword.js +1 -1
  58. package/src/commons/MediaPlayer/__test__/index.test.js +45 -0
  59. package/src/commons/RowItem/index.js +12 -7
  60. package/src/commons/SubUnit/ShortDetail.js +10 -22
  61. package/src/commons/SubUnit/__test__/ShortDetail.test.js +57 -48
  62. package/src/commons/WheelDateTimePicker/index.js +18 -4
  63. package/src/configs/API.js +4 -2
  64. package/src/configs/Colors.js +1 -0
  65. package/src/configs/Constants.js +39 -0
  66. package/src/configs/Images.js +2 -0
  67. package/src/context/actionType.ts +2 -0
  68. package/src/context/mockStore.ts +1 -0
  69. package/src/context/reducer.ts +10 -0
  70. package/src/hooks/Common/useBlockBackAndroid.js +3 -1
  71. package/src/iot/RemoteControl/Bluetooth.js +3 -3
  72. package/src/navigations/AddDeviceStack.js +10 -0
  73. package/src/navigations/SmartIrStack.js +31 -0
  74. package/src/navigations/SmartLockStack.js +51 -0
  75. package/src/navigations/UnitStack.js +12 -3
  76. package/src/screens/ActivityLog/hooks/index.js +18 -4
  77. package/src/screens/ActivityLog/index.js +3 -0
  78. package/src/screens/AddCommon/SelectSubUnit.js +30 -6
  79. package/src/screens/AddCommon/SelectUnit.js +24 -2
  80. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +120 -1
  81. package/src/screens/AddCommon/__test__/SelectUnit.test.js +16 -1
  82. package/src/screens/AddNewAction/SelectSensorDevices.js +4 -2
  83. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +97 -37
  84. package/src/screens/AddNewGateway/PlugAndPlay/FirstWarning.js +4 -2
  85. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +178 -35
  86. package/src/screens/AddNewGateway/PlugAndPlay/__test__/ConnectWifiWarning.test.js +58 -0
  87. package/src/screens/AddNewGateway/PlugAndPlay/__test__/GatewayWifiList.test.js +26 -2
  88. package/src/screens/AddNewGateway/SelectGateway.js +132 -0
  89. package/src/screens/AddNewGateway/SelectGatewayStyles.js +55 -0
  90. package/src/screens/AddNewOneTap/index.js +32 -17
  91. package/src/screens/Automate/index.js +2 -2
  92. package/src/screens/Device/EditDevice/index.js +5 -3
  93. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +13 -2
  94. package/src/screens/Device/components/SensorDisplayItem.js +3 -0
  95. package/src/screens/Device/detail.js +56 -16
  96. package/src/screens/Device/hooks/useDisconnectedDevice.js +21 -5
  97. package/src/screens/GuestInfo/components/AccessScheduleItem.js +9 -2
  98. package/src/screens/GuestInfo/components/RecurringDetail.js +3 -2
  99. package/src/screens/GuestInfo/components/TemporaryDetail.js +3 -2
  100. package/src/screens/GuestInfo/styles/AccessScheduleItemStyles.js +3 -0
  101. package/src/screens/Notification/__test__/NotificationItem.test.js +28 -5
  102. package/src/screens/Notification/components/NotificationItem.js +128 -20
  103. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +11 -7
  104. package/src/screens/ScanChipQR/hooks/index.js +89 -19
  105. package/src/screens/ScriptDetail/index.js +1 -6
  106. package/src/screens/SelectUnit/index.js +1 -0
  107. package/src/screens/SharedUnit/index.js +1 -1
  108. package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +54 -0
  109. package/src/screens/SmartIr/__test__/SelectBrand.test.js +74 -0
  110. package/src/screens/SmartIr/__test__/SelectDeviceType.test.js +64 -0
  111. package/src/screens/SmartIr/__test__/SmartIr.test.js +62 -0
  112. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +86 -0
  113. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByTypeStyles.js +76 -0
  114. package/src/screens/SmartIr/components/SelectBrand.js +61 -0
  115. package/src/screens/SmartIr/components/SelectBrandStyles.js +14 -0
  116. package/src/screens/SmartIr/components/SelectDeviceType.js +96 -0
  117. package/src/screens/SmartIr/components/SelectDeviceTypeStyles.js +30 -0
  118. package/src/screens/SmartIr/index.js +28 -0
  119. package/src/screens/SmartIr/styles.js +14 -0
  120. package/src/screens/Unit/AddMenu.js +4 -1
  121. package/src/screens/Unit/Detail.js +31 -5
  122. package/src/screens/Unit/components/MyUnitDevice/index.js +2 -4
  123. package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +38 -9
  124. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +32 -1
  125. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +1 -1
  126. package/src/utils/I18n/translations/en.json +40 -2
  127. package/src/utils/I18n/translations/vi.json +40 -3
  128. package/src/utils/Route/index.js +11 -0
@@ -26,6 +26,11 @@ const AddCommonSelectSubUnit = ({ route }) => {
26
26
  smart_account_id_from_backend,
27
27
  username,
28
28
  brand,
29
+ scan_sensor_data,
30
+ gateway,
31
+ devicePrefixName,
32
+ wifi_ssid,
33
+ wifi_pass,
29
34
  } = route.params;
30
35
  const [selectedIndex, setSelectedIndex] = useState(-1);
31
36
  const [unit, setUnit] = useState([]);
@@ -45,6 +50,10 @@ const AddCommonSelectSubUnit = ({ route }) => {
45
50
  case 'AddVconnexDevice':
46
51
  setTitle(t('select_a_sub_unit'));
47
52
  break;
53
+ case 'AddDeviceNewFlow':
54
+ setTitle(t('text_select_sub_unit'));
55
+ setSubTitle(t('select_a_sub_unit_want_add_device'));
56
+ break;
48
57
  default:
49
58
  setTitle(t('add_new_gateway'));
50
59
  setSubTitle(t('select_a_sub_unit'));
@@ -98,10 +107,22 @@ const AddCommonSelectSubUnit = ({ route }) => {
98
107
  SCConfig.VCONNEX_CLIENT_ID,
99
108
  SCConfig.VCONNEX_REDIRECT_URI_APP,
100
109
  unit.user_id,
110
+ unit_id,
101
111
  subUnits[selectedIndex]?.id
102
112
  ),
103
113
  });
104
114
  break;
115
+ case 'AddDeviceNewFlow':
116
+ navigation.navigate(Routes.ConnectingProcess, {
117
+ station: subUnits[selectedIndex],
118
+ unit: unit,
119
+ scan_sensor_data: scan_sensor_data,
120
+ gateway: gateway,
121
+ devicePrefixName: devicePrefixName,
122
+ wifi_ssid: wifi_ssid,
123
+ wifi_pass: wifi_pass,
124
+ });
125
+ break;
105
126
  default:
106
127
  break;
107
128
  }
@@ -110,8 +131,7 @@ const AddCommonSelectSubUnit = ({ route }) => {
110
131
  navigation,
111
132
  subUnits,
112
133
  selectedIndex,
113
- unit?.name,
114
- unit.user_id,
134
+ unit,
115
135
  route.params,
116
136
  nameSubUnit,
117
137
  sensor_data,
@@ -121,6 +141,11 @@ const AddCommonSelectSubUnit = ({ route }) => {
121
141
  smart_account_id_from_backend,
122
142
  username,
123
143
  brand,
144
+ scan_sensor_data,
145
+ gateway,
146
+ devicePrefixName,
147
+ wifi_ssid,
148
+ wifi_pass,
124
149
  ]);
125
150
 
126
151
  const handleSelectIndex = (index) => {
@@ -131,7 +156,6 @@ const AddCommonSelectSubUnit = ({ route }) => {
131
156
  setSelectedIndex(-1);
132
157
  }
133
158
  };
134
-
135
159
  const addSubUnit = useCallback(() => {
136
160
  navigation.navigate(Routes.AddSubUnitStack, {
137
161
  screen: Routes.AddSubUnit,
@@ -159,14 +183,14 @@ const AddCommonSelectSubUnit = ({ route }) => {
159
183
  >
160
184
  <RadioCircle
161
185
  active={selectedIndex === index}
162
- testID={TESTID.SELECT_UNIT_RADIO_BUTTON}
186
+ testID={TESTID.SELECT_SUBUNIT_RADIO_BUTTON}
163
187
  />
164
188
  <TouchableOpacity
165
189
  style={styles.row}
166
190
  onPress={() => handleSelectIndex(index)}
167
- testID={TESTID.SELECT_UNIT_SELECT}
191
+ testID={TESTID.SELECT_SUBUNIT_SELECT}
168
192
  >
169
- <Text style={styles.text} testID={TESTID.SELECT_UNIT_NAME}>
193
+ <Text style={styles.text} testID={TESTID.SELECT_SUBUNIT_NAME}>
170
194
  {item.name}
171
195
  </Text>
172
196
  </TouchableOpacity>
@@ -21,7 +21,7 @@ import { TESTID } from '../../configs/Constants';
21
21
  const AddCommonSelectUnit = ({ route }) => {
22
22
  const t = useTranslations();
23
23
  const navigation = useNavigation();
24
- const { addType } = route.params;
24
+ const { addType, scan_sensor_data } = route.params;
25
25
  const [selectedIndex, setSelectedIndex] = useState(-1);
26
26
  const [units, setUnits] = useState([]);
27
27
  const [title, setTitle] = useState('');
@@ -51,6 +51,10 @@ const AddCommonSelectUnit = ({ route }) => {
51
51
  case 'AddVconnexDevice':
52
52
  setTitle(t('text_select_a_unit'));
53
53
  break;
54
+ case 'AddDeviceNewFlow':
55
+ setTitle(t('text_select_a_unit'));
56
+ setSubTitle(t('text_select_a_unit_have_device'));
57
+ break;
54
58
  default:
55
59
  setTitle(t('add_new_sub_unit'));
56
60
  setSubTitle(t('add_new_subunit_select_unit'));
@@ -114,10 +118,28 @@ const AddCommonSelectUnit = ({ route }) => {
114
118
  },
115
119
  });
116
120
  break;
121
+ case 'AddDeviceNewFlow':
122
+ navigation.navigate(Routes.AddGatewaySelectGateway, {
123
+ unit_id: units[selectedIndex].id,
124
+ addType: 'AddDeviceNewFlow',
125
+ scan_sensor_data,
126
+ });
127
+ break;
117
128
  default:
118
129
  break;
119
130
  }
120
- }, [addType, navigation, units, selectedIndex, route.params]);
131
+ }, [
132
+ addType,
133
+ navigation,
134
+ units,
135
+ selectedIndex,
136
+ route.params.code,
137
+ route.params.backend_url,
138
+ route.params.username,
139
+ route.params.password,
140
+ route.params.brand,
141
+ scan_sensor_data,
142
+ ]);
121
143
 
122
144
  const handleSelectIndex = (index) => {
123
145
  if (index !== selectedIndex) {
@@ -1,10 +1,13 @@
1
1
  import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
-
3
+ import { TouchableOpacity } from 'react-native';
4
4
  import AddCommonSelectSubUnit from '../SelectSubUnit';
5
5
  import { ViewButtonBottom } from '../../../commons';
6
6
  import { SCProvider } from '../../../context';
7
7
  import { mockSCStore } from '../../../context/mockStore';
8
+ import Text from '../../../commons/Text';
9
+ import axios from 'axios';
10
+ import { TESTID } from '../../../configs/Constants';
8
11
 
9
12
  jest.mock('axios');
10
13
 
@@ -59,3 +62,119 @@ describe('Test SelectSubUnit', () => {
59
62
  expect(mockedNavigate).toHaveBeenCalled();
60
63
  });
61
64
  });
65
+ describe('Test SelectSubUnit container', () => {
66
+ beforeEach(() => {
67
+ mockedNavigate.mockClear();
68
+ mockedGoBack.mockClear();
69
+ });
70
+ let tree;
71
+ const list_type = [
72
+ 'AddNewGateway',
73
+ 'AddHassiDevice',
74
+ 'AddVconnexDevice',
75
+ 'AddDeviceNewFlow',
76
+ ];
77
+ const result = [
78
+ 'Select a sub-unit that you want to add this gateway',
79
+ '',
80
+ '',
81
+ 'Then, select a sub-unit that you want to add this device in',
82
+ ];
83
+
84
+ list_type.forEach(function (type, i) {
85
+ test(`create SelectSubUnit ${type} container`, () => {
86
+ const route = { params: { addType: type } };
87
+ act(() => {
88
+ tree = renderer.create(wrapComponent(route));
89
+ });
90
+ const instance = tree.root;
91
+ const button = instance.findAllByType(TouchableOpacity);
92
+ expect(button.length).toBe(3);
93
+ const button1 = instance.findAllByType(Text);
94
+ expect(button1[1].props.children).toEqual(result[i]);
95
+ });
96
+ test(`press next to navigate ${type}`, async () => {
97
+ const route = { params: { addType: type } };
98
+ const response = {
99
+ status: 200,
100
+ success: true,
101
+ data: [
102
+ { id: 1, name: 'Unit 1' },
103
+ { id: 2, name: 'Unit 2' },
104
+ ],
105
+ };
106
+
107
+ axios.get.mockImplementation(async () => {
108
+ return response;
109
+ });
110
+
111
+ await act(async () => {
112
+ tree = renderer.create(wrapComponent(route));
113
+ });
114
+
115
+ const instance = tree.root;
116
+ const selectSubUnit = instance.findAllByType(TouchableOpacity);
117
+ await act(async () => {
118
+ selectSubUnit[1].props.onPress();
119
+ });
120
+
121
+ const next = instance.find(
122
+ (item) =>
123
+ item.props.testID ===
124
+ `${TESTID.PREFIX.SELECT_UNIT}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
125
+ );
126
+
127
+ await act(async () => {
128
+ next.props.onPress();
129
+ });
130
+
131
+ switch (type) {
132
+ case 'AddNewGateway':
133
+ expect(mockedNavigate).toBeCalledWith('ScanChipQR', {
134
+ addType: 'AddNewGateway',
135
+ station: undefined,
136
+ });
137
+ break;
138
+ case 'AddHassiDevice':
139
+ expect(mockedNavigate).toBeCalledWith('SmartAccountConnecting', {
140
+ unit_id: undefined,
141
+ brand: undefined,
142
+ listSelectDevice: undefined,
143
+ listSensorIds: undefined,
144
+ nameSubUnit: '',
145
+ sensor_data: undefined,
146
+ smart_account_id: undefined,
147
+ smart_account_id_from_backend: undefined,
148
+ station: undefined,
149
+ username: undefined,
150
+ });
151
+ break;
152
+ case 'AddVconnexDevice':
153
+ expect(mockedNavigate).toBeCalledWith('Browser', {
154
+ // eslint-disable-next-line max-len
155
+ link: 'https://partner-api.vconnex.vn/oauth/authorize?client_id=&redirect_uri=&response_type=code&scope=SYNCH&scope=CONTROL&scope=QUERY&state=undefined@undefined@undefined',
156
+ });
157
+ break;
158
+ case 'AddDeviceNewFlow':
159
+ expect(mockedNavigate).toBeCalledWith('ConnectingProcess', {
160
+ gateway: undefined,
161
+ scan_sensor_data: undefined,
162
+ station: undefined,
163
+ unit: [
164
+ {
165
+ id: 1,
166
+ name: 'Unit 1',
167
+ },
168
+ {
169
+ id: 2,
170
+ name: 'Unit 2',
171
+ },
172
+ ],
173
+ });
174
+ break;
175
+ default:
176
+ break;
177
+ }
178
+ });
179
+ });
180
+ });
@@ -35,13 +35,21 @@ describe('Test SelectUnit container', () => {
35
35
  mockedGoBack.mockClear();
36
36
  });
37
37
  let tree;
38
- const list_type = ['AddSubUnit', 'AddDevice', 'AddMember', 'AddLGDevice', ''];
38
+ const list_type = [
39
+ 'AddSubUnit',
40
+ 'AddDevice',
41
+ 'AddMember',
42
+ 'AddLGDevice',
43
+ '',
44
+ 'AddDeviceNewFlow',
45
+ ];
39
46
  const result = [
40
47
  'Add new sub-unit',
41
48
  'Add new device',
42
49
  'Select a unit',
43
50
  'Select a unit',
44
51
  'Add new sub-unit',
52
+ 'Select a unit',
45
53
  ];
46
54
  list_type.forEach(function (type, i) {
47
55
  test(`create SelectUnit ${type} container`, () => {
@@ -126,6 +134,13 @@ describe('Test SelectUnit container', () => {
126
134
  unit_id: 1,
127
135
  });
128
136
  break;
137
+ case 'AddDeviceNewFlow':
138
+ expect(mockedNavigate).toBeCalledWith('AddGatewaySelectGateway', {
139
+ unit_id: 1,
140
+ addType: 'AddDeviceNewFlow',
141
+ scan_sensor_data: undefined,
142
+ });
143
+ break;
129
144
  default:
130
145
  break;
131
146
  }
@@ -175,7 +175,7 @@ const SelectSensorDevices = memo(({ route }) => {
175
175
  {t(title)}
176
176
  </Text>
177
177
 
178
- {!!listStation.length > 0 ? (
178
+ {listStation ? (
179
179
  <NavBar
180
180
  listStation={listStation}
181
181
  listMenuItem={listMenuItem}
@@ -185,7 +185,9 @@ const SelectSensorDevices = memo(({ route }) => {
185
185
  />
186
186
  ) : (
187
187
  <View style={styles.noneData}>
188
- <Text center>{t('text_sub_unit_not_have_device')}</Text>
188
+ <Text center>
189
+ {t('you_do_not_have_the_device_or_have_share_control_device')}
190
+ </Text>
189
191
  </View>
190
192
  )}
191
193
 
@@ -1,4 +1,10 @@
1
- import React, { memo, useEffect, useState, useCallback } from 'react';
1
+ import React, {
2
+ memo,
3
+ useEffect,
4
+ useState,
5
+ useCallback,
6
+ useContext,
7
+ } from 'react';
2
8
  import {
3
9
  View,
4
10
  StyleSheet,
@@ -16,15 +22,28 @@ import ScanQrGateway from '../../../../assets/images/scan-qr-gateway.svg';
16
22
  import { useTranslations } from '../../../hooks/Common/useTranslations';
17
23
  import { getBottomSpace } from 'react-native-iphone-x-helper';
18
24
  import BottomButtonView from '../../../commons/BottomButtonView';
19
- import { Colors, API } from '../../../configs';
20
- import { axiosPost } from '../../../utils/Apis/axios';
25
+ import { Colors } from '../../../configs';
21
26
  import Routes from '../../../utils/Route';
27
+ import { SCContext } from '../../../context';
28
+ import { Action } from '../../../context/actionType';
29
+
30
+ const isIos = Platform.OS === 'ios';
31
+ const isAndroid = Platform.OS === 'android';
22
32
 
23
33
  const ConnectWifiWarning = memo(({ route }) => {
24
- const { wifi_ssid, wifi_pass, unit_id, chip_id } = route.params;
34
+ const {
35
+ wifi_ssid,
36
+ wifi_pass,
37
+ unit_id,
38
+ chip_id,
39
+ devicePrefixName,
40
+ body,
41
+ unit_name,
42
+ } = route.params;
25
43
  const t = useTranslations();
26
44
  const { navigate, goBack } = useNavigation();
27
45
  const [isLoading, setIsLoading] = useState(false);
46
+ const { setAction } = useContext(SCContext);
28
47
 
29
48
  const getPermissionWifiAndroid = useCallback(async () => {
30
49
  const granted = await PermissionsAndroid.request(
@@ -44,57 +63,98 @@ const ConnectWifiWarning = memo(({ route }) => {
44
63
  }, [t]);
45
64
 
46
65
  useEffect(() => {
47
- Platform.OS === 'android' && getPermissionWifiAndroid();
66
+ isAndroid && getPermissionWifiAndroid();
48
67
  }, [getPermissionWifiAndroid]);
49
68
 
50
- const handleSend = () => {
69
+ const handleSend = async () => {
51
70
  const socket = dgram.createSocket({ type: 'udp4' });
52
- socket.bind(54321);
53
- socket.once('listening', function () {
54
- socket.send(
55
- JSON.stringify({ type: 'scan', data: { wifi: '' } }),
56
- undefined,
57
- undefined,
58
- 54321,
59
- '192.168.27.1',
60
- undefined
61
- );
62
- });
63
- socket.on('message', (msg, rinfo) => {
71
+ await socket.bind(54321);
72
+ let intervalSend = null;
73
+ if (isIos) {
74
+ intervalSend = setInterval(() => {
75
+ socket.send(
76
+ JSON.stringify({ type: 'scan', data: { wifi: '' } }),
77
+ undefined,
78
+ undefined,
79
+ 54321,
80
+ '192.168.27.1',
81
+ undefined
82
+ );
83
+ }, 1000);
84
+ } else {
85
+ await socket.once('listening', async () => {
86
+ await socket.send(
87
+ JSON.stringify({ type: 'scan', data: { wifi: '' } }),
88
+ undefined,
89
+ undefined,
90
+ 54321,
91
+ '192.168.27.1',
92
+ undefined
93
+ );
94
+ });
95
+ }
96
+
97
+ await socket.on('message', (msg, rinfo) => {
98
+ isIos && clearInterval(intervalSend);
64
99
  const data = JSON.parse(msg.toString());
65
100
  if (data.hasOwnProperty('wifi')) {
66
101
  navigate(Routes.GatewayWifiList, {
67
102
  list_wifi: data.wifi,
68
103
  unit_id: unit_id,
69
104
  chip_id: chip_id,
105
+ scan_sensor_data: { ...body },
106
+ wifi_ssid: wifi_ssid,
107
+ wifi_pass: wifi_pass,
108
+ unit_name: unit_name,
109
+ devicePrefixName: devicePrefixName,
70
110
  socket: socket,
71
111
  });
72
112
  }
73
- if (data.hasOwnProperty('gateway')) {
74
- const checkWifiInterval = setInterval(() => {
75
- // eslint-disable-next-line promise/prefer-await-to-then
76
- WifiManager.getCurrentWifiSSID().then(async (ssid) => {
77
- if (ssid !== wifi_ssid) {
78
- const { success } = await axiosPost(
79
- API.UNIT.ADD_GATEWAY(unit_id),
80
- {
81
- chip: chip_id,
82
- imei: data.gateway.imei,
83
- chip_name: data.gateway.model,
113
+ if (isIos) {
114
+ if (data.hasOwnProperty('gateway')) {
115
+ const checkWifiInterval = setInterval(() => {
116
+ WifiManager.getCurrentWifiSSID().then((ssid) => {
117
+ if (ssid !== wifi_ssid) {
118
+ const IsRobot = devicePrefixName === 'ROBOT';
119
+ if (IsRobot) {
120
+ setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
121
+ navigate(Routes.AddDeviceStack, {
122
+ screen: Routes.AddCommonSelectSubUnit,
123
+ params: {
124
+ scan_sensor_data: { ...body },
125
+ addType: 'AddDeviceNewFlow',
126
+ gateway: data?.gateway,
127
+ unit_id: unit_id,
128
+ devicePrefixName: devicePrefixName,
129
+ wifi_ssid: wifi_ssid,
130
+ wifi_pass: wifi_pass,
131
+ },
132
+ });
133
+ clearInterval(checkWifiInterval);
134
+ } else {
135
+ setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
136
+ navigate(Routes.AddDeviceStack, {
137
+ screen: Routes.ConnectingProcess,
138
+ params: {
139
+ unit_id: unit_id,
140
+ unit_name: unit_name,
141
+ scan_sensor_data: { ...body },
142
+ gateway: data?.gateway,
143
+ devicePrefixName: devicePrefixName,
144
+ chip_id: chip_id,
145
+ },
146
+ });
147
+ clearInterval(checkWifiInterval);
84
148
  }
85
- );
86
- if (success) {
87
- navigate(Routes.Dashboard);
88
- ToastBottomHelper.success(t('add_gateway_success'));
89
- clearInterval(checkWifiInterval);
90
149
  }
91
- }
92
- });
93
- }, 3000);
150
+ });
151
+ }, 3000);
152
+ }
94
153
  }
95
154
  });
96
155
  socket.on('error', () => {
97
156
  ToastBottomHelper.error(t('server_error'));
157
+ setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
98
158
  goBack();
99
159
  });
100
160
  };
@@ -9,15 +9,17 @@ import { ViewButtonBottom } from '../../../commons';
9
9
  import { Colors } from '../../../configs';
10
10
 
11
11
  const FirstWarning = memo(({ route }) => {
12
- const { unit_id } = route.params;
12
+ const { unit_id, unit_name } = route.params;
13
13
  const t = useTranslations();
14
14
  const { goBack, navigate } = useNavigation();
15
15
 
16
16
  const onRight = useCallback(() => {
17
17
  navigate(Routes.ScanChipQR, {
18
18
  unit_id: unit_id,
19
+ unit_name: unit_name,
20
+ isNewFlow: true,
19
21
  });
20
- }, [navigate, unit_id]);
22
+ }, [navigate, unit_name, unit_id]);
21
23
 
22
24
  return (
23
25
  <View style={styles.screen}>