@eohjsc/react-native-smart-city 0.7.22 → 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 (61) hide show
  1. package/package.json +1 -1
  2. package/src/commons/ActionGroup/TerminalBoxTemplate.js +3 -0
  3. package/src/commons/ActionTemplate/OnOffButtonAction.js +38 -4
  4. package/src/commons/ActionTemplate/OnOffSimpleAction.js +55 -15
  5. package/src/commons/ActionTemplate/OnOffSmartLockAction.js +46 -8
  6. package/src/commons/ActionTemplate/SwitchButtonAction.js +35 -4
  7. package/src/commons/ActionTemplate/ThreeButtonAction.js +13 -3
  8. package/src/commons/ActionTemplate/__test__/OnOffButtonAction.test.js +46 -7
  9. package/src/commons/ActionTemplate/__test__/OnOffSimpleAction.test.js +66 -6
  10. package/src/commons/ActionTemplate/__test__/OnOffSmartLockAction.test.js +53 -13
  11. package/src/commons/ActionTemplate/__test__/SwitchButtonAction.test.js +46 -7
  12. package/src/commons/ActionTemplate/__test__/index.test.js +6 -2
  13. package/src/commons/ActionTemplate/index.js +65 -10
  14. package/src/commons/MediaPlayerDetail/MediaPlayerFull.js +26 -32
  15. package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +8 -6
  16. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +6 -0
  17. package/src/commons/SubUnit/OneTap/index.js +5 -0
  18. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +9 -11
  19. package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +3 -1
  20. package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +1 -1
  21. package/src/configs/API.js +6 -0
  22. package/src/configs/AccessibilityLabel.js +2 -0
  23. package/src/screens/ActivityLog/__test__/index.test.js +10 -0
  24. package/src/screens/ActivityLog/hooks/index.js +1 -1
  25. package/src/screens/Automate/AddNewAction/ChooseAction.js +15 -51
  26. package/src/screens/Automate/AddNewAction/SelectControlDevices.js +13 -3
  27. package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +74 -54
  28. package/src/screens/Automate/AddNewAction/__test__/ChooseAction.test.js +114 -4
  29. package/src/screens/Automate/AddNewAction/__test__/SetupConfigCondition.test.js +37 -8
  30. package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +5 -0
  31. package/src/screens/Automate/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +18 -2
  32. package/src/screens/Automate/Components/InputName.js +7 -6
  33. package/src/screens/Automate/Constants.js +12 -0
  34. package/src/screens/Automate/EditActionsList/UpdateActionScript.js +24 -55
  35. package/src/screens/Automate/EditActionsList/__tests__/UpdateActionScript.test.js +298 -41
  36. package/src/screens/Automate/EditActionsList/__tests__/index.test.js +2 -2
  37. package/src/screens/Automate/EditActionsList/index.js +26 -14
  38. package/src/screens/Automate/MultiUnits.js +9 -1
  39. package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +3 -3
  40. package/src/screens/Automate/ScriptDetail/Components/AddActionScript.js +4 -10
  41. package/src/screens/Automate/ScriptDetail/Components/DeleteScript.js +2 -4
  42. package/src/screens/Automate/ScriptDetail/__test__/index.test.js +78 -0
  43. package/src/screens/Automate/ScriptDetail/index.js +16 -10
  44. package/src/screens/Automate/ScriptDetail/utils.js +39 -15
  45. package/src/screens/Automate/SetSchedule/AddEditConditionSchedule.js +27 -160
  46. package/src/screens/Automate/SetSchedule/EditSchedule.js +269 -0
  47. package/src/screens/Automate/SetSchedule/__test__/AddEditConditionSchedule.test.js +327 -22
  48. package/src/screens/Automate/SetSchedule/__test__/index.test.js +35 -22
  49. package/src/screens/Automate/SetSchedule/components/RepeatOptionsPopup.js +2 -8
  50. package/src/screens/Automate/SetSchedule/index.js +15 -129
  51. package/src/screens/Automate/SetSchedule/styles/indexStyles.js +9 -0
  52. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -1
  53. package/src/screens/Automate/hooks/useAction.js +222 -0
  54. package/src/screens/Device/__test__/detail.test.js +48 -1
  55. package/src/screens/Device/detail.js +46 -3
  56. package/src/screens/PlayBackCamera/__test__/index.test.js +48 -13
  57. package/src/screens/PlayBackCamera/index.js +1 -1
  58. package/src/utils/Apis/axios.js +6 -0
  59. package/src/utils/I18n/translations/en.js +8 -0
  60. package/src/utils/I18n/translations/vi.js +8 -0
  61. package/src/screens/Automate/constants.js +0 -0
@@ -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;