@eohjsc/react-native-smart-city 0.3.11 → 0.3.14

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/index.js CHANGED
@@ -17,6 +17,7 @@ import NotificationStack from './src/navigations/NotificationStack';
17
17
  import MyPinnedSharedUnit from './src/commons/Dashboard/MyPinnedSharedUnit';
18
18
  import MyUnit from './src/commons/Dashboard/MyUnit';
19
19
  import SharedUnit from './src/commons/Unit/SharedUnit';
20
+ import { Action } from './src/context/actionType';
20
21
 
21
22
  export {
22
23
  AddSubUnitStack,
@@ -40,4 +41,5 @@ export {
40
41
  SharedUnit,
41
42
  MyUnit,
42
43
  SCWrapper,
44
+ Action,
43
45
  };
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.3.11",
4
+ "version": "0.3.14",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -7,7 +7,7 @@ import { useRemoteControl } from '../../hooks/IoT';
7
7
  import { useConfigGlobalState } from '../../iot/states';
8
8
  import IconComponent from '../IconComponent';
9
9
 
10
- const ItemQuickAction = memo(({ sensor, wrapperStyle, setStatus, unit }) => {
10
+ const ItemQuickAction = memo(({ sensor, wrapperStyle, setStatus }) => {
11
11
  const [isSendingCommand, setIsSendingCommand] = useState(false);
12
12
  const [action, setAction] = useState(sensor.action);
13
13
  // eslint-disable-next-line no-unused-vars
@@ -47,6 +47,8 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
47
47
  const configValue = configValues[config];
48
48
  if (configValue !== null && configValue !== undefined) {
49
49
  setValue(configValue);
50
+ } else {
51
+ setValue(valueDefault);
50
52
  }
51
53
  // eslint-disable-next-line react-hooks/exhaustive-deps
52
54
  }, [JSON.stringify(configValues)]);
@@ -326,7 +326,7 @@ describe('Test NumberUpDownActionTemplate', () => {
326
326
  });
327
327
  const instance = wrapper.root;
328
328
  const text = instance.findAllByType(ActivityIndicator);
329
- expect(text).toHaveLength(1);
329
+ expect(text).toHaveLength(0);
330
330
  });
331
331
  test('action up sensor device type is GOOGLE_HOME', async () => {
332
332
  const mockDoAction = jest.fn();
@@ -363,7 +363,7 @@ describe('Test ActionGroup', () => {
363
363
  });
364
364
  const instance = wrapper.root;
365
365
  const activity = instance.findAllByType(ActivityIndicator);
366
- expect(activity.length).toEqual(1);
366
+ expect(activity.length).toEqual(0);
367
367
  });
368
368
 
369
369
  test('render ActionGroup StatesGridActionTemplate', async () => {
@@ -234,7 +234,7 @@ const HistoryChart = memo(
234
234
  )}
235
235
  <DateTimePickerModal
236
236
  isVisible={eventPicker.showModalStart}
237
- date={eventPicker.startTime.valueOf()}
237
+ date={eventPicker.startTime?._d}
238
238
  mode={formatType || 'datetime'}
239
239
  onConfirm={onConfirmStart}
240
240
  onCancel={onCancel}
@@ -244,7 +244,7 @@ const HistoryChart = memo(
244
244
  />
245
245
  <DateTimePickerModal
246
246
  isVisible={eventPicker.showModalEnd}
247
- date={eventPicker.endTime.valueOf()}
247
+ date={eventPicker.endTime?._d}
248
248
  mode={formatType || 'datetime'}
249
249
  onConfirm={onConfirmEnd}
250
250
  onCancel={onCancel}
@@ -82,7 +82,7 @@ const ItemDevice = memo(
82
82
  const textConnected = isConnected
83
83
  ? t('connected')
84
84
  : isConnecting
85
- ? ''
85
+ ? t('connecting')
86
86
  : t('disconnected');
87
87
 
88
88
  return (
@@ -98,7 +98,7 @@ const ItemDevice = memo(
98
98
  <TouchableOpacity onPress={goToSensorDisplay}>
99
99
  <IconComponent icon={sensor.icon} iconKit={sensor.icon_kit} />
100
100
  </TouchableOpacity>
101
- <ItemQuickAction sensor={sensor} unit={unit} />
101
+ {!isConnecting && <ItemQuickAction sensor={sensor} unit={unit} />}
102
102
  </View>
103
103
  <TouchableOpacity onPress={goToSensorDisplay}>
104
104
  <Text
@@ -19,16 +19,20 @@ const NumberUpDownActionTemplate = memo(({ data, onSelectAction }) => {
19
19
  const { configuration, template, title } = data;
20
20
  const { config, text_format, min_value, max_value, action } = configuration;
21
21
  const [configValues] = useConfigGlobalState('configValues');
22
- const [value, setValue] = useState((config && configValues[config]) || 28);
22
+ const [value, setValue] = useState();
23
23
  const [actionName, setActionName] = useState(null);
24
+ const valueDefault = 28;
24
25
 
25
26
  useEffect(() => {
26
27
  if (!config) {
28
+ setValue(valueDefault);
27
29
  return;
28
30
  }
29
31
  const configValue = configValues[config];
30
32
  if (configValue !== null && configValue !== undefined) {
31
33
  setValue(configValue);
34
+ } else {
35
+ setValue(valueDefault);
32
36
  }
33
37
  }, [configValues, config]);
34
38
 
@@ -112,7 +112,7 @@ export class SCConfig {
112
112
 
113
113
  export const initSCConfig = (config) => {
114
114
  api.setBaseURL(config.apiRoot ?? SCDefaultConfig.apiRoot);
115
- LocaleConfig.defaultLocale = config.language;
115
+ LocaleConfig.defaultLocale = config.language ?? SCConfig.language;
116
116
  SCConfig.language = config.language ?? SCConfig.language;
117
117
  SCConfig.apiRoot = config.apiRoot ?? SCDefaultConfig.apiRoot;
118
118
  SCConfig.GOOGLE_MAP_API_KEY =
@@ -21,6 +21,7 @@ export const Action = {
21
21
  SET_GOOGLE_HOME_CONNECTIONS: 'SET_GOOGLE_HOME_CONNECTIONS',
22
22
  CHANGE_GOOGLE_HOME_CONN_STATE: 'CHANGE_GOOGLE_HOME_CONN_STATE',
23
23
  UPDATE_VALUE_EVALUATIONS: 'UPDATE_VALUE_EVALUATIONS',
24
+ ON_RECEIVE_NOTIFICATION: 'ON_RECEIVE_NOTIFICATION',
24
25
  };
25
26
 
26
27
  export type AuthData = {
@@ -77,6 +78,7 @@ export type AppType = {
77
78
  isBluetoothEnabled: boolean;
78
79
  isNetworkConnected: boolean;
79
80
  camera_opened: any[];
81
+ notificationData: any;
80
82
  };
81
83
 
82
84
  export type IoTType = {
@@ -59,6 +59,7 @@ export const initialState = {
59
59
  isBluetoothEnabled: false,
60
60
  isNetworkConnected: false,
61
61
  camera_opened: [],
62
+ notificationData: null,
62
63
  },
63
64
  iot: {
64
65
  googlehome: {
@@ -318,6 +319,15 @@ export const reducer = (currentState: ContextData, action: Action) => {
318
319
  ),
319
320
  };
320
321
 
322
+ case Action.ON_RECEIVE_NOTIFICATION:
323
+ return {
324
+ ...currentState,
325
+ app: {
326
+ ...currentState.app,
327
+ notificationData: payload,
328
+ },
329
+ };
330
+
321
331
  default:
322
332
  return currentState;
323
333
  }
@@ -1,26 +1,20 @@
1
- import { useEffect, useState, useCallback } from 'react';
2
- import OneSignal from 'react-native-onesignal';
1
+ import { useEffect, useState } from 'react';
2
+ import { useSCContextSelector } from '../context';
3
3
 
4
4
  const useReceiveNotifications = (callBack) => {
5
- const [dataNofitication, setDataNofitication] = useState(null);
6
-
7
- const onReceived = useCallback((data) => {
8
- const { additionalData } = data;
9
- setDataNofitication(additionalData);
10
- }, []);
5
+ const [dataNotification, setDataNotification] = useState(null);
6
+ const notificationData = useSCContextSelector(
7
+ (state) => state.app.notificationData
8
+ );
11
9
 
12
10
  useEffect(() => {
13
- OneSignal.setNotificationWillShowInForegroundHandler(
14
- (notifReceivedEvent) => {
15
- let notif = notifReceivedEvent.getNotification();
16
- setTimeout(() => notifReceivedEvent.complete(notif), 0);
17
- onReceived(notif);
18
- callBack && callBack();
19
- }
20
- );
21
- }, [callBack, onReceived]);
11
+ if (notificationData) {
12
+ setDataNotification(notificationData);
13
+ callBack && callBack();
14
+ }
15
+ }, [callBack, notificationData]);
22
16
 
23
- return { dataNofitication };
17
+ return { dataNotification };
24
18
  };
25
19
 
26
20
  export default useReceiveNotifications;
@@ -1,5 +1,7 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
+ import Toast from 'react-native-toast-message';
4
+
3
5
  import MockAdapter from 'axios-mock-adapter';
4
6
  import { SCProvider } from '../../../context';
5
7
  import { mockSCStore } from '../../../context/mockStore';
@@ -117,6 +119,30 @@ describe('Test ScriptDetail', () => {
117
119
  expect(alertAction.props.visible).toBeFalsy();
118
120
  });
119
121
 
122
+ test('test rename script failed', async () => {
123
+ await act(async () => {
124
+ tree = await create(wrapComponent(route));
125
+ });
126
+ const instance = tree.root;
127
+ const menu = instance.findByType(MenuActionMore);
128
+ const alertAction = instance.findByType(AlertAction);
129
+ const rename = menu.props.listMenuItem[0];
130
+
131
+ await act(async () => {
132
+ await menu.props.onItemClick(rename);
133
+ await menu.props.hideComplete();
134
+ });
135
+ expect(menu.props.isVisible).toBeFalsy();
136
+ expect(alertAction.props.visible).toBeTruthy();
137
+
138
+ mock.onPatch(API.AUTOMATE.SCRIPT(1)).reply(500, { name: 'new_name' });
139
+ await act(async () => {
140
+ await alertAction.props.rightButtonClick();
141
+ });
142
+ expect(alertAction.props.visible).toBeFalsy();
143
+ expect(Toast.show).toHaveBeenCalled();
144
+ });
145
+
120
146
  test('test delete script', async () => {
121
147
  await act(async () => {
122
148
  tree = await create(wrapComponent(route));
@@ -99,9 +99,14 @@ const ScriptDetail = ({ route }) => {
99
99
  name: inputName,
100
100
  }
101
101
  );
102
- success && setScriptName(script.name);
102
+ if (success) {
103
+ setScriptName(script.name);
104
+ ToastBottomHelper.success(t('rename_successfully'));
105
+ } else {
106
+ ToastBottomHelper.error(t('rename_failed'));
107
+ }
103
108
  hideAlertAction();
104
- }, [id, inputName, hideAlertAction]);
109
+ }, [id, inputName, hideAlertAction, t]);
105
110
 
106
111
  const deleteScript = useCallback(async () => {
107
112
  hideAlertAction();
@@ -113,12 +118,16 @@ const ScriptDetail = ({ route }) => {
113
118
  } else {
114
119
  goBack();
115
120
  }
121
+ ToastBottomHelper.success(t('removed_successfully'));
122
+ } else {
123
+ ToastBottomHelper.error(t('remove_failed'));
116
124
  }
117
125
  }, [
118
126
  hideAlertAction,
119
127
  id,
120
128
  isCreateScriptSuccess,
121
129
  isCreateNewAction,
130
+ t,
122
131
  dispatch,
123
132
  isAutomateTab,
124
133
  goBack,
@@ -189,7 +189,7 @@ const UnitDetail = ({ route }) => {
189
189
  });
190
190
 
191
191
  return () => {
192
- subscription.remove();
192
+ subscription?.remove();
193
193
  };
194
194
  }, [fetchDetails]);
195
195
 
@@ -69,7 +69,7 @@ const Summaries = memo(({ unit }) => {
69
69
  });
70
70
 
71
71
  return () => {
72
- subscription.remove();
72
+ subscription?.remove();
73
73
  };
74
74
  }, [fetchUnitSummary]);
75
75
 
@@ -19,7 +19,9 @@ const RunningDevices = memo(({ unit, summaryDetail }) => {
19
19
  await connectGoogleHome(unit.remote_control_options.googlehome))();
20
20
  }
21
21
  }
22
- }, [connectGoogleHome, unit]);
22
+ // eslint-disable-next-line react-hooks/exhaustive-deps
23
+ }, [unit]);
24
+
23
25
  return (
24
26
  <View style={styles.container}>
25
27
  {!!devices &&