@eohjsc/react-native-smart-city 0.7.3-rc11 → 0.7.3-rc12

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eohjsc/react-native-smart-city",
3
3
  "title": "React Native Smart Home",
4
- "version": "0.7.3-rc11",
4
+ "version": "0.7.3-rc12",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -86,7 +86,7 @@ export default StyleSheet.create({
86
86
  alignItems: 'center',
87
87
  },
88
88
  menuIcon: {
89
- paddingLeft: 16,
89
+ paddingRight: 10,
90
90
  height: '100%',
91
91
  justifyContent: 'center',
92
92
  },
@@ -50,6 +50,8 @@ export default SharedStack;
50
50
 
51
51
  const styles = StyleSheet.create({
52
52
  btnMenu: {
53
+ paddingLeft: 0,
54
+ paddingRight: 10,
53
55
  paddingHorizontal: 16,
54
56
  height: '100%',
55
57
  justifyContent: 'center',
@@ -14,7 +14,13 @@ import RenderActionItem from './RenderActionItem';
14
14
  const ChooseAction = ({ route }) => {
15
15
  const t = useTranslations();
16
16
  const { navigate } = useNavigation();
17
- const { unitId, device, automateId, numberActionCanAdd } = route?.params;
17
+ const {
18
+ unitId,
19
+ device,
20
+ automateId,
21
+ numberActionCanAdd,
22
+ multiUnit = {},
23
+ } = route.params;
18
24
  const [data, setData] = useState([]);
19
25
  const [actions, setActions] = useState([]);
20
26
 
@@ -48,7 +54,7 @@ const ChooseAction = ({ route }) => {
48
54
  API.AUTOMATE.ADD_SCRIPT_ACTION(automateId),
49
55
  {
50
56
  list_action,
51
- unit: unitId,
57
+ unit: unitId || multiUnit.id,
52
58
  }
53
59
  );
54
60
 
@@ -58,7 +64,15 @@ const ChooseAction = ({ route }) => {
58
64
  merge: true,
59
65
  params: { saveAt: moment().valueOf() },
60
66
  });
61
- }, [actions, numberActionCanAdd, automateId, unitId, navigate, t]);
67
+ }, [
68
+ actions,
69
+ numberActionCanAdd,
70
+ automateId,
71
+ unitId,
72
+ multiUnit.id,
73
+ navigate,
74
+ t,
75
+ ]);
62
76
 
63
77
  const handleOnSelectAction = (action) => {
64
78
  setActions((prevActions) => {
@@ -1,17 +1,17 @@
1
+ import { useNavigation } from '@react-navigation/native';
1
2
  import React, { useCallback, useEffect, useState } from 'react';
2
3
  import { View } from 'react-native';
3
- import { useNavigation } from '@react-navigation/native';
4
4
 
5
- import { useTranslations } from '../../../hooks/Common/useTranslations';
5
+ import GridItem from '../../../commons/Grid/GridItem';
6
6
  import Text from '../../../commons/Text';
7
- import { axiosGet } from '../../../utils/Apis/axios';
8
7
  import { API, Colors } from '../../../configs';
8
+ import { AUTOMATE_TYPE } from '../../../configs/Constants';
9
+ import { useTranslations } from '../../../hooks/Common/useTranslations';
10
+ import { axiosGet } from '../../../utils/Apis/axios';
9
11
  import Routes from '../../../utils/Route';
10
- import styles from './Styles/SelectActionStyles';
11
12
  import { LoadingSelectAction } from './Components';
12
- import { AUTOMATE_TYPE } from '../../../configs/Constants';
13
13
  import NewActionWrapper from './NewActionWrapper';
14
- import GridItem from '../../../commons/Grid/GridItem';
14
+ import styles from './Styles/SelectActionStyles';
15
15
 
16
16
  const ChooseConfig = ({ route }) => {
17
17
  const t = useTranslations();
@@ -44,6 +44,7 @@ const ChooseConfig = ({ route }) => {
44
44
  config,
45
45
  automate,
46
46
  closeScreen,
47
+ unitId: automate?.unit,
47
48
  });
48
49
  },
49
50
  [automate, closeScreen, navigate]
@@ -8,8 +8,13 @@ import SelectDevices from './Components/SelectDevices';
8
8
 
9
9
  const SelectControlDevices = ({ route }) => {
10
10
  const t = useTranslations();
11
- const { unitId, closeScreen, automateId, numberActionCanAdd } =
12
- route?.params || {};
11
+ const {
12
+ unitId,
13
+ closeScreen,
14
+ automateId,
15
+ numberActionCanAdd,
16
+ multiUnit = {},
17
+ } = route.params || {};
13
18
 
14
19
  const [stations, setStations] = useState([]);
15
20
  const [listStation, setListStation] = useState([]);
@@ -19,22 +24,26 @@ const SelectControlDevices = ({ route }) => {
19
24
  const [loading, setLoading] = useState(true);
20
25
 
21
26
  const fetchDetails = useCallback(async () => {
22
- await fetchWithCache(API.UNIT.DEVICE_CONTROL(unitId), {}, (response) => {
23
- const { success, data } = response;
24
- if (success) {
25
- const newData = data.filter((item) => item.sensors.length > 0);
26
- const listMenu = newData.map((item, index) => ({
27
- text: item.name,
28
- station: item,
29
- index: index,
30
- }));
31
- setStations(newData);
32
- setListMenuItem(listMenu);
33
- setListStation(listMenu);
27
+ await fetchWithCache(
28
+ API.UNIT.DEVICE_CONTROL(unitId || multiUnit.id),
29
+ {},
30
+ (response) => {
31
+ const { success, data } = response;
32
+ if (success) {
33
+ const newData = data.filter((item) => item.sensors.length > 0);
34
+ const listMenu = newData.map((item, index) => ({
35
+ text: item.name,
36
+ station: item,
37
+ index: index,
38
+ }));
39
+ setStations(newData);
40
+ setListMenuItem(listMenu);
41
+ setListStation(listMenu);
42
+ }
34
43
  }
35
- });
44
+ );
36
45
  setLoading(false);
37
- }, [unitId]);
46
+ }, [multiUnit.id, unitId]);
38
47
 
39
48
  useEffect(() => {
40
49
  fetchDetails();
@@ -48,9 +57,10 @@ const SelectControlDevices = ({ route }) => {
48
57
  device: selectedDevice,
49
58
  closeScreen,
50
59
  numberActionCanAdd,
60
+ multiUnit,
51
61
  });
52
62
  },
53
- [navigate, unitId, automateId, closeScreen, numberActionCanAdd]
63
+ [navigate, unitId, automateId, closeScreen, numberActionCanAdd, multiUnit]
54
64
  );
55
65
 
56
66
  if (loading) {
@@ -1,16 +1,22 @@
1
- import React, { useCallback, useEffect, useState } from 'react';
2
1
  import { useNavigation } from '@react-navigation/native';
2
+ import React, { useCallback, useEffect, useState } from 'react';
3
3
 
4
+ import { API } from '../../../configs';
5
+ import { AUTOMATE_TYPE } from '../../../configs/Constants';
4
6
  import { useTranslations } from '../../../hooks/Common/useTranslations';
5
7
  import { fetchWithCache } from '../../../utils/Apis/axios';
6
- import { API } from '../../../configs';
7
8
  import Routes from '../../../utils/Route';
8
9
  import SelectDevices from './Components/SelectDevices';
9
- import { AUTOMATE_TYPE } from '../../../configs/Constants';
10
10
 
11
11
  const SelectMonitorDevices = ({ route }) => {
12
12
  const t = useTranslations();
13
- const { automate = {}, isCreateNewAction, closeScreen } = route?.params || {};
13
+ const {
14
+ automate = {},
15
+ isCreateNewAction,
16
+ closeScreen,
17
+ multiUnit = {},
18
+ } = route.params || {};
19
+ const { type, unit, sensor_id } = automate;
14
20
 
15
21
  const [stations, setStations] = useState([]);
16
22
  const [listStation, setListStation] = useState([]);
@@ -22,11 +28,11 @@ const SelectMonitorDevices = ({ route }) => {
22
28
 
23
29
  const fetchDetails = useCallback(async () => {
24
30
  const configs = { params: {} };
25
- if (automate?.type === AUTOMATE_TYPE.EVENT) {
31
+ if (type === AUTOMATE_TYPE.EVENT) {
26
32
  configs.params.type = 'event';
27
33
  }
28
34
  await fetchWithCache(
29
- API.UNIT.DEVICE_SENSOR(automate?.unit),
35
+ API.UNIT.DEVICE_SENSOR(unit || multiUnit.id),
30
36
  configs,
31
37
  (response) => {
32
38
  const { success, data } = response;
@@ -46,17 +52,17 @@ const SelectMonitorDevices = ({ route }) => {
46
52
  }
47
53
  );
48
54
  setLoading(false);
49
- }, [automate?.type, automate?.unit]);
55
+ }, [multiUnit.id, type, unit]);
50
56
 
51
57
  useEffect(() => {
52
- if (!automate?.sensor_id) {
58
+ if (!sensor_id) {
53
59
  return;
54
60
  }
55
61
  let selectSensor = {};
56
62
  let found = false;
57
63
  for (let i = 0; i < stations.length; i++) {
58
64
  for (let j = 0; j < stations[i].sensors.length; j++) {
59
- if (stations[i].sensors[j].id === automate.sensor_id) {
65
+ if (stations[i].sensors[j].id === sensor_id) {
60
66
  selectSensor = stations[i].sensors[j];
61
67
  found = true;
62
68
  break;
@@ -67,7 +73,7 @@ const SelectMonitorDevices = ({ route }) => {
67
73
  }
68
74
  }
69
75
  setDefaultSelectedDevice(selectSensor);
70
- }, [automate?.sensor_id, stations]);
76
+ }, [sensor_id, stations]);
71
77
 
72
78
  useEffect(() => {
73
79
  fetchDetails();
@@ -86,6 +92,7 @@ const SelectMonitorDevices = ({ route }) => {
86
92
  stationName: stations[indexStation]?.name,
87
93
  isCreateNewAction,
88
94
  closeScreen,
95
+ unitId: automate?.unit,
89
96
  });
90
97
  },
91
98
  [navigate, automate, stations, isCreateNewAction, closeScreen]
@@ -40,7 +40,7 @@ const SetupScriptDelay = ({ route }) => {
40
40
  params: { saveAt: moment().valueOf() },
41
41
  });
42
42
  } else {
43
- ToastBottomHelper.error(t('text_done'));
43
+ ToastBottomHelper.error(t('error_please_try_later'));
44
44
  }
45
45
  }, [automateId, navigate, delay, t]);
46
46
 
@@ -17,9 +17,9 @@ import moment from 'moment';
17
17
  const SetupScriptNotify = ({ route }) => {
18
18
  const t = useTranslations();
19
19
  const { goBack, navigate } = useNavigation();
20
- const { automate = {}, unitId } = route?.params || {};
20
+ const { automate = {}, unitId, multiUnit } = route.params || {};
21
21
  const { id: automateId } = automate;
22
- const [notify, setNotify] = useState({ unit: unitId });
22
+ const [notify, setNotify] = useState({ unit: unitId || multiUnit.id });
23
23
 
24
24
  const onChangeTitle = (value) => {
25
25
  setNotify((state) => ({
@@ -47,7 +47,7 @@ const SetupScriptNotify = ({ route }) => {
47
47
  params: { saveAt: moment().valueOf() },
48
48
  });
49
49
  } else {
50
- ToastBottomHelper.error(t('text_done'));
50
+ ToastBottomHelper.error(t('error_please_try_later'));
51
51
  }
52
52
  }, [automateId, navigate, notify, t]);
53
53
 
@@ -69,6 +69,35 @@ describe('Test SetupScriptNotify', () => {
69
69
  expect(spyToast).toHaveBeenCalled();
70
70
  });
71
71
 
72
+ it('SetupScriptNotify onPress create script notify success with multi unit', async () => {
73
+ route.params.unitId = null;
74
+ route.params.multiUnit = { id: 1 };
75
+ const spyToast = jest.spyOn(ToastBottomHelper, 'success');
76
+ mock.onPost(API.AUTOMATE.ADD_SCRIPT_NOTIFY(1)).reply(200);
77
+ await act(async () => {
78
+ tree = await renderer.create(wrapComponent(route));
79
+ });
80
+ const instance = tree.root;
81
+ const inputs = instance.findAllByType(_TextInput);
82
+ expect(inputs).toHaveLength(2);
83
+
84
+ await act(async () => {
85
+ inputs[0].props.onChange('Title');
86
+ });
87
+ const touchable = instance.findAllByType(TouchableWithoutFeedback);
88
+ await act(async () => {
89
+ touchable[0].props.onPress();
90
+ });
91
+ await act(async () => {
92
+ inputs[1].props.onChange('Message');
93
+ });
94
+ const button = instance.findByType(BottomButtonView);
95
+ await act(async () => {
96
+ button.props.onPressMain();
97
+ });
98
+ expect(spyToast).toHaveBeenCalled();
99
+ });
100
+
72
101
  it('SetupScriptNotify onPress create script notify error', async () => {
73
102
  const spyToast = jest.spyOn(ToastBottomHelper, 'error');
74
103
  mock.onPost(API.AUTOMATE.ADD_SCRIPT_NOTIFY(1)).reply(400);
@@ -7,16 +7,16 @@ import Text from '../../../commons/Text';
7
7
  import { useTranslations } from '../../../hooks/Common/useTranslations';
8
8
  import Routes from '../../../utils/Route';
9
9
  import styles from './styles/AddNewAutoSmartStyles';
10
+ import { AUTOMATE_TYPE } from '../../../configs/Constants';
10
11
 
11
12
  const AddTypeSmart = ({ smartTypes, route }) => {
12
13
  const t = useTranslations();
13
14
  const { navigate, goBack } = useNavigation();
14
15
  const { automate = {}, closeScreen } = route?.params || {};
16
+ const { id, unit, type } = automate;
15
17
 
16
18
  const [selectedIndex, setSelectedIndex] = useState(
17
- automate?.id
18
- ? smartTypes.findIndex((obj) => obj.type === automate.type)
19
- : -1
19
+ id ? smartTypes.findIndex((obj) => obj.type === type) : -1
20
20
  );
21
21
 
22
22
  const handleOnContinue = useCallback(
@@ -27,18 +27,18 @@ const AddTypeSmart = ({ smartTypes, route }) => {
27
27
  ...automate,
28
28
  type: dataAutomate?.type,
29
29
  },
30
- unitId: automate?.unit,
30
+ unitId: unit,
31
31
  closeScreen: closeScreen,
32
32
  };
33
33
 
34
- if (!automate?.unit) {
34
+ if (!unit && dataAutomate.type !== AUTOMATE_TYPE.SCHEDULE) {
35
35
  navigate(Routes.SelectUnit, params);
36
36
  return;
37
37
  }
38
38
 
39
39
  navigate(dataAutomate.route, params);
40
40
  },
41
- [smartTypes, automate, closeScreen, navigate]
41
+ [smartTypes, automate, unit, closeScreen, navigate]
42
42
  );
43
43
 
44
44
  const onSelectType = (index) => {
@@ -51,7 +51,7 @@ const AddTypeSmart = ({ smartTypes, route }) => {
51
51
  <HeaderCustom isShowClose onClose={goBack} />
52
52
  <View style={styles.container}>
53
53
  <Text semibold type={'H2'} style={styles.titleCreate}>
54
- {automate?.id ? t('update_smart') : t('create_smart')}
54
+ {id ? t('update_smart') : t('create_smart')}
55
55
  </Text>
56
56
  <Text type={'Body'} style={styles.titleChoose}>
57
57
  {t('choose_the_automation_method_you_want')}
@@ -40,6 +40,7 @@ const AddActionScript = memo(
40
40
  closeScreen: currentScreenName,
41
41
  numberActionCanAdd:
42
42
  max_actions_per_automation - numberActionAdded,
43
+ routeName: unit ? null : Routes.SelectControlDevices,
43
44
  };
44
45
 
45
46
  navigate(
@@ -54,10 +55,17 @@ const AddActionScript = memo(
54
55
  image: <Notify />,
55
56
  onClick: () => {
56
57
  setIsVisible(false);
57
- navigate(Routes.SetupScriptNotify, {
58
- automate,
59
- unitId: unit,
60
- });
58
+ if (unit) {
59
+ navigate(Routes.SetupScriptNotify, {
60
+ automate,
61
+ unitId: unit,
62
+ });
63
+ } else {
64
+ navigate(Routes.SelectUnit, {
65
+ automate,
66
+ routeName: Routes.SetupScriptNotify,
67
+ });
68
+ }
61
69
  },
62
70
  },
63
71
  {
@@ -308,6 +308,8 @@ describe('Test ScriptDetail', () => {
308
308
  unitId: route.params.preAutomate.unit,
309
309
  automateId: route.params.preAutomate.id,
310
310
  numberActionCanAdd: 2,
311
+ closeScreen: undefined,
312
+ routeName: null,
311
313
  }
312
314
  );
313
315
  mockedNavigate.mockClear();
@@ -76,7 +76,7 @@ const SelectUnit = () => {
76
76
  isAutomateTab,
77
77
  isMultiUnits,
78
78
  routeName,
79
- unit: selectedItem,
79
+ multiUnit: selectedItem,
80
80
  automateId,
81
81
  scriptName,
82
82
  oldType,
@@ -1320,6 +1320,8 @@ export default {
1320
1320
  smart_supplier: 'Nhà Cung Cấp Thông Minh',
1321
1321
  text_email_or_phone_number: 'Email hoặc Số điện thoại',
1322
1322
  enter_password: 'Mật khẩu',
1323
+ you_need_to_enter_password:
1324
+ 'Bạn cần nhập mật khẩu để xác nhận yêu cầu của mình',
1323
1325
  connecting_smart_account: 'Đang kết nối tài khoản',
1324
1326
  warning_connecting_smart_account:
1325
1327
  'Đừng tắt thiết bị hoặc đóng ứng dụng này trong quá trình thiết lập. Quá trình thiết lập có thể mất vài ' +