@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
@@ -742,6 +742,7 @@ describe('Test ScriptDetail', () => {
742
742
  unitId: route.params.preAutomate.unit,
743
743
  automateId: route.params.preAutomate.id,
744
744
  numberActionCanAdd: 2,
745
+ scriptItems: [],
745
746
  closeScreen: undefined,
746
747
  routeName: null,
747
748
  });
@@ -901,6 +902,7 @@ describe('Test ScriptDetail', () => {
901
902
  unitId: route.params.preAutomate.unit,
902
903
  automateId: route.params.preAutomate.id,
903
904
  numberActionCanAdd: 2,
905
+ scriptItems: [],
904
906
  closeScreen: undefined,
905
907
  routeName: null,
906
908
  },
@@ -1211,6 +1213,82 @@ describe('Test ScriptDetail', () => {
1211
1213
  );
1212
1214
  });
1213
1215
 
1216
+ it('Test render textCondition schedule time range', async () => {
1217
+ route.params = {
1218
+ ...route.params,
1219
+ preAutomate: {
1220
+ type: AUTOMATE_TYPE.SCHEDULE,
1221
+ conditions: [
1222
+ {
1223
+ type: AUTOMATE_TYPE.SCHEDULE,
1224
+ repeat: 'time_range',
1225
+ time_start: '09:30:00',
1226
+ time_end: '10:00:00',
1227
+ weekday_repeat: null,
1228
+ },
1229
+ ],
1230
+ },
1231
+ };
1232
+ await act(async () => {
1233
+ tree = await create(wrapComponent(route));
1234
+ });
1235
+ const instance = tree.root;
1236
+ const itemAutomate = instance.findByType(ItemConditionScriptDetail);
1237
+ expect(itemAutomate.findAllByType(Text)[1].props.children).toEqual(
1238
+ 'From 09:30 to 10:00 Everyday'
1239
+ );
1240
+ });
1241
+
1242
+ it('Test render textCondition schedule time range with weekday', async () => {
1243
+ route.params = {
1244
+ ...route.params,
1245
+ preAutomate: {
1246
+ type: AUTOMATE_TYPE.SCHEDULE,
1247
+ conditions: [
1248
+ {
1249
+ type: AUTOMATE_TYPE.SCHEDULE,
1250
+ repeat: 'time_range',
1251
+ time_start: '09:30:00',
1252
+ time_end: '10:00:00',
1253
+ weekday_repeat: ['1', '3', '0'],
1254
+ },
1255
+ ],
1256
+ },
1257
+ };
1258
+ await act(async () => {
1259
+ tree = await create(wrapComponent(route));
1260
+ });
1261
+ const instance = tree.root;
1262
+ const itemAutomate = instance.findByType(ItemConditionScriptDetail);
1263
+ expect(itemAutomate.findAllByType(Text)[1].props.children).toEqual(
1264
+ 'From 09:30 to 10:00 on Mon, Wed, Sun'
1265
+ );
1266
+ });
1267
+
1268
+ it('Test render textCondition schedule interval repeat', async () => {
1269
+ route.params = {
1270
+ ...route.params,
1271
+ preAutomate: {
1272
+ type: AUTOMATE_TYPE.SCHEDULE,
1273
+ conditions: [
1274
+ {
1275
+ type: AUTOMATE_TYPE.SCHEDULE,
1276
+ repeat: 'interval',
1277
+ interval_repeat: 5,
1278
+ },
1279
+ ],
1280
+ },
1281
+ };
1282
+ await act(async () => {
1283
+ tree = await create(wrapComponent(route));
1284
+ });
1285
+ const instance = tree.root;
1286
+ const itemAutomate = instance.findByType(ItemConditionScriptDetail);
1287
+ expect(itemAutomate.findAllByType(Text)[1].props.children).toEqual(
1288
+ 'Repeat every 5 minutes'
1289
+ );
1290
+ });
1291
+
1214
1292
  it('test navigate to UnitDetail on event beforeRemove', async () => {
1215
1293
  Platform.OS = 'ios';
1216
1294
  route.params.closeScreen = Routes.UnitDetail;
@@ -110,11 +110,7 @@ const ScriptDetail = ({ route }) => {
110
110
  chip_id_local_control,
111
111
  } = script || {};
112
112
 
113
- const [local_control, setLocalControl] = useState({
114
- is_local_control,
115
- chip_local_control,
116
- chip_id_local_control,
117
- });
113
+ const [local_control, setLocalControl] = useState({});
118
114
  const [enableScript, setEnableScript] = useState(enable);
119
115
  const [listMenuItemCondition, setListMenuItemCondition] = useState([]);
120
116
  const [isShowAddCondition, setIsShowAddCondition] = useState(false);
@@ -384,6 +380,14 @@ const ScriptDetail = ({ route }) => {
384
380
  newActionsList && setData(newActionsList);
385
381
  }, [newActionsList]);
386
382
 
383
+ useEffect(() => {
384
+ setLocalControl({
385
+ is_local_control,
386
+ chip_local_control,
387
+ chip_id_local_control,
388
+ });
389
+ }, [is_local_control, chip_local_control, chip_id_local_control]);
390
+
387
391
  const rightComponent = useMemo(
388
392
  () => (
389
393
  <View style={styles.rightComponent}>
@@ -766,7 +770,7 @@ const ScriptDetail = ({ route }) => {
766
770
  />
767
771
  <AddActionScript
768
772
  automate={automate}
769
- numberActionAdded={data.length}
773
+ scriptItems={data}
770
774
  isVisible={isShowAddAction}
771
775
  setIsVisible={setIsShowAddAction}
772
776
  type={type}
@@ -778,7 +782,7 @@ const ScriptDetail = ({ route }) => {
778
782
  isVisible={isShowAddCondition}
779
783
  setIsVisible={setIsShowAddCondition}
780
784
  type={type}
781
- navigate={navigate}
785
+ navigate={handleNavigate}
782
786
  />
783
787
  <RenameScript
784
788
  automate={automate}
@@ -790,6 +794,7 @@ const ScriptDetail = ({ route }) => {
790
794
  automate={automate}
791
795
  setIsVisible={setIsShowDelete}
792
796
  isVisible={isShowDelete}
797
+ goBack={handleGoBack}
793
798
  />
794
799
  <DeleteCondition
795
800
  automate={automate}
@@ -895,12 +900,13 @@ const Item = ({ item, index, enableScript, t, local_control }) => {
895
900
  const paddedIndex = (index + 1).toString().padStart(2, '0');
896
901
  const {
897
902
  action_script,
903
+ toggle_script,
898
904
  notify_script,
899
905
  delay_script,
900
906
  email_script,
901
907
  sms_script,
902
908
  } = item;
903
- if (action_script) {
909
+ if (action_script || toggle_script) {
904
910
  const {
905
911
  sensor_icon_kit,
906
912
  unit_name,
@@ -908,7 +914,7 @@ const Item = ({ item, index, enableScript, t, local_control }) => {
908
914
  sensor_name,
909
915
  action_name,
910
916
  data,
911
- } = action_script;
917
+ } = action_script || toggle_script;
912
918
  return (
913
919
  <View style={styles.wrapItem}>
914
920
  <View style={styles.leftItem}>
@@ -942,7 +948,7 @@ const Item = ({ item, index, enableScript, t, local_control }) => {
942
948
  {sensor_name}
943
949
  </Text>
944
950
  <Text numberOfLines={1} type="H4" color={color}>
945
- {action_name} {data}
951
+ {toggle_script ? t('toggle') : `${action_name} ${data || ''}`}
946
952
  </Text>
947
953
  </View>
948
954
  </View>
@@ -1,25 +1,5 @@
1
1
  import { AUTOMATE_TYPE } from '../../../configs/Constants';
2
- import { REPEAT_OPTIONS } from '../SetSchedule/components/RepeatOptionsPopup';
3
-
4
- export const generateAutomationDataConditionText = (
5
- type,
6
- config_name,
7
- condition,
8
- valueEvaluation,
9
- t
10
- ) => {
11
- condition.config_name = config_name;
12
- let automate = {};
13
- if ([AUTOMATE_TYPE.VALUE_CHANGE].includes(type)) {
14
- automate = { value_change: condition };
15
- } else if (type === AUTOMATE_TYPE.SCHEDULE) {
16
- automate = { schedule: condition };
17
- } else if ([AUTOMATE_TYPE.EVENT].includes(type)) {
18
- automate = { event: condition };
19
- }
20
- automate.type = type;
21
- return generateAutomationConditionText(automate, valueEvaluation, t);
22
- };
2
+ import { REPEAT_OPTIONS } from '../Constants';
23
3
 
24
4
  export const getAutomationData = (automate) => {
25
5
  const { type, event_sensor, event_action, schedule, event, value_change } =
@@ -93,11 +73,16 @@ export const generateAutomationConditionText = (
93
73
  }
94
74
  return `${config_name} ${t(text)} ${value}`;
95
75
  } else if (type === AUTOMATE_TYPE.SCHEDULE) {
96
- const { repeat, time_repeat, date_repeat, weekday_repeat } = conditionItem;
97
- const time =
98
- time_repeat?.length >= 8
99
- ? time_repeat.substring(0, time_repeat?.length - 3)
100
- : time_repeat;
76
+ const {
77
+ repeat,
78
+ time_repeat,
79
+ time_start,
80
+ time_end,
81
+ date_repeat,
82
+ weekday_repeat,
83
+ interval_repeat,
84
+ } = conditionItem;
85
+
101
86
  const date = date_repeat?.split('-').reverse().join('/');
102
87
  const weekday = {
103
88
  1: t('mon'),
@@ -109,14 +94,14 @@ export const generateAutomationConditionText = (
109
94
  0: t('sun'),
110
95
  };
111
96
 
112
- if (repeat === REPEAT_OPTIONS.ONCE) {
113
- return `${time} ${date}`;
114
- } else if (repeat === REPEAT_OPTIONS.EVERYDAY) {
115
- return `${t('every_day_at', { time })}`;
116
- } else if (repeat === REPEAT_OPTIONS.EVERYWEEK) {
97
+ const shortTime = (time) => {
98
+ return time?.length >= 8 ? time.substring(0, time?.length - 3) : time;
99
+ };
100
+
101
+ const getTextWeekDay = (weekdayRepeat) => {
117
102
  //sort 0 is last number, exp: [1,3,5,0]
118
- const newWeekdayRepeat = weekday_repeat.map((item) => parseInt(item, 10));
119
- const sortWeekday = newWeekdayRepeat.sort((a, b) => {
103
+ const newWeekdayRepeat = weekdayRepeat?.map((item) => parseInt(item, 10));
104
+ const sortWeekday = newWeekdayRepeat?.sort((a, b) => {
120
105
  if (a !== 0 && b === 0) {
121
106
  return -1;
122
107
  }
@@ -125,8 +110,27 @@ export const generateAutomationConditionText = (
125
110
  }
126
111
  return a - b;
127
112
  });
128
- const textWeekday = sortWeekday.map((item) => weekday[item]).join(', ');
129
- return `${textWeekday} ${t('at')} ${time}`;
113
+ return sortWeekday?.map((item) => weekday[item]).join(', ');
114
+ };
115
+
116
+ if (repeat === REPEAT_OPTIONS.ONCE) {
117
+ return `${shortTime(time_repeat)} ${date}`;
118
+ } else if (repeat === REPEAT_OPTIONS.EVERYDAY) {
119
+ return `${t('every_day_at', { time: shortTime(time_repeat) })}`;
120
+ } else if (repeat === REPEAT_OPTIONS.EVERYWEEK) {
121
+ const textWeekday = getTextWeekDay(weekday_repeat);
122
+ return `${textWeekday} ${t('at')} ${shortTime(time_repeat)}`;
123
+ } else if (repeat === REPEAT_OPTIONS.TIMERANGE) {
124
+ const textWeekday = getTextWeekDay(weekday_repeat);
125
+ return `${t('from_to', {
126
+ from: shortTime(time_start),
127
+ to: shortTime(time_end),
128
+ weekdays: textWeekday
129
+ ? `${t('on_weekday')} ${textWeekday}`
130
+ : t('every_day'),
131
+ })}`;
132
+ } else if (repeat === REPEAT_OPTIONS.INTERVAL) {
133
+ return `${t('repeat_every', { interval: interval_repeat })}`;
130
134
  }
131
135
  }
132
136
  return null;
@@ -1,173 +1,40 @@
1
1
  import { useNavigation } from '@react-navigation/native';
2
- import moment from 'moment';
3
- import React, { memo, useCallback, useState } from 'react';
4
- import { ScrollView } from 'react-native';
5
- import Calendar from '../../../commons/Calendar';
6
- import WheelDateTimePicker from '../../../commons/WheelDateTimePicker';
7
- import { useBoolean } from '../../../hooks/Common';
8
- import { useTranslations } from '../../../hooks/Common/useTranslations';
2
+ import React, { useCallback } from 'react';
3
+ import EditSchedule from './EditSchedule';
9
4
  import Routes from '../../../utils/Route';
10
- import NewActionWrapper from '../AddNewAction/NewActionWrapper';
11
- import RepeatOptionsPopup, {
12
- REPEAT_OPTIONS,
13
- } from './components/RepeatOptionsPopup';
14
- import RowItem from './components/RowItem';
15
- import SelectWeekday from './components/SelectWeekday';
16
- import styles from './styles/indexStyles';
17
5
  import { axiosPost, axiosPut } from '../../../utils/Apis/axios';
18
6
  import { API } from '../../../configs';
19
- import { AUTOMATE_TYPE } from '../../../configs/Constants';
20
-
21
- const getDateString = (date, t) => {
22
- //Move outside component to prevent re-creation on every render.
23
- const today = moment();
24
- if (date.isSame(today, 'day')) {
25
- return date.format(`[${t('today')}], D MMMM YYYY `);
26
- }
27
- return date.format('ddd, D MMMM YYYY');
28
- };
29
7
 
30
8
  const AddEditConditionSchedule = ({ route }) => {
31
- const t = useTranslations();
32
- const { automate, condition = {}, isUpdateCondition } = route.params;
9
+ const { automate, condition, isUpdateCondition } = route.params;
33
10
  const { navigate } = useNavigation();
34
- const [repeat, setRepeat] = useState(
35
- condition.repeat ? condition.repeat : REPEAT_OPTIONS.ONCE
36
- );
37
- const [time, setTime] = useState(
38
- condition.time_repeat
39
- ? moment(condition.time_repeat, 'HH:mm:ss')
40
- : moment().second(0)
41
- );
42
- const [date, setDate] = useState(
43
- condition.date_repeat
44
- ? moment(condition.date_repeat, 'YYYY-MM-DD')
45
- : moment()
46
- );
47
- const [weekday, setWeekday] = useState(
48
- condition.weekday_repeat ? condition.weekday_repeat : []
49
- );
50
-
51
- const [showRepeatOptions, setShowRepeatOptions, setHideRepeatOptions] =
52
- useBoolean();
53
- const [showTimePicker, setShowTimePicker, setHideTimePicker] = useBoolean();
54
- const [showCalendar, setShowCalendar, setHideCalendar] = useBoolean();
55
-
56
- const handleOnSave = useCallback(async () => {
57
- const data = {
58
- type: AUTOMATE_TYPE.SCHEDULE,
59
- repeat,
60
- time_repeat: time.format('HH:mm:ss'),
61
- date_repeat:
62
- repeat === REPEAT_OPTIONS.ONCE ? date.format('YYYY-MM-DD') : null,
63
- weekday_repeat: repeat === REPEAT_OPTIONS.EVERYWEEK ? weekday : null,
64
- };
65
11
 
66
- let response;
67
- if (isUpdateCondition) {
68
- response = await axiosPut(
69
- API.AUTOMATE.UPDATE_CONDITION(automate.id, condition.id),
70
- data
71
- );
72
- } else {
73
- response = await axiosPost(API.AUTOMATE.ADD_CONDITION(automate.id), data);
74
- }
75
- const { success } = response;
76
- if (success) {
77
- navigate({
78
- name: Routes.ScriptDetail,
79
- params: { preAutomate: automate },
80
- });
81
- }
82
- }, [
83
- repeat,
84
- time,
85
- date,
86
- weekday,
87
- isUpdateCondition,
88
- automate,
89
- condition.id,
90
- navigate,
91
- ]);
92
-
93
- const onSetRepeatOption = useCallback(
94
- (value) => {
95
- setRepeat(value);
96
- setHideRepeatOptions();
97
- },
98
- [setRepeat, setHideRepeatOptions]
99
- );
100
-
101
- const onTimePicked = useCallback(
102
- (timeData) => {
103
- setTime(moment(timeData));
12
+ const handleOnSave = useCallback(
13
+ async (data) => {
14
+ let response;
15
+ if (isUpdateCondition) {
16
+ response = await axiosPut(
17
+ API.AUTOMATE.UPDATE_CONDITION(automate.id, condition?.id),
18
+ data
19
+ );
20
+ } else {
21
+ response = await axiosPost(
22
+ API.AUTOMATE.ADD_CONDITION(automate.id),
23
+ data
24
+ );
25
+ }
26
+ const { success } = response;
27
+ if (success) {
28
+ navigate({
29
+ name: Routes.ScriptDetail,
30
+ params: { preAutomate: automate },
31
+ });
32
+ }
104
33
  },
105
- [setTime]
34
+ [isUpdateCondition, automate, condition?.id, navigate]
106
35
  );
107
36
 
108
- const onDatePicked = useCallback(
109
- (datePicked) => {
110
- setDate(datePicked);
111
- },
112
- [setDate]
113
- );
114
-
115
- return (
116
- <NewActionWrapper
117
- name={t('set_schedule')}
118
- onNext={handleOnSave}
119
- canNext={true}
120
- nextTitle={t('save')}
121
- >
122
- <ScrollView
123
- contentContainerStyle={styles.scollView}
124
- scrollIndicatorInsets={{ right: 1 }}
125
- >
126
- <RowItem
127
- title={t('set_time')}
128
- value={time.format('HH:mm')}
129
- icon="clock-circle"
130
- onPress={setShowTimePicker}
131
- />
132
- {repeat === REPEAT_OPTIONS.ONCE && (
133
- <RowItem
134
- title={t('select_date')}
135
- value={getDateString(date, t)}
136
- icon="calendar"
137
- onPress={setShowCalendar}
138
- />
139
- )}
140
- {repeat === REPEAT_OPTIONS.EVERYWEEK && (
141
- <SelectWeekday weekday={weekday} setWeekday={setWeekday} />
142
- )}
143
- <RowItem
144
- title={t('repeat')}
145
- value={t(`${repeat}`)}
146
- arrow
147
- onPress={setShowRepeatOptions}
148
- />
149
- </ScrollView>
150
- <RepeatOptionsPopup
151
- isVisible={showRepeatOptions}
152
- onHide={setHideRepeatOptions}
153
- onSetRepeat={onSetRepeatOption}
154
- />
155
- <WheelDateTimePicker
156
- mode="time"
157
- isVisible={showTimePicker}
158
- defaultValue={time.valueOf()}
159
- onCancel={setHideTimePicker}
160
- onPicked={onTimePicked}
161
- />
162
- <Calendar
163
- isVisible={showCalendar}
164
- defaultDate={date}
165
- minDate={moment()}
166
- onCancel={setHideCalendar}
167
- onConfirm={onDatePicked}
168
- />
169
- </NewActionWrapper>
170
- );
37
+ return <EditSchedule condition={condition} onSave={handleOnSave} />;
171
38
  };
172
39
 
173
- export default memo(AddEditConditionSchedule);
40
+ export default AddEditConditionSchedule;