@eohjsc/react-native-smart-city 0.3.39 → 0.3.41
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/AddNewDevice/gateway-icon.svg +12 -0
- package/package.json +1 -1
- package/src/commons/Header/HeaderCustom.js +9 -6
- package/src/commons/SelectGateway/index.js +63 -21
- package/src/commons/SelectGateway/styles.js +25 -4
- package/src/commons/SelectSubUnit/index.js +2 -3
- package/src/commons/SelectSubUnit/styles.js +1 -3
- package/src/commons/StatusBox/index.js +19 -0
- package/src/commons/StatusBox/styles.js +30 -0
- package/src/commons/SubUnit/ShortDetail.js +7 -4
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +3 -1
- package/src/commons/index.js +8 -1
- package/src/configs/API.js +4 -0
- package/src/configs/AccessibilityLabel.js +2 -1
- package/src/configs/Colors.js +1 -0
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +2 -2
- package/src/screens/AddNewGateway/ConnectingDevice.js +6 -2
- package/src/screens/AddNewGateway/ConnectingModbusDevice.js +4 -2
- package/src/screens/AddNewGateway/ConnectingWifiDevice.js +15 -7
- package/src/screens/AddNewGateway/ConnectingWifiGuide.js +4 -3
- package/src/screens/AddNewGateway/ConnectingZigbeeDevice.js +3 -2
- package/src/screens/AddNewGateway/RenameNewDevices.js +85 -50
- package/src/screens/AddNewGateway/RenameNewDevicesStyles.js +18 -14
- package/src/screens/AddNewGateway/ScanGatewayQR.js +2 -1
- package/src/screens/AddNewGateway/ScanModbusQR.js +5 -5
- package/src/screens/AddNewGateway/SelectDeviceSubUnit.js +3 -0
- package/src/screens/AddNewGateway/SelectDeviceType.js +7 -6
- package/src/screens/AddNewGateway/SelectModbusGateway.js +19 -3
- package/src/screens/AddNewGateway/SelectZigbeeGateway.js +3 -2
- package/src/screens/AddNewGateway/ShareWifiPassword.js +12 -2
- package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +6 -3
- package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +28 -9
- package/src/screens/AddNewGateway/__test__/ScanModbusQR.test.js +1 -3
- package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +1 -1
- package/src/screens/Device/detail.js +14 -10
- package/src/screens/Gateway/__test__/index.test.js +32 -5
- package/src/screens/Gateway/components/GatewayItem/__test__/index.test.js +83 -0
- package/src/screens/Gateway/components/GatewayItem/index.js +27 -0
- package/src/screens/Gateway/components/GatewayItem/styles.js +62 -0
- package/src/screens/Gateway/hooks/useGateway.js +38 -0
- package/src/screens/Gateway/index.js +77 -5
- package/src/screens/Gateway/styles.js +32 -0
- package/src/screens/SubUnit/Detail.js +2 -1
- package/src/screens/Unit/AddMenu.js +1 -1
- package/src/screens/Unit/Detail.js +3 -1
- package/src/utils/I18n/translations/en.json +17 -1
- package/src/utils/I18n/translations/vi.json +16 -0
- package/src/utils/Route/index.js +1 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React, { memo, useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import { TouchableOpacity, View } from 'react-native';
|
|
2
|
+
import { ScrollView, TouchableOpacity, View } from 'react-native';
|
|
3
3
|
import { IconOutline } from '@ant-design/icons-react-native';
|
|
4
4
|
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
5
5
|
|
|
6
6
|
import { Colors } from '../../configs';
|
|
7
7
|
import Text from '../../commons/Text';
|
|
8
8
|
import AddDeviceIcon from '../../../assets/images/Popover/Dashboard/AddDevice.svg';
|
|
9
|
+
import GatewayIcon from '../../../assets/images/AddNewDevice/gateway-icon.svg';
|
|
9
10
|
import _TextInput from '../../commons/Form/TextInput';
|
|
10
11
|
import { useNavigation } from '@react-navigation/native';
|
|
11
12
|
import AccessibilityLabel from '../../configs/AccessibilityLabel';
|
|
@@ -13,12 +14,15 @@ import Routes from '../../utils/Route';
|
|
|
13
14
|
import styles from './RenameNewDevicesStyles';
|
|
14
15
|
import { axiosGet, axiosPost } from '../../utils/Apis/axios';
|
|
15
16
|
import API from '../../configs/API';
|
|
17
|
+
import { HeaderCustom } from '../../commons/Header';
|
|
18
|
+
import { useMemo } from 'react';
|
|
16
19
|
|
|
17
20
|
const RenameNewDevices = memo(({ route }) => {
|
|
18
21
|
const t = useTranslations();
|
|
19
22
|
const navigation = useNavigation();
|
|
20
23
|
|
|
21
|
-
const { unitId, stationId, chipId, sensorId } =
|
|
24
|
+
const { unitId, stationId, stationName, chipId, sensorId, addDeviceType } =
|
|
25
|
+
route?.params || {};
|
|
22
26
|
|
|
23
27
|
const [info, setInfo] = useState({});
|
|
24
28
|
|
|
@@ -36,12 +40,21 @@ const RenameNewDevices = memo(({ route }) => {
|
|
|
36
40
|
|
|
37
41
|
useEffect(() => {
|
|
38
42
|
(async () => {
|
|
39
|
-
|
|
43
|
+
let params = new URLSearchParams();
|
|
44
|
+
if (sensorId) {
|
|
45
|
+
params.append('sensor', sensorId);
|
|
46
|
+
}
|
|
47
|
+
const { success, data } = await axiosGet(
|
|
48
|
+
API.CHIP.RENAME_DEVICES(chipId),
|
|
49
|
+
{
|
|
50
|
+
params,
|
|
51
|
+
}
|
|
52
|
+
);
|
|
40
53
|
if (success) {
|
|
41
54
|
setInfo(data);
|
|
42
55
|
}
|
|
43
56
|
})();
|
|
44
|
-
}, [chipId, sensorId]);
|
|
57
|
+
}, [chipId, sensorId, stationId]);
|
|
45
58
|
|
|
46
59
|
const updateItemName = (type, sensor_index, end_device_index) => (value) => {
|
|
47
60
|
setInfo((currentInfo) => {
|
|
@@ -68,63 +81,85 @@ const RenameNewDevices = memo(({ route }) => {
|
|
|
68
81
|
});
|
|
69
82
|
};
|
|
70
83
|
|
|
84
|
+
const scrollviewHeight = useMemo(() => {
|
|
85
|
+
const baseHeight = 40;
|
|
86
|
+
let contentItems = 1;
|
|
87
|
+
|
|
88
|
+
if (addDeviceType !== 'gateway') {
|
|
89
|
+
info?.sensors?.map(
|
|
90
|
+
(sensor) => (contentItems += sensor?.end_devices?.length)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
return baseHeight + contentItems * 43;
|
|
94
|
+
}, [addDeviceType, info.sensors]);
|
|
95
|
+
|
|
71
96
|
const renameLabel = AccessibilityLabel.CONNECTED_DEVICE_RENAME_DEVICE;
|
|
72
97
|
|
|
73
98
|
return (
|
|
74
99
|
<View style={styles.container}>
|
|
100
|
+
<HeaderCustom
|
|
101
|
+
title={t('connect_device')}
|
|
102
|
+
isShowSeparator
|
|
103
|
+
isCanBack={false}
|
|
104
|
+
/>
|
|
75
105
|
<View style={styles.content}>
|
|
76
106
|
<IconOutline name="check-circle" size={28} color={Colors.Green6} />
|
|
77
107
|
<Text semibold color={Colors.Black} size={20} style={styles.textStatus}>
|
|
78
108
|
{t('successfully_connected')}
|
|
79
109
|
</Text>
|
|
80
|
-
{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
textInputStyle={styles.textItem}
|
|
106
|
-
onChange={updateItemName('sensor', sensor_index)}
|
|
107
|
-
/>
|
|
110
|
+
<Text size={14} color={Colors.Gray9} style={styles.textStation}>
|
|
111
|
+
{stationName}
|
|
112
|
+
</Text>
|
|
113
|
+
<View style={{ ...styles.devicesWrapper, height: scrollviewHeight }}>
|
|
114
|
+
<ScrollView>
|
|
115
|
+
{addDeviceType === 'gateway' ? (
|
|
116
|
+
<View style={styles.boxDevice}>
|
|
117
|
+
<GatewayIcon width={43} height={43} />
|
|
118
|
+
{info.can_rename ? (
|
|
119
|
+
<_TextInput
|
|
120
|
+
accessibilityLabel={`${renameLabel}-chip`}
|
|
121
|
+
value={info.name}
|
|
122
|
+
textInputStyle={styles.textItem}
|
|
123
|
+
onChange={updateItemName('chip')}
|
|
124
|
+
/>
|
|
125
|
+
) : (
|
|
126
|
+
<Text
|
|
127
|
+
size={14}
|
|
128
|
+
color={Colors.Gray9}
|
|
129
|
+
style={styles.textStation}
|
|
130
|
+
accessibilityLabel={`${renameLabel}-chip-name`}
|
|
131
|
+
>
|
|
132
|
+
{info.name}
|
|
133
|
+
</Text>
|
|
134
|
+
)}
|
|
108
135
|
</View>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
136
|
+
) : (
|
|
137
|
+
!!info?.sensors?.length &&
|
|
138
|
+
info.sensors.map((sensor, sensor_index) =>
|
|
139
|
+
(sensor?.end_devices || []).map(
|
|
140
|
+
(end_device, end_device_index) => (
|
|
141
|
+
<View style={styles.boxDevice} key={`${end_device?.id}`}>
|
|
142
|
+
<AddDeviceIcon width={43} height={43} />
|
|
143
|
+
<_TextInput
|
|
144
|
+
accessibilityLabel={`${renameLabel}-end_device-${end_device?.id}`}
|
|
145
|
+
value={end_device?.name}
|
|
146
|
+
textInputStyle={styles.textItem}
|
|
147
|
+
onChange={updateItemName(
|
|
148
|
+
'end_device',
|
|
149
|
+
sensor_index,
|
|
150
|
+
end_device_index
|
|
151
|
+
)}
|
|
152
|
+
/>
|
|
153
|
+
</View>
|
|
154
|
+
)
|
|
124
155
|
)
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
|
|
156
|
+
)
|
|
157
|
+
)}
|
|
158
|
+
</ScrollView>
|
|
159
|
+
</View>
|
|
160
|
+
<Text size={16} color={Colors.Gray8} style={styles.textRename}>
|
|
161
|
+
{t('click_on_box_to_rename_device')}
|
|
162
|
+
</Text>
|
|
128
163
|
</View>
|
|
129
164
|
<TouchableOpacity
|
|
130
165
|
style={styles.btnDone}
|
|
@@ -4,12 +4,14 @@ import { Colors } from '../../configs';
|
|
|
4
4
|
const styles = StyleSheet.create({
|
|
5
5
|
container: {
|
|
6
6
|
flex: 1,
|
|
7
|
-
backgroundColor: Colors.
|
|
8
|
-
justifyContent: '
|
|
7
|
+
backgroundColor: Colors.White,
|
|
8
|
+
justifyContent: 'space-between',
|
|
9
9
|
alignItems: 'center',
|
|
10
10
|
},
|
|
11
11
|
boxDevice: {
|
|
12
|
-
|
|
12
|
+
width: 250,
|
|
13
|
+
flexDirection: 'row',
|
|
14
|
+
paddingLeft: 16,
|
|
13
15
|
borderWidth: 1,
|
|
14
16
|
borderRadius: 10,
|
|
15
17
|
borderColor: Colors.Gray4,
|
|
@@ -23,16 +25,25 @@ const styles = StyleSheet.create({
|
|
|
23
25
|
shadowOpacity: 1,
|
|
24
26
|
shadowRadius: 12,
|
|
25
27
|
elevation: 2,
|
|
28
|
+
marginBottom: 16,
|
|
26
29
|
},
|
|
27
30
|
device: {
|
|
28
31
|
flexDirection: 'row',
|
|
29
32
|
alignItems: 'center',
|
|
30
33
|
},
|
|
34
|
+
textItem: {
|
|
35
|
+
borderWidth: 0,
|
|
36
|
+
textAlign: 'center',
|
|
37
|
+
marginTop: -20,
|
|
38
|
+
fontSize: 16,
|
|
39
|
+
lineHeight: 24,
|
|
40
|
+
maxWidth: 170,
|
|
41
|
+
},
|
|
31
42
|
content: {
|
|
32
43
|
flex: 1,
|
|
33
|
-
backgroundColor: Colors.Gray19,
|
|
34
44
|
justifyContent: 'center',
|
|
35
45
|
alignItems: 'center',
|
|
46
|
+
marginBottom: 24,
|
|
36
47
|
},
|
|
37
48
|
btnDone: {
|
|
38
49
|
height: 48,
|
|
@@ -57,19 +68,12 @@ const styles = StyleSheet.create({
|
|
|
57
68
|
textInput: {
|
|
58
69
|
marginTop: 0,
|
|
59
70
|
},
|
|
60
|
-
roomName: {
|
|
61
|
-
borderWidth: 0,
|
|
62
|
-
borderBottomWidth: 1,
|
|
63
|
-
borderBottomColor: Colors.Primary,
|
|
64
|
-
paddingLeft: 0,
|
|
65
|
-
fontSize: 16,
|
|
66
|
-
lineHeight: 24,
|
|
67
|
-
margin: 0,
|
|
68
|
-
padding: 0,
|
|
69
|
-
},
|
|
70
71
|
wrapRename: {
|
|
71
72
|
marginHorizontal: 16,
|
|
72
73
|
},
|
|
74
|
+
devicesWrapper: {
|
|
75
|
+
paddingHorizontal: 16,
|
|
76
|
+
},
|
|
73
77
|
});
|
|
74
78
|
|
|
75
79
|
export default styles;
|
|
@@ -13,7 +13,7 @@ const ScanGatewayQR = memo(({ route }) => {
|
|
|
13
13
|
const { navigate, goBack } = useNavigation();
|
|
14
14
|
|
|
15
15
|
const onScan = useCallback(
|
|
16
|
-
(body, setLoading) => {
|
|
16
|
+
async (body, setLoading) => {
|
|
17
17
|
let data;
|
|
18
18
|
try {
|
|
19
19
|
data = JSON.parse(body);
|
|
@@ -31,6 +31,7 @@ const ScanGatewayQR = memo(({ route }) => {
|
|
|
31
31
|
unitId,
|
|
32
32
|
stationId,
|
|
33
33
|
qrData: data,
|
|
34
|
+
addDeviceType: 'gateway',
|
|
34
35
|
});
|
|
35
36
|
setLoading(true);
|
|
36
37
|
},
|
|
@@ -14,7 +14,7 @@ import { Colors } from '../../configs';
|
|
|
14
14
|
|
|
15
15
|
const ScanModbusQR = memo(({ route }) => {
|
|
16
16
|
const t = useTranslations();
|
|
17
|
-
const { unitId, stationId,
|
|
17
|
+
const { unitId, stationId, stationName } = route?.params || {};
|
|
18
18
|
const { navigate, goBack } = useNavigation();
|
|
19
19
|
const [showPopupGuide, setShowPopupGuide, setHidePopupGuide] = useBoolean();
|
|
20
20
|
const [isInvalidQrCode, setIsInvalidQrCode] = useState(false);
|
|
@@ -35,14 +35,14 @@ const ScanModbusQR = memo(({ route }) => {
|
|
|
35
35
|
setLoading(false);
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
navigate(Routes.
|
|
38
|
+
navigate(Routes.SelectModbusGateway, {
|
|
39
39
|
unitId,
|
|
40
|
-
stationId
|
|
41
|
-
|
|
40
|
+
stationId,
|
|
41
|
+
stationName,
|
|
42
42
|
qrData: data,
|
|
43
43
|
});
|
|
44
44
|
},
|
|
45
|
-
[navigate, unitId, stationId,
|
|
45
|
+
[navigate, unitId, stationId, stationName]
|
|
46
46
|
);
|
|
47
47
|
|
|
48
48
|
const onRetry = useCallback(() => {
|
|
@@ -18,6 +18,7 @@ const SelectDeviceSubUnit = ({ route }) => {
|
|
|
18
18
|
unitId,
|
|
19
19
|
unitName,
|
|
20
20
|
stationId: subUnit?.id,
|
|
21
|
+
stationName: subUnit?.id,
|
|
21
22
|
});
|
|
22
23
|
break;
|
|
23
24
|
case DEVICE_TYPE.MODBUS:
|
|
@@ -25,6 +26,7 @@ const SelectDeviceSubUnit = ({ route }) => {
|
|
|
25
26
|
unitId,
|
|
26
27
|
unitName,
|
|
27
28
|
stationId: subUnit?.id,
|
|
29
|
+
stationName: subUnit?.id,
|
|
28
30
|
});
|
|
29
31
|
break;
|
|
30
32
|
case DEVICE_TYPE.ZIGBEE:
|
|
@@ -32,6 +34,7 @@ const SelectDeviceSubUnit = ({ route }) => {
|
|
|
32
34
|
unitId,
|
|
33
35
|
unitName,
|
|
34
36
|
stationId: subUnit?.id,
|
|
37
|
+
stationName: subUnit?.id,
|
|
35
38
|
});
|
|
36
39
|
break;
|
|
37
40
|
}
|
|
@@ -53,7 +53,7 @@ const SelectDeviceGrid = ({ options, onSelect }) => {
|
|
|
53
53
|
|
|
54
54
|
const SelectDeviceType = ({ route }) => {
|
|
55
55
|
const t = useTranslations();
|
|
56
|
-
const { unitId, unitName, stationId } = route?.params || {};
|
|
56
|
+
const { unitId, unitName, stationId, stationName } = route?.params || {};
|
|
57
57
|
const { navigate, goBack } = useNavigation();
|
|
58
58
|
const [addType, setAddType] = useState();
|
|
59
59
|
const [selectedAddType, setSelectedAddType] = useState();
|
|
@@ -78,6 +78,7 @@ const SelectDeviceType = ({ route }) => {
|
|
|
78
78
|
unitId,
|
|
79
79
|
unitName,
|
|
80
80
|
stationId,
|
|
81
|
+
stationName,
|
|
81
82
|
deviceType: DEVICE_TYPE.WIFI_DEVICE,
|
|
82
83
|
},
|
|
83
84
|
title: t('wifi_device'),
|
|
@@ -86,13 +87,12 @@ const SelectDeviceType = ({ route }) => {
|
|
|
86
87
|
{
|
|
87
88
|
id: 3,
|
|
88
89
|
image: <AddModbusDeviceIcon width={60} height={60} />,
|
|
89
|
-
route: stationId
|
|
90
|
-
? Routes.SelectModbusGateway
|
|
91
|
-
: Routes.SelectDeviceSubUnit,
|
|
90
|
+
route: stationId ? Routes.ScanModbusQR : Routes.SelectDeviceSubUnit,
|
|
92
91
|
data: {
|
|
93
92
|
unitId,
|
|
94
93
|
unitName,
|
|
95
94
|
stationId,
|
|
95
|
+
stationName,
|
|
96
96
|
deviceType: DEVICE_TYPE.MODBUS,
|
|
97
97
|
},
|
|
98
98
|
title: t('modbus'),
|
|
@@ -108,6 +108,7 @@ const SelectDeviceType = ({ route }) => {
|
|
|
108
108
|
unitId,
|
|
109
109
|
unitName,
|
|
110
110
|
stationId,
|
|
111
|
+
stationName,
|
|
111
112
|
deviceType: DEVICE_TYPE.ZIGBEE,
|
|
112
113
|
},
|
|
113
114
|
title: t('zigbee'),
|
|
@@ -118,7 +119,7 @@ const SelectDeviceType = ({ route }) => {
|
|
|
118
119
|
list.shift();
|
|
119
120
|
}
|
|
120
121
|
return list;
|
|
121
|
-
}, [unitId, t, unitName,
|
|
122
|
+
}, [unitId, t, stationId, unitName, stationName]);
|
|
122
123
|
|
|
123
124
|
const onRight = useCallback(() => {
|
|
124
125
|
if (selectedAddType?.route && selectedAddType?.data) {
|
|
@@ -140,7 +141,7 @@ const SelectDeviceType = ({ route }) => {
|
|
|
140
141
|
<View style={styles.contentContainer}>
|
|
141
142
|
<SelectDeviceGrid options={listDeviceType} onSelect={handleOnSelect} />
|
|
142
143
|
<ViewButtonBottom
|
|
143
|
-
leftTitle={t('
|
|
144
|
+
leftTitle={t('cancel')}
|
|
144
145
|
onLeftClick={goBack}
|
|
145
146
|
rightTitle={t('text_next')}
|
|
146
147
|
rightDisabled={!addType}
|
|
@@ -7,22 +7,38 @@ import Routes from '../../utils/Route';
|
|
|
7
7
|
const SelectModbusGateway = ({ route }) => {
|
|
8
8
|
const t = useTranslations();
|
|
9
9
|
const navigation = useNavigation();
|
|
10
|
-
const { unitId, stationId } =
|
|
10
|
+
const { unitId, unitName, stationId, stationName, qrData } =
|
|
11
|
+
route?.params || {};
|
|
11
12
|
|
|
12
13
|
const onPressNext = useCallback(
|
|
13
14
|
(gateway) => {
|
|
14
|
-
navigation.navigate(Routes.
|
|
15
|
+
navigation.navigate(Routes.ConnectingModbusDevice, {
|
|
15
16
|
unitId,
|
|
16
17
|
stationId,
|
|
18
|
+
stationName,
|
|
17
19
|
chipId: gateway.id,
|
|
20
|
+
qrData,
|
|
18
21
|
});
|
|
19
22
|
},
|
|
20
|
-
[navigation, unitId, stationId]
|
|
23
|
+
[navigation, unitId, stationId, stationName, qrData]
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const onPressOk = useCallback(
|
|
27
|
+
(gateway) => {
|
|
28
|
+
navigation.navigate(Routes.SelectDeviceType, {
|
|
29
|
+
stationName,
|
|
30
|
+
stationId,
|
|
31
|
+
unitId,
|
|
32
|
+
unitName,
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
[navigation, stationName, stationId, unitId, unitName]
|
|
21
36
|
);
|
|
22
37
|
|
|
23
38
|
return (
|
|
24
39
|
<SelectGateway
|
|
25
40
|
onPressNext={onPressNext}
|
|
41
|
+
onPressOk={onPressOk}
|
|
26
42
|
title={t('text_select_a_gateway')}
|
|
27
43
|
subTitle={t('text_select_a_gateway')}
|
|
28
44
|
unitId={unitId}
|
|
@@ -7,17 +7,18 @@ import Routes from '../../utils/Route';
|
|
|
7
7
|
const SelectZigbeeGateway = ({ route }) => {
|
|
8
8
|
const t = useTranslations();
|
|
9
9
|
const navigation = useNavigation();
|
|
10
|
-
const { unitId, stationId } = route?.params || {};
|
|
10
|
+
const { unitId, stationId, stationName } = route?.params || {};
|
|
11
11
|
|
|
12
12
|
const onPressNext = useCallback(
|
|
13
13
|
(gateway) => {
|
|
14
14
|
navigation.navigate(Routes.ZigbeeDeviceConnectGuide, {
|
|
15
15
|
unitId,
|
|
16
16
|
stationId,
|
|
17
|
+
stationName,
|
|
17
18
|
chipId: gateway.id,
|
|
18
19
|
});
|
|
19
20
|
},
|
|
20
|
-
[navigation, unitId, stationId]
|
|
21
|
+
[navigation, unitId, stationId, stationName]
|
|
21
22
|
);
|
|
22
23
|
|
|
23
24
|
return (
|
|
@@ -42,7 +42,8 @@ const WifiItem = ({ item, setIsShowPopupPassword, setSelectedWifi }) => {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
const ShareWifiPassword = ({ route }) => {
|
|
45
|
-
const { wifiList, unitId, stationId, qrData } =
|
|
45
|
+
const { wifiList, unitId, stationId, qrData, addDeviceType } =
|
|
46
|
+
route?.params || {};
|
|
46
47
|
const t = useTranslations();
|
|
47
48
|
const navigation = useNavigation();
|
|
48
49
|
|
|
@@ -103,13 +104,22 @@ const ShareWifiPassword = ({ route }) => {
|
|
|
103
104
|
ssid: selectedWifi,
|
|
104
105
|
password: selectedWifiPassword,
|
|
105
106
|
},
|
|
107
|
+
addDeviceType,
|
|
106
108
|
});
|
|
107
109
|
}
|
|
108
110
|
}, 1000);
|
|
109
111
|
|
|
110
112
|
return true;
|
|
111
113
|
},
|
|
112
|
-
[
|
|
114
|
+
[
|
|
115
|
+
addDeviceType,
|
|
116
|
+
navigation,
|
|
117
|
+
qrData,
|
|
118
|
+
selectedWifi,
|
|
119
|
+
selectedWifiPassword,
|
|
120
|
+
stationId,
|
|
121
|
+
unitId,
|
|
122
|
+
]
|
|
113
123
|
);
|
|
114
124
|
|
|
115
125
|
const onPasswordReady = useCallback(async () => {
|
|
@@ -48,6 +48,7 @@ describe('Test connecting modbus device', () => {
|
|
|
48
48
|
params: {
|
|
49
49
|
unitId: 1,
|
|
50
50
|
stationId: 2,
|
|
51
|
+
stationName: 'station',
|
|
51
52
|
chipId: 3,
|
|
52
53
|
qrData: {},
|
|
53
54
|
},
|
|
@@ -64,6 +65,9 @@ describe('Test connecting modbus device', () => {
|
|
|
64
65
|
});
|
|
65
66
|
|
|
66
67
|
it('receive sensor-id from channel then rename sensor-id', async () => {
|
|
68
|
+
mock.onPost().reply(200, {
|
|
69
|
+
id: 1,
|
|
70
|
+
});
|
|
67
71
|
await act(async () => {
|
|
68
72
|
tree = await create(wrapComponent(route));
|
|
69
73
|
});
|
|
@@ -74,15 +78,14 @@ describe('Test connecting modbus device', () => {
|
|
|
74
78
|
channel = channels[key];
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
|
-
await act(async () => {
|
|
78
|
-
await channel.trigger('progress', { data: { sensorId: 1 } });
|
|
79
|
-
});
|
|
80
81
|
await act(async () => {
|
|
81
82
|
await channel.trigger('progress', { success: 1 });
|
|
82
83
|
});
|
|
83
84
|
expect(mockedNavigate).toHaveBeenCalledWith(Routes.RenameNewDevices, {
|
|
85
|
+
addDeviceType: undefined,
|
|
84
86
|
unitId: 1,
|
|
85
87
|
stationId: 2,
|
|
88
|
+
stationName: 'station',
|
|
86
89
|
chipId: 3,
|
|
87
90
|
sensorId: 1,
|
|
88
91
|
});
|
|
@@ -59,6 +59,15 @@ describe('Test rename new devices', () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it('rendering base', async () => {
|
|
62
|
+
route = {
|
|
63
|
+
params: {
|
|
64
|
+
unitId: 1,
|
|
65
|
+
stationId: 2,
|
|
66
|
+
chipId: 3,
|
|
67
|
+
qrData: {},
|
|
68
|
+
addDeviceType: 'gateway',
|
|
69
|
+
},
|
|
70
|
+
};
|
|
62
71
|
await act(async () => {
|
|
63
72
|
tree = await create(wrapComponent(route));
|
|
64
73
|
});
|
|
@@ -81,7 +90,7 @@ describe('Test rename new devices', () => {
|
|
|
81
90
|
expect(mock.history.get).toHaveLength(1);
|
|
82
91
|
});
|
|
83
92
|
|
|
84
|
-
it('rendering
|
|
93
|
+
it('rendering end devices', async () => {
|
|
85
94
|
mock.onGet().reply(200, {
|
|
86
95
|
id: 1,
|
|
87
96
|
name: 'chip',
|
|
@@ -104,14 +113,6 @@ describe('Test rename new devices', () => {
|
|
|
104
113
|
tree = await create(wrapComponent(route));
|
|
105
114
|
});
|
|
106
115
|
const instance = tree.root;
|
|
107
|
-
expect(
|
|
108
|
-
instance.findAll(
|
|
109
|
-
(el) =>
|
|
110
|
-
el.props.accessibilityLabel?.indexOf(
|
|
111
|
-
`${AccessibilityLabel.CONNECTED_DEVICE_RENAME_DEVICE}-sensor`
|
|
112
|
-
) === 0 && el.type === _TextInput
|
|
113
|
-
)
|
|
114
|
-
).toHaveLength(1);
|
|
115
116
|
expect(
|
|
116
117
|
instance.findAll(
|
|
117
118
|
(el) =>
|
|
@@ -126,6 +127,15 @@ describe('Test rename new devices', () => {
|
|
|
126
127
|
mock.onGet().reply(200, {
|
|
127
128
|
can_rename: true,
|
|
128
129
|
});
|
|
130
|
+
route = {
|
|
131
|
+
params: {
|
|
132
|
+
unitId: 1,
|
|
133
|
+
stationId: 2,
|
|
134
|
+
chipId: 3,
|
|
135
|
+
qrData: {},
|
|
136
|
+
addDeviceType: 'gateway',
|
|
137
|
+
},
|
|
138
|
+
};
|
|
129
139
|
await act(async () => {
|
|
130
140
|
tree = await create(wrapComponent(route));
|
|
131
141
|
});
|
|
@@ -154,6 +164,15 @@ describe('Test rename new devices', () => {
|
|
|
154
164
|
id: 1,
|
|
155
165
|
can_rename: true,
|
|
156
166
|
});
|
|
167
|
+
route = {
|
|
168
|
+
params: {
|
|
169
|
+
unitId: 1,
|
|
170
|
+
stationId: 2,
|
|
171
|
+
chipId: 3,
|
|
172
|
+
qrData: {},
|
|
173
|
+
addDeviceType: 'gateway',
|
|
174
|
+
},
|
|
175
|
+
};
|
|
157
176
|
await act(async () => {
|
|
158
177
|
tree = await create(wrapComponent(route));
|
|
159
178
|
});
|
|
@@ -66,8 +66,6 @@ describe('test scan modbus QR', () => {
|
|
|
66
66
|
it('on scan correct QR code', async () => {
|
|
67
67
|
await scanQRCode({ imei: 'SENSOR-xxx' }, jest.fn());
|
|
68
68
|
expect(mockedNavigate).toHaveBeenCalled();
|
|
69
|
-
expect(mockedNavigate.mock.calls[0][0]).toEqual(
|
|
70
|
-
Routes.ConnectingModbusDevice
|
|
71
|
-
);
|
|
69
|
+
expect(mockedNavigate.mock.calls[0][0]).toEqual(Routes.SelectModbusGateway);
|
|
72
70
|
});
|
|
73
71
|
});
|
|
@@ -68,7 +68,7 @@ describe('Test select modbus gateway', () => {
|
|
|
68
68
|
selectGateway.props.onPressNext({ id: 3 });
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
expect(mockedNavigate).toBeCalledWith(Routes.
|
|
71
|
+
expect(mockedNavigate).toBeCalledWith(Routes.ConnectingModbusDevice, {
|
|
72
72
|
unitId: 1,
|
|
73
73
|
stationId: 2,
|
|
74
74
|
chipId: 3,
|
|
@@ -220,6 +220,15 @@ const DeviceDetail = ({ route }) => {
|
|
|
220
220
|
}
|
|
221
221
|
}, [fetchSensorDetail, sensorId, sensorData]);
|
|
222
222
|
|
|
223
|
+
const fetchRemoteControlOptions = useCallback(async () => {
|
|
224
|
+
const { success, data } = await axiosGet(
|
|
225
|
+
API.DEVICE.REMOTE_CONTROL_OPTIONS(sensor?.id),
|
|
226
|
+
{},
|
|
227
|
+
true
|
|
228
|
+
);
|
|
229
|
+
success && setControlOptions(data);
|
|
230
|
+
}, [sensor]);
|
|
231
|
+
|
|
223
232
|
const fetchDataDeviceDetail = useCallback(async () => {
|
|
224
233
|
if (!token) {
|
|
225
234
|
return;
|
|
@@ -259,16 +268,11 @@ const DeviceDetail = ({ route }) => {
|
|
|
259
268
|
}
|
|
260
269
|
setLoading((preState) => ({ ...preState, displayTemplate: false }));
|
|
261
270
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (controlResult.success) {
|
|
269
|
-
setControlOptions(controlResult.data);
|
|
270
|
-
}
|
|
271
|
-
}, [token, sensor, setDeviceId, setLastEvent]);
|
|
271
|
+
success &&
|
|
272
|
+
data.items.length &&
|
|
273
|
+
data.items.some((item) => item.type === 'action') &&
|
|
274
|
+
(await fetchRemoteControlOptions());
|
|
275
|
+
}, [token, sensor, setDeviceId, fetchRemoteControlOptions]);
|
|
272
276
|
|
|
273
277
|
const {
|
|
274
278
|
deviceId: emergencyDeviceId,
|