@eohjsc/react-native-smart-city 0.2.84 → 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.
- package/assets/images/brightness.svg +12 -0
- package/package.json +3 -1
- package/src/Images/Common/SuccessfullyConnected.svg +4 -0
- package/src/Images/Common/eye-closed.png +0 -0
- package/src/Images/Common/eye-closed@2x.png +0 -0
- package/src/Images/Common/eye-closed@3x.png +0 -0
- package/src/Images/Common/eye.png +0 -0
- package/src/Images/Common/eye@2x.png +0 -0
- package/src/Images/Common/eye@3x.png +0 -0
- package/src/commons/ActionGroup/LightActionTemplate.js +103 -0
- package/src/commons/ActionGroup/LightActionTemplateStyles.js +57 -0
- package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +33 -31
- package/src/commons/ActionGroup/__test__/LightActionTemplate.test.js +59 -0
- package/src/commons/ActionGroup/index.js +3 -0
- package/src/commons/CardShadow/index.js +5 -2
- package/src/commons/CardShadow/styles.js +2 -3
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +16 -0
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +42 -0
- package/src/commons/ConnectingProcess/__test__/Connecting.test.js +27 -0
- package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +18 -0
- package/src/commons/ConnectingProcess/index.js +202 -0
- package/src/commons/ConnectingProcess/styles.js +69 -0
- package/src/commons/Device/LinearChart.js +1 -0
- package/src/commons/Form/TextInputPassword.js +1 -1
- package/src/configs/API.js +2 -0
- package/src/configs/Constants.js +15 -0
- package/src/configs/Images.js +2 -0
- package/src/context/actionType.ts +2 -0
- package/src/context/reducer.ts +10 -0
- package/src/hooks/Common/useBlockBackAndroid.js +3 -1
- package/src/navigations/AddDeviceStack.js +10 -0
- package/src/screens/AddCommon/SelectSubUnit.js +29 -6
- package/src/screens/AddCommon/SelectUnit.js +24 -2
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +120 -1
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +16 -1
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +45 -15
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +52 -23
- package/src/screens/AddNewGateway/SelectGateway.js +132 -0
- package/src/screens/AddNewGateway/SelectGatewayStyles.js +55 -0
- package/src/screens/Device/detail.js +6 -6
- package/src/screens/Notification/__test__/NotificationItem.test.js +12 -2
- package/src/screens/Notification/components/NotificationItem.js +60 -12
- package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +10 -7
- package/src/screens/ScanChipQR/hooks/index.js +46 -22
- package/src/screens/Unit/Detail.js +23 -1
- package/src/utils/I18n/translations/en.json +8 -0
- package/src/utils/I18n/translations/vi.json +8 -1
- package/src/utils/Route/index.js +2 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import React, { useEffect, useCallback, useState } from 'react';
|
|
2
|
+
import { SafeAreaView, View, TouchableOpacity } from 'react-native';
|
|
3
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
4
|
+
import Routes from '../../utils/Route';
|
|
5
|
+
import { useNavigation } from '@react-navigation/native';
|
|
6
|
+
import * as Progress from 'react-native-progress';
|
|
7
|
+
import ImageSuccessfully from '../../Images/Common/SuccessfullyConnected.svg';
|
|
8
|
+
|
|
9
|
+
import Text from '../Text';
|
|
10
|
+
import { axiosPost } from '../../utils/Apis/axios';
|
|
11
|
+
import { API, Colors, Constants } from '../../configs';
|
|
12
|
+
import styles from './styles';
|
|
13
|
+
import DeviceItem from './DeviceItem/DeviceItem';
|
|
14
|
+
import { useSCContextSelector } from '../../context';
|
|
15
|
+
|
|
16
|
+
const ConnectingProcess = ({ route }) => {
|
|
17
|
+
const { navigate, goBack } = useNavigation();
|
|
18
|
+
const t = useTranslations();
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
scan_sensor_data,
|
|
22
|
+
gateway,
|
|
23
|
+
station,
|
|
24
|
+
unit,
|
|
25
|
+
unit_id,
|
|
26
|
+
devicePrefixName,
|
|
27
|
+
wifi_ssid,
|
|
28
|
+
wifi_pass,
|
|
29
|
+
chip_id,
|
|
30
|
+
} = route.params;
|
|
31
|
+
const [percent, setPercent] = useState(0);
|
|
32
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
33
|
+
const [sensor, setSensor] = useState(null);
|
|
34
|
+
const user = useSCContextSelector((state) => state?.auth?.account?.user);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
processLoading();
|
|
37
|
+
}, [processLoading]);
|
|
38
|
+
|
|
39
|
+
const processLoading = useCallback(() => {
|
|
40
|
+
let interval;
|
|
41
|
+
if (isLoading) {
|
|
42
|
+
interval = setInterval(() => {
|
|
43
|
+
setPercent((prev) => {
|
|
44
|
+
if (prev === 1) {
|
|
45
|
+
clearInterval(interval);
|
|
46
|
+
return 1;
|
|
47
|
+
} else {
|
|
48
|
+
return prev + 0.2;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}, 180);
|
|
52
|
+
} else {
|
|
53
|
+
clearInterval(interval);
|
|
54
|
+
}
|
|
55
|
+
}, [isLoading]);
|
|
56
|
+
|
|
57
|
+
const ConnectingDevice = useCallback(async () => {
|
|
58
|
+
setIsLoading(true);
|
|
59
|
+
switch (devicePrefixName) {
|
|
60
|
+
case 'SENSOR':
|
|
61
|
+
{
|
|
62
|
+
const body = { imei: scan_sensor_data?.imei, chip: gateway?.id };
|
|
63
|
+
const { success, data } = await axiosPost(
|
|
64
|
+
API.SUB_UNIT.SENSOR_SCAN(station.id),
|
|
65
|
+
body
|
|
66
|
+
);
|
|
67
|
+
if (success) {
|
|
68
|
+
setSensor(data);
|
|
69
|
+
} else {
|
|
70
|
+
goBack();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
case 'ROBOT': {
|
|
75
|
+
const { success, data } = await axiosPost(API.UNIT.CHIP_SCAN(unit.id), {
|
|
76
|
+
imei: gateway?.imei,
|
|
77
|
+
qr_code: scan_sensor_data?.imei,
|
|
78
|
+
name: gateway?.model,
|
|
79
|
+
station: station?.id,
|
|
80
|
+
wifi_ssid: wifi_ssid,
|
|
81
|
+
wifi_pass: wifi_pass,
|
|
82
|
+
phone: user?.phone_number,
|
|
83
|
+
});
|
|
84
|
+
if (success) {
|
|
85
|
+
setSensor(data);
|
|
86
|
+
} else {
|
|
87
|
+
goBack();
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 'LITE': {
|
|
92
|
+
const { success } = await axiosPost(API.UNIT.ADD_GATEWAY(unit_id), {
|
|
93
|
+
chip: chip_id,
|
|
94
|
+
imei: gateway?.imei,
|
|
95
|
+
chip_name: gateway?.model,
|
|
96
|
+
});
|
|
97
|
+
if (success) {
|
|
98
|
+
setSensor({ name: gateway?.model });
|
|
99
|
+
} else {
|
|
100
|
+
goBack();
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
setIsLoading(false);
|
|
106
|
+
}, [
|
|
107
|
+
devicePrefixName,
|
|
108
|
+
scan_sensor_data?.imei,
|
|
109
|
+
gateway?.id,
|
|
110
|
+
gateway?.imei,
|
|
111
|
+
gateway?.model,
|
|
112
|
+
station,
|
|
113
|
+
goBack,
|
|
114
|
+
unit,
|
|
115
|
+
wifi_ssid,
|
|
116
|
+
wifi_pass,
|
|
117
|
+
user?.phone_number,
|
|
118
|
+
unit_id,
|
|
119
|
+
chip_id,
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
const Connecting = useCallback(() => {
|
|
123
|
+
return (
|
|
124
|
+
<>
|
|
125
|
+
<View style={styles.progressBar}>
|
|
126
|
+
<View style={styles.connecting}>
|
|
127
|
+
<Text type="H4" bold>
|
|
128
|
+
{t('connecting')}
|
|
129
|
+
</Text>
|
|
130
|
+
</View>
|
|
131
|
+
</View>
|
|
132
|
+
<View style={styles.percentLoad}>
|
|
133
|
+
<Progress.Bar
|
|
134
|
+
progress={percent}
|
|
135
|
+
animated={true}
|
|
136
|
+
color={Colors.Primary}
|
|
137
|
+
indeterminateAnimationDuration={1000}
|
|
138
|
+
height={7}
|
|
139
|
+
width={Constants.width - 80}
|
|
140
|
+
useNativeDriver={true}
|
|
141
|
+
/>
|
|
142
|
+
<Text style={styles.textPercentLoad}>{`${parseInt(
|
|
143
|
+
percent * 100,
|
|
144
|
+
10
|
|
145
|
+
)}%`}</Text>
|
|
146
|
+
</View>
|
|
147
|
+
</>
|
|
148
|
+
);
|
|
149
|
+
}, [percent, t]);
|
|
150
|
+
|
|
151
|
+
const ConnectingSuccess = useCallback(() => {
|
|
152
|
+
return (
|
|
153
|
+
<View style={styles.ConnectingSuccess}>
|
|
154
|
+
<ImageSuccessfully />
|
|
155
|
+
<Text bold style={styles.connectingText}>
|
|
156
|
+
{t('successfully_connected')}
|
|
157
|
+
</Text>
|
|
158
|
+
<Text size={14} style={styles.textHome}>
|
|
159
|
+
Home - {station?.name}
|
|
160
|
+
</Text>
|
|
161
|
+
<DeviceItem icon={sensor?.icon_kit} name={sensor?.name} />
|
|
162
|
+
</View>
|
|
163
|
+
);
|
|
164
|
+
}, [sensor?.icon_kit, sensor?.name, station?.name, t]);
|
|
165
|
+
|
|
166
|
+
const handleDone = useCallback(() => {
|
|
167
|
+
navigate(Routes.UnitStack, {
|
|
168
|
+
screen: Routes.UnitDetail,
|
|
169
|
+
params: {
|
|
170
|
+
unitId: unit?.id || unit_id,
|
|
171
|
+
unitData: unit,
|
|
172
|
+
routeName: 'DashboardStack',
|
|
173
|
+
stationId: station?.id,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}, [navigate, station?.id, unit, unit_id]);
|
|
177
|
+
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
ConnectingDevice();
|
|
180
|
+
}, [ConnectingDevice]);
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<SafeAreaView style={styles.wrap}>
|
|
184
|
+
<View style={styles.boxText}>
|
|
185
|
+
<Text bold style={styles.connectingText}>
|
|
186
|
+
{t('connect_device')}
|
|
187
|
+
</Text>
|
|
188
|
+
{!!isLoading && <Connecting />}
|
|
189
|
+
{!isLoading && <ConnectingSuccess />}
|
|
190
|
+
</View>
|
|
191
|
+
{!isLoading && (
|
|
192
|
+
<TouchableOpacity style={styles.buttonDone} onPress={handleDone}>
|
|
193
|
+
<Text color={Colors.Primary} type={'H4'}>
|
|
194
|
+
{t('done')}
|
|
195
|
+
</Text>
|
|
196
|
+
</TouchableOpacity>
|
|
197
|
+
)}
|
|
198
|
+
</SafeAreaView>
|
|
199
|
+
);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
export default ConnectingProcess;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors } from '../../configs';
|
|
3
|
+
import {
|
|
4
|
+
getStatusBarHeight,
|
|
5
|
+
getBottomSpace,
|
|
6
|
+
} from 'react-native-iphone-x-helper';
|
|
7
|
+
|
|
8
|
+
export default StyleSheet.create({
|
|
9
|
+
wrap: {
|
|
10
|
+
paddingTop: getStatusBarHeight(true),
|
|
11
|
+
backgroundColor: Colors.White,
|
|
12
|
+
width: '100%',
|
|
13
|
+
height: '100%',
|
|
14
|
+
justifyContent: 'space-between',
|
|
15
|
+
},
|
|
16
|
+
connectingText: {
|
|
17
|
+
marginLeft: 30,
|
|
18
|
+
marginTop: 16,
|
|
19
|
+
fontSize: 20,
|
|
20
|
+
color: Colors.Gray9,
|
|
21
|
+
},
|
|
22
|
+
animatedEllipsis: {
|
|
23
|
+
fontSize: 25,
|
|
24
|
+
color: Colors.Gray9,
|
|
25
|
+
marginTop: 14,
|
|
26
|
+
},
|
|
27
|
+
warningText: {
|
|
28
|
+
marginHorizontal: 30,
|
|
29
|
+
marginTop: 16,
|
|
30
|
+
fontSize: 14,
|
|
31
|
+
color: Colors.Gray8,
|
|
32
|
+
},
|
|
33
|
+
boxText: {
|
|
34
|
+
flex: 1,
|
|
35
|
+
},
|
|
36
|
+
progressBar: {
|
|
37
|
+
flexDirection: 'column',
|
|
38
|
+
marginTop: 180,
|
|
39
|
+
marginHorizontal: 30,
|
|
40
|
+
},
|
|
41
|
+
connecting: {
|
|
42
|
+
flexDirection: 'row',
|
|
43
|
+
justifyContent: 'center',
|
|
44
|
+
marginBottom: 10,
|
|
45
|
+
},
|
|
46
|
+
percentLoad: {
|
|
47
|
+
flexDirection: 'row',
|
|
48
|
+
justifyContent: 'center',
|
|
49
|
+
alignItems: 'center',
|
|
50
|
+
},
|
|
51
|
+
textPercentLoad: {
|
|
52
|
+
marginLeft: 10,
|
|
53
|
+
},
|
|
54
|
+
ConnectingSuccess: {
|
|
55
|
+
marginTop: 180,
|
|
56
|
+
justifyContent: 'center',
|
|
57
|
+
alignItems: 'center',
|
|
58
|
+
},
|
|
59
|
+
textHome: {
|
|
60
|
+
paddingTop: 16,
|
|
61
|
+
paddingBottom: 8,
|
|
62
|
+
},
|
|
63
|
+
buttonDone: {
|
|
64
|
+
width: '100%',
|
|
65
|
+
justifyContent: 'center',
|
|
66
|
+
alignItems: 'center',
|
|
67
|
+
paddingBottom: getBottomSpace() + 24,
|
|
68
|
+
},
|
|
69
|
+
});
|
package/src/configs/API.js
CHANGED
|
@@ -53,6 +53,8 @@ const API = {
|
|
|
53
53
|
CHIP: {
|
|
54
54
|
CHECK_FINALIZED: () =>
|
|
55
55
|
SCConfig.apiRoot + '/property_manager/stations/check_chip_finalized/',
|
|
56
|
+
GET_CHIPS_FROM_UNIT: (id) =>
|
|
57
|
+
SCConfig.apiRoot + `/property_manager/get_chips/?unit_id=${id}`,
|
|
56
58
|
},
|
|
57
59
|
SENSOR: {
|
|
58
60
|
SENSOR_DETAIL: (id) =>
|
package/src/configs/Constants.js
CHANGED
|
@@ -487,6 +487,12 @@ export const TESTID = {
|
|
|
487
487
|
TOUCH_SHARED_UNIT: 'TOUCH_SHARED_UNIT',
|
|
488
488
|
SHARED_UNIT_OWN_BY: 'SHARED_UNIT_OWN_BY',
|
|
489
489
|
|
|
490
|
+
// Select subunit
|
|
491
|
+
|
|
492
|
+
SELECT_SUBUNIT_NAME: 'SELECT_SUBUNIT_NAME',
|
|
493
|
+
SELECT_SUBUNIT_RADIO_BUTTON: 'SELECT_SUBUNIT_RADIO_BUTTON',
|
|
494
|
+
SELECT_SUBUNIT_SELECT: 'SELECT_SUBUNIT_SELECT',
|
|
495
|
+
|
|
490
496
|
// Select unit
|
|
491
497
|
SELECT_UNIT_NAME: 'SELECT_UNIT_NAME',
|
|
492
498
|
SELECT_UNIT_RADIO_BUTTON: 'SELECT_UNIT_RADIO_BUTTON',
|
|
@@ -561,6 +567,12 @@ export const TESTID = {
|
|
|
561
567
|
ADD_NEW_GATEWAY_THEN_SELECT: 'ADD_NEW_GATEWAY_THEN_SELECT',
|
|
562
568
|
ADD_NEW_GATEWAY_TEXT_IMEI: 'ADD_NEW_GATEWAY_TEXT_IMEI',
|
|
563
569
|
|
|
570
|
+
// Select Gateway
|
|
571
|
+
|
|
572
|
+
SELECT_GATEWAY_NAME: 'SELECT_GATEWAY_NAME',
|
|
573
|
+
SELECT_GATEWAY_RADIO_BUTTON: 'SELECT_GATEWAY_RADIO_BUTTON',
|
|
574
|
+
SELECT_GATEWAY_SELECT: 'SELECT_GATEWAY_SELECT',
|
|
575
|
+
|
|
564
576
|
// Header
|
|
565
577
|
HEADER_ANI_TITLE: 'HEADER_ANI_TITLE',
|
|
566
578
|
|
|
@@ -648,6 +660,9 @@ export const NOTIFICATION_TYPES = {
|
|
|
648
660
|
NOTIFY_REMOVE_MEMBER: 'NOTIFY_REMOVE_MEMBER',
|
|
649
661
|
NOTIFY_MEMBER_LEAVE_UNIT: 'NOTIFY_MEMBER_LEAVE_UNIT',
|
|
650
662
|
NOTIFY_RENAME_UNIT: 'NOTIFY_RENAME_UNIT',
|
|
663
|
+
NOTIFY_DEVICE_DISCONNECT: 'NOTIFY_DEVICE_DISCONNECT',
|
|
664
|
+
NOTIFY_RENAME_SUB_UNIT: 'NOTIFY_RENAME_SUB_UNIT',
|
|
665
|
+
NOTIFY_UPDATE_ADDRESS: 'NOTIFY_UPDATE_ADDRESS',
|
|
651
666
|
};
|
|
652
667
|
|
|
653
668
|
export const ACTIVITY_LOG_TYPES = {
|
package/src/configs/Images.js
CHANGED
|
@@ -11,4 +11,6 @@ export default {
|
|
|
11
11
|
buttonLeftCurtain: require('../Images/Common/buttonLeftCurtain.png'),
|
|
12
12
|
buttonRightCurtain: require('../Images/Common/buttonRightCurtain.png'),
|
|
13
13
|
shadowButton: require('../Images/Common/shadowButton.png'),
|
|
14
|
+
eye: require('../Images/Common/eye.png'),
|
|
15
|
+
eyeClosed: require('../Images/Common/eye-closed.png'),
|
|
14
16
|
};
|
|
@@ -6,6 +6,7 @@ export const Action = {
|
|
|
6
6
|
LIST_ACTION: 'LIST_ACTION',
|
|
7
7
|
IS_FIRST_OPEN_CAMERA: 'IS_FIRST_OPEN_CAMERA',
|
|
8
8
|
IS_LAVIDA_SOURCE: 'IS_LAVIDA_SOURCE',
|
|
9
|
+
IS_CONNECT_WIFI_GATEWAY: 'IS_CONNECT_WIFI_GATEWAY',
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
export type AuthData = {
|
|
@@ -50,4 +51,5 @@ export type ActionDataMap = {
|
|
|
50
51
|
export type AppType = {
|
|
51
52
|
isFirstOpenCamera: boolean;
|
|
52
53
|
isLavidaSource: boolean;
|
|
54
|
+
isConnectWifiGateway: boolean;
|
|
53
55
|
};
|
package/src/context/reducer.ts
CHANGED
|
@@ -40,6 +40,7 @@ export const initialState = {
|
|
|
40
40
|
app: {
|
|
41
41
|
isFirstOpenCamera: true,
|
|
42
42
|
isLavidaSource: false,
|
|
43
|
+
isConnectWifiGateway: false,
|
|
43
44
|
},
|
|
44
45
|
};
|
|
45
46
|
|
|
@@ -107,6 +108,15 @@ export const reducer = (currentState: ContextData, action: Action) => {
|
|
|
107
108
|
},
|
|
108
109
|
};
|
|
109
110
|
}
|
|
111
|
+
case Action.IS_CONNECT_WIFI_GATEWAY: {
|
|
112
|
+
return {
|
|
113
|
+
...currentState,
|
|
114
|
+
app: {
|
|
115
|
+
...currentState.app,
|
|
116
|
+
isConnectWifiGateway: payload,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
110
120
|
default:
|
|
111
121
|
return currentState;
|
|
112
122
|
}
|
|
@@ -2,10 +2,12 @@ import { useIsFocused } from '@react-navigation/native';
|
|
|
2
2
|
import { useCallback, useEffect } from 'react';
|
|
3
3
|
import { BackHandler } from 'react-native';
|
|
4
4
|
|
|
5
|
-
export const useBlockBackAndroid = () => {
|
|
5
|
+
export const useBlockBackAndroid = (actionBack) => {
|
|
6
6
|
const focused = useIsFocused();
|
|
7
7
|
const blockBack = useCallback(() => {
|
|
8
|
+
actionBack && actionBack();
|
|
8
9
|
return true;
|
|
10
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9
11
|
}, []);
|
|
10
12
|
useEffect(() => {
|
|
11
13
|
if (focused) {
|
|
@@ -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
|
|
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.
|
|
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.
|
|
190
|
+
testID={TESTID.SELECT_SUBUNIT_SELECT}
|
|
168
191
|
>
|
|
169
|
-
<Text style={styles.text} testID={TESTID.
|
|
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
|
-
}, [
|
|
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
|
+
});
|