@eohjsc/react-native-smart-city 0.7.21 → 0.7.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/package.json +1 -1
  2. package/src/Images/Common/default_end_device.png +0 -0
  3. package/src/commons/ActionGroup/TerminalBoxTemplate.js +3 -0
  4. package/src/commons/ActionTemplate/OnOffButtonAction.js +38 -4
  5. package/src/commons/ActionTemplate/OnOffSimpleAction.js +55 -15
  6. package/src/commons/ActionTemplate/OnOffSmartLockAction.js +46 -8
  7. package/src/commons/ActionTemplate/SwitchButtonAction.js +35 -4
  8. package/src/commons/ActionTemplate/ThreeButtonAction.js +13 -3
  9. package/src/commons/ActionTemplate/__test__/OnOffButtonAction.test.js +46 -7
  10. package/src/commons/ActionTemplate/__test__/OnOffSimpleAction.test.js +66 -6
  11. package/src/commons/ActionTemplate/__test__/OnOffSmartLockAction.test.js +53 -13
  12. package/src/commons/ActionTemplate/__test__/SwitchButtonAction.test.js +46 -7
  13. package/src/commons/ActionTemplate/__test__/index.test.js +6 -2
  14. package/src/commons/ActionTemplate/index.js +65 -10
  15. package/src/commons/Dashboard/MyUnit/index.js +19 -20
  16. package/src/commons/DevMode/Search.js +1 -1
  17. package/src/commons/Device/RainningSensor/CurrentRainSensor.js +5 -5
  18. package/src/commons/MediaPlayerDetail/MediaPlayerFull.js +26 -32
  19. package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +8 -6
  20. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +6 -0
  21. package/src/commons/SubUnit/OneTap/index.js +5 -0
  22. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +9 -11
  23. package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +2 -2
  24. package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +1 -1
  25. package/src/configs/API.js +10 -0
  26. package/src/configs/AccessibilityLabel.js +5 -1
  27. package/src/configs/Images.js +1 -0
  28. package/src/navigations/AddMemberStack.js +3 -3
  29. package/src/screens/ActivityLog/__test__/index.test.js +10 -0
  30. package/src/screens/ActivityLog/hooks/index.js +1 -1
  31. package/src/screens/AddCommon/SelectUnit.js +3 -2
  32. package/src/screens/AddLocationMaps/__test__/index.test.js +13 -13
  33. package/src/screens/Automate/AddNewAction/ChooseAction.js +15 -51
  34. package/src/screens/Automate/AddNewAction/SelectControlDevices.js +13 -3
  35. package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +74 -54
  36. package/src/screens/Automate/AddNewAction/__test__/ChooseAction.test.js +114 -4
  37. package/src/screens/Automate/AddNewAction/__test__/ChooseConfig.test.js +9 -11
  38. package/src/screens/Automate/AddNewAction/__test__/SetupConfigCondition.test.js +37 -8
  39. package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +5 -0
  40. package/src/screens/Automate/AddNewAutoSmart/__test__/AddAutomationTypeSmart.test.js +31 -0
  41. package/src/screens/Automate/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +18 -2
  42. package/src/screens/Automate/Components/InputName.js +7 -6
  43. package/src/screens/Automate/Constants.js +12 -0
  44. package/src/screens/Automate/EditActionsList/UpdateActionScript.js +24 -55
  45. package/src/screens/Automate/EditActionsList/__tests__/UpdateActionScript.test.js +298 -41
  46. package/src/screens/Automate/EditActionsList/__tests__/index.test.js +2 -2
  47. package/src/screens/Automate/EditActionsList/index.js +26 -14
  48. package/src/screens/Automate/MultiUnits.js +9 -1
  49. package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +3 -3
  50. package/src/screens/Automate/ScriptDetail/Components/AddActionScript.js +4 -10
  51. package/src/screens/Automate/ScriptDetail/Components/DeleteScript.js +2 -4
  52. package/src/screens/Automate/ScriptDetail/__test__/index.test.js +78 -0
  53. package/src/screens/Automate/ScriptDetail/index.js +16 -10
  54. package/src/screens/Automate/ScriptDetail/utils.js +39 -35
  55. package/src/screens/Automate/SetSchedule/AddEditConditionSchedule.js +27 -160
  56. package/src/screens/Automate/SetSchedule/EditSchedule.js +269 -0
  57. package/src/screens/Automate/SetSchedule/__test__/AddEditConditionSchedule.test.js +327 -22
  58. package/src/screens/Automate/SetSchedule/__test__/index.test.js +35 -22
  59. package/src/screens/Automate/SetSchedule/components/RepeatOptionsPopup.js +2 -8
  60. package/src/screens/Automate/SetSchedule/index.js +15 -129
  61. package/src/screens/Automate/SetSchedule/styles/indexStyles.js +9 -0
  62. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -1
  63. package/src/screens/Automate/hooks/useAction.js +222 -0
  64. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +69 -13
  65. package/src/screens/ConfirmUnitDeletion/index.js +14 -14
  66. package/src/screens/Device/__test__/detail.test.js +48 -1
  67. package/src/screens/Device/detail.js +46 -3
  68. package/src/screens/PlayBackCamera/__test__/index.test.js +48 -13
  69. package/src/screens/PlayBackCamera/index.js +1 -1
  70. package/src/screens/Sharing/Components/ConfigItem.js +34 -0
  71. package/src/screens/Sharing/Components/DeviceItem.js +77 -0
  72. package/src/screens/Sharing/Components/ItemChangeRole.js +3 -4
  73. package/src/screens/Sharing/Components/ShareDeviceSelector.js +255 -0
  74. package/src/screens/Sharing/Components/Styles/CheckBoxCustomStyles.js +1 -1
  75. package/src/screens/Sharing/Components/Styles/DeviceItemStyles.js +11 -27
  76. package/src/screens/Sharing/{Styles/SelectPermissionStyles.js → Components/Styles/ShareDeviceSelectorStyles.js} +3 -11
  77. package/src/screens/Sharing/Components/SubUnitItem.js +28 -0
  78. package/src/screens/Sharing/Components/SubUnitTreeView.js +68 -0
  79. package/src/screens/Sharing/Components/TitleCheckBox.js +23 -41
  80. package/src/screens/Sharing/Components/__test__/ItemChangeRole.test.js +7 -7
  81. package/src/screens/Sharing/Components/__test__/ShareDeviceSelector.test.js +298 -0
  82. package/src/screens/Sharing/Components/index.js +14 -1
  83. package/src/screens/Sharing/InfoMemberUnit.js +20 -20
  84. package/src/screens/Sharing/SelectShareDevice.js +11 -255
  85. package/src/screens/Sharing/SelectUser.js +12 -12
  86. package/src/screens/Sharing/UpdateShareDevice.js +45 -301
  87. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +58 -11
  88. package/src/screens/Sharing/__test__/SelectShareDevice.test.js +51 -160
  89. package/src/screens/Sharing/__test__/SelectUser.test.js +72 -10
  90. package/src/screens/Sharing/__test__/UpdateShareDevice.test.js +49 -209
  91. package/src/utils/Apis/axios.js +6 -0
  92. package/src/utils/I18n/translations/en.js +9 -1
  93. package/src/utils/I18n/translations/vi.js +10 -2
  94. package/src/commons/Sharing/StationDevicePermissions.js +0 -204
  95. package/src/screens/Automate/constants.js +0 -0
  96. package/src/screens/Sharing/Components/CheckBoxConfig.js +0 -44
  97. package/src/screens/Sharing/Components/CheckBoxSubUnit.js +0 -35
  98. package/src/screens/Sharing/Components/EndDevice.js +0 -93
  99. package/src/screens/Sharing/Components/Styles/CheckBoxConfigStyles.js +0 -18
  100. package/src/screens/Sharing/Components/Styles/TitleCheckBoxStyles.js +0 -21
  101. package/src/screens/Sharing/Components/__test__/TitleCheckBox.test.js +0 -31
@@ -90,6 +90,7 @@ const API = {
90
90
  CONFIG: {
91
91
  DISPLAY_HISTORY_V3: () => '/chip_manager/configs/value_history_v3/',
92
92
  DISPLAY_HISTORY_V4: () => '/chip_manager/configs/value_history_v4/',
93
+ DISPLAY_HISTORY_V5: () => '/chip_manager/configs/value_history_v5/',
93
94
  },
94
95
  AUTOMATE: {
95
96
  ACTION_ONE_TAP: (id) => `/property_manager/automate/${id}/action_one_tap/`,
@@ -109,12 +110,16 @@ const API = {
109
110
  `/property_manager/automate/${automateId}/update_script_notify/`,
110
111
  UPDATE_SCRIPT_ACTION: (automateId) =>
111
112
  `/property_manager/automate/${automateId}/update_script_action/`,
113
+ UPDATE_SCRIPT_TOGGLE: (automateId) =>
114
+ `/property_manager/automate/${automateId}/update_script_toggle/`,
112
115
  UPDATE_SCRIPT_EMAIL: (automateId) =>
113
116
  `/property_manager/automate/${automateId}/update_script_email/`,
114
117
  UPDATE_SCRIPT_SMS: (automateId) =>
115
118
  `/property_manager/automate/${automateId}/update_script_sms/`,
116
119
  ADD_SCRIPT_ACTION: (id) =>
117
120
  `/property_manager/automate/${id}/add_script_action/`,
121
+ ADD_SCRIPT_TOGGLE: (id) =>
122
+ `/property_manager/automate/${id}/add_script_toggle/`,
118
123
  ADD_SCRIPT_NOTIFY: (id) =>
119
124
  `/property_manager/automate/${id}/add_script_notify/`,
120
125
  ADD_SCRIPT_DELAY: (id) =>
@@ -125,6 +130,7 @@ const API = {
125
130
  FETCH_AUTOMATE: (automateId) =>
126
131
  `/property_manager/automate_v2/${automateId}/`,
127
132
  CREATE_AUTOMATE: () => '/property_manager/automate/',
133
+ CREATE_AUTOMATE_V2: () => '/property_manager/automate_v2/',
128
134
  UPDATE_AUTOMATE: (automateId) =>
129
135
  `/property_manager/automate/${automateId}/`,
130
136
  ENABLE_SCRIPT: (automateId) =>
@@ -158,6 +164,8 @@ const API = {
158
164
  UNITS: () => '/property_manager/sharing/units/',
159
165
  UNIT_PERMISSIONS: (id) =>
160
166
  `/property_manager/sharing/units/${id}/permissions/`,
167
+ UNIT_PERMISSIONS_v2: (id) =>
168
+ `/property_manager/sharing/units/${id}/permissions_v2/`,
161
169
  UNITS_MEMBERS: (id) => `/property_manager/sharing/units/${id}/members/`,
162
170
  UNITS_MEMBER_DETAIL: (id, shareId) =>
163
171
  `/property_manager/sharing/units/${id}/members/${shareId}/`,
@@ -165,6 +173,8 @@ const API = {
165
173
  `/property_manager/sharing/units/${unit_id}/member/${member_id}/information/`,
166
174
  UNIT_MEMBER_SHARE_DEVICE: (unit_id, member_id) =>
167
175
  `/property_manager/sharing/units/${unit_id}/member/${member_id}/shared_devices/`,
176
+ UNIT_MEMBER_SHARE_DEVICE_V2: (unit_id, member_id) =>
177
+ `/property_manager/sharing/units/${unit_id}/member/${member_id}/shared_devices_v2/`,
168
178
  SHARE: () => '/property_manager/sharing/share/',
169
179
  SHARE_V2: () => '/property_manager/sharing/share_v2/',
170
180
  SEARCH_USER_BY_PHONE: (phone) => `/accounts/search/phone/${phone}/`,
@@ -306,6 +306,7 @@ export default {
306
306
  ONE_BUTTON: 'ONE_BUTTON',
307
307
  ON_BUTTON: 'ON_BUTTON',
308
308
  OFF_BUTTON: 'OFF_BUTTON',
309
+ TOGGLE_BUTTON: 'TOGGLE_BUTTON',
309
310
 
310
311
  // Device Detail
311
312
  DEVICE_DETAIL_MEDIA_PLAYER: 'DEVICE_DETAIL_MEDIA_PLAYER',
@@ -452,7 +453,9 @@ export default {
452
453
  CHECK_BOX_CUSTOM: 'CHECK_BOX_CUSTOM',
453
454
  CHECK_BOX_CONFIG: 'CHECK_BOX_CONFIG',
454
455
  EXPAND_END_DEVICE: 'EXPAND_END_DEVICE',
455
- CLICK_NAME_END_DEVICE: 'CLICK_NAME_END_DEVICE',
456
+ NAME_END_DEVICE: 'CLICK_NAME_END_DEVICE',
457
+ ICON_END_DEVICE: 'ICON_END_DEVICE',
458
+ ICON_CHECK: 'ICON_CHECK',
456
459
  },
457
460
 
458
461
  // Select subunit
@@ -608,6 +611,7 @@ export default {
608
611
  // OnOffSimpleAction
609
612
  ON_OFF_SIMPLE_ACTION_ON: 'ON_OFF_SIMPLE_ACTION_ON',
610
613
  ON_OFF_SIMPLE_ACTION_OFF: 'ON_OFF_SIMPLE_ACTION_OFF',
614
+ ON_OFF_SIMPLE_ACTION_TOGGLE: 'ON_OFF_SIMPLE_ACTION_TOGGLE',
611
615
 
612
616
  // Add New Device LG
613
617
  ADD_NEW_DEVICE_LG_ADD: 'ADD_NEW_DEVICE_LG_ADD',
@@ -27,4 +27,5 @@ export default {
27
27
  inforCode: require('../Images/DevMode/inforCode.png'),
28
28
  activeCurrentSensor: require('../Images/Common/Sunny.png'),
29
29
  unitDefaultBackground: require('../Images/Common/unit_default_background.png'),
30
+ defaultEndDeviceIcon: require('../Images/Common/default_end_device.png'),
30
31
  };
@@ -1,12 +1,12 @@
1
- import { createNativeStackNavigator } from '@react-navigation/native-stack';
2
1
  import React, { memo } from 'react';
3
2
 
4
3
  import AddCommonSelectUnit from '../screens/AddCommon/SelectUnit';
5
4
  import Route from '../utils/Route';
6
- import { screenOptions } from './utils';
5
+ import SelectShareDevice from '../screens/Sharing/SelectShareDevice';
7
6
  import SharingInviteMembers from '../screens/Sharing/SelectUser';
8
7
  import UpdateShareDevice from '../screens/Sharing/UpdateShareDevice';
9
- import SelectShareDevice from '../screens/Sharing/SelectShareDevice';
8
+ import { createNativeStackNavigator } from '@react-navigation/native-stack';
9
+ import { screenOptions } from './utils';
10
10
 
11
11
  const Stack = createNativeStackNavigator();
12
12
 
@@ -198,4 +198,14 @@ describe('Test Activity log', () => {
198
198
  const items = instance.findAllByType(ItemLog);
199
199
  expect(items).toHaveLength(0);
200
200
  });
201
+
202
+ it('render type null', async () => {
203
+ route.params.type = undefined;
204
+ await act(async () => {
205
+ tree = await create(wrapComponent(route));
206
+ });
207
+ const instance = tree.root;
208
+ const items = instance.findAllByType(ItemLog);
209
+ expect(items).toHaveLength(0);
210
+ });
201
211
  });
@@ -120,7 +120,7 @@ export default ({ id, type, share, filterEnabled }) => {
120
120
 
121
121
  const fetchMembers = async () => {
122
122
  const api = apiMaps[type];
123
- if (!filterEnabled?.user) {
123
+ if (!api?.memberUrl || !filterEnabled?.user) {
124
124
  return;
125
125
  }
126
126
  const { success, data } = await axiosGet(api.memberUrl(share?.id));
@@ -1,8 +1,9 @@
1
- import { useNavigation } from '@react-navigation/native';
2
- import { useTranslations } from '../../hooks/Common/useTranslations';
3
1
  import React, { useCallback, useEffect, useState } from 'react';
2
+
4
3
  import Routes from '../../utils/Route';
5
4
  import SelectUnit from '../../commons/SelectUnit';
5
+ import { useNavigation } from '@react-navigation/native';
6
+ import { useTranslations } from '../../hooks/Common/useTranslations';
6
7
 
7
8
  const AddCommonSelectUnit = ({ route }) => {
8
9
  const t = useTranslations();
@@ -1,22 +1,22 @@
1
- import MockAdapter from 'axios-mock-adapter';
2
- import React from 'react';
3
- import { Alert } from 'react-native';
4
- import RNAndroidLocationEnabler from 'react-native-android-location-enabler';
5
- import RNP from 'react-native-permissions';
1
+ import {
2
+ GEOLOCATION_ERROR,
3
+ OpenSetting,
4
+ } from '../../../utils/Permission/common';
6
5
  import { act, create } from 'react-test-renderer';
7
6
 
8
- import { useNavigation } from '@react-navigation/native';
9
- import { RESULTS } from 'react-native-permissions';
10
7
  import { API } from '../../../configs';
11
8
  import { AccessibilityLabel } from '../../../configs/Constants';
9
+ import AddLocationMaps from '../index';
10
+ import { Alert } from 'react-native';
11
+ import MockAdapter from 'axios-mock-adapter';
12
+ import { RESULTS } from 'react-native-permissions';
13
+ import RNAndroidLocationEnabler from 'react-native-android-location-enabler';
14
+ import RNP from 'react-native-permissions';
15
+ import React from 'react';
12
16
  import { SCProvider } from '../../../context';
13
- import { mockSCStore } from '../../../context/mockStore';
14
17
  import api from '../../../utils/Apis/axios';
15
- import {
16
- GEOLOCATION_ERROR,
17
- OpenSetting,
18
- } from '../../../utils/Permission/common';
19
- import AddLocationMaps from '../index';
18
+ import { mockSCStore } from '../../../context/mockStore';
19
+ import { useNavigation } from '@react-navigation/native';
20
20
 
21
21
  const wrapComponent = (route) => (
22
22
  <SCProvider initState={mockSCStore({})}>
@@ -1,14 +1,13 @@
1
- import React, { useCallback, useEffect, useState } from 'react';
1
+ import React, { useCallback } from 'react';
2
2
  import { View } from 'react-native';
3
3
  import { useNavigation } from '@react-navigation/native';
4
4
 
5
5
  import { useTranslations } from '../../../hooks/Common/useTranslations';
6
- import { axiosGet, axiosPost } from '../../../utils/Apis/axios';
7
- import { API } from '../../../configs';
8
6
  import Routes from '../../../utils/Route';
9
7
  import NewActionWrapper from './NewActionWrapper';
10
8
  import moment from 'moment';
11
9
  import { ToastBottomHelper } from '../../../utils/Utils';
10
+ import useAction from '../hooks/useAction';
12
11
  import RenderActionItem from './RenderActionItem';
13
12
 
14
13
  const ChooseAction = ({ route }) => {
@@ -18,24 +17,16 @@ const ChooseAction = ({ route }) => {
18
17
  unitId,
19
18
  device,
20
19
  automateId,
20
+ scriptItems,
21
21
  numberActionCanAdd,
22
22
  multiUnit = {},
23
23
  } = route.params;
24
- const [data, setData] = useState([]);
25
- const [actions, setActions] = useState([]);
26
24
 
27
- const fetchData = useCallback(async () => {
28
- const { success, data: automateData } = await axiosGet(
29
- API.DEVICE.DISPLAY_ACTIONS(device.id)
30
- );
31
-
32
- if (success) {
33
- setData(automateData);
34
- }
35
- }, [device.id]);
25
+ const { displayActions, saveActions, onSelectAction, onAddSubmit } =
26
+ useAction(device, scriptItems);
36
27
 
37
28
  const onSave = useCallback(async () => {
38
- if (actions.length > numberActionCanAdd) {
29
+ if (saveActions.length > numberActionCanAdd) {
39
30
  ToastBottomHelper.error(
40
31
  `${t('you_can_only_add_more', { number: numberActionCanAdd })} ${t(
41
32
  numberActionCanAdd > 1 ? 'actions' : 'action'
@@ -45,18 +36,8 @@ const ChooseAction = ({ route }) => {
45
36
  );
46
37
  return;
47
38
  }
48
- let list_action = [...actions];
49
- list_action = list_action.map((item) => ({
50
- action: item.action,
51
- data: item.data,
52
- }));
53
- const { success } = await axiosPost(
54
- API.AUTOMATE.ADD_SCRIPT_ACTION(automateId),
55
- {
56
- list_action,
57
- unit: unitId || multiUnit.id,
58
- }
59
- );
39
+
40
+ const success = await onAddSubmit(automateId, unitId || multiUnit.id);
60
41
 
61
42
  success &&
62
43
  navigate({
@@ -65,50 +46,32 @@ const ChooseAction = ({ route }) => {
65
46
  params: { saveAt: moment().valueOf() },
66
47
  });
67
48
  }, [
68
- actions,
69
49
  numberActionCanAdd,
70
50
  automateId,
51
+ saveActions.length,
71
52
  unitId,
72
53
  multiUnit.id,
54
+ onAddSubmit,
73
55
  navigate,
74
56
  t,
75
57
  ]);
76
58
 
77
- const handleOnSelectAction = (action) => {
78
- setActions((prevActions) => {
79
- const index = prevActions.findIndex(
80
- (item) => item.index === action.index
81
- );
82
- if (index !== -1) {
83
- const newActions = [...prevActions];
84
- newActions[index] = action;
85
- return newActions;
86
- } else {
87
- return [...prevActions, action];
88
- }
89
- });
90
- };
91
-
92
- useEffect(() => {
93
- fetchData();
94
- }, [fetchData]);
95
-
96
59
  return (
97
60
  <NewActionWrapper
98
- canNext={actions.length}
61
+ canNext={saveActions.length}
99
62
  onNext={onSave}
100
63
  nextTitle={t('save')}
101
64
  name={t('set_up {name}', { name: device?.name })}
102
65
  >
103
66
  <View>
104
- {!!data?.length &&
105
- data.map((item, index) => (
67
+ {!!displayActions?.length &&
68
+ displayActions.map((item, index) => (
106
69
  <RenderActionItem
107
70
  key={`action_item_${index}`}
108
71
  device={device}
109
72
  item={item}
110
73
  index={index}
111
- handleOnSelectAction={handleOnSelectAction}
74
+ handleOnSelectAction={onSelectAction}
112
75
  t={t}
113
76
  />
114
77
  ))}
@@ -116,4 +79,5 @@ const ChooseAction = ({ route }) => {
116
79
  </NewActionWrapper>
117
80
  );
118
81
  };
82
+
119
83
  export default ChooseAction;
@@ -10,8 +10,9 @@ const SelectControlDevices = ({ route }) => {
10
10
  const t = useTranslations();
11
11
  const {
12
12
  unitId,
13
- closeScreen,
14
13
  automateId,
14
+ closeScreen,
15
+ scriptItems,
15
16
  numberActionCanAdd,
16
17
  multiUnit = {},
17
18
  } = route.params || {};
@@ -54,13 +55,22 @@ const SelectControlDevices = ({ route }) => {
54
55
  navigate(Routes.ChooseAction, {
55
56
  unitId,
56
57
  automateId,
57
- device: selectedDevice,
58
58
  closeScreen,
59
+ device: selectedDevice,
60
+ scriptItems,
59
61
  numberActionCanAdd,
60
62
  multiUnit,
61
63
  });
62
64
  },
63
- [navigate, unitId, automateId, closeScreen, numberActionCanAdd, multiUnit]
65
+ [
66
+ navigate,
67
+ unitId,
68
+ automateId,
69
+ closeScreen,
70
+ scriptItems,
71
+ numberActionCanAdd,
72
+ multiUnit,
73
+ ]
64
74
  );
65
75
 
66
76
  if (loading) {
@@ -52,6 +52,10 @@ const SetupConfigCondition = () => {
52
52
  const { navigate } = useNavigation();
53
53
  const { params = {} } = useRoute();
54
54
  const { config, automate, closeScreen, unitId } = params;
55
+ const [conditionData, setConditionData] = useState({
56
+ type: AUTOMATE_TYPE.VALUE_CHANGE,
57
+ config: automate.config,
58
+ });
55
59
  const [selectedCondition, setSelectedCondition] = useState(undefined);
56
60
  const [customCondition, setCustomCondition] = useState(undefined);
57
61
  const [isShowModal, setIsShowModal] = useState(false);
@@ -86,67 +90,77 @@ const SetupConfigCondition = () => {
86
90
 
87
91
  const setupCustomCondition = () => {
88
92
  setSelectedCondition('custom');
89
- automate.value = NaN;
93
+ setConditionData((prev) => ({
94
+ ...prev,
95
+ value: NaN,
96
+ }));
90
97
  setIsShowModal(true);
91
98
  };
92
99
 
93
- const handleNavigate = useCallback(async () => {
94
- if (!isCreateCondition && !isUpdateCondition) {
95
- navigate(Routes.ValueChangeName, {
96
- automate,
97
- closeScreen,
98
- unitId,
99
- });
100
- return;
101
- }
102
- const data = {
103
- type: AUTOMATE_TYPE.VALUE_CHANGE,
104
- condition: automate.condition,
105
- config: automate.config,
106
- value: automate.value,
107
- };
108
- const apiCall = isCreateCondition
109
- ? await axiosPost(API.AUTOMATE.ADD_CONDITION(automate.id), data)
110
- : await axiosPut(
111
- API.AUTOMATE.UPDATE_CONDITION(automate.id, isUpdateCondition),
112
- data
113
- );
100
+ const handleNavigate = useCallback(
101
+ async (data) => {
102
+ if (!isCreateCondition && !isUpdateCondition) {
103
+ navigate(Routes.ValueChangeName, {
104
+ automate: {
105
+ ...automate,
106
+ conditions: [data],
107
+ },
108
+ closeScreen,
109
+ unitId,
110
+ });
111
+ return;
112
+ }
114
113
 
115
- const { success } = apiCall;
116
-
117
- if (success) {
118
- ToastBottomHelper.success(
119
- isCreateCondition
120
- ? t('add_condition_success')
121
- : t('edit_condition_success')
122
- );
123
- navigate({
124
- name: Routes.ScriptDetail,
125
- params: { preAutomate: automate },
126
- });
127
- }
128
- }, [
129
- automate,
130
- closeScreen,
131
- isCreateCondition,
132
- isUpdateCondition,
133
- navigate,
134
- t,
135
- unitId,
136
- ]);
114
+ const apiCall = isCreateCondition
115
+ ? await axiosPost(API.AUTOMATE.ADD_CONDITION(automate.id), data)
116
+ : await axiosPut(
117
+ API.AUTOMATE.UPDATE_CONDITION(automate.id, isUpdateCondition),
118
+ data
119
+ );
120
+
121
+ const { success } = apiCall;
122
+
123
+ if (success) {
124
+ ToastBottomHelper.success(
125
+ isCreateCondition
126
+ ? t('add_condition_success')
127
+ : t('edit_condition_success')
128
+ );
129
+ navigate({
130
+ name: Routes.ScriptDetail,
131
+ params: { preAutomate: automate },
132
+ });
133
+ }
134
+ },
135
+ [
136
+ automate,
137
+ closeScreen,
138
+ isCreateCondition,
139
+ isUpdateCondition,
140
+ navigate,
141
+ t,
142
+ unitId,
143
+ ]
144
+ );
137
145
 
138
146
  const setupCondition = async (condition) => {
139
- automate.condition = condition?.condition;
140
- automate.value = condition?.value;
141
147
  setSelectedCondition(condition);
142
- handleNavigate();
148
+ const data = {
149
+ ...conditionData,
150
+ condition: condition?.condition,
151
+ value: condition?.value,
152
+ };
153
+ handleNavigate(data);
143
154
  };
144
155
 
145
156
  const resetCustomizeCondition = useCallback(() => {
146
- automate.condition = null;
147
- automate.value = NaN;
157
+ setConditionData((prev) => ({
158
+ ...prev,
159
+ condition: null,
160
+ value: NaN,
161
+ }));
148
162
  setCustomCondition(undefined);
149
- }, [automate]);
163
+ }, []);
150
164
 
151
165
  useFocusEffect(
152
166
  useCallback(() => {
@@ -197,7 +211,10 @@ const SetupConfigCondition = () => {
197
211
  <GridItem
198
212
  key={`GridItem${index}`}
199
213
  onPress={() => {
200
- automate.condition = item.value;
214
+ setConditionData((prev) => ({
215
+ ...prev,
216
+ condition: item.value,
217
+ }));
201
218
  setCustomCondition(item.value);
202
219
  }}
203
220
  selected={item.value === customCondition}
@@ -217,7 +234,10 @@ const SetupConfigCondition = () => {
217
234
  placeholder={t('value')}
218
235
  onChange={(value) => {
219
236
  const floatValue = parseFloat(value.replace(',', '.'));
220
- automate.value = floatValue;
237
+ setConditionData((prev) => ({
238
+ ...prev,
239
+ value: floatValue,
240
+ }));
221
241
  }}
222
242
  textInputStyle={styles.numberInput}
223
243
  wrapStyle={styles.wrapTextInput}
@@ -229,12 +249,12 @@ const SetupConfigCondition = () => {
229
249
  title={t('continue')}
230
250
  accessibilityLabel={AccessibilityLabel.BUTTON_CONTINUE}
231
251
  onPress={async () => {
232
- if (isNaN(automate.value) || !automate.condition) {
252
+ if (isNaN(conditionData.value) || !conditionData.condition) {
233
253
  ToastBottomHelper.error(t('please_enter_a_number'), '', 3000);
234
254
  return;
235
255
  }
236
256
  setIsShowModal(false);
237
- handleNavigate();
257
+ handleNavigate(conditionData);
238
258
  }}
239
259
  style={styles.buttonContinue}
240
260
  textSemiBold={false}