@eohjsc/react-native-smart-city 0.2.26 → 0.2.27
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/Illustrations.svg +83 -0
- package/assets/images/{WeatherChange.svg → ValueChange.svg} +0 -0
- package/index.js +2 -0
- package/package.json +3 -1
- package/src/Images/Common/file.png +0 -0
- package/src/Images/Common/fullscreen.png +0 -0
- package/src/commons/ActionGroup/OnOffTemplate/index.js +5 -0
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +294 -0
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplateWithNullConfigValue.test.js +60 -0
- package/src/commons/AlertAction/__test__/AlertAction.test.js +6 -6
- package/src/commons/AlertAction/index.js +2 -0
- package/src/commons/Automate/ItemAutomate.js +7 -1
- package/src/commons/Automate/__test__/ItemAutomate.test.js +16 -0
- package/src/commons/Automate/__test__/ItemScriptAction.test.js +16 -0
- package/src/commons/BackDefault/__test__/BackDefault.test.js +21 -0
- package/src/commons/BottomScrollPicker/index.js +5 -1
- package/src/commons/BottomSheet/index.js +10 -5
- package/src/commons/ButtonPopup/__test__/__snapshots__/ButtonPopup.test.js.snap +2 -0
- package/src/commons/ButtonPopup/index.js +2 -0
- package/src/commons/Calendar/index.js +72 -0
- package/src/commons/Calendar/styles.js +11 -0
- package/src/commons/Device/ItemAddNew/index.js +2 -2
- package/src/commons/Explore/__test__/HeaderExplore.test.js +25 -0
- package/src/commons/Explore/__test__/LocationItem.test.js +31 -0
- package/src/commons/Header/HeaderCustom.js +7 -3
- package/src/commons/HeaderAni/index.js +31 -3
- package/src/commons/HorizontalPicker/index.js +134 -0
- package/src/commons/HorizontalPicker/styles.js +56 -0
- package/src/commons/Modal/__test__/ModalBottom.test.js +39 -0
- package/src/commons/RowItem/__test__/RowItem.test.js +16 -0
- package/src/commons/RowItem/index.js +61 -0
- package/src/commons/RowItem/styles.js +53 -0
- package/src/commons/Sharing/WrapHeaderScrollable.js +78 -74
- package/src/commons/SubUnit/OneTap/ItemOneTap.js +73 -69
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +47 -1
- package/src/commons/SubUnit/OneTap/index.js +2 -2
- package/src/commons/Unit/__test__/SharedUnit.test.js +330 -0
- package/src/commons/WheelDateTimePicker/index.js +16 -8
- package/src/commons/index.js +2 -0
- package/src/configs/API.js +5 -1
- package/src/configs/Constants.js +18 -3
- package/src/configs/Theme.js +20 -0
- package/src/context/SCContext.tsx +2 -2
- package/src/context/mockStore.ts +3 -1
- package/src/hooks/Common/__test__/useStatusbar.test.js +28 -0
- package/src/navigations/AutomateStack.js +45 -0
- package/src/navigations/UnitStack.js +33 -14
- package/src/navigations/utils.js +8 -0
- package/src/screens/AddNewAction/Components/LoadingSelectAction.js +40 -0
- package/src/screens/AddNewAction/Components/index.js +3 -0
- package/src/screens/AddNewAction/SelectAction.js +147 -62
- package/src/screens/AddNewAction/{SelectDevice.js → SelectSensorDevices.js} +42 -12
- package/src/screens/AddNewAction/SetupSensor.js +221 -0
- package/src/screens/AddNewAction/Styles/SelectActionStyles.js +43 -5
- package/src/screens/AddNewAction/Styles/{SelectDeviceStyles.js → SelectSensorDevicesStyles.js} +0 -0
- package/src/screens/AddNewAction/Styles/SetupSensorStyles.js +76 -0
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +0 -19
- package/src/screens/AddNewAction/__test__/{SelectDevice.test.js → SelectSensorDevices.test.js} +3 -3
- package/src/screens/AddNewAction/__test__/SetupSensor.test.js +125 -0
- package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +69 -12
- package/src/screens/AddNewAutoSmart/index.js +42 -14
- package/src/screens/AddNewOneTap/AddNewOneTapStyles.js +4 -3
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +1 -0
- package/src/screens/AddNewOneTap/index.js +7 -4
- package/src/screens/AllCamera/__test__/index.test.js +103 -0
- package/src/screens/Automate/Components/Loading.js +64 -0
- package/src/screens/Automate/Styles/indexStyles.js +64 -0
- package/src/screens/Automate/__test__/Loading.test.js +16 -0
- package/src/screens/Automate/__test__/index.test.js +93 -0
- package/src/screens/Automate/index.js +148 -0
- package/src/screens/Device/__test__/detail.test.js +64 -0
- package/src/screens/Device/detail.js +17 -7
- package/src/screens/EditActionsList/index.js +2 -2
- package/src/screens/GuestInfo/__test__/index.test.js +176 -0
- package/src/screens/GuestInfo/components/AccessScheduleItem.js +6 -1
- package/src/screens/GuestInfo/components/AccessScheduleSheet.js +26 -15
- package/src/screens/GuestInfo/components/HeaderGuestInfo.js +6 -1
- package/src/screens/GuestInfo/components/RecurringDetail.js +9 -2
- package/src/screens/GuestInfo/components/TemporaryDetail.js +9 -2
- package/src/screens/GuestInfo/constant.js +2 -2
- package/src/screens/GuestInfo/index.js +4 -5
- package/src/screens/PlayBackCamera/Timer.js +1 -1
- package/src/screens/ScriptDetail/Styles/indexStyles.js +14 -0
- package/src/screens/ScriptDetail/__test__/index.test.js +119 -0
- package/src/screens/ScriptDetail/hooks/index.js +55 -0
- package/src/screens/ScriptDetail/index.js +124 -23
- package/src/screens/SelectUnit/Styles/indexStyles.js +55 -0
- package/src/screens/SelectUnit/__test__/index.test.js +85 -0
- package/src/screens/SelectUnit/index.js +100 -0
- package/src/screens/SetSchedule/__test__/index.test.js +97 -0
- package/src/screens/SetSchedule/components/RepeatOptionsPopup.js +56 -0
- package/src/screens/SetSchedule/components/RowItem.js +27 -0
- package/src/screens/SetSchedule/components/SelectWeekday.js +65 -0
- package/src/screens/SetSchedule/index.js +139 -0
- package/src/screens/SetSchedule/styles/RepeatOptionsPopupStyles.js +22 -0
- package/src/screens/SetSchedule/styles/RowItemStyles.js +29 -0
- package/src/screens/SetSchedule/styles/SelectWeekdayStyles.js +26 -0
- package/src/screens/{AddNewScriptAction/AddNewScriptActionStyles.js → SetSchedule/styles/indexStyles.js} +6 -12
- package/src/screens/Sharing/__test__/MemberList.test.js +21 -28
- package/src/screens/SubUnit/EditSubUnit.js +274 -0
- package/src/screens/SubUnit/EditSubUnitStyles.js +119 -0
- package/src/screens/SubUnit/ManageSubUnit.js +112 -370
- package/src/screens/SubUnit/ManageSubUnitStyles.js +40 -0
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +427 -0
- package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +42 -386
- package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +85 -0
- package/src/screens/SubUnit/hooks/useManageSubUnit.js +35 -0
- package/src/screens/Unit/Detail.js +3 -2
- package/src/screens/Unit/ManageUnit.js +10 -0
- package/src/screens/Unit/components/SearchLocation/__test__/RowLocation.test.js +36 -0
- package/src/screens/Unit/components/__test__/MyUnit.test.js +35 -0
- package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +32 -0
- package/src/screens/UnitSummary/components/__test__/UnitSummary.test.js +67 -0
- package/src/screens/UnitSummary/components/__test__/index.test.js +48 -0
- package/src/screens/UnitSummary/components/index.js +1 -37
- package/src/screens/UnitSummary/components/indexstyles.js +39 -0
- package/src/utils/Apis/axios.js +0 -4
- package/src/utils/I18n/translations/en.json +30 -4
- package/src/utils/I18n/translations/vi.json +29 -3
- package/src/utils/Route/index.js +6 -1
- package/src/utils/__test__/InitData.test.js +20 -0
- package/src/commons/Automate/ItemAddNewScriptAction.js +0 -30
- package/src/screens/AddNewScriptAction/index.js +0 -100
|
@@ -2,6 +2,8 @@ import React, { memo } from 'react';
|
|
|
2
2
|
import { StyleSheet } from 'react-native';
|
|
3
3
|
import { IconOutline } from '@ant-design/icons-react-native';
|
|
4
4
|
import { createStackNavigator } from '@react-navigation/stack';
|
|
5
|
+
import { get } from 'lodash';
|
|
6
|
+
|
|
5
7
|
import { useTranslations } from '../hooks/Common/useTranslations';
|
|
6
8
|
import { Colors, Device } from '../configs';
|
|
7
9
|
import Route from '../utils/Route';
|
|
@@ -22,7 +24,6 @@ import TDSGuide from '../screens/TDSGuide';
|
|
|
22
24
|
import WaterQualityGuide from '../screens/WaterQualityGuide';
|
|
23
25
|
import DeviceInfo from '../screens/DeviceInfo';
|
|
24
26
|
import AddNewOneTap from '../screens/AddNewOneTap';
|
|
25
|
-
import AddNewScriptAction from '../screens/AddNewScriptAction';
|
|
26
27
|
import AddNewAutoSmart from '../screens/AddNewAutoSmart';
|
|
27
28
|
import PlaybackCamera from '../screens/PlayBackCamera';
|
|
28
29
|
import AllCamera from '../screens/AllCamera';
|
|
@@ -30,10 +31,12 @@ import ManageAccessScreen from '../screens/ManageAccess';
|
|
|
30
31
|
import GuestInfo from '../screens/GuestInfo';
|
|
31
32
|
import ScriptDetail from '../screens/ScriptDetail';
|
|
32
33
|
import EditActionsList from '../screens/EditActionsList';
|
|
33
|
-
import
|
|
34
|
+
import SelectUnit from '../screens/SelectUnit';
|
|
35
|
+
import SetSchedule from '../screens/SetSchedule';
|
|
36
|
+
import SelectSensorDevices from '../screens/AddNewAction/SelectSensorDevices';
|
|
34
37
|
import SelectAction from '../screens/AddNewAction/SelectAction';
|
|
35
|
-
|
|
36
|
-
import
|
|
38
|
+
import EditSubUnit from '../screens/SubUnit/EditSubUnit';
|
|
39
|
+
import SetUpSensor from '../screens/AddNewAction/SetupSensor';
|
|
37
40
|
|
|
38
41
|
const Stack = createStackNavigator();
|
|
39
42
|
|
|
@@ -63,7 +66,7 @@ export const UnitStack = memo((props) => {
|
|
|
63
66
|
<Stack.Screen
|
|
64
67
|
name={Route.UnitDetail}
|
|
65
68
|
component={UnitDetail}
|
|
66
|
-
initialParams={
|
|
69
|
+
initialParams={get(props, 'route.params', null)}
|
|
67
70
|
options={{ headerShown: false }}
|
|
68
71
|
/>
|
|
69
72
|
<Stack.Screen
|
|
@@ -101,11 +104,16 @@ export const UnitStack = memo((props) => {
|
|
|
101
104
|
}}
|
|
102
105
|
/>
|
|
103
106
|
<Stack.Screen
|
|
107
|
+
name={Route.ManageSubUnit}
|
|
108
|
+
component={ManageSubUnit}
|
|
109
|
+
options={{ headerShown: false }}
|
|
110
|
+
/>
|
|
111
|
+
<Stack.Screen
|
|
112
|
+
name={Route.EditSubUnit}
|
|
113
|
+
component={EditSubUnit}
|
|
104
114
|
options={{
|
|
105
115
|
headerTitle: '',
|
|
106
116
|
}}
|
|
107
|
-
name={Route.ManageSubUnit}
|
|
108
|
-
component={ManageSubUnit}
|
|
109
117
|
/>
|
|
110
118
|
<Stack.Screen
|
|
111
119
|
name={Route.DeviceDetail}
|
|
@@ -208,6 +216,7 @@ export const UnitStack = memo((props) => {
|
|
|
208
216
|
component={ScriptDetail}
|
|
209
217
|
options={{
|
|
210
218
|
headerShown: false,
|
|
219
|
+
gestureEnabled: false,
|
|
211
220
|
}}
|
|
212
221
|
/>
|
|
213
222
|
<Stack.Screen
|
|
@@ -218,15 +227,18 @@ export const UnitStack = memo((props) => {
|
|
|
218
227
|
}}
|
|
219
228
|
/>
|
|
220
229
|
<Stack.Screen
|
|
221
|
-
name={Route.
|
|
222
|
-
component={
|
|
223
|
-
options={{
|
|
224
|
-
|
|
225
|
-
|
|
230
|
+
name={Route.SelectSensorDevices}
|
|
231
|
+
component={SelectSensorDevices}
|
|
232
|
+
options={{ headerShown: false }}
|
|
233
|
+
/>
|
|
234
|
+
<Stack.Screen
|
|
235
|
+
name={Route.SelectUnit}
|
|
236
|
+
component={SelectUnit}
|
|
237
|
+
options={{ headerShown: false }}
|
|
226
238
|
/>
|
|
227
239
|
<Stack.Screen
|
|
228
|
-
name={Route.
|
|
229
|
-
component={
|
|
240
|
+
name={Route.SetUpSensor}
|
|
241
|
+
component={SetUpSensor}
|
|
230
242
|
options={{ headerShown: false }}
|
|
231
243
|
/>
|
|
232
244
|
<Stack.Screen
|
|
@@ -234,6 +246,13 @@ export const UnitStack = memo((props) => {
|
|
|
234
246
|
component={SelectAction}
|
|
235
247
|
options={{ headerShown: false }}
|
|
236
248
|
/>
|
|
249
|
+
<Stack.Screen
|
|
250
|
+
name={Route.SetSchedule}
|
|
251
|
+
component={SetSchedule}
|
|
252
|
+
options={{
|
|
253
|
+
headerShown: false,
|
|
254
|
+
}}
|
|
255
|
+
/>
|
|
237
256
|
</Stack.Navigator>
|
|
238
257
|
);
|
|
239
258
|
});
|
package/src/navigations/utils.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { CardStyleInterpolators } from '@react-navigation/stack';
|
|
3
|
+
import { StackActions } from '@react-navigation/native';
|
|
2
4
|
|
|
3
5
|
// NavigationContainer is referred here - Check NavigationStack
|
|
4
6
|
export const navigationRef = React.createRef();
|
|
@@ -11,6 +13,12 @@ export function goBack() {
|
|
|
11
13
|
navigationRef.current?.goBack();
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
export const screenOptions = {
|
|
17
|
+
cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const popAction = (value) => StackActions.pop(value);
|
|
21
|
+
|
|
14
22
|
export default {
|
|
15
23
|
navigate,
|
|
16
24
|
goBack,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import ContentLoader, { Rect } from 'react-content-loader/native';
|
|
4
|
+
import { Constants } from '../../../configs';
|
|
5
|
+
|
|
6
|
+
const LoadingSelectAction = ({ style }) => (
|
|
7
|
+
<View style={style}>
|
|
8
|
+
<ContentLoader>
|
|
9
|
+
<Rect x="16" y="40" rx="10" ry="10" width={120} height="20" />
|
|
10
|
+
<Rect
|
|
11
|
+
x="16"
|
|
12
|
+
y="76"
|
|
13
|
+
rx="10"
|
|
14
|
+
ry="10"
|
|
15
|
+
width={Constants.width - 32}
|
|
16
|
+
height="70"
|
|
17
|
+
/>
|
|
18
|
+
<Rect x="16" y="178" rx="10" ry="10" width={120} height="20" />
|
|
19
|
+
<Rect
|
|
20
|
+
x="16"
|
|
21
|
+
y="214"
|
|
22
|
+
rx="10"
|
|
23
|
+
ry="10"
|
|
24
|
+
width={Constants.width - 32}
|
|
25
|
+
height="70"
|
|
26
|
+
/>
|
|
27
|
+
<Rect x="16" y="316" rx="10" ry="10" width={120} height="20" />
|
|
28
|
+
<Rect
|
|
29
|
+
x="16"
|
|
30
|
+
y="352"
|
|
31
|
+
rx="10"
|
|
32
|
+
ry="10"
|
|
33
|
+
width={Constants.width - 32}
|
|
34
|
+
height="70"
|
|
35
|
+
/>
|
|
36
|
+
</ContentLoader>
|
|
37
|
+
</View>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export default LoadingSelectAction;
|
|
@@ -1,55 +1,80 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
3
|
-
useCallback,
|
|
4
|
-
useEffect,
|
|
5
|
-
useState,
|
|
6
|
-
useContext,
|
|
7
|
-
} from 'react';
|
|
8
|
-
import { ScrollView, View } from 'react-native';
|
|
1
|
+
import React, { memo, useCallback, useEffect, useState, useMemo } from 'react';
|
|
2
|
+
import { Image, TouchableOpacity, View } from 'react-native';
|
|
9
3
|
import { useNavigation } from '@react-navigation/native';
|
|
4
|
+
import { Icon } from '@ant-design/react-native';
|
|
10
5
|
|
|
11
6
|
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
12
|
-
import { SCContext } from '../../context';
|
|
13
|
-
import { Action } from '../../context/actionType';
|
|
14
|
-
import { HeaderCustom } from '../../commons/Header';
|
|
15
7
|
import BottomButtonView from '../../commons/BottomButtonView';
|
|
16
8
|
import Text from '../../commons/Text';
|
|
17
9
|
import ActionTemplate from '../../commons/ActionTemplate';
|
|
18
10
|
import { axiosGet, axiosPost } from '../../utils/Apis/axios';
|
|
19
|
-
import { API } from '../../configs';
|
|
11
|
+
import { API, Images } from '../../configs';
|
|
20
12
|
import { TESTID } from '../../configs/Constants';
|
|
21
13
|
import Routes from '../../utils/Route';
|
|
22
14
|
import styles from './Styles/SelectActionStyles';
|
|
23
15
|
import moment from 'moment';
|
|
16
|
+
import { Colors } from '../../configs';
|
|
17
|
+
import { TitleCheckBox } from '../Sharing/Components';
|
|
18
|
+
import WrapHeaderScrollable from '../../commons/Sharing/WrapHeaderScrollable';
|
|
19
|
+
import { popAction } from '../../navigations/utils';
|
|
20
|
+
import { LoadingSelectAction } from './Components';
|
|
24
21
|
|
|
25
22
|
const SelectAction = memo(({ route }) => {
|
|
26
23
|
const t = useTranslations();
|
|
27
|
-
const { navigate } = useNavigation();
|
|
28
|
-
const {
|
|
29
|
-
|
|
24
|
+
const { navigate, dispatch } = useNavigation();
|
|
25
|
+
const {
|
|
26
|
+
unit,
|
|
27
|
+
device,
|
|
28
|
+
automateId,
|
|
29
|
+
scriptName,
|
|
30
|
+
isScript = false,
|
|
31
|
+
type,
|
|
32
|
+
} = route.params;
|
|
30
33
|
const [data, setData] = useState([]);
|
|
31
34
|
const [actions, setActions] = useState({
|
|
32
35
|
name: '',
|
|
33
36
|
action: '',
|
|
34
37
|
});
|
|
38
|
+
const [sensorData, setSensorData] = useState([]);
|
|
39
|
+
const [checkedItem, setCheckedItem] = useState({});
|
|
40
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
35
41
|
|
|
36
42
|
const fetchData = useCallback(async () => {
|
|
43
|
+
setIsLoading(true);
|
|
37
44
|
const { success, data } = await axiosGet(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
isScript
|
|
46
|
+
? API.AUTOMATE.GET_SENSOR_CONFIG(device.id)
|
|
47
|
+
: API.SENSOR.DISPLAY_ACTIONS(device.id),
|
|
48
|
+
isScript && {},
|
|
49
|
+
isScript && true
|
|
41
50
|
);
|
|
42
51
|
if (success) {
|
|
43
|
-
setData(data);
|
|
52
|
+
isScript ? setSensorData(data) : setData(data);
|
|
44
53
|
}
|
|
45
|
-
|
|
54
|
+
const to = setTimeout(() => {
|
|
55
|
+
setIsLoading(false);
|
|
56
|
+
clearTimeout(to);
|
|
57
|
+
}, 1000);
|
|
58
|
+
}, [device.id, isScript]);
|
|
46
59
|
|
|
47
60
|
const onSave = useCallback(async () => {
|
|
48
|
-
if (
|
|
61
|
+
if (isScript) {
|
|
62
|
+
const itemTemp = sensorData.find((i) => i.id === checkedItem?.id);
|
|
63
|
+
navigate(Routes.AddNewOneTap, {
|
|
64
|
+
automateData: {
|
|
65
|
+
condition: itemTemp?.conditionValue || '<',
|
|
66
|
+
value: itemTemp?.value,
|
|
67
|
+
config: itemTemp?.id,
|
|
68
|
+
},
|
|
69
|
+
type,
|
|
70
|
+
unit,
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
49
73
|
const { success } = await axiosPost(
|
|
50
74
|
API.AUTOMATE.ADD_SCRIPT_ACTION(automateId),
|
|
51
75
|
{
|
|
52
76
|
action: actions.action,
|
|
77
|
+
unit: unit.id,
|
|
53
78
|
}
|
|
54
79
|
);
|
|
55
80
|
if (success) {
|
|
@@ -59,44 +84,52 @@ const SelectAction = memo(({ route }) => {
|
|
|
59
84
|
havePermission: true,
|
|
60
85
|
unit,
|
|
61
86
|
dateNow: moment().valueOf(), // TODO will remove dateNow later
|
|
87
|
+
type: type,
|
|
62
88
|
});
|
|
63
89
|
}
|
|
64
|
-
} else {
|
|
65
|
-
setAction(Action.LIST_ACTION, {
|
|
66
|
-
action: actions.action,
|
|
67
|
-
unit_name: unit.name,
|
|
68
|
-
action_name: actions.name,
|
|
69
|
-
sensor_name: device.name,
|
|
70
|
-
sensor_icon_kit: device.icon_kit,
|
|
71
|
-
station_name: stationName,
|
|
72
|
-
});
|
|
73
|
-
navigate(Routes.AddNewScriptAction, {
|
|
74
|
-
automateType: 'one-tap',
|
|
75
|
-
name: scriptName,
|
|
76
|
-
unit,
|
|
77
|
-
});
|
|
78
90
|
}
|
|
79
91
|
}, [
|
|
80
92
|
actions.action,
|
|
81
|
-
actions.name,
|
|
82
93
|
automateId,
|
|
83
|
-
device.icon_kit,
|
|
84
|
-
device.name,
|
|
85
94
|
navigate,
|
|
86
95
|
scriptName,
|
|
87
|
-
|
|
88
|
-
stationName,
|
|
96
|
+
type,
|
|
89
97
|
unit,
|
|
98
|
+
isScript,
|
|
99
|
+
checkedItem,
|
|
100
|
+
sensorData,
|
|
90
101
|
]);
|
|
91
102
|
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
fetchData();
|
|
94
|
-
}, [fetchData]);
|
|
95
|
-
|
|
96
103
|
const handleOnSelectAction = (action) => {
|
|
97
104
|
setActions({ ...action });
|
|
98
105
|
};
|
|
99
106
|
|
|
107
|
+
const handleClose = useCallback(() => {
|
|
108
|
+
isScript ? dispatch(popAction(3)) : alert(t('feature_under_development'));
|
|
109
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
110
|
+
}, [isScript, t]);
|
|
111
|
+
|
|
112
|
+
const onChecked = useCallback(
|
|
113
|
+
(_, isChecked, id) => {
|
|
114
|
+
setCheckedItem(isChecked ? sensorData.find((i) => i?.id === id) : {});
|
|
115
|
+
},
|
|
116
|
+
[sensorData]
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const onPressItem = (item) => () => {
|
|
120
|
+
navigate(Routes.SetUpSensor, { item, sensorData, setSensorData });
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const rightComponent = useMemo(
|
|
124
|
+
() => (
|
|
125
|
+
<TouchableOpacity style={styles.closeButton} onPress={handleClose}>
|
|
126
|
+
<Icon name={'close'} size={24} color={Colors.Black} />
|
|
127
|
+
</TouchableOpacity>
|
|
128
|
+
),
|
|
129
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
130
|
+
[]
|
|
131
|
+
);
|
|
132
|
+
|
|
100
133
|
const RenderActionItem = ({ data }) => {
|
|
101
134
|
const actionTemplate = [];
|
|
102
135
|
|
|
@@ -123,28 +156,80 @@ const SelectAction = memo(({ route }) => {
|
|
|
123
156
|
);
|
|
124
157
|
};
|
|
125
158
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
<HeaderCustom isShowClose />
|
|
129
|
-
<ScrollView
|
|
130
|
-
style={styles.wrap}
|
|
131
|
-
contentContainerStyle={styles.contentContainerStyle}
|
|
132
|
-
>
|
|
133
|
-
<Text bold type="H2" style={styles.title}>
|
|
134
|
-
{t('set_up {name}', {
|
|
135
|
-
name: device.name,
|
|
136
|
-
})}
|
|
137
|
-
</Text>
|
|
138
|
-
|
|
139
|
-
<RenderActionItem data={data} testID={TESTID.ACTION_ITEM} />
|
|
140
|
-
</ScrollView>
|
|
141
|
-
|
|
159
|
+
const renderBottomButtonView = useMemo(
|
|
160
|
+
() => (
|
|
142
161
|
<BottomButtonView
|
|
143
162
|
style={styles.bottomButtonView}
|
|
144
|
-
mainTitle={t('save')}
|
|
163
|
+
mainTitle={t(isScript ? 'continue' : 'save')}
|
|
145
164
|
onPressMain={onSave}
|
|
146
|
-
typeMain={actions?.action ? 'primary' : 'disabled'}
|
|
165
|
+
typeMain={actions?.action || !!checkedItem?.id ? 'primary' : 'disabled'}
|
|
147
166
|
/>
|
|
167
|
+
),
|
|
168
|
+
[onSave, actions, checkedItem, isScript, t]
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
fetchData();
|
|
173
|
+
}, [fetchData]);
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<View style={styles.wrap}>
|
|
177
|
+
<WrapHeaderScrollable
|
|
178
|
+
title={t('set_up {name}', { name: device?.name })}
|
|
179
|
+
headerAniStyle={styles.headerAniStyle}
|
|
180
|
+
rightComponent={rightComponent}
|
|
181
|
+
>
|
|
182
|
+
{isScript ? (
|
|
183
|
+
isLoading ? (
|
|
184
|
+
<LoadingSelectAction style={styles.container} />
|
|
185
|
+
) : (
|
|
186
|
+
sensorData.map((item) => {
|
|
187
|
+
const isHasValue = !!item?.value;
|
|
188
|
+
return (
|
|
189
|
+
<View style={styles.wrapItem} key={item?.id}>
|
|
190
|
+
<TitleCheckBox
|
|
191
|
+
onPress={onChecked}
|
|
192
|
+
id={item?.id}
|
|
193
|
+
title={item?.name}
|
|
194
|
+
titleStyle={styles.titleStyle}
|
|
195
|
+
wrapStyle={styles.wrapStyleCheckBox}
|
|
196
|
+
isChecked={checkedItem?.id === item?.id}
|
|
197
|
+
/>
|
|
198
|
+
<TouchableOpacity
|
|
199
|
+
onPress={onPressItem(item)}
|
|
200
|
+
style={[styles.wrapCondition, styles.shadowView]}
|
|
201
|
+
>
|
|
202
|
+
<Text type="Body" color={Colors.Gray7}>
|
|
203
|
+
{t('condition')}
|
|
204
|
+
</Text>
|
|
205
|
+
<Text
|
|
206
|
+
numberOfLines={1}
|
|
207
|
+
type="H4"
|
|
208
|
+
semibold={isHasValue}
|
|
209
|
+
style={styles.description}
|
|
210
|
+
>
|
|
211
|
+
{isHasValue
|
|
212
|
+
? `${item?.name} ${
|
|
213
|
+
item?.title ? item.title : t('is_below') + ' (<)'
|
|
214
|
+
} ${item.value} ${item?.unit}`
|
|
215
|
+
: `${t('no')} ${t('condition')}`}
|
|
216
|
+
</Text>
|
|
217
|
+
{isHasValue && (
|
|
218
|
+
<Image
|
|
219
|
+
source={Images.arrowBack}
|
|
220
|
+
style={styles.arrowRight}
|
|
221
|
+
/>
|
|
222
|
+
)}
|
|
223
|
+
</TouchableOpacity>
|
|
224
|
+
</View>
|
|
225
|
+
);
|
|
226
|
+
})
|
|
227
|
+
)
|
|
228
|
+
) : (
|
|
229
|
+
<RenderActionItem data={data} testID={TESTID.ACTION_ITEM} />
|
|
230
|
+
)}
|
|
231
|
+
</WrapHeaderScrollable>
|
|
232
|
+
{renderBottomButtonView}
|
|
148
233
|
</View>
|
|
149
234
|
);
|
|
150
235
|
});
|
|
@@ -11,18 +11,27 @@ import Device from './Device';
|
|
|
11
11
|
import BottomButtonView from '../../commons/BottomButtonView';
|
|
12
12
|
import { HeaderCustom } from '../../commons/Header';
|
|
13
13
|
import Routes from '../../utils/Route';
|
|
14
|
-
import styles from './Styles/
|
|
14
|
+
import styles from './Styles/SelectSensorDevicesStyles';
|
|
15
|
+
import { AUTOMATE_SELECT } from '../../configs/Constants';
|
|
16
|
+
import { popAction } from '../../navigations/utils';
|
|
15
17
|
|
|
16
|
-
const
|
|
18
|
+
const SelectSensorDevices = memo(({ route }) => {
|
|
17
19
|
const t = useTranslations();
|
|
18
|
-
const {
|
|
20
|
+
const {
|
|
21
|
+
unit,
|
|
22
|
+
automateId,
|
|
23
|
+
title = AUTOMATE_SELECT.SELECT_DEVICES,
|
|
24
|
+
type,
|
|
25
|
+
isScript,
|
|
26
|
+
scriptName,
|
|
27
|
+
} = route.params;
|
|
19
28
|
|
|
20
29
|
const [listStation, setListStation] = useState([]);
|
|
21
30
|
const [listMenuItem, setListMenuItem] = useState([]);
|
|
22
31
|
const [indexStation, setIndexStation] = useState(0);
|
|
23
32
|
const [station, setStation] = useState([]);
|
|
24
33
|
const [selectedDevice, setSelectedDevice] = useState();
|
|
25
|
-
const { navigate } = useNavigation();
|
|
34
|
+
const { navigate, dispatch } = useNavigation();
|
|
26
35
|
|
|
27
36
|
const onSnapToItem = useCallback(
|
|
28
37
|
(item, index) => {
|
|
@@ -33,9 +42,13 @@ const SelectDevice = memo(({ route }) => {
|
|
|
33
42
|
);
|
|
34
43
|
|
|
35
44
|
const fetchDetails = useCallback(async () => {
|
|
36
|
-
|
|
45
|
+
let callAPI = API.UNIT.DEVICE_CONTROL(unit.id);
|
|
46
|
+
if (title === AUTOMATE_SELECT.SELECT_SENSOR) {
|
|
47
|
+
// TODO will update API later
|
|
48
|
+
callAPI = API.UNIT.DEVICE_CONTROL(unit.id);
|
|
49
|
+
}
|
|
50
|
+
await fetchWithCache(callAPI, {}, (response) => {
|
|
37
51
|
const { success, data } = response;
|
|
38
|
-
|
|
39
52
|
if (success) {
|
|
40
53
|
const listMenu = data.map((item, index) => ({
|
|
41
54
|
text: item.name,
|
|
@@ -47,7 +60,7 @@ const SelectDevice = memo(({ route }) => {
|
|
|
47
60
|
setListStation(listMenu.concat([{ text: '' }]));
|
|
48
61
|
}
|
|
49
62
|
});
|
|
50
|
-
}, [unit.id]);
|
|
63
|
+
}, [title, unit.id]);
|
|
51
64
|
|
|
52
65
|
useEffect(() => {
|
|
53
66
|
fetchDetails();
|
|
@@ -61,26 +74,43 @@ const SelectDevice = memo(({ route }) => {
|
|
|
61
74
|
}
|
|
62
75
|
};
|
|
63
76
|
|
|
64
|
-
const onPressContinue = () => {
|
|
77
|
+
const onPressContinue = useCallback(() => {
|
|
65
78
|
navigate(Routes.SelectAction, {
|
|
66
79
|
unit,
|
|
67
80
|
device: selectedDevice,
|
|
68
81
|
automateId: automateId,
|
|
69
82
|
stationName: station[indexStation]?.name,
|
|
83
|
+
isScript,
|
|
84
|
+
type,
|
|
70
85
|
scriptName,
|
|
71
86
|
});
|
|
72
|
-
}
|
|
87
|
+
}, [
|
|
88
|
+
selectedDevice,
|
|
89
|
+
automateId,
|
|
90
|
+
station,
|
|
91
|
+
indexStation,
|
|
92
|
+
navigate,
|
|
93
|
+
unit,
|
|
94
|
+
type,
|
|
95
|
+
isScript,
|
|
96
|
+
scriptName,
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
const onClose = useCallback(() => {
|
|
100
|
+
isScript ? dispatch(popAction(2)) : alert(t('feature_under_development'));
|
|
101
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
102
|
+
}, [isScript]);
|
|
73
103
|
|
|
74
104
|
return (
|
|
75
105
|
<View style={styles.wrap}>
|
|
76
|
-
<HeaderCustom isShowClose />
|
|
106
|
+
<HeaderCustom isShowClose onClose={onClose} />
|
|
77
107
|
|
|
78
108
|
<ScrollView
|
|
79
109
|
style={styles.wrap}
|
|
80
110
|
contentContainerStyle={styles.contentContainerStyle}
|
|
81
111
|
>
|
|
82
112
|
<Text bold type="H2" style={styles.title}>
|
|
83
|
-
{t(
|
|
113
|
+
{t(title)}
|
|
84
114
|
</Text>
|
|
85
115
|
|
|
86
116
|
<NavBar
|
|
@@ -117,4 +147,4 @@ const SelectDevice = memo(({ route }) => {
|
|
|
117
147
|
);
|
|
118
148
|
});
|
|
119
149
|
|
|
120
|
-
export default
|
|
150
|
+
export default SelectSensorDevices;
|