@eohjsc/react-native-smart-city 0.7.3-rc16 → 0.7.3-rc18
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/package.json +1 -1
- package/src/commons/ActionGroup/SliderRangeTemplate.js +7 -7
- package/src/commons/Automate/ItemAutomate.js +8 -7
- package/src/commons/SubUnit/OneTap/ItemOneTap.js +1 -2
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +0 -2
- package/src/navigations/EmergencyContactsStack.js +0 -1
- package/src/navigations/UnitStack.js +49 -56
- package/src/screens/AddNewGateway/SelectDeviceType.js +1 -1
- package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +1 -1
- package/src/screens/Automate/Components/InputName.js +10 -7
- package/src/screens/Automate/MultiUnits.js +19 -22
- package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +2 -1
- package/src/screens/Automate/ScriptDetail/index.js +27 -17
- package/src/screens/Automate/__test__/MultiUnits.test.js +1 -4
- package/src/screens/Automate/__test__/index.test.js +0 -1
- package/src/screens/Automate/index.js +0 -1
- package/src/screens/Device/hooks/useEvaluateValue.js +1 -1
- package/src/screens/Notification/components/NotificationItem.js +1 -1
- package/src/screens/SelectUnit/__test__/index.test.js +1 -1
- package/src/screens/SelectUnit/index.js +1 -1
package/package.json
CHANGED
|
@@ -48,18 +48,20 @@ const SliderRangeTemplate = memo(
|
|
|
48
48
|
clearTimeout(timeout.current);
|
|
49
49
|
if (value) {
|
|
50
50
|
const data = parseInt(value, 10);
|
|
51
|
+
const numericValue = Math.min(max_value, Math.max(min_value, data));
|
|
52
|
+
setValue(numericValue);
|
|
51
53
|
await doAction(
|
|
52
54
|
action_data,
|
|
53
55
|
JSON.stringify({
|
|
54
|
-
value_brness:
|
|
55
|
-
value:
|
|
56
|
+
value_brness: numericValue,
|
|
57
|
+
value: numericValue,
|
|
56
58
|
})
|
|
57
59
|
);
|
|
58
60
|
}
|
|
59
61
|
timeout.current = setTimeout(() => {
|
|
60
62
|
setProcessing(false);
|
|
61
63
|
}, 3000);
|
|
62
|
-
}, [action_data, doAction, value]);
|
|
64
|
+
}, [action_data, doAction, max_value, min_value, value]);
|
|
63
65
|
|
|
64
66
|
useEffect(() => {
|
|
65
67
|
if (!processing) {
|
|
@@ -72,12 +74,10 @@ const SliderRangeTemplate = memo(
|
|
|
72
74
|
|
|
73
75
|
const onInputChange = (text) => {
|
|
74
76
|
if (text === '' || isNaN(text)) {
|
|
75
|
-
setValue(
|
|
77
|
+
setValue(0);
|
|
76
78
|
return;
|
|
77
79
|
}
|
|
78
|
-
|
|
79
|
-
const numericValue = Number(text);
|
|
80
|
-
setValue(Math.min(max_value, Math.max(min_value, numericValue)));
|
|
80
|
+
setValue(Number(text));
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
return (
|
|
@@ -18,10 +18,11 @@ const ItemAutomate = ({
|
|
|
18
18
|
enableScript = true,
|
|
19
19
|
}) => {
|
|
20
20
|
const t = useTranslations();
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const Icon = item
|
|
24
|
-
const
|
|
21
|
+
const { type, config, unit } = automate;
|
|
22
|
+
const item = AUTOMATES[type];
|
|
23
|
+
const { icon: Icon, title, explanation } = item || {};
|
|
24
|
+
const isItemOneTap = AUTOMATES[type] === AUTOMATES.one_tap;
|
|
25
|
+
const valueEvaluations = useGetEvaluateValue(config, unit);
|
|
25
26
|
|
|
26
27
|
const textCondition = useMemo(() => {
|
|
27
28
|
return generateAutomationConditionText(automate, valueEvaluations, t);
|
|
@@ -33,9 +34,9 @@ const ItemAutomate = ({
|
|
|
33
34
|
} else if (isSelected && isItemOneTap) {
|
|
34
35
|
return t('quick_button_create_at_dashboard');
|
|
35
36
|
} else {
|
|
36
|
-
return t(
|
|
37
|
+
return t(explanation);
|
|
37
38
|
}
|
|
38
|
-
}, [isItemOneTap, isSelected,
|
|
39
|
+
}, [isItemOneTap, isSelected, explanation, t, textCondition]);
|
|
39
40
|
|
|
40
41
|
const handleSelectIndex = useCallback(() => {
|
|
41
42
|
if (onPress) {
|
|
@@ -63,7 +64,7 @@ const ItemAutomate = ({
|
|
|
63
64
|
bold
|
|
64
65
|
color={enableScript ? Colors.Black : Colors.Gray7}
|
|
65
66
|
>
|
|
66
|
-
{t(
|
|
67
|
+
{t(title)}
|
|
67
68
|
</Text>
|
|
68
69
|
<Text type="Label" color={Colors.Gray8} numberOfLines={1}>
|
|
69
70
|
{renderText}
|
|
@@ -27,10 +27,9 @@ const ItemOneTap = memo(({ automate = {}, wrapSyles, onPressItem }) => {
|
|
|
27
27
|
|
|
28
28
|
const goToDetail = useCallback(() => {
|
|
29
29
|
navigate(Routes.ScriptDetail, {
|
|
30
|
-
id,
|
|
31
30
|
preAutomate: automate,
|
|
32
31
|
});
|
|
33
|
-
}, [automate, navigate
|
|
32
|
+
}, [automate, navigate]);
|
|
34
33
|
|
|
35
34
|
const handleScriptAction = useCallback(async () => {
|
|
36
35
|
const { success } = await axiosPost(API.AUTOMATE.ACTION_ONE_TAP(id));
|
|
@@ -107,7 +107,6 @@ describe('test Item', () => {
|
|
|
107
107
|
await goDetail[0].props.onPress();
|
|
108
108
|
});
|
|
109
109
|
expect(global.mockedNavigate).toHaveBeenCalledWith(Routes.ScriptDetail, {
|
|
110
|
-
id: 1,
|
|
111
110
|
preAutomate: data.listAutomate[0].data[0],
|
|
112
111
|
});
|
|
113
112
|
|
|
@@ -194,7 +193,6 @@ describe('test Item', () => {
|
|
|
194
193
|
await goDetail[0].props.onPress();
|
|
195
194
|
});
|
|
196
195
|
expect(global.mockedNavigate).toHaveBeenCalledWith(Routes.ScriptDetail, {
|
|
197
|
-
id: 1,
|
|
198
196
|
preAutomate: data.listAutomate[0].data[0],
|
|
199
197
|
});
|
|
200
198
|
});
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import React, { memo, useContext, useEffect } from 'react';
|
|
2
|
-
import { AppState, View } from 'react-native';
|
|
3
1
|
import { IconOutline } from '@ant-design/icons-react-native';
|
|
4
|
-
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
|
5
|
-
import { BleManager } from 'react-native-ble-plx';
|
|
6
2
|
import NetInfo from '@react-native-community/netinfo';
|
|
3
|
+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
|
7
4
|
import { get } from 'lodash';
|
|
5
|
+
import React, { memo, useContext, useEffect } from 'react';
|
|
6
|
+
import { AppState, View } from 'react-native';
|
|
7
|
+
import { BleManager } from 'react-native-ble-plx';
|
|
8
8
|
|
|
9
9
|
import Text from '../commons/Text';
|
|
10
|
+
import { API, Colors, Device } from '../configs';
|
|
11
|
+
import { SCContext } from '../context';
|
|
12
|
+
import { Action } from '../context/actionType';
|
|
10
13
|
import { useTranslations } from '../hooks/Common/useTranslations';
|
|
11
14
|
import { unwatchAllConfigs } from '../iot/Monitor';
|
|
12
|
-
import { API, Colors, Device } from '../configs';
|
|
13
|
-
import Route from '../utils/Route';
|
|
14
15
|
import ActivityLogScreen from '../screens/ActivityLog';
|
|
16
|
+
import Route from '../utils/Route';
|
|
15
17
|
import { screenOptions } from './utils';
|
|
16
|
-
import { SCContext } from '../context';
|
|
17
|
-
import { Action } from '../context/actionType';
|
|
18
18
|
|
|
19
|
+
import { useBluetoothConnection } from '../hooks/IoT';
|
|
20
|
+
import { realScanBluetoothDevices } from '../iot/RemoteControl/Bluetooth';
|
|
21
|
+
import AllCamera from '../screens/AllCamera';
|
|
22
|
+
import AllGateway from '../screens/AllGateway';
|
|
19
23
|
import AQIGuide from '../screens/AQIGuide';
|
|
20
|
-
import
|
|
24
|
+
import ChooseAction from '../screens/Automate/AddNewAction/ChooseAction';
|
|
25
|
+
import ChooseConfig from '../screens/Automate/AddNewAction/ChooseConfig';
|
|
26
|
+
import SelectControlDevices from '../screens/Automate/AddNewAction/SelectControlDevices';
|
|
27
|
+
import SelectMonitorDevices from '../screens/Automate/AddNewAction/SelectMonitorDevices';
|
|
28
|
+
import SetupConfigCondition from '../screens/Automate/AddNewAction/SetupConfigCondition';
|
|
29
|
+
import SetupScriptDelay from '../screens/Automate/AddNewAction/SetupScriptDelay';
|
|
30
|
+
import SetupScriptNotify from '../screens/Automate/AddNewAction/SetupScriptNotify';
|
|
31
|
+
import AddAutomationTypeSmart from '../screens/Automate/AddNewAutoSmart/AddAutomationTypeSmart';
|
|
32
|
+
import AddUnknownTypeSmart from '../screens/Automate/AddNewAutoSmart/AddUnknownTypeSmart';
|
|
33
|
+
import EditActionsList from '../screens/Automate/EditActionsList';
|
|
34
|
+
import UpdateActionScript from '../screens/Automate/EditActionsList/UpdateActionScript';
|
|
35
|
+
import AddNewOneTap from '../screens/Automate/OneTap';
|
|
36
|
+
import ScenarioName from '../screens/Automate/Scenario/ScenarioName';
|
|
37
|
+
import ScriptDetail from '../screens/Automate/ScriptDetail';
|
|
38
|
+
import SetSchedule from '../screens/Automate/SetSchedule';
|
|
39
|
+
import ValueChangeName from '../screens/Automate/ValueChange/ValueChangeName';
|
|
21
40
|
import ChangePosition from '../screens/ChangePosition';
|
|
41
|
+
import ConfirmUnitDeletion from '../screens/ConfirmUnitDeletion';
|
|
42
|
+
import DeviceDetail from '../screens/Device/detail';
|
|
43
|
+
import EditDevice from '../screens/Device/EditDevice/index';
|
|
44
|
+
import DeviceInfo from '../screens/DeviceInfo';
|
|
45
|
+
import EmergencySetting from '../screens/EmergencySetting';
|
|
46
|
+
import EnterPassword from '../screens/EnterPassword';
|
|
47
|
+
import GuestInfo from '../screens/GuestInfo';
|
|
48
|
+
import ManageAccessScreen from '../screens/ManageAccess';
|
|
49
|
+
import MoveToAnotherSubUnit from '../screens/MoveToAnotherSubUnit';
|
|
50
|
+
import PlaybackCamera from '../screens/PlayBackCamera';
|
|
51
|
+
import SelectUnit from '../screens/SelectUnit';
|
|
52
|
+
import InfoMemberUnit from '../screens/Sharing/InfoMemberUnit';
|
|
22
53
|
import UnitMemberList from '../screens/Sharing/UnitMemberList';
|
|
54
|
+
import SideMenuDetail from '../screens/SideMenuDetail';
|
|
55
|
+
import EditSubUnit from '../screens/SubUnit/EditSubUnit';
|
|
23
56
|
import ManageSubUnit from '../screens/SubUnit/ManageSubUnit';
|
|
24
|
-
import
|
|
57
|
+
import TDSGuide from '../screens/TDSGuide';
|
|
25
58
|
import ChooseLocation from '../screens/Unit/ChooseLocation';
|
|
59
|
+
import UnitDetail from '../screens/Unit/Detail';
|
|
26
60
|
import ManageUnit from '../screens/Unit/ManageUnit';
|
|
61
|
+
import SelectAddress from '../screens/Unit/SelectAddress';
|
|
62
|
+
import SelectAddToFavorites from '../screens/Unit/SelectAddToFavorites';
|
|
27
63
|
import ListSmartAccount from '../screens/Unit/SmartAccount';
|
|
28
|
-
import UnitDetail from '../screens/Unit/Detail';
|
|
29
64
|
import UnitSummary from '../screens/UnitSummary';
|
|
30
65
|
import UVIndexGuide from '../screens/UVIndexGuide';
|
|
31
|
-
import TDSGuide from '../screens/TDSGuide';
|
|
32
66
|
import WaterQualityGuide from '../screens/WaterQualityGuide';
|
|
33
|
-
import DeviceInfo from '../screens/DeviceInfo';
|
|
34
|
-
import AddNewOneTap from '../screens/Automate/OneTap';
|
|
35
|
-
import AddUnknownTypeSmart from '../screens/Automate/AddNewAutoSmart/AddUnknownTypeSmart';
|
|
36
|
-
import PlaybackCamera from '../screens/PlayBackCamera';
|
|
37
|
-
import AllCamera from '../screens/AllCamera';
|
|
38
|
-
import ManageAccessScreen from '../screens/ManageAccess';
|
|
39
|
-
import MoveToAnotherSubUnit from '../screens/MoveToAnotherSubUnit';
|
|
40
|
-
import GuestInfo from '../screens/GuestInfo';
|
|
41
|
-
import ScriptDetail from '../screens/Automate/ScriptDetail';
|
|
42
|
-
import EditActionsList from '../screens/Automate/EditActionsList';
|
|
43
|
-
import SelectUnit from '../screens/SelectUnit';
|
|
44
|
-
import SetSchedule from '../screens/Automate/SetSchedule';
|
|
45
|
-
import SelectMonitorDevices from '../screens/Automate/AddNewAction/SelectMonitorDevices';
|
|
46
|
-
import EditSubUnit from '../screens/SubUnit/EditSubUnit';
|
|
47
|
-
import SetupConfigCondition from '../screens/Automate/AddNewAction/SetupConfigCondition';
|
|
48
|
-
import EditDevice from '../screens/Device/EditDevice/index';
|
|
49
|
-
import EmergencySetting from '../screens/EmergencySetting';
|
|
50
|
-
import ConfirmUnitDeletion from '../screens/ConfirmUnitDeletion';
|
|
51
|
-
import InfoMemberUnit from '../screens/Sharing/InfoMemberUnit';
|
|
52
|
-
import EnterPassword from '../screens/EnterPassword';
|
|
53
|
-
import AllGateway from '../screens/AllGateway';
|
|
54
|
-
import SelectAddToFavorites from '../screens/Unit/SelectAddToFavorites';
|
|
55
|
-
import { HanetCameraStack } from './HanetCameraStack';
|
|
56
67
|
import { axiosGet, fetchWithCache } from '../utils/Apis/axios';
|
|
57
|
-
import SideMenuDetail from '../screens/SideMenuDetail';
|
|
58
|
-
import { styles } from './UnitStackStyles';
|
|
59
|
-
import { useBluetoothConnection } from '../hooks/IoT';
|
|
60
|
-
import { realScanBluetoothDevices } from '../iot/RemoteControl/Bluetooth';
|
|
61
68
|
import { ToastBottomHelper } from '../utils/Utils';
|
|
62
|
-
import
|
|
63
|
-
import
|
|
64
|
-
import ChooseAction from '../screens/Automate/AddNewAction/ChooseAction';
|
|
65
|
-
import ScenarioName from '../screens/Automate/Scenario/ScenarioName';
|
|
66
|
-
import ValueChangeName from '../screens/Automate/ValueChange/ValueChangeName';
|
|
67
|
-
import AddAutomationTypeSmart from '../screens/Automate/AddNewAutoSmart/AddAutomationTypeSmart';
|
|
68
|
-
import SetupScriptNotify from '../screens/Automate/AddNewAction/SetupScriptNotify';
|
|
69
|
-
import SetupScriptDelay from '../screens/Automate/AddNewAction/SetupScriptDelay';
|
|
70
|
-
import UpdateActionScript from '../screens/Automate/EditActionsList/UpdateActionScript';
|
|
69
|
+
import { HanetCameraStack } from './HanetCameraStack';
|
|
70
|
+
import { styles } from './UnitStackStyles';
|
|
71
71
|
|
|
72
72
|
const Stack = createNativeStackNavigator();
|
|
73
73
|
|
|
@@ -186,7 +186,6 @@ export const UnitStack = memo((props) => {
|
|
|
186
186
|
borderBottomWidth: Device.isIOS === 'android' ? 1 : 0,
|
|
187
187
|
borderColor: Colors.Gray4,
|
|
188
188
|
},
|
|
189
|
-
headerBackTitle: true,
|
|
190
189
|
}}
|
|
191
190
|
>
|
|
192
191
|
<Stack.Screen
|
|
@@ -296,13 +295,7 @@ export const UnitStack = memo((props) => {
|
|
|
296
295
|
title: t('tds_information'),
|
|
297
296
|
}}
|
|
298
297
|
/>
|
|
299
|
-
<Stack.Screen
|
|
300
|
-
name={Route.AQIGuide}
|
|
301
|
-
component={AQIGuide}
|
|
302
|
-
options={{
|
|
303
|
-
title: t('AQI Guide'),
|
|
304
|
-
}}
|
|
305
|
-
/>
|
|
298
|
+
<Stack.Screen name={Route.AQIGuide} component={AQIGuide} />
|
|
306
299
|
<Stack.Screen
|
|
307
300
|
name={Route.WaterQualityGuide}
|
|
308
301
|
component={WaterQualityGuide}
|
|
@@ -192,7 +192,7 @@ const SelectDeviceType = ({ route }) => {
|
|
|
192
192
|
useEffect(() => {
|
|
193
193
|
const fetchCountSummary = async () => {
|
|
194
194
|
const { success, data } = await axiosGet(API.DEV_MODE.GATEWAY.COUNT(), {
|
|
195
|
-
unit: unit?.id,
|
|
195
|
+
params: { unit: unit?.id },
|
|
196
196
|
});
|
|
197
197
|
if (success) {
|
|
198
198
|
setUnitCountSummary(data);
|
|
@@ -31,7 +31,7 @@ const AddTypeSmart = ({ smartTypes, route }) => {
|
|
|
31
31
|
closeScreen: closeScreen,
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
if (!unit && dataAutomate.type
|
|
34
|
+
if (!unit && dataAutomate.type === AUTOMATE_TYPE.VALUE_CHANGE) {
|
|
35
35
|
navigate(Routes.SelectUnit, params);
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
@@ -9,12 +9,14 @@ import styles from './InputNameStyles';
|
|
|
9
9
|
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
10
10
|
import { axiosPost, axiosPut } from '../../../utils/Apis/axios';
|
|
11
11
|
import NewActionWrapper from '../../Automate/AddNewAction/NewActionWrapper';
|
|
12
|
+
import Routes from '../../../utils/Route';
|
|
12
13
|
|
|
13
14
|
const InputName = ({ title, placeholder }) => {
|
|
14
|
-
const { automate, closeScreen } = useRoute().params;
|
|
15
|
+
const { automate = {}, closeScreen } = useRoute().params;
|
|
16
|
+
const { id: automateNameId, name: automateName } = automate;
|
|
15
17
|
const t = useTranslations();
|
|
16
18
|
const { navigate } = useNavigation();
|
|
17
|
-
const [name, setName] = useState(
|
|
19
|
+
const [name, setName] = useState(automateName);
|
|
18
20
|
const [processing, setProcessing] = useState(false);
|
|
19
21
|
const handleContinue = useCallback(async () => {
|
|
20
22
|
if (processing) {
|
|
@@ -29,21 +31,22 @@ const InputName = ({ title, placeholder }) => {
|
|
|
29
31
|
name: name,
|
|
30
32
|
};
|
|
31
33
|
|
|
32
|
-
const { success, data } =
|
|
33
|
-
? await axiosPut(API.AUTOMATE.UPDATE_AUTOMATE(
|
|
34
|
+
const { success, data } = automateNameId
|
|
35
|
+
? await axiosPut(API.AUTOMATE.UPDATE_AUTOMATE(automateNameId), params)
|
|
34
36
|
: await axiosPost(API.AUTOMATE.CREATE_AUTOMATE(), params);
|
|
35
37
|
|
|
36
38
|
if (success) {
|
|
37
39
|
navigate({
|
|
38
|
-
name:
|
|
40
|
+
name: Routes.ScriptDetail,
|
|
39
41
|
merge: true,
|
|
40
42
|
params: {
|
|
41
|
-
|
|
43
|
+
preAutomate: data,
|
|
44
|
+
closeScreen: closeScreen,
|
|
42
45
|
},
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
48
|
setProcessing(false);
|
|
46
|
-
}, [processing, automate, name, navigate, closeScreen]);
|
|
49
|
+
}, [processing, automate, name, automateNameId, navigate, closeScreen]);
|
|
47
50
|
|
|
48
51
|
return (
|
|
49
52
|
<NewActionWrapper
|
|
@@ -25,9 +25,12 @@ const MultiUnits = () => {
|
|
|
25
25
|
const isFocused = useIsFocused();
|
|
26
26
|
const { navigate } = useNavigation();
|
|
27
27
|
const { params = {}, name: currentRouteName } = useRoute();
|
|
28
|
-
const { unit
|
|
28
|
+
const { unit = {} } = params;
|
|
29
|
+
const { id: unitId, name } = unit;
|
|
29
30
|
const [data, setData] = useState([]);
|
|
30
31
|
const permissions = useBackendPermission();
|
|
32
|
+
const { smart_script_for_multi_unit, max_automations_per_unit } =
|
|
33
|
+
permissions || {};
|
|
31
34
|
|
|
32
35
|
const [tabActive, setTabActive] = useState(AUTOMATE_TABS.SCENARIO);
|
|
33
36
|
|
|
@@ -37,8 +40,8 @@ const MultiUnits = () => {
|
|
|
37
40
|
|
|
38
41
|
const getData = useCallback(
|
|
39
42
|
async (fetchParams) => {
|
|
40
|
-
if (
|
|
41
|
-
await fetchWithCache(API.UNIT.AUTOMATE(
|
|
43
|
+
if (unitId) {
|
|
44
|
+
await fetchWithCache(API.UNIT.AUTOMATE(unitId), {}, (response) => {
|
|
42
45
|
const { success, data: automateData } = response;
|
|
43
46
|
success && setData(automateData);
|
|
44
47
|
});
|
|
@@ -50,7 +53,7 @@ const MultiUnits = () => {
|
|
|
50
53
|
success && setData(automateData);
|
|
51
54
|
}
|
|
52
55
|
},
|
|
53
|
-
[
|
|
56
|
+
[unitId]
|
|
54
57
|
);
|
|
55
58
|
|
|
56
59
|
const onPressTabName = (tab) => () => {
|
|
@@ -62,32 +65,26 @@ const MultiUnits = () => {
|
|
|
62
65
|
navigate(Routes.UnitStack, {
|
|
63
66
|
screen: Routes.ScriptDetail,
|
|
64
67
|
params: {
|
|
65
|
-
id: item?.id,
|
|
66
|
-
unitId: unit?.id,
|
|
67
68
|
preAutomate: item,
|
|
68
69
|
},
|
|
69
70
|
});
|
|
70
71
|
},
|
|
71
|
-
[navigate
|
|
72
|
+
[navigate]
|
|
72
73
|
);
|
|
73
74
|
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
newAutomate && onPressItem(newAutomate);
|
|
76
|
-
}, [newAutomate, onPressItem]);
|
|
77
|
-
|
|
78
75
|
const handleOnAddNew = useCallback(() => {
|
|
79
|
-
if (
|
|
80
|
-
if (
|
|
76
|
+
if (unitId) {
|
|
77
|
+
if (max_automations_per_unit <= data.length) {
|
|
81
78
|
ToastBottomHelper.error(
|
|
82
79
|
t('reach_max_automations_per_unit', {
|
|
83
|
-
length:
|
|
80
|
+
length: max_automations_per_unit,
|
|
84
81
|
}),
|
|
85
82
|
'',
|
|
86
83
|
7000
|
|
87
84
|
);
|
|
88
85
|
return;
|
|
89
86
|
}
|
|
90
|
-
} else if (!
|
|
87
|
+
} else if (!smart_script_for_multi_unit) {
|
|
91
88
|
ToastBottomHelper.error(
|
|
92
89
|
t('no_permission_smart_script_for_multi_unit'),
|
|
93
90
|
'',
|
|
@@ -99,7 +96,7 @@ const MultiUnits = () => {
|
|
|
99
96
|
navigate(Routes.UnitStack, {
|
|
100
97
|
screen: Routes.ScenarioName,
|
|
101
98
|
params: {
|
|
102
|
-
automate: { type: AUTOMATE_TYPE.ONE_TAP, unit:
|
|
99
|
+
automate: { type: AUTOMATE_TYPE.ONE_TAP, unit: unitId },
|
|
103
100
|
closeScreen: currentRouteName,
|
|
104
101
|
},
|
|
105
102
|
});
|
|
@@ -107,9 +104,9 @@ const MultiUnits = () => {
|
|
|
107
104
|
}
|
|
108
105
|
|
|
109
106
|
navigate(Routes.UnitStack, {
|
|
110
|
-
screen: Routes.
|
|
107
|
+
screen: Routes.AddAutomationTypeSmart,
|
|
111
108
|
params: {
|
|
112
|
-
automate: { unit:
|
|
109
|
+
automate: { unit: unitId },
|
|
113
110
|
closeScreen: currentRouteName,
|
|
114
111
|
},
|
|
115
112
|
});
|
|
@@ -117,11 +114,11 @@ const MultiUnits = () => {
|
|
|
117
114
|
currentRouteName,
|
|
118
115
|
data.length,
|
|
119
116
|
navigate,
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
max_automations_per_unit,
|
|
118
|
+
smart_script_for_multi_unit,
|
|
122
119
|
t,
|
|
123
120
|
tabActive,
|
|
124
|
-
|
|
121
|
+
unitId,
|
|
125
122
|
]);
|
|
126
123
|
|
|
127
124
|
const renderContent = useMemo(() => {
|
|
@@ -166,7 +163,7 @@ const MultiUnits = () => {
|
|
|
166
163
|
return (
|
|
167
164
|
<View style={styles.wrap}>
|
|
168
165
|
<WrapHeaderScrollable
|
|
169
|
-
title={
|
|
166
|
+
title={unitId ? name : t('multi_units_automate')}
|
|
170
167
|
headerAniStyle={styles.headerAniStyle}
|
|
171
168
|
>
|
|
172
169
|
<View style={styles.wrapContent}>
|
|
@@ -45,11 +45,10 @@ const ScriptDetail = ({ route }) => {
|
|
|
45
45
|
usePopover();
|
|
46
46
|
const t = useTranslations();
|
|
47
47
|
const {
|
|
48
|
-
id,
|
|
49
48
|
saveAt,
|
|
50
49
|
preAutomate = {}, // pre-loaded automate data
|
|
51
|
-
newAutomate, // updated automate data
|
|
52
50
|
newActionsList, // updated actions list
|
|
51
|
+
closeScreen,
|
|
53
52
|
} = params;
|
|
54
53
|
const [automate, setAutomate] = useState(preAutomate);
|
|
55
54
|
const isFocused = useIsFocused();
|
|
@@ -63,7 +62,7 @@ const ScriptDetail = ({ route }) => {
|
|
|
63
62
|
const [enableScript, setEnableScript] = useState(enable);
|
|
64
63
|
const onShowActivityLog = useCallback(() => {
|
|
65
64
|
navigate(Routes.ActivityLog, {
|
|
66
|
-
id:
|
|
65
|
+
id: automateId,
|
|
67
66
|
type:
|
|
68
67
|
type === AUTOMATE_TYPE.ONE_TAP
|
|
69
68
|
? `automate.${AUTOMATE_TYPE.ONE_TAP}`
|
|
@@ -74,7 +73,7 @@ const ScriptDetail = ({ route }) => {
|
|
|
74
73
|
user: Boolean(unit),
|
|
75
74
|
},
|
|
76
75
|
});
|
|
77
|
-
}, [navigate,
|
|
76
|
+
}, [navigate, automateId, type, unit]);
|
|
78
77
|
|
|
79
78
|
const listMenuItem = useMemo(
|
|
80
79
|
() => [
|
|
@@ -107,39 +106,41 @@ const ScriptDetail = ({ route }) => {
|
|
|
107
106
|
|
|
108
107
|
const fetchAutomateActions = useCallback(async () => {
|
|
109
108
|
const { success, data: automateData } = await axiosGet(
|
|
110
|
-
API.AUTOMATE.SCRIPT_ITEMS(
|
|
109
|
+
API.AUTOMATE.SCRIPT_ITEMS(automateId)
|
|
111
110
|
);
|
|
112
111
|
if (success) {
|
|
113
112
|
setData(automateData.script_items || []);
|
|
114
113
|
}
|
|
115
|
-
}, [
|
|
114
|
+
}, [automateId]);
|
|
116
115
|
|
|
117
116
|
const fetchAutomate = useCallback(async () => {
|
|
118
117
|
const { success, data: automateData } = await axiosGet(
|
|
119
|
-
API.AUTOMATE.FETCH_AUTOMATE(
|
|
118
|
+
API.AUTOMATE.FETCH_AUTOMATE(automateId)
|
|
120
119
|
);
|
|
121
120
|
if (success) {
|
|
122
121
|
setAutomate(automateData);
|
|
123
122
|
setEnableScript(automateData.script.enable);
|
|
124
123
|
}
|
|
125
|
-
}, [
|
|
124
|
+
}, [automateId]);
|
|
126
125
|
|
|
127
126
|
const onPressEdit = useCallback(() => {
|
|
128
127
|
navigate(Routes.EditActionsList, {
|
|
129
128
|
data,
|
|
130
|
-
id,
|
|
129
|
+
id: automateId,
|
|
131
130
|
unitId: automate.unit,
|
|
132
131
|
});
|
|
133
|
-
}, [navigate, data,
|
|
132
|
+
}, [navigate, data, automateId, automate.unit]);
|
|
134
133
|
|
|
135
134
|
const handleScriptAction = useCallback(async () => {
|
|
136
|
-
const { success } = await axiosPost(
|
|
135
|
+
const { success } = await axiosPost(
|
|
136
|
+
API.AUTOMATE.ACTION_ONE_TAP(automateId)
|
|
137
|
+
);
|
|
137
138
|
if (success) {
|
|
138
139
|
ToastBottomHelper.success(t('activated_successfully'));
|
|
139
140
|
} else {
|
|
140
141
|
ToastBottomHelper.error(t('activation_failed'));
|
|
141
142
|
}
|
|
142
|
-
}, [
|
|
143
|
+
}, [automateId, t]);
|
|
143
144
|
|
|
144
145
|
const handleUpdateAutomate = useCallback(async () => {
|
|
145
146
|
if (!can_edit) {
|
|
@@ -158,6 +159,19 @@ const ScriptDetail = ({ route }) => {
|
|
|
158
159
|
});
|
|
159
160
|
}, [automate, can_edit, enableScript, navigate, route.name, t]);
|
|
160
161
|
|
|
162
|
+
const handleGoBack = useCallback(async () => {
|
|
163
|
+
if (closeScreen === Routes.UnitDetail) {
|
|
164
|
+
navigate(closeScreen, { unitId: unit });
|
|
165
|
+
} else if (
|
|
166
|
+
closeScreen === Routes.MultiUnits ||
|
|
167
|
+
closeScreen === Routes.Automate
|
|
168
|
+
) {
|
|
169
|
+
navigate(closeScreen, {});
|
|
170
|
+
} else {
|
|
171
|
+
goBack();
|
|
172
|
+
}
|
|
173
|
+
}, [closeScreen, goBack, navigate, unit]);
|
|
174
|
+
|
|
161
175
|
const onChangeSwitch = useCallback(
|
|
162
176
|
async (checked) => {
|
|
163
177
|
setEnableScript(checked);
|
|
@@ -210,17 +224,13 @@ const ScriptDetail = ({ route }) => {
|
|
|
210
224
|
saveAt && fetchAutomateActions();
|
|
211
225
|
}, [saveAt, fetchAutomateActions]);
|
|
212
226
|
|
|
213
|
-
useEffect(() => {
|
|
214
|
-
newAutomate && setAutomate(newAutomate);
|
|
215
|
-
}, [newAutomate]);
|
|
216
|
-
|
|
217
227
|
return (
|
|
218
228
|
<View style={styles.wrap}>
|
|
219
229
|
<WrapHeaderScrollable
|
|
220
230
|
title={name}
|
|
221
231
|
headerAniStyle={styles.headerAniStyle}
|
|
222
232
|
rightComponent={rightComponent}
|
|
223
|
-
onGoBack={
|
|
233
|
+
onGoBack={handleGoBack}
|
|
224
234
|
>
|
|
225
235
|
<View style={styles.wrapContent}>
|
|
226
236
|
{!!can_edit && (
|
|
@@ -76,7 +76,6 @@ describe('Test MultiUnits', () => {
|
|
|
76
76
|
params: {
|
|
77
77
|
isMultiUnits: true,
|
|
78
78
|
unitName: null,
|
|
79
|
-
unit: null,
|
|
80
79
|
},
|
|
81
80
|
});
|
|
82
81
|
await act(async () => {
|
|
@@ -111,7 +110,6 @@ describe('Test MultiUnits', () => {
|
|
|
111
110
|
expect(global.mockedNavigate).toBeCalledWith(Routes.UnitStack, {
|
|
112
111
|
screen: Routes.ScriptDetail,
|
|
113
112
|
params: {
|
|
114
|
-
id: response[1].id,
|
|
115
113
|
preAutomate: response[1],
|
|
116
114
|
},
|
|
117
115
|
});
|
|
@@ -120,7 +118,7 @@ describe('Test MultiUnits', () => {
|
|
|
120
118
|
ItemAddNews[0].props.onAddNew();
|
|
121
119
|
});
|
|
122
120
|
expect(global.mockedNavigate).toBeCalledWith(Routes.UnitStack, {
|
|
123
|
-
screen: Routes.
|
|
121
|
+
screen: Routes.AddAutomationTypeSmart,
|
|
124
122
|
params: {
|
|
125
123
|
automate: { unit: undefined },
|
|
126
124
|
closeScreen: undefined,
|
|
@@ -264,7 +262,6 @@ describe('Test MultiUnits', () => {
|
|
|
264
262
|
params: {
|
|
265
263
|
isMultiUnits: true,
|
|
266
264
|
unitName: null,
|
|
267
|
-
unit: null,
|
|
268
265
|
},
|
|
269
266
|
});
|
|
270
267
|
await act(async () => {
|
|
@@ -129,7 +129,7 @@ export const useGetEvaluateValue = (configId, unitId) => {
|
|
|
129
129
|
if (configId && valueEvaluations[configId] === undefined) {
|
|
130
130
|
(async () => {
|
|
131
131
|
const { success, data } = await axiosGet(API.VALUE_EVALUATIONS(), {
|
|
132
|
-
configs__id: configId,
|
|
132
|
+
params: { configs__id: configId },
|
|
133
133
|
});
|
|
134
134
|
if (success) {
|
|
135
135
|
setAction(Action.INIT_VALUE_EVALUATIONS, {
|
|
@@ -158,7 +158,7 @@ describe('Test Select unit screen', () => {
|
|
|
158
158
|
await iconClose[0].props.onPress();
|
|
159
159
|
});
|
|
160
160
|
expect(global.mockedNavigate).toHaveBeenCalledWith(Routes.ScriptDetail, {
|
|
161
|
-
id: 1,
|
|
161
|
+
automate: { id: 1 },
|
|
162
162
|
havePermission: true,
|
|
163
163
|
isMultiUnits: undefined,
|
|
164
164
|
name: '1',
|