@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
@@ -20,7 +20,7 @@ const mockedPermission = jest.fn();
20
20
 
21
21
  jest.mock('../../../../utils/Permission/backend', () => ({
22
22
  useBackendPermission: () => ({
23
- max_actions_per_automation: 1,
23
+ max_actions_per_automation: 2,
24
24
  }),
25
25
  }));
26
26
 
@@ -33,12 +33,27 @@ let response = [
33
33
  text_off: 'text_off',
34
34
  action_on: 'action_on',
35
35
  action_off: 'action_off',
36
+ config: 9,
37
+ is_on_value: [1],
36
38
  },
37
39
  },
38
40
  {
41
+ title: 'Trigger',
39
42
  template: 'one_button_action_template',
40
43
  configuration: { text: 'text', action: 'action' },
41
44
  },
45
+ {
46
+ title: 'Garage',
47
+ template: 'three_button_action_template',
48
+ configuration: {
49
+ action1: 'garage open',
50
+ action2: 'garage close',
51
+ action3: 'garage stop',
52
+ text1: 'Open',
53
+ text2: 'Close',
54
+ text3: 'Stop',
55
+ },
56
+ },
42
57
  ];
43
58
  const wrapComponent = (route) => (
44
59
  <SCProvider initState={mockSCStore({})}>
@@ -48,35 +63,38 @@ const wrapComponent = (route) => (
48
63
 
49
64
  describe('Test UpdateActionScript', () => {
50
65
  let tree;
51
- let route = {
52
- params: {
53
- unitId: 1,
54
- automateId: 1,
55
- scriptItemId: 1,
56
- numberActionAdded: 0,
57
- device: { id: 1 },
58
- },
59
- };
66
+ let activatedScript;
67
+ let route;
68
+
60
69
  beforeEach(() => {
70
+ activatedScript = {
71
+ id: 1,
72
+ action_script: {
73
+ id: 1,
74
+ action_name: 'ON',
75
+ data: null,
76
+ end_device_id: 2,
77
+ sensor_name: 'LED',
78
+ station_name: 'Room',
79
+ unit_name: 'EoH Office',
80
+ },
81
+ toggle_script: null,
82
+ order: 1,
83
+ };
84
+ route = {
85
+ params: {
86
+ unitId: 1,
87
+ automateId: 1,
88
+ activatedScript,
89
+ scriptItems: [activatedScript],
90
+ device: { id: 1 },
91
+ },
92
+ };
61
93
  useRoute.mockReturnValue({
62
94
  params: {},
63
95
  });
64
96
  mockedPermission.mockClear();
65
- });
66
-
67
- it('test update action script', async () => {
68
- mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
69
- mock.onPut(API.AUTOMATE.UPDATE_SCRIPT_ACTION(1)).reply(200);
70
- mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, { script_items: [] });
71
- await act(async () => {
72
- tree = await renderer.create(wrapComponent(route));
73
- });
74
- const instance = tree.root;
75
- await showAllCards(instance);
76
- await selectActionOn(instance);
77
- await pressSaveButton(instance);
78
-
79
- expect(global.mockedNavigate).toHaveBeenCalled();
97
+ mock.reset();
80
98
  });
81
99
 
82
100
  const pressSaveButton = async (instance) => {
@@ -90,20 +108,6 @@ describe('Test UpdateActionScript', () => {
90
108
  });
91
109
  };
92
110
 
93
- it('test update action script fail', async () => {
94
- mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
95
- mock.onPut(API.AUTOMATE.UPDATE_SCRIPT_ACTION(1)).reply(400);
96
- await act(async () => {
97
- tree = await renderer.create(wrapComponent(route));
98
- });
99
- const instance = tree.root;
100
- await showAllCards(instance);
101
- await selectActionOn(instance);
102
- await pressSaveButton(instance);
103
-
104
- expect(global.mockedNavigate).not.toHaveBeenCalled();
105
- });
106
-
107
111
  const selectActionOn = async (instance) => {
108
112
  const buttonOn = instance.findAll(
109
113
  (el) =>
@@ -126,6 +130,17 @@ describe('Test UpdateActionScript', () => {
126
130
  });
127
131
  };
128
132
 
133
+ const selectActionToggle = async (instance) => {
134
+ const buttonToggle = instance.findAll(
135
+ (el) =>
136
+ el.props.accessibilityLabel === AccessibilityLabel.TOGGLE_BUTTON &&
137
+ el.type === TouchableOpacity
138
+ );
139
+ await act(async () => {
140
+ buttonToggle[0].props.onPress();
141
+ });
142
+ };
143
+
129
144
  const selectActionOne = async (instance) => {
130
145
  const buttonOne = instance.findAll(
131
146
  (el) =>
@@ -137,6 +152,243 @@ describe('Test UpdateActionScript', () => {
137
152
  });
138
153
  };
139
154
 
155
+ const selectActionFirstThreeTemplate = async (instance) => {
156
+ const buttonOne = instance.findAll(
157
+ (el) =>
158
+ el.props.accessibilityLabel === AccessibilityLabel.BUTTON_TEMPLATE_1 &&
159
+ el.type === TouchableOpacity
160
+ );
161
+ await act(async () => {
162
+ buttonOne[0].props.onPress();
163
+ });
164
+ };
165
+
166
+ it('test update action script', async () => {
167
+ mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
168
+ mock.onPut(API.AUTOMATE.UPDATE_SCRIPT_ACTION(1)).reply(200);
169
+ mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, { script_items: [] });
170
+ await act(async () => {
171
+ tree = await renderer.create(wrapComponent(route));
172
+ });
173
+ const instance = tree.root;
174
+ await showAllCards(instance);
175
+ await selectActionOn(instance);
176
+ await pressSaveButton(instance);
177
+
178
+ expect(mock.history.put).toHaveLength(1);
179
+ expect(mock.history.put[0].url).toEqual(
180
+ API.AUTOMATE.UPDATE_SCRIPT_ACTION(1)
181
+ );
182
+ expect(mock.history.put[0].data).toEqual(
183
+ JSON.stringify({
184
+ id: 1,
185
+ list_action: [
186
+ {
187
+ action: 'action_on',
188
+ data: null,
189
+ order: 1,
190
+ },
191
+ ],
192
+ number_action: 1,
193
+ unit: 1,
194
+ })
195
+ );
196
+ expect(global.mockedNavigate).toHaveBeenCalled();
197
+ });
198
+
199
+ it('test update action script to toggle script and add new action', async () => {
200
+ mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
201
+ mock.onDelete(API.AUTOMATE.DELETE_SCRIPT_ITEM(1, 1)).reply(200);
202
+ mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(200);
203
+ mock.onPost(API.AUTOMATE.ADD_SCRIPT_TOGGLE(1)).reply(200);
204
+ mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, { script_items: [] });
205
+ await act(async () => {
206
+ tree = await renderer.create(wrapComponent(route));
207
+ });
208
+ const instance = tree.root;
209
+ await showAllCards(instance);
210
+ await selectActionToggle(instance);
211
+ await selectActionOne(instance);
212
+ await pressSaveButton(instance);
213
+
214
+ expect(mock.history.delete).toHaveLength(1);
215
+ expect(mock.history.delete[0].url).toEqual(
216
+ API.AUTOMATE.DELETE_SCRIPT_ITEM(1, 1)
217
+ );
218
+ expect(mock.history.post).toHaveLength(2);
219
+ expect(mock.history.post[0].url).toEqual(API.AUTOMATE.ADD_SCRIPT_TOGGLE(1));
220
+ expect(mock.history.post[0].data).toEqual(
221
+ JSON.stringify({
222
+ list_action: [
223
+ {
224
+ action_on: 'action_on',
225
+ action_off: 'action_off',
226
+ config: 9,
227
+ action_on_data: null,
228
+ action_off_data: null,
229
+ is_on_values: [1],
230
+ order: 1,
231
+ },
232
+ ],
233
+ start_order: 1,
234
+ number_action: 2,
235
+ unit: 1,
236
+ })
237
+ );
238
+ expect(mock.history.post[1].url).toEqual(API.AUTOMATE.ADD_SCRIPT_ACTION(1));
239
+ expect(mock.history.post[1].data).toEqual(
240
+ JSON.stringify({
241
+ list_action: [
242
+ {
243
+ action: 'action',
244
+ data: null,
245
+ order: 2,
246
+ },
247
+ ],
248
+ unit: 1,
249
+ })
250
+ );
251
+ expect(global.mockedNavigate).toHaveBeenCalled();
252
+ });
253
+
254
+ it('test update toggle script', async () => {
255
+ activatedScript = {
256
+ ...activatedScript,
257
+ action_script: null,
258
+ toggle_script: {
259
+ id: 1,
260
+ end_device_id: 2,
261
+ sensor_name: 'LED',
262
+ station_name: 'Room',
263
+ unit_name: 'EoH Office',
264
+ },
265
+ };
266
+ route.params = {
267
+ ...route.params,
268
+ activatedScript,
269
+ scriptItems: [activatedScript],
270
+ };
271
+ mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
272
+ mock.onPut(API.AUTOMATE.UPDATE_SCRIPT_TOGGLE(1)).reply(200);
273
+ mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, { script_items: [] });
274
+ await act(async () => {
275
+ tree = await renderer.create(wrapComponent(route));
276
+ });
277
+ const instance = tree.root;
278
+ await showAllCards(instance);
279
+ await selectActionToggle(instance);
280
+ await pressSaveButton(instance);
281
+
282
+ expect(mock.history.put).toHaveLength(1);
283
+ expect(mock.history.put[0].url).toEqual(
284
+ API.AUTOMATE.UPDATE_SCRIPT_TOGGLE(1)
285
+ );
286
+ expect(mock.history.put[0].data).toEqual(
287
+ JSON.stringify({
288
+ id: 1,
289
+ list_action: [
290
+ {
291
+ action_on: 'action_on',
292
+ action_off: 'action_off',
293
+ config: 9,
294
+ action_on_data: null,
295
+ action_off_data: null,
296
+ is_on_values: [1],
297
+ order: 1,
298
+ },
299
+ ],
300
+ number_action: 1,
301
+ unit: 1,
302
+ })
303
+ );
304
+ expect(global.mockedNavigate).toHaveBeenCalled();
305
+ });
306
+
307
+ it('test update toggle script to action script and add new toggle', async () => {
308
+ activatedScript = {
309
+ ...activatedScript,
310
+ action_script: null,
311
+ toggle_script: {
312
+ id: 1,
313
+ end_device_id: 2,
314
+ sensor_name: 'LED',
315
+ station_name: 'Room',
316
+ unit_name: 'EoH Office',
317
+ },
318
+ };
319
+ route.params = {
320
+ ...route.params,
321
+ activatedScript,
322
+ scriptItems: [activatedScript],
323
+ };
324
+ mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
325
+ mock.onDelete(API.AUTOMATE.DELETE_SCRIPT_ITEM(1, 1)).reply(200);
326
+ mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(200);
327
+ mock.onPost(API.AUTOMATE.ADD_SCRIPT_TOGGLE(1)).reply(200);
328
+ mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, { script_items: [] });
329
+ await act(async () => {
330
+ tree = await renderer.create(wrapComponent(route));
331
+ });
332
+ const instance = tree.root;
333
+ await showAllCards(instance);
334
+ await selectActionOne(instance);
335
+ await selectActionToggle(instance);
336
+ await pressSaveButton(instance);
337
+
338
+ expect(mock.history.delete).toHaveLength(1);
339
+ expect(mock.history.delete[0].url).toEqual(
340
+ API.AUTOMATE.DELETE_SCRIPT_ITEM(1, 1)
341
+ );
342
+ expect(mock.history.post).toHaveLength(2);
343
+ expect(mock.history.post[0].url).toEqual(API.AUTOMATE.ADD_SCRIPT_ACTION(1));
344
+ expect(mock.history.post[0].data).toEqual(
345
+ JSON.stringify({
346
+ list_action: [
347
+ {
348
+ action: 'action',
349
+ data: null,
350
+ order: 2,
351
+ },
352
+ ],
353
+ start_order: 2,
354
+ number_action: 2,
355
+ unit: 1,
356
+ })
357
+ );
358
+ expect(mock.history.post[1].url).toEqual(API.AUTOMATE.ADD_SCRIPT_TOGGLE(1));
359
+ expect(mock.history.post[1].data).toEqual(
360
+ JSON.stringify({
361
+ list_action: [
362
+ {
363
+ action_on: 'action_on',
364
+ action_off: 'action_off',
365
+ config: 9,
366
+ action_on_data: null,
367
+ action_off_data: null,
368
+ is_on_values: [1],
369
+ order: 1,
370
+ },
371
+ ],
372
+ unit: 1,
373
+ })
374
+ );
375
+ expect(global.mockedNavigate).toHaveBeenCalled();
376
+ });
377
+
378
+ it('test update action script fail', async () => {
379
+ mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
380
+ mock.onPut(API.AUTOMATE.UPDATE_SCRIPT_ACTION(1)).reply(400);
381
+ await act(async () => {
382
+ tree = await renderer.create(wrapComponent(route));
383
+ });
384
+ const instance = tree.root;
385
+ await showAllCards(instance);
386
+ await selectActionOn(instance);
387
+ await pressSaveButton(instance);
388
+
389
+ expect(global.mockedNavigate).not.toHaveBeenCalled();
390
+ });
391
+
140
392
  it('test can not update because adding too many times allowed', async () => {
141
393
  mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
142
394
  const spyToast = jest.spyOn(ToastBottomHelper, 'error');
@@ -145,13 +397,18 @@ describe('Test UpdateActionScript', () => {
145
397
  });
146
398
 
147
399
  const instance = tree.root;
148
- expect(instance.findAllByType(RenderActionItem).length).toBe(2);
400
+ expect(instance.findAllByType(RenderActionItem).length).toBe(3);
149
401
  await showAllCards(instance);
150
402
  await selectActionOn(instance);
151
403
  await selectActionOff(instance);
152
404
  await selectActionOne(instance);
405
+ await selectActionFirstThreeTemplate(instance);
153
406
  await pressSaveButton(instance);
154
407
 
155
- expect(spyToast).toHaveBeenCalled();
408
+ expect(spyToast).toHaveBeenCalledWith(
409
+ 'You can only add more 1 action',
410
+ null,
411
+ 3000
412
+ );
156
413
  });
157
414
  });
@@ -170,12 +170,12 @@ describe('EditActionsList', () => {
170
170
  Routes.UpdateActionScript,
171
171
  {
172
172
  automateId: 1,
173
+ activatedScript: actionsList[0],
173
174
  closeScreen: Routes.EditActionsList,
174
175
  device: {
175
176
  id: 1,
176
177
  },
177
- numberActionAdded: 4,
178
- scriptItemId: 1,
178
+ scriptItems: actionsList,
179
179
  unitId: undefined,
180
180
  }
181
181
  );
@@ -144,19 +144,20 @@ const EditActionsList = () => {
144
144
  const paddedIndex = (index + 1).toString().padStart(2, '0');
145
145
  const {
146
146
  action_script,
147
+ toggle_script,
147
148
  notify_script,
148
149
  delay_script,
149
150
  email_script,
150
151
  sms_script,
151
152
  } = item;
152
- if (action_script) {
153
+ if (action_script || toggle_script) {
153
154
  const {
154
155
  sensor_icon_kit,
155
156
  station_name,
156
157
  sensor_name,
157
158
  action_name,
158
159
  data: data_action,
159
- } = action_script;
160
+ } = action_script || toggle_script;
160
161
 
161
162
  return (
162
163
  <CommonItem
@@ -178,7 +179,9 @@ const EditActionsList = () => {
178
179
  {sensor_name}
179
180
  </Text>
180
181
  <Text numberOfLines={1} type="H4" color={Colors.Gray9}>
181
- {action_name} {data_action}
182
+ {toggle_script
183
+ ? t('toggle')
184
+ : `${action_name} ${data_action || ''}`}
182
185
  </Text>
183
186
  </>
184
187
  }
@@ -316,6 +319,7 @@ const EditActionsList = () => {
316
319
  const renderAction = useMemo(() => {
317
320
  const {
318
321
  action_script,
322
+ toggle_script,
319
323
  notify_script,
320
324
  delay_script,
321
325
  email_script,
@@ -323,17 +327,17 @@ const EditActionsList = () => {
323
327
  id: scriptItemId,
324
328
  } = scriptItem;
325
329
 
326
- if (action_script) {
330
+ if (action_script || toggle_script) {
327
331
  onClosePopup();
328
332
  setScriptItem({});
329
333
  navigate(Routes.UpdateActionScript, {
330
334
  unitId,
331
335
  automateId: id,
336
+ activatedScript: scriptItem,
332
337
  device: {
333
- id: action_script.end_device_id,
338
+ id: action_script?.end_device_id || toggle_script?.end_device_id,
334
339
  },
335
- numberActionAdded: actionsList.length,
336
- scriptItemId: scriptItemId,
340
+ scriptItems: actionsList,
337
341
  closeScreen: Routes.EditActionsList,
338
342
  });
339
343
  }
@@ -407,27 +411,35 @@ const EditActionsList = () => {
407
411
  );
408
412
 
409
413
  const renderMessageRemove = useMemo(() => {
410
- const { action_script, notify_script, delay_script, email_script } =
411
- itemRemove;
412
- if (action_script) {
414
+ const {
415
+ action_script,
416
+ toggle_script,
417
+ notify_script,
418
+ delay_script,
419
+ email_script,
420
+ } = itemRemove;
421
+ if (action_script || toggle_script) {
422
+ const actionName = action_script?.action_name || t('toggle');
423
+ const stationName =
424
+ action_script?.station_name || toggle_script?.station_name;
413
425
  return (
414
426
  <ParsedText
415
427
  style={styles.messageDelete}
416
428
  parse={[
417
429
  {
418
- pattern: new RegExp(itemRemove.action_script.action_name),
430
+ pattern: new RegExp(actionName),
419
431
  style: styles.textHighlight,
420
432
  },
421
433
  {
422
- pattern: new RegExp(itemRemove.action_script.station_name),
434
+ pattern: new RegExp(stationName),
423
435
  style: styles.textHighlight,
424
436
  },
425
437
  ]}
426
438
  childrenProps={{ allowFontScaling: false }}
427
439
  >
428
440
  {t('message_delete_action', {
429
- actionName: itemRemove.action_script.action_name,
430
- stationName: itemRemove.action_script.station_name,
441
+ actionName: actionName,
442
+ stationName: stationName,
431
443
  })}
432
444
  </ParsedText>
433
445
  );
@@ -96,7 +96,15 @@ const MultiUnits = () => {
96
96
  navigate(Routes.UnitStack, {
97
97
  screen: Routes.ScenarioName,
98
98
  params: {
99
- automate: { type: AUTOMATE_TYPE.ONE_TAP, unit: unitId },
99
+ automate: {
100
+ type: AUTOMATE_TYPE.ONE_TAP,
101
+ conditions: [
102
+ {
103
+ type: AUTOMATE_TYPE.ONE_TAP,
104
+ },
105
+ ],
106
+ unit: unitId,
107
+ },
100
108
  closeScreen: currentRouteName,
101
109
  },
102
110
  });
@@ -50,7 +50,7 @@ describe('test OneTap', () => {
50
50
  script: { id: 1, name: 'William Miller' },
51
51
  };
52
52
 
53
- mock.onPost(API.AUTOMATE.CREATE_AUTOMATE()).reply(200, response);
53
+ mock.onPost(API.AUTOMATE.CREATE_AUTOMATE_V2()).reply(200, response);
54
54
 
55
55
  await act(async () => {
56
56
  tree = await create(wrapComponent(route));
@@ -99,7 +99,7 @@ describe('test OneTap', () => {
99
99
  params: { type: 'one_tap' },
100
100
  };
101
101
 
102
- mock.onPost(API.AUTOMATE.CREATE_AUTOMATE()).reply(400);
102
+ mock.onPost(API.AUTOMATE.CREATE_AUTOMATE_V2()).reply(400);
103
103
 
104
104
  await act(async () => {
105
105
  tree = await create(wrapComponent(route));
@@ -130,7 +130,7 @@ describe('test OneTap', () => {
130
130
  },
131
131
  };
132
132
 
133
- mock.onPost(API.AUTOMATE.CREATE_AUTOMATE()).reply(400);
133
+ mock.onPost(API.AUTOMATE.CREATE_AUTOMATE_V2()).reply(400);
134
134
  await act(async () => {
135
135
  tree = await create(wrapComponent(route));
136
136
  });
@@ -20,14 +20,7 @@ import AccessibilityLabel from '../../../../configs/AccessibilityLabel';
20
20
  import { AUTOMATE_TYPE } from '../../../../configs/Constants';
21
21
 
22
22
  const AddActionScript = memo(
23
- ({
24
- automate,
25
- isVisible,
26
- setIsVisible,
27
- numberActionAdded,
28
- type,
29
- navigate,
30
- }) => {
23
+ ({ automate, isVisible, setIsVisible, scriptItems, type, navigate }) => {
31
24
  const t = useTranslations();
32
25
  const { id, unit } = automate;
33
26
 
@@ -46,9 +39,10 @@ const AddActionScript = memo(
46
39
  const navParams = {
47
40
  unitId: unit,
48
41
  automateId: id,
42
+ scriptItems: scriptItems,
49
43
  closeScreen: currentScreenName,
50
44
  numberActionCanAdd:
51
- max_actions_per_automation - numberActionAdded,
45
+ max_actions_per_automation - scriptItems.length,
52
46
  routeName: unit ? null : Routes.SelectControlDevices,
53
47
  };
54
48
 
@@ -134,7 +128,7 @@ const AddActionScript = memo(
134
128
  id,
135
129
  max_actions_per_automation,
136
130
  navigate,
137
- numberActionAdded,
131
+ scriptItems,
138
132
  setIsVisible,
139
133
  t,
140
134
  unit,
@@ -4,17 +4,15 @@ import AlertAction from '../../../../commons/AlertAction';
4
4
  import { axiosDelete } from '../../../../utils/Apis/axios';
5
5
  import { ToastBottomHelper } from '../../../../utils/Utils';
6
6
  import { useTranslations } from '../../../../hooks/Common/useTranslations';
7
- import { useNavigation } from '@react-navigation/native';
8
7
 
9
- const RenameScript = ({ automate, isVisible, setIsVisible }) => {
8
+ const RenameScript = ({ automate, isVisible, setIsVisible, goBack }) => {
10
9
  const t = useTranslations();
11
- const { goBack } = useNavigation();
12
10
 
13
11
  const deleteScript = useCallback(async () => {
14
12
  const { success } = await axiosDelete(API.AUTOMATE.SCRIPT(automate.id));
15
13
  if (success) {
16
14
  setIsVisible(false);
17
- goBack();
15
+ goBack && goBack();
18
16
  ToastBottomHelper.success(t('removed_successfully'));
19
17
  } else {
20
18
  ToastBottomHelper.error(t('remove_failed'));