@eohjsc/react-native-smart-city 0.2.82 → 0.2.85

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 (99) hide show
  1. package/assets/images/Event.svg +9 -0
  2. package/assets/images/brightness.svg +12 -0
  3. package/package.json +4 -2
  4. package/src/Images/Common/SuccessfullyConnected.svg +4 -0
  5. package/src/Images/Common/eye-closed.png +0 -0
  6. package/src/Images/Common/eye-closed@2x.png +0 -0
  7. package/src/Images/Common/eye-closed@3x.png +0 -0
  8. package/src/Images/Common/eye.png +0 -0
  9. package/src/Images/Common/eye@2x.png +0 -0
  10. package/src/Images/Common/eye@3x.png +0 -0
  11. package/src/commons/ActionGroup/CurtainButtonTemplate.js +32 -21
  12. package/src/commons/ActionGroup/LightActionTemplate.js +103 -0
  13. package/src/commons/ActionGroup/LightActionTemplateStyles.js +57 -0
  14. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +8 -6
  15. package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +33 -31
  16. package/src/commons/ActionGroup/OnOffTemplate/index.js +11 -3
  17. package/src/commons/ActionGroup/OneBigButtonTemplate.js +10 -7
  18. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +5 -2
  19. package/src/commons/ActionGroup/StatesGridActionTemplate.js +7 -3
  20. package/src/commons/ActionGroup/ThreeButtonTemplate.js +33 -24
  21. package/src/commons/ActionGroup/__test__/LightActionTemplate.test.js +59 -0
  22. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +18 -6
  23. package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +9 -1
  24. package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +25 -13
  25. package/src/commons/ActionGroup/__test__/index.test.js +48 -14
  26. package/src/commons/ActionGroup/index.js +3 -0
  27. package/src/commons/Automate/ItemAutomate.js +1 -1
  28. package/src/commons/Automate/ItemAutomateStyles.js +5 -1
  29. package/src/commons/CardShadow/index.js +5 -2
  30. package/src/commons/CardShadow/styles.js +2 -3
  31. package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +16 -0
  32. package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +42 -0
  33. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +27 -0
  34. package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +18 -0
  35. package/src/commons/ConnectingProcess/index.js +202 -0
  36. package/src/commons/ConnectingProcess/styles.js +69 -0
  37. package/src/commons/Device/HorizontalBarChart.js +7 -1
  38. package/src/commons/Device/ItemDevice.js +8 -5
  39. package/src/commons/Device/LinearChart.js +1 -0
  40. package/src/commons/Device/WaterQualitySensor/ListQualityIndicator.js +1 -1
  41. package/src/commons/Device/WaterQualitySensor/QualityIndicatorsItem.js +1 -1
  42. package/src/commons/EmergencyButton/AlertSendConfirm.js +2 -2
  43. package/src/commons/EmergencyButton/AlertSent.js +2 -2
  44. package/src/commons/Form/TextInputPassword.js +1 -1
  45. package/src/commons/FullLoading/index.js +35 -0
  46. package/src/commons/SubUnit/Favorites/index.js +2 -0
  47. package/src/commons/SubUnit/OneTap/ItemOneTap.js +3 -0
  48. package/src/commons/SubUnit/ShortDetail.js +7 -1
  49. package/src/commons/index.js +2 -0
  50. package/src/configs/API.js +6 -4
  51. package/src/configs/Constants.js +25 -0
  52. package/src/configs/Images.js +2 -0
  53. package/src/context/actionType.ts +2 -0
  54. package/src/context/reducer.ts +10 -0
  55. package/src/hooks/Common/useBlockBackAndroid.js +3 -1
  56. package/src/iot/RemoteControl/Internet.js +8 -1
  57. package/src/iot/RemoteControl/index.js +4 -2
  58. package/src/navigations/AddDeviceStack.js +10 -0
  59. package/src/screens/AddCommon/SelectSubUnit.js +29 -6
  60. package/src/screens/AddCommon/SelectUnit.js +24 -2
  61. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +120 -1
  62. package/src/screens/AddCommon/__test__/SelectUnit.test.js +16 -1
  63. package/src/screens/AddNewAction/SelectAction.js +46 -28
  64. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +3 -3
  65. package/src/screens/AddNewAutoSmart/index.js +18 -1
  66. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +55 -16
  67. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +52 -23
  68. package/src/screens/AddNewGateway/SelectGateway.js +132 -0
  69. package/src/screens/AddNewGateway/SelectGatewayStyles.js +55 -0
  70. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -52
  71. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +2 -2
  72. package/src/screens/Device/EditDevice/index.js +2 -2
  73. package/src/screens/Device/__test__/detail.test.js +18 -11
  74. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +2 -2
  75. package/src/screens/Device/components/SensorDisplayItem.js +2 -2
  76. package/src/screens/Device/detail.js +64 -26
  77. package/src/screens/Device/styles.js +2 -0
  78. package/src/screens/Notification/__test__/NotificationItem.test.js +197 -15
  79. package/src/screens/Notification/components/NotificationItem.js +188 -14
  80. package/src/screens/Notification/styles/NotificationItemStyles.js +3 -3
  81. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +10 -7
  82. package/src/screens/ScanChipQR/hooks/index.js +48 -40
  83. package/src/screens/SubUnit/AddSubUnit.js +4 -1
  84. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +148 -0
  85. package/src/screens/Unit/Detail.js +33 -1
  86. package/src/screens/Unit/ManageUnit.js +1 -1
  87. package/src/screens/Unit/ManageUnitStyles.js +0 -6
  88. package/src/screens/Unit/SmartAccount.js +5 -1
  89. package/src/screens/Unit/Summaries.js +2 -2
  90. package/src/screens/Unit/__test__/CheckSendEmail.test.js +10 -0
  91. package/src/screens/Unit/__test__/Detail.test.js +10 -0
  92. package/src/screens/Unit/components/__test__/SharedUnit.test.js +21 -2
  93. package/src/screens/UnitSummary/__test__/index.test.js +3 -3
  94. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +2 -2
  95. package/src/screens/UnitSummary/index.js +52 -9
  96. package/src/utils/Apis/axios.js +1 -1
  97. package/src/utils/I18n/translations/en.json +16 -0
  98. package/src/utils/I18n/translations/vi.json +16 -1
  99. package/src/utils/Route/index.js +2 -0
@@ -4,7 +4,13 @@ import { ToastBottomHelper } from '../../utils/Utils';
4
4
  import { axiosPost } from '../../utils/Apis/axios';
5
5
  import { API } from '../../configs';
6
6
 
7
- export const sendCommandOverInternet = async (sensor, action, data, source) => {
7
+ export const sendCommandOverInternet = async (
8
+ sensor,
9
+ action,
10
+ data,
11
+ source,
12
+ actionName
13
+ ) => {
8
14
  if (data !== null) {
9
15
  if (Number.isInteger(data)) {
10
16
  data = data.toString(16).toUpperCase();
@@ -15,6 +21,7 @@ export const sendCommandOverInternet = async (sensor, action, data, source) => {
15
21
  key: action.key,
16
22
  data,
17
23
  source,
24
+ action_name: actionName,
18
25
  });
19
26
  if (success) {
20
27
  ToastBottomHelper.success(t('Command is sent to device via internet'));
@@ -12,7 +12,8 @@ export const sendRemoteCommand = async (
12
12
  sensor,
13
13
  action,
14
14
  data,
15
- userId = null
15
+ userId = null,
16
+ actionName
16
17
  ) => {
17
18
  // No action, raise not authorized
18
19
  let result = false;
@@ -31,7 +32,8 @@ export const sendRemoteCommand = async (
31
32
  sensor,
32
33
  action,
33
34
  data,
34
- 'bluetooth'
35
+ 'bluetooth',
36
+ actionName
35
37
  );
36
38
  } else {
37
39
  throw err;
@@ -3,9 +3,11 @@ import React, { memo } from 'react';
3
3
 
4
4
  import AddCommonSelectUnit from '../screens/AddCommon/SelectUnit';
5
5
  import AddCommonSelectSubUnit from '../screens/AddCommon/SelectSubUnit';
6
+ import AddGatewaySelectGateway from '../screens/AddNewGateway/SelectGateway';
6
7
  import AddNewDevice from '../screens/AddNewDevice';
7
8
  import ConnectDevices from '../screens/AddNewDevice/ConnectDevices';
8
9
  import ConnectingDevices from '../screens/AddNewDevice/ConnectingDevices';
10
+ import ConnectingProcess from '../commons/ConnectingProcess';
9
11
  import ScanSensorQR from '../screens/ScanSensorQR';
10
12
  import Route from '../utils/Route';
11
13
  import { screenOptions } from './utils';
@@ -28,6 +30,14 @@ export const AddDeviceStack = memo(() => {
28
30
  name={Route.AddCommonSelectSubUnit}
29
31
  component={AddCommonSelectSubUnit}
30
32
  />
33
+ <Stack.Screen
34
+ name={Route.AddGatewaySelectGateway}
35
+ component={AddGatewaySelectGateway}
36
+ />
37
+ <Stack.Screen
38
+ name={Route.ConnectingProcess}
39
+ component={ConnectingProcess}
40
+ />
31
41
  <Stack.Screen name={Route.AddNewDevice} component={AddNewDevice} />
32
42
  <Stack.Screen name={Route.ScanSensorQR} component={ScanSensorQR} />
33
43
  <Stack.Screen
@@ -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'));
@@ -102,6 +111,17 @@ const AddCommonSelectSubUnit = ({ route }) => {
102
111
  ),
103
112
  });
104
113
  break;
114
+ case 'AddDeviceNewFlow':
115
+ navigation.navigate(Routes.ConnectingProcess, {
116
+ station: subUnits[selectedIndex],
117
+ unit: unit,
118
+ scan_sensor_data: scan_sensor_data,
119
+ gateway: gateway,
120
+ devicePrefixName: devicePrefixName,
121
+ wifi_ssid: wifi_ssid,
122
+ wifi_pass: wifi_pass,
123
+ });
124
+ break;
105
125
  default:
106
126
  break;
107
127
  }
@@ -110,8 +130,7 @@ const AddCommonSelectSubUnit = ({ route }) => {
110
130
  navigation,
111
131
  subUnits,
112
132
  selectedIndex,
113
- unit?.name,
114
- unit.user_id,
133
+ unit,
115
134
  route.params,
116
135
  nameSubUnit,
117
136
  sensor_data,
@@ -121,6 +140,11 @@ const AddCommonSelectSubUnit = ({ route }) => {
121
140
  smart_account_id_from_backend,
122
141
  username,
123
142
  brand,
143
+ scan_sensor_data,
144
+ gateway,
145
+ devicePrefixName,
146
+ wifi_ssid,
147
+ wifi_pass,
124
148
  ]);
125
149
 
126
150
  const handleSelectIndex = (index) => {
@@ -131,7 +155,6 @@ const AddCommonSelectSubUnit = ({ route }) => {
131
155
  setSelectedIndex(-1);
132
156
  }
133
157
  };
134
-
135
158
  const addSubUnit = useCallback(() => {
136
159
  navigation.navigate(Routes.AddSubUnitStack, {
137
160
  screen: Routes.AddSubUnit,
@@ -159,14 +182,14 @@ const AddCommonSelectSubUnit = ({ route }) => {
159
182
  >
160
183
  <RadioCircle
161
184
  active={selectedIndex === index}
162
- testID={TESTID.SELECT_UNIT_RADIO_BUTTON}
185
+ testID={TESTID.SELECT_SUBUNIT_RADIO_BUTTON}
163
186
  />
164
187
  <TouchableOpacity
165
188
  style={styles.row}
166
189
  onPress={() => handleSelectIndex(index)}
167
- testID={TESTID.SELECT_UNIT_SELECT}
190
+ testID={TESTID.SELECT_SUBUNIT_SELECT}
168
191
  >
169
- <Text style={styles.text} testID={TESTID.SELECT_UNIT_NAME}>
192
+ <Text style={styles.text} testID={TESTID.SELECT_SUBUNIT_NAME}>
170
193
  {item.name}
171
194
  </Text>
172
195
  </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-stg.vconnex.vn/oauth/authorize?client_id=&redirect_uri=&response_type=code&scope=SYNCH&scope=CONTROL&scope=QUERY&state=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
  }
@@ -148,38 +148,56 @@ const SelectAction = memo(({ route }) => {
148
148
  checkedItem,
149
149
  t,
150
150
  ]);
151
-
152
151
  const onSave = useCallback(async () => {
153
152
  if (isSelectSensor) {
154
153
  await checkConditionToContinue();
155
154
  } else {
156
- let list_action = [...actions];
157
- list_action = list_action.map((item) => ({
158
- action: item.action,
159
- data: item.data,
160
- }));
161
- const { success } = await axiosPost(
162
- API.AUTOMATE.ADD_SCRIPT_ACTION(automateId),
163
- {
164
- list_action,
165
- unit: unit.id,
155
+ if (automateId) {
156
+ let list_action = [...actions];
157
+ list_action = list_action.map((item) => ({
158
+ action: item.action,
159
+ data: item.data,
160
+ }));
161
+ const { success } = await axiosPost(
162
+ API.AUTOMATE.ADD_SCRIPT_ACTION(automateId),
163
+ {
164
+ list_action,
165
+ unit: unit.id,
166
+ }
167
+ );
168
+ if (!success) {
169
+ ToastBottomHelper.error(t('not_permission'));
166
170
  }
167
- );
168
- if (!success) {
169
- ToastBottomHelper.error(t('not_permission'));
171
+ navigate(Routes.ScriptDetail, {
172
+ id: automateId,
173
+ name: scriptName,
174
+ havePermission: true,
175
+ unit,
176
+ saveAt: moment().valueOf(),
177
+ type: type,
178
+ isAutomateTab,
179
+ isCreateNewAction,
180
+ isMultiUnits,
181
+ automate,
182
+ });
183
+ } else {
184
+ navigate(Routes.AddNewOneTap, {
185
+ automateData: {
186
+ action: actions[0].action,
187
+ },
188
+ type,
189
+ unit,
190
+ isAutomateTab,
191
+ isSelectSensor,
192
+ isMultiUnits,
193
+ automateId,
194
+ automate: {
195
+ ...automate,
196
+ action: actions[0].action,
197
+ },
198
+ scriptName,
199
+ });
170
200
  }
171
- navigate(Routes.ScriptDetail, {
172
- id: automateId,
173
- name: scriptName,
174
- havePermission: true,
175
- unit,
176
- saveAt: moment().valueOf(),
177
- type: type,
178
- isAutomateTab,
179
- isCreateNewAction,
180
- isMultiUnits,
181
- automate,
182
- });
183
201
  }
184
202
  // eslint-disable-next-line react-hooks/exhaustive-deps
185
203
  }, [
@@ -284,14 +302,14 @@ const SelectAction = memo(({ route }) => {
284
302
  () => (
285
303
  <BottomButtonView
286
304
  style={styles.bottomButtonView}
287
- mainTitle={t(isSelectSensor ? 'continue' : 'save')}
305
+ mainTitle={t(automateId ? 'save' : 'continue')}
288
306
  onPressMain={onSave}
289
307
  typeMain={
290
308
  actions.length > 0 || !!checkedItem?.id ? 'primary' : 'disabled'
291
309
  }
292
310
  />
293
311
  ),
294
- [onSave, actions, checkedItem, isSelectSensor, t]
312
+ [t, automateId, onSave, actions.length, checkedItem?.id]
295
313
  );
296
314
 
297
315
  useEffect(() => {
@@ -3,7 +3,7 @@ import { act, create } from 'react-test-renderer';
3
3
  import AddNewAutoSmart from '..';
4
4
  import { SCProvider } from '../../../context';
5
5
  import { mockSCStore } from '../../../context/mockStore';
6
- import { TESTID } from '../../../configs/Constants';
6
+ import { AUTOMATE_TYPE, TESTID } from '../../../configs/Constants';
7
7
  import ItemAutomate from '../../../commons/Automate/ItemAutomate';
8
8
  import Routes from '../../../utils/Route';
9
9
 
@@ -34,7 +34,7 @@ describe('test AddNewAutoSmart', () => {
34
34
  let tree;
35
35
  let route = {
36
36
  params: {
37
- type: 'value_change',
37
+ type: AUTOMATE_TYPE.VALUE_CHANGE,
38
38
  unit: { id: 1 },
39
39
  },
40
40
  };
@@ -49,7 +49,7 @@ describe('test AddNewAutoSmart', () => {
49
49
  });
50
50
  const instance = tree.root;
51
51
  const items = instance.findAllByType(ItemAutomate);
52
- expect(items).toHaveLength(2);
52
+ expect(items).toHaveLength(3);
53
53
 
54
54
  await act(async () => {
55
55
  await items[0].props.onPress();
@@ -42,6 +42,13 @@ const AddNewAutoSmart = memo(({ route }) => {
42
42
  type: AUTOMATE_TYPE.SCHEDULE,
43
43
  route: Routes.SetSchedule,
44
44
  },
45
+ {
46
+ type: AUTOMATE_TYPE.EVENT,
47
+ route: Routes.SelectSensorDevices,
48
+ data: {
49
+ title: AUTOMATE_SELECT.SELECT_DEVICE,
50
+ },
51
+ },
45
52
  ],
46
53
  [AUTOMATE_TYPE.VALUE_CHANGE]: [
47
54
  {
@@ -55,6 +62,13 @@ const AddNewAutoSmart = memo(({ route }) => {
55
62
  type: AUTOMATE_TYPE.SCHEDULE,
56
63
  route: Routes.SetSchedule,
57
64
  },
65
+ {
66
+ type: AUTOMATE_TYPE.EVENT,
67
+ route: Routes.SelectSensorDevices,
68
+ data: {
69
+ title: AUTOMATE_SELECT.SELECT_DEVICE,
70
+ },
71
+ },
58
72
  ],
59
73
  [AUTOMATE_TYPE.ONE_TAP_ONLY]: [
60
74
  {
@@ -84,7 +98,10 @@ const AddNewAutoSmart = memo(({ route }) => {
84
98
  scriptName,
85
99
  };
86
100
 
87
- if (dataAutomate.type === AUTOMATE_TYPE.VALUE_CHANGE && isMultiUnits) {
101
+ if (
102
+ (dataAutomate.type === AUTOMATE_TYPE.VALUE_CHANGE && isMultiUnits) ||
103
+ (dataAutomate.type === AUTOMATE_TYPE.EVENT && isMultiUnits)
104
+ ) {
88
105
  navigate(Routes.SelectUnit, params);
89
106
  } else {
90
107
  navigate(dataAutomate.route, params);
@@ -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,18 @@ 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';
22
29
 
23
30
  const ConnectWifiWarning = memo(({ route }) => {
24
- const { wifi_ssid, wifi_pass, unit_id, chip_id } = route.params;
31
+ const { wifi_ssid, wifi_pass, unit_id, chip_id, devicePrefixName, body } =
32
+ route.params;
25
33
  const t = useTranslations();
26
34
  const { navigate, goBack } = useNavigation();
27
35
  const [isLoading, setIsLoading] = useState(false);
36
+ const { setAction } = useContext(SCContext);
28
37
 
29
38
  const getPermissionWifiAndroid = useCallback(async () => {
30
39
  const granted = await PermissionsAndroid.request(
@@ -60,7 +69,7 @@ const ConnectWifiWarning = memo(({ route }) => {
60
69
  undefined
61
70
  );
62
71
  });
63
- socket.on('message', function (msg, rinfo) {
72
+ socket.on('message', (msg, rinfo) => {
64
73
  const data = JSON.parse(msg.toString());
65
74
  if (data.hasOwnProperty('wifi')) {
66
75
  navigate(Routes.GatewayWifiList, {
@@ -70,28 +79,58 @@ const ConnectWifiWarning = memo(({ route }) => {
70
79
  socket: socket,
71
80
  });
72
81
  }
82
+ });
83
+ socket.on('message', (msg, rinfo) => {
84
+ const data = JSON.parse(msg.toString());
73
85
  if (data.hasOwnProperty('gateway')) {
74
- navigate(Routes.Dashboard);
75
- ToastBottomHelper.success(t('completed'));
86
+ const checkWifiInterval = setInterval(() => {
87
+ // eslint-disable-next-line promise/prefer-await-to-then
88
+ WifiManager.getCurrentWifiSSID().then(async (ssid) => {
89
+ if (ssid !== wifi_ssid) {
90
+ const IsRobot = devicePrefixName === 'ROBOT';
91
+ if (IsRobot) {
92
+ setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
93
+ navigate(Routes.AddDeviceStack, {
94
+ screen: Routes.AddCommonSelectSubUnit,
95
+ params: {
96
+ scan_sensor_data: { ...body },
97
+ addType: 'AddDeviceNewFlow',
98
+ gateway: data?.gateway,
99
+ unit_id: unit_id,
100
+ devicePrefixName: devicePrefixName,
101
+ wifi_ssid: wifi_ssid,
102
+ wifi_pass: wifi_pass,
103
+ },
104
+ });
105
+ clearInterval(checkWifiInterval);
106
+ } else {
107
+ setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
108
+ navigate(Routes.AddDeviceStack, {
109
+ screen: Routes.ConnectingProcess,
110
+ params: {
111
+ unit_id: unit_id,
112
+ scan_sensor_data: { ...body },
113
+ gateway: data?.gateway,
114
+ devicePrefixName: devicePrefixName,
115
+ chip_id: chip_id,
116
+ },
117
+ });
118
+ clearInterval(checkWifiInterval);
119
+ }
120
+ }
121
+ });
122
+ }, 3000);
76
123
  }
77
124
  });
78
125
  socket.on('error', () => {
79
126
  ToastBottomHelper.error(t('server_error'));
127
+ setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
80
128
  goBack();
81
129
  });
82
- return () => {
83
- socket.close();
84
- };
85
130
  };
86
131
 
87
132
  const handleConnectWifiGateway = async () => {
88
133
  setIsLoading(true);
89
- const { success } = await axiosPost(API.UNIT.ADD_GATEWAY(unit_id), {
90
- chip: chip_id,
91
- });
92
- if (success) {
93
- ToastBottomHelper.success(t('add_gateway_success'));
94
- }
95
134
  // eslint-disable-next-line promise/prefer-await-to-then
96
135
  WifiManager.connectToProtectedSSID(wifi_ssid, wifi_pass, false).then(
97
136
  () => {