@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
@@ -0,0 +1,269 @@
1
+ import moment from 'moment';
2
+ import React, { useCallback, useMemo, useState } from 'react';
3
+ import { ScrollView } from 'react-native';
4
+ import _TextInput from '../../../commons/Form/TextInput';
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';
9
+ import NewActionWrapper from '../AddNewAction/NewActionWrapper';
10
+ import RepeatOptionsPopup from './components/RepeatOptionsPopup';
11
+ import { AUTOMATE_TYPE } from '../../../configs/Constants';
12
+ import { REPEAT_OPTIONS, TIME_RANGE_REPEAT_OPTIONS } from '../Constants';
13
+ import RowItem from './components/RowItem';
14
+ import SelectWeekday from './components/SelectWeekday';
15
+ import styles from './styles/indexStyles';
16
+
17
+ const getDateString = (date, t) => {
18
+ const today = moment();
19
+ if (date.isSame(today, 'day')) {
20
+ return date.format(`[${t('today')}], D MMMM YYYY `);
21
+ }
22
+ return date.format('ddd, D MMMM YYYY');
23
+ };
24
+
25
+ const parseTime = (value) =>
26
+ value ? moment(value, 'HH:mm:ss') : moment().second(0);
27
+
28
+ const parseDate = (value) => (value ? moment(value, 'YYYY-MM-DD') : moment());
29
+
30
+ const EditSchedule = ({ condition = {}, onSave }) => {
31
+ const t = useTranslations();
32
+ const [repeat, setRepeat] = useState(condition.repeat || REPEAT_OPTIONS.ONCE);
33
+
34
+ const [timeRangeRepeat, setTimeRangeRepeat] = useState(
35
+ condition.weekday_repeat?.length
36
+ ? TIME_RANGE_REPEAT_OPTIONS.EVERYWEEK
37
+ : TIME_RANGE_REPEAT_OPTIONS.EVERYDAY
38
+ );
39
+ const [timeRepeat, setTimeRepeat] = useState(
40
+ parseTime(condition.time_repeat)
41
+ );
42
+ const [timeStart, setTimeStart] = useState(parseTime(condition.time_start));
43
+ const [timeEnd, setTimeEnd] = useState(parseTime(condition.time_end));
44
+ const [dateRepeat, setDateRepeat] = useState(
45
+ parseDate(condition.date_repeat)
46
+ );
47
+ const [weekdayRepeat, setWeekdayRepeat] = useState(
48
+ condition.weekday_repeat || []
49
+ );
50
+ const [intervalRepeat, setIntervalRepeat] = useState(
51
+ condition.interval_repeat || 1
52
+ );
53
+
54
+ const [showRepeatOptions, setShowRepeatOptions, setHideRepeatOptions] =
55
+ useBoolean();
56
+ const [
57
+ showTimeRangeRepeatOptions,
58
+ setShowTimeRangeRepeatOptions,
59
+ setHideTimeRangeRepeatOptions,
60
+ ] = useBoolean();
61
+ const [showTimePicker, setShowTimePicker, setHideTimePicker] = useBoolean();
62
+ const [showTimeStartPicker, setShowTimeStartPicker, setHideTimeStartPicker] =
63
+ useBoolean();
64
+ const [showTimeEndPicker, setShowTimeEndPicker, setHideTimeEndPicker] =
65
+ useBoolean();
66
+ const [showCalendar, setShowCalendar, setHideCalendar] = useBoolean();
67
+
68
+ const scheduleData = useMemo(() => {
69
+ let data = {
70
+ type: AUTOMATE_TYPE.SCHEDULE,
71
+ repeat: repeat,
72
+ };
73
+
74
+ switch (repeat) {
75
+ case REPEAT_OPTIONS.INTERVAL:
76
+ data.interval_repeat = parseInt(intervalRepeat, 10);
77
+ break;
78
+
79
+ case REPEAT_OPTIONS.TIMERANGE:
80
+ data.time_start = timeStart.format('HH:mm:ss');
81
+ data.time_end = timeEnd.format('HH:mm:ss');
82
+ data.weekday_repeat =
83
+ timeRangeRepeat === TIME_RANGE_REPEAT_OPTIONS.EVERYWEEK
84
+ ? weekdayRepeat
85
+ : null;
86
+ break;
87
+
88
+ default:
89
+ data.time_repeat = timeRepeat.format('HH:mm:ss');
90
+ data.date_repeat =
91
+ repeat === REPEAT_OPTIONS.ONCE
92
+ ? dateRepeat.format('YYYY-MM-DD')
93
+ : null;
94
+ data.weekday_repeat =
95
+ repeat === REPEAT_OPTIONS.EVERYWEEK ? weekdayRepeat : null;
96
+ break;
97
+ }
98
+ return data;
99
+ }, [
100
+ repeat,
101
+ timeRepeat,
102
+ timeStart,
103
+ timeEnd,
104
+ timeRangeRepeat,
105
+ dateRepeat,
106
+ weekdayRepeat,
107
+ intervalRepeat,
108
+ ]);
109
+
110
+ const onNext = useCallback(() => {
111
+ onSave(scheduleData);
112
+ }, [onSave, scheduleData]);
113
+
114
+ const onSetRepeatOption = useCallback(
115
+ (value) => {
116
+ setRepeat(value);
117
+ setHideRepeatOptions();
118
+ },
119
+ [setHideRepeatOptions]
120
+ );
121
+
122
+ const onSetTimeRangeRepeatOption = useCallback(
123
+ (value) => {
124
+ setTimeRangeRepeat(value);
125
+ setHideTimeRangeRepeatOptions();
126
+ },
127
+ [setHideTimeRangeRepeatOptions]
128
+ );
129
+
130
+ const onTimePicked = useCallback((timeData) => {
131
+ setTimeRepeat(moment(timeData));
132
+ }, []);
133
+
134
+ const onTimeStartPicked = useCallback((timeData) => {
135
+ setTimeStart(moment(timeData));
136
+ }, []);
137
+
138
+ const onTimeEndPicked = useCallback((timeData) => {
139
+ setTimeEnd(moment(timeData));
140
+ }, []);
141
+
142
+ const onDatePicked = useCallback((datePicked) => {
143
+ setDateRepeat(datePicked);
144
+ }, []);
145
+
146
+ return (
147
+ <NewActionWrapper
148
+ name={t('set_schedule')}
149
+ onNext={onNext}
150
+ canNext={true}
151
+ nextTitle={t('save')}
152
+ >
153
+ <ScrollView
154
+ contentContainerStyle={styles.scollView}
155
+ scrollIndicatorInsets={{ right: 1 }}
156
+ >
157
+ <RowItem
158
+ title={t('repeat')}
159
+ value={t(`${repeat}`)}
160
+ arrow
161
+ onPress={setShowRepeatOptions}
162
+ />
163
+ {[
164
+ REPEAT_OPTIONS.ONCE,
165
+ REPEAT_OPTIONS.EVERYDAY,
166
+ REPEAT_OPTIONS.EVERYWEEK,
167
+ ].includes(repeat) && (
168
+ <RowItem
169
+ title={t('set_time')}
170
+ value={timeRepeat.format('HH:mm')}
171
+ icon="clock-circle"
172
+ onPress={setShowTimePicker}
173
+ />
174
+ )}
175
+ {repeat === REPEAT_OPTIONS.ONCE && (
176
+ <RowItem
177
+ title={t('select_date')}
178
+ value={getDateString(dateRepeat, t)}
179
+ icon="calendar"
180
+ onPress={setShowCalendar}
181
+ />
182
+ )}
183
+ {repeat === REPEAT_OPTIONS.INTERVAL && (
184
+ <_TextInput
185
+ label={t('interval_repeat')}
186
+ keyboardType="numeric"
187
+ wrapStyle={styles.inputWrap}
188
+ textInputStyle={styles.inputNumber}
189
+ value={intervalRepeat.toString()}
190
+ onChange={setIntervalRepeat}
191
+ maxLength={4}
192
+ />
193
+ )}
194
+ {repeat === REPEAT_OPTIONS.TIMERANGE && (
195
+ <>
196
+ <RowItem
197
+ title={t('time_range_repeat')}
198
+ value={t(`${timeRangeRepeat}`)}
199
+ arrow
200
+ onPress={setShowTimeRangeRepeatOptions}
201
+ />
202
+ <RowItem
203
+ title={t('from')}
204
+ value={timeStart.format('HH:mm')}
205
+ icon="clock-circle"
206
+ onPress={setShowTimeStartPicker}
207
+ />
208
+ <RowItem
209
+ title={t('to')}
210
+ value={timeEnd.format('HH:mm')}
211
+ icon="clock-circle"
212
+ onPress={setShowTimeEndPicker}
213
+ />
214
+ </>
215
+ )}
216
+ {(repeat === REPEAT_OPTIONS.EVERYWEEK ||
217
+ (repeat === REPEAT_OPTIONS.TIMERANGE &&
218
+ timeRangeRepeat === TIME_RANGE_REPEAT_OPTIONS.EVERYWEEK)) && (
219
+ <SelectWeekday
220
+ weekday={weekdayRepeat}
221
+ setWeekday={setWeekdayRepeat}
222
+ />
223
+ )}
224
+ </ScrollView>
225
+ <RepeatOptionsPopup
226
+ isVisible={showRepeatOptions}
227
+ onHide={setHideRepeatOptions}
228
+ onSetRepeat={onSetRepeatOption}
229
+ options={REPEAT_OPTIONS}
230
+ />
231
+ <RepeatOptionsPopup
232
+ isVisible={showTimeRangeRepeatOptions}
233
+ onHide={setHideTimeRangeRepeatOptions}
234
+ onSetRepeat={onSetTimeRangeRepeatOption}
235
+ options={TIME_RANGE_REPEAT_OPTIONS}
236
+ />
237
+ <WheelDateTimePicker
238
+ mode="time"
239
+ isVisible={showTimePicker}
240
+ defaultValue={timeRepeat.valueOf()}
241
+ onCancel={setHideTimePicker}
242
+ onPicked={onTimePicked}
243
+ />
244
+ <WheelDateTimePicker
245
+ mode="time"
246
+ isVisible={showTimeStartPicker}
247
+ defaultValue={timeStart.valueOf()}
248
+ onCancel={setHideTimeStartPicker}
249
+ onPicked={onTimeStartPicked}
250
+ />
251
+ <WheelDateTimePicker
252
+ mode="time"
253
+ isVisible={showTimeEndPicker}
254
+ defaultValue={timeEnd.valueOf()}
255
+ onCancel={setHideTimeEndPicker}
256
+ onPicked={onTimeEndPicked}
257
+ />
258
+ <Calendar
259
+ isVisible={showCalendar}
260
+ defaultDate={dateRepeat}
261
+ minDate={moment()}
262
+ onCancel={setHideCalendar}
263
+ onConfirm={onDatePicked}
264
+ />
265
+ </NewActionWrapper>
266
+ );
267
+ };
268
+
269
+ export default EditSchedule;