@eohjsc/react-native-smart-city 0.3.41 → 0.3.44

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 (54) hide show
  1. package/package.json +1 -1
  2. package/src/commons/AlertAction/index.js +22 -5
  3. package/src/commons/Device/FlatListItems.js +1 -1
  4. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +1 -1
  5. package/src/commons/Device/WindSpeed/Anemometer/index.js +21 -17
  6. package/src/commons/OneTapTemplate/__test__/OptionsDropdownActionTemplate.test.js +1 -1
  7. package/src/commons/Processing/__test__/Connecting.test.js +1 -1
  8. package/src/commons/Processing/index.js +60 -6
  9. package/src/commons/Processing/styles.js +19 -0
  10. package/src/commons/SubUnit/ShortDetail.js +3 -4
  11. package/src/commons/SubUnit/__test__/ShortDetail.test.js +1 -2
  12. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +5 -2
  13. package/src/configs/AccessibilityLabel.js +1 -0
  14. package/src/hooks/Explore/useKeyboardAnimated.js +13 -22
  15. package/src/hooks/IoT/__test__/useRemoteControl.test.js +1 -1
  16. package/src/hooks/IoT/useRemoteControl.js +9 -2
  17. package/src/iot/RemoteControl/HomeAssistant.js +1 -1
  18. package/src/screens/AddNewGateway/ConnectingDevice.js +24 -7
  19. package/src/screens/AddNewGateway/ConnectingModbusDevice.js +42 -20
  20. package/src/screens/AddNewGateway/ConnectingWifiDevice.js +24 -30
  21. package/src/screens/AddNewGateway/ConnectingWifiGuide.js +3 -3
  22. package/src/screens/AddNewGateway/ConnectingZigbeeDevice.js +4 -5
  23. package/src/screens/AddNewGateway/PlugAndPlay/ConnectRouterGuide.js +7 -7
  24. package/src/screens/AddNewGateway/PlugAndPlay/__test__/ConnectRouterGuide.test.js +69 -0
  25. package/src/screens/AddNewGateway/PlugAndPlay/__test__/ZigbeeDeviceConnectGuide.test.js +71 -0
  26. package/src/screens/AddNewGateway/RenameNewDevices.js +6 -12
  27. package/src/screens/AddNewGateway/ScanModbusQR.js +9 -5
  28. package/src/screens/AddNewGateway/ScanWifiDeviceQR.js +3 -3
  29. package/src/screens/AddNewGateway/SelectDeviceSubUnit.js +4 -7
  30. package/src/screens/AddNewGateway/SelectDeviceType.js +18 -19
  31. package/src/screens/AddNewGateway/SelectModbusGateway.js +5 -8
  32. package/src/screens/AddNewGateway/SelectZigbeeGateway.js +3 -4
  33. package/src/screens/AddNewGateway/ShareWifiPassword.js +13 -4
  34. package/src/screens/AddNewGateway/__test__/ConnectingWifiDevice.test.js +5 -1
  35. package/src/screens/AddNewGateway/__test__/ConnectingWifiGuide.test.js +6 -2
  36. package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +8 -4
  37. package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +64 -0
  38. package/src/screens/AddNewGateway/__test__/SelectDeviceType.test.js +3 -1
  39. package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +6 -2
  40. package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +6 -2
  41. package/src/screens/Device/EditDevice/index.js +4 -8
  42. package/src/screens/Device/detail.js +2 -1
  43. package/src/screens/Explore/index.js +22 -7
  44. package/src/screens/HanetCamera/MemberInfo.js +4 -8
  45. package/src/screens/ScriptDetail/index.js +3 -8
  46. package/src/screens/SubUnit/EditSubUnit.js +22 -41
  47. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +51 -59
  48. package/src/screens/Unit/ManageUnit.js +25 -47
  49. package/src/screens/Unit/ManageUnitStyles.js +0 -4
  50. package/src/screens/Unit/__test__/ManageUnit.test.js +6 -14
  51. package/src/utils/I18n/translations/en.json +8 -2
  52. package/src/utils/I18n/translations/vi.json +8 -2
  53. package/src/hooks/Common/useKeyboardShowTranslation.js +0 -120
  54. package/src/utils/runTiming.js +0 -52
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.41",
4
+ "version": "0.3.44",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -1,11 +1,10 @@
1
- import React from 'react';
2
- import { StyleSheet, View } from 'react-native';
1
+ import React, { useState, useEffect } from 'react';
2
+ import { StyleSheet, View, Platform, Animated, Easing } from 'react-native';
3
3
 
4
4
  import ModalCustom from '../../commons/Modal/ModalCustom';
5
5
  import Text from '../../commons/Text';
6
6
  import ViewButtonBottom from '../ViewButtonBottom';
7
7
  import { Colors, Device } from '../../configs';
8
- import Animated from 'react-native-reanimated';
9
8
 
10
9
  const AlertAction = ({
11
10
  visible,
@@ -21,10 +20,21 @@ const AlertAction = ({
21
20
  onHide,
22
21
  children,
23
22
  accessibilityLabelPrefix = '',
24
- animatedStyle,
25
23
  boxLeftButtonStyle,
26
24
  boxRightButtonStyle,
25
+ transY,
27
26
  }) => {
27
+ const [keyboardAnim] = useState(new Animated.Value(0));
28
+
29
+ useEffect(() => {
30
+ Animated.timing(keyboardAnim, {
31
+ toValue: transY,
32
+ duration: 220,
33
+ easing: Easing.linear,
34
+ useNativeDriver: false,
35
+ }).start();
36
+ }, [keyboardAnim, transY]);
37
+
28
38
  return (
29
39
  <ModalCustom
30
40
  isVisible={visible}
@@ -36,7 +46,14 @@ const AlertAction = ({
36
46
  style={styles.container}
37
47
  hideModalContentWhileAnimating
38
48
  >
39
- <Animated.View style={[styles.popoverStyle, animatedStyle]}>
49
+ <Animated.View
50
+ style={[
51
+ styles.popoverStyle,
52
+ Platform.OS === 'ios' && {
53
+ marginBottom: keyboardAnim,
54
+ },
55
+ ]}
56
+ >
40
57
  <View style={styles.modalWrapper}>
41
58
  <View style={styles.modalHeader}>
42
59
  <Text
@@ -82,7 +82,7 @@ const FlatListItems = memo(({ data, style, title, offsetTitle }) => {
82
82
 
83
83
  {filtersNeedReplace.length > 0 && filtersNeedReplace[0].measure === 'H' && (
84
84
  <AlertStatusMachine
85
- message={t('%{number}_filter_need_to_be_replaced', {
85
+ message={t('{number}_filter_need_to_be_replaced', {
86
86
  number: filtersNeedReplace.length,
87
87
  })}
88
88
  style={styles.alertReplaceFilter}
@@ -14,7 +14,7 @@ const PMSensorIndicatior = memo(({ data = [], style }) => {
14
14
  key={item.id.toString()}
15
15
  color={item.color}
16
16
  standard={item.standard}
17
- value={item.value}
17
+ value={item.value || '--'}
18
18
  evaluate={item.evaluate}
19
19
  measure={item.measure}
20
20
  style={style}
@@ -1,7 +1,6 @@
1
1
  import React, { memo, useCallback } from 'react';
2
2
  import Svg, { Path, Text, G, Circle } from 'react-native-svg';
3
3
  import { View, StyleSheet } from 'react-native';
4
- import Animated from 'react-native-reanimated';
5
4
 
6
5
  import {
7
6
  drawArc,
@@ -10,8 +9,6 @@ import {
10
9
  import { Colors, Fonts } from '../../../../configs';
11
10
 
12
11
  const { PI } = Math;
13
- const { multiply } = Animated;
14
- const AnimatedPath = Animated.createAnimatedComponent(Path);
15
12
 
16
13
  const Anemometer = memo(
17
14
  ({
@@ -31,7 +28,6 @@ const Anemometer = memo(
31
28
  };
32
29
 
33
30
  const value = data.length ? data[0].value : 0;
34
-
35
31
  const radius = (size - strokeWidth) / 2;
36
32
  const viewBox = `0 0 ${width} ${width}`;
37
33
  const d = drawArc(center.x, center.y, radius, startAngle, endAngle);
@@ -39,14 +35,10 @@ const Anemometer = memo(
39
35
  const strokeAngle = (endAngle - startAngle) / numberOfSection;
40
36
  const strokeLength = (strokeAngle * circumference) / 360 - 1;
41
37
  const strokeDasharrayBg = `${strokeLength} 1`;
42
- const strokeDasharray = `${
43
- ((endAngle - startAngle) / 360) * circumference
44
- } ${((endAngle - startAngle) / 360) * circumference}`;
45
38
  const totalAngle = (3 * PI) / 2;
46
39
  const alpha = (value * totalAngle) / maxValue;
47
- const currentAngle = alpha - totalAngle;
48
-
49
- const strokeDashoffset = multiply(currentAngle, radius);
40
+ const arc = circumference * 0.75;
41
+ const offset = arc - (value / maxValue) * arc;
50
42
 
51
43
  const textAngles = useCallback(() => {
52
44
  let arr = [];
@@ -128,6 +120,20 @@ const Anemometer = memo(
128
120
 
129
121
  return (
130
122
  <View style={styles.standard}>
123
+ <View style={styles.wrapOffset}>
124
+ <Svg width={width} height={width} {...viewBox}>
125
+ <Circle
126
+ cx={'50%'}
127
+ cy={'50%'}
128
+ fill="none"
129
+ r={radius}
130
+ stroke={Colors.Lime6}
131
+ strokeDasharray={`${circumference * 0.75} ${circumference}`}
132
+ strokeDashoffset={offset}
133
+ strokeWidth={strokeWidth}
134
+ />
135
+ </Svg>
136
+ </View>
131
137
  <Svg width={width} height={width} {...viewBox}>
132
138
  <Path
133
139
  x={(width - size) / 2}
@@ -137,13 +143,6 @@ const Anemometer = memo(
137
143
  strokeDasharray={strokeDasharrayBg}
138
144
  {...{ d, strokeWidth }}
139
145
  />
140
- <AnimatedPath
141
- x={(width - size) / 2}
142
- y={(width - size) / 2}
143
- fill="none"
144
- stroke={Colors.Lime6}
145
- {...{ d, strokeWidth, strokeDasharray, strokeDashoffset }}
146
- />
147
146
  {textAngles()}
148
147
  <Text
149
148
  fill={Colors.Gray8}
@@ -194,4 +193,9 @@ const styles = StyleSheet.create({
194
193
  flexDirection: 'row',
195
194
  justifyContent: 'center',
196
195
  },
196
+ wrapOffset: {
197
+ transform: [{ rotate: '135deg' }],
198
+ position: 'absolute',
199
+ zIndex: 2,
200
+ },
197
201
  });
@@ -108,7 +108,7 @@ describe('Test OptionsDropdownActionTemplate', () => {
108
108
  expect(radioCircle[0].props.active).toEqual(true);
109
109
  });
110
110
 
111
- it.only('Test onPressDone', async () => {
111
+ it('Test onPressDone', async () => {
112
112
  await act(async () => {
113
113
  tree = await create(wrapComponent(data));
114
114
  });
@@ -65,7 +65,7 @@ describe('Test Processing', () => {
65
65
  const bar = tree.root.findByType(Progress.Bar);
66
66
  expect(bar.props.progress).toEqual(0.5);
67
67
  const state = tree.root.findAllByType(Text);
68
- expect(state[1].props.children).toEqual('xxx');
68
+ expect(state[1].props.children).toEqual('Connecting');
69
69
  });
70
70
  it('unmount component will unsubscribe from channel', async () => {
71
71
  await act(async () => {
@@ -1,12 +1,16 @@
1
1
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
2
2
  import { View } from 'react-native';
3
3
  import * as Progress from 'react-native-progress';
4
+ import uuid from 'uuid';
5
+
4
6
  import Text from '../Text';
5
- import { Colors, Constants } from '../../configs';
6
- import styles from './styles';
7
7
  import { HeaderCustom } from '../Header';
8
8
  import { getPusher } from '../../utils/Pusher';
9
- import uuid from 'uuid';
9
+ import { ModalCustom } from '../Modal';
10
+ import { Colors, Constants } from '../../configs';
11
+ import styles from './styles';
12
+ import { useTranslations } from '../../hooks/Common/useTranslations';
13
+ import ViewButtonBottom from '../ViewButtonBottom';
10
14
 
11
15
  const Processing = ({
12
16
  title,
@@ -15,13 +19,22 @@ const Processing = ({
15
19
  complete,
16
20
  onReady,
17
21
  onMessage,
22
+ goBack,
23
+ showPopupTurnOnGuide,
24
+ setHidePopupTurnOnGuide,
25
+ setIsRecallChipScan,
26
+ isChangeAddressSuccess,
18
27
  }) => {
28
+ const t = useTranslations();
19
29
  const channelName = useMemo(() => {
20
30
  return 'cache-' + uuid.v4();
21
31
  }, []);
22
32
 
33
+ // eslint-disable-next-line no-unused-vars
23
34
  const [state, setState] = useState(initState);
24
35
  const [percent, setPercent] = useState(0);
36
+ const [basePercent, setBasePercent] = useState(0);
37
+ const [totalPercent, setTotalPercent] = useState(0);
25
38
 
26
39
  const processMessage = useCallback(
27
40
  (
@@ -58,6 +71,11 @@ const Processing = ({
58
71
  [complete, fail, onMessage]
59
72
  );
60
73
 
74
+ const handleOk = useCallback(() => {
75
+ setHidePopupTurnOnGuide();
76
+ setIsRecallChipScan(true);
77
+ }, [setHidePopupTurnOnGuide, setIsRecallChipScan]);
78
+
61
79
  useEffect(() => {
62
80
  const channel = getPusher().subscribe(channelName);
63
81
  channel.bind('progress', (message) => {
@@ -73,6 +91,20 @@ const Processing = ({
73
91
  onReady && onReady(channelName);
74
92
  }, [onReady, channelName]);
75
93
 
94
+ useEffect(() => {
95
+ if (isChangeAddressSuccess) {
96
+ setBasePercent(0.5);
97
+ }
98
+ }, [isChangeAddressSuccess]);
99
+
100
+ useEffect(() => {
101
+ if (basePercent === 0.5) {
102
+ setTotalPercent(basePercent + percent * 0.5);
103
+ } else {
104
+ setTotalPercent(percent);
105
+ }
106
+ }, [basePercent, percent]);
107
+
76
108
  return (
77
109
  <View style={styles.wrap}>
78
110
  <View style={styles.screen}>
@@ -80,12 +112,12 @@ const Processing = ({
80
112
  <View style={styles.body}>
81
113
  <View style={styles.connecting}>
82
114
  <Text type="H4" bold>
83
- {state}
115
+ {t('connecting')}
84
116
  </Text>
85
117
  </View>
86
118
  <View style={styles.percentLoad}>
87
119
  <Progress.Bar
88
- progress={percent}
120
+ progress={totalPercent}
89
121
  animated={true}
90
122
  color={Colors.Primary}
91
123
  indeterminateAnimationDuration={1000}
@@ -94,12 +126,34 @@ const Processing = ({
94
126
  useNativeDriver={true}
95
127
  />
96
128
  <Text style={styles.textPercentLoad}>{`${parseInt(
97
- percent * 100,
129
+ totalPercent * 100,
98
130
  10
99
131
  )}%`}</Text>
100
132
  </View>
101
133
  </View>
102
134
  </View>
135
+ <ModalCustom
136
+ onBackButtonPress={goBack}
137
+ isVisible={showPopupTurnOnGuide}
138
+ style={styles.modal}
139
+ >
140
+ <View style={styles.modalWrapper}>
141
+ <View style={styles.modalContent}>
142
+ <Text type="H4" semibold style={styles.txtCenter}>
143
+ {t('turn_on_device')}
144
+ </Text>
145
+ <Text style={styles.txtCenter}>
146
+ {t('turn_on_device_after_change_address_success')}
147
+ </Text>
148
+ </View>
149
+ <ViewButtonBottom
150
+ leftTitle={t('cancel')}
151
+ onLeftClick={goBack}
152
+ rightTitle={t('ok')}
153
+ onRightClick={handleOk}
154
+ />
155
+ </View>
156
+ </ModalCustom>
103
157
  </View>
104
158
  );
105
159
  };
@@ -33,4 +33,23 @@ export default StyleSheet.create({
33
33
  textPercentLoad: {
34
34
  marginLeft: 10,
35
35
  },
36
+ modal: {
37
+ flex: 1,
38
+ justifyContent: 'center',
39
+ alignItems: 'center',
40
+ },
41
+ modalWrapper: {
42
+ backgroundColor: Colors.White,
43
+ borderRadius: 10,
44
+ justifyContent: 'center',
45
+ alignItems: 'center',
46
+ width: 280,
47
+ },
48
+ modalContent: {
49
+ paddingHorizontal: 16,
50
+ paddingTop: 16,
51
+ },
52
+ txtCenter: {
53
+ textAlign: 'center',
54
+ },
36
55
  });
@@ -102,10 +102,9 @@ const ShortDetailSubUnit = ({ unit, station, isOwner }) => {
102
102
  navigate(Routes.AddGatewayStack, {
103
103
  screen: Routes.SelectDeviceType,
104
104
  params: {
105
- unitId: unit.id,
106
- unitName: unit.name,
107
- stationId: station?.id,
108
- stationName: station?.name,
105
+ unitId: unit?.id,
106
+ unitName: unit?.name,
107
+ subUnit: station,
109
108
  },
110
109
  });
111
110
  };
@@ -174,10 +174,9 @@ describe('test ShortDetail Subunit', () => {
174
174
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.AddGatewayStack, {
175
175
  screen: Routes.SelectDeviceType,
176
176
  params: {
177
- stationName: props.station.name,
178
- stationId: props.station.id,
179
177
  unitId: props.unit.id,
180
178
  unitName: props.unit.name,
179
+ subUnit: props.station,
181
180
  },
182
181
  });
183
182
  });
@@ -117,9 +117,12 @@ const ConfigHistoryChart = memo(({ configs }) => {
117
117
  });
118
118
  params.append(
119
119
  'date_from',
120
- moment(startDate).format('YYYY-MM-DD HH:mm:ss')
120
+ moment(startDate).utc().format('YYYY-MM-DD HH:mm:ss')
121
+ );
122
+ params.append(
123
+ 'date_to',
124
+ moment(endDate).utc().format('YYYY-MM-DD HH:mm:ss')
121
125
  );
122
- params.append('date_to', moment(endDate).format('YYYY-MM-DD HH:mm:ss'));
123
126
  const { success, data } = await axiosGet(API.CONFIG.DISPLAY_HISTORY(), {
124
127
  params,
125
128
  });
@@ -252,6 +252,7 @@ export default {
252
252
  EMERGENCY_SELECT_CONTACT: 'EMERGENCY_SELECT_CONTACT',
253
253
  EMERGENCY_TITLE: 'EMERGENCY_TITLE',
254
254
  EMERGENCY_BUTTON: 'EMERGENCY_BUTTON',
255
+ CONTACT_NAME: 'CONTACT_NAME',
255
256
 
256
257
  // ADD SUB UNIT
257
258
  ADD_SUB_UNIT_SCREEN: 'ADD_SUB_UNIT_SCREEN',
@@ -1,41 +1,32 @@
1
- import { Clock, Value } from 'react-native-reanimated';
2
- import { useCallback, useEffect, useMemo } from 'react';
1
+ import { useCallback, useEffect, useState } from 'react';
3
2
  import { Keyboard, Platform } from 'react-native';
4
- import { runTiming } from '../../utils/runTiming';
5
3
 
6
- const useKeyboardAnimated = (tabHeight) => {
7
- const clock = new Clock();
8
- const marginStart = useMemo(() => new Value(0), []);
9
- const marginEnd = useMemo(() => new Value(0), []);
4
+ const action = Platform.OS === 'ios' ? 'Will' : 'Did';
5
+
6
+ const useKeyboardAnimated = (tabHeight = 0) => {
7
+ const [keyboardHeight, setKeyboardHeight] = useState(0);
8
+
10
9
  const _keyboardWillHide = useCallback(() => {
11
- marginStart.setValue(marginEnd);
12
- marginEnd.setValue(0);
13
- }, [marginStart, marginEnd]);
10
+ setKeyboardHeight(0);
11
+ }, []);
12
+
14
13
  const _keyboardWillShow = useCallback(
15
14
  (e) => {
16
- marginStart.setValue(marginEnd);
17
- marginEnd.setValue(e.endCoordinates.height - tabHeight);
15
+ setKeyboardHeight(e.endCoordinates.height - tabHeight);
18
16
  },
19
- [marginEnd, marginStart, tabHeight]
17
+ [tabHeight]
20
18
  );
21
19
 
22
- const transY = runTiming(clock, marginStart, marginEnd);
23
-
24
- const action = Platform.OS === 'ios' ? 'Will' : 'Did';
25
-
26
20
  useEffect(() => {
27
- // @ts-ignore
28
21
  Keyboard.addListener('keyboard' + action + 'Hide', _keyboardWillHide);
29
- // @ts-ignore
30
22
  Keyboard.addListener('keyboard' + action + 'Show', _keyboardWillShow);
31
- // cleanup function
32
23
  return () => {
33
24
  Keyboard.removeListener('keyboard' + action + 'Show', _keyboardWillShow);
34
25
  Keyboard.removeListener('keyboard' + action + 'Hide', _keyboardWillHide);
35
26
  };
36
- }, [_keyboardWillHide, _keyboardWillShow, action, tabHeight]);
27
+ }, [_keyboardWillHide, _keyboardWillShow, tabHeight]);
37
28
 
38
- return [transY];
29
+ return keyboardHeight;
39
30
  };
40
31
 
41
32
  export default useKeyboardAnimated;
@@ -89,7 +89,7 @@ describe('Test useRemoteControl', () => {
89
89
 
90
90
  it('test send remote command via bluetooth failed then send via internet', async () => {
91
91
  action.command_prefer_over_bluetooth = true;
92
- action.command_prefer_over_internet = true;
92
+ action.command_prefer_over_internet = false;
93
93
  const { result: sendRemoteCommand } = renderHook(() => useRemoteControl(), {
94
94
  wrapper,
95
95
  });
@@ -29,10 +29,17 @@ const useRemoteControl = () => {
29
29
  try {
30
30
  result = await sendCommandOverBluetooth(device, action, data, userId);
31
31
  } catch (err) {
32
- if (err !== SEND_COMMAND_OVER_BLUETOOTH_FAIL) {
32
+ result = false;
33
+ if (err === SEND_COMMAND_OVER_BLUETOOTH_FAIL) {
34
+ result = await sendCommandOverInternet(
35
+ device,
36
+ action,
37
+ data,
38
+ 'bluetooth'
39
+ );
40
+ } else {
33
41
  throw err;
34
42
  }
35
- result = false;
36
43
  }
37
44
  }
38
45
 
@@ -122,7 +122,7 @@ export const homeAssistantConnect = async (
122
122
  onDisconnected,
123
123
  onReconnected
124
124
  ) => {
125
- let connections = {};
125
+ let connections = { ...oldConnections };
126
126
 
127
127
  for (let i = 0; i < options.length; i++) {
128
128
  const option = options[i];
@@ -1,5 +1,5 @@
1
1
  import { useNavigation } from '@react-navigation/native';
2
- import React, { useCallback, useState } from 'react';
2
+ import React, { useCallback, useEffect, useState } from 'react';
3
3
  import Processing from '../../commons/Processing';
4
4
  import Routes from '../../utils/Route';
5
5
 
@@ -9,18 +9,21 @@ const ConnectingDevice = ({
9
9
  initState,
10
10
  onReady,
11
11
  unitId,
12
- stationId,
13
- stationName,
12
+ subUnit,
14
13
  chipId,
15
14
  sensorId,
16
15
  addDeviceType,
16
+ goBack,
17
+ showPopupTurnOnGuide,
18
+ setHidePopupTurnOnGuide,
19
+ setIsRecallChipScan,
20
+ isChangeAddressSuccess,
17
21
  }) => {
18
22
  const { navigate } = useNavigation();
19
23
 
20
24
  const [renameParams, setRenameParams] = useState({
21
25
  unitId,
22
- stationId,
23
- stationName,
26
+ subUnit,
24
27
  chipId,
25
28
  sensorId,
26
29
  addDeviceType,
@@ -28,9 +31,9 @@ const ConnectingDevice = ({
28
31
 
29
32
  const complete = useCallback(
30
33
  (deviceInfo) => {
31
- navigate(Routes.RenameNewDevices, { ...renameParams, chipId, sensorId });
34
+ navigate(Routes.RenameNewDevices, renameParams);
32
35
  },
33
- [chipId, navigate, renameParams, sensorId]
36
+ [navigate, renameParams]
34
37
  );
35
38
 
36
39
  const onMessage = useCallback(
@@ -52,6 +55,15 @@ const ConnectingDevice = ({
52
55
  [setRenameParams]
53
56
  );
54
57
 
58
+ useEffect(() => {
59
+ if (!!chipId) {
60
+ setRenameParams((prev) => ({ ...prev, chipId }));
61
+ }
62
+ if (!!sensorId) {
63
+ setRenameParams((prev) => ({ ...prev, sensorId }));
64
+ }
65
+ }, [chipId, sensorId]);
66
+
55
67
  return (
56
68
  <Processing
57
69
  title={title}
@@ -60,6 +72,11 @@ const ConnectingDevice = ({
60
72
  complete={complete}
61
73
  onReady={onReady}
62
74
  onMessage={onMessage}
75
+ goBack={goBack}
76
+ showPopupTurnOnGuide={showPopupTurnOnGuide}
77
+ setHidePopupTurnOnGuide={setHidePopupTurnOnGuide}
78
+ setIsRecallChipScan={setIsRecallChipScan}
79
+ isChangeAddressSuccess={isChangeAddressSuccess}
63
80
  />
64
81
  );
65
82
  };
@@ -1,50 +1,68 @@
1
1
  import { useNavigation } from '@react-navigation/native';
2
- import React, { useCallback, useState } from 'react';
3
- import { Alert } from 'react-native';
2
+ import React, { useCallback, useEffect, useState } from 'react';
4
3
  import API from '../../configs/API';
4
+ import { useBoolean } from '../../hooks/Common';
5
5
  import { useTranslations } from '../../hooks/Common/useTranslations';
6
6
  import { axiosPost } from '../../utils/Apis/axios';
7
+ import { getPusher } from '../../utils/Pusher';
7
8
  import ConnectingDevice from './ConnectingDevice';
8
9
 
9
10
  const ConnectingModbusDevice = ({ route }) => {
10
11
  const t = useTranslations();
11
- const { unitId, stationId, stationName, chipId, qrData } =
12
- route?.params || {};
12
+ const { unitId, subUnit, chipId, qrData } = route?.params || {};
13
13
  const [sensorId, setSensorId] = useState(null);
14
+ const [channelNameTemp, setChannelNameTemp] = useState('');
15
+ const [isChangeAddressSuccess, setIsChangeAddressSuccess] = useState(false);
16
+ const [isRecallChipScan, setIsRecallChipScan] = useState(false);
17
+ const [
18
+ showPopupTurnOnGuide,
19
+ setShowPopupTurnOnGuide,
20
+ setHidePopupTurnOnGuide,
21
+ ] = useBoolean();
22
+
14
23
  const { goBack } = useNavigation();
15
24
 
16
- const addingModbusDeviceFail = useCallback(
17
- (message) => {
18
- Alert.alert(t('fail_add_modbus_device'), message, [
19
- {
20
- text: t('ok'),
21
- onPress: goBack,
22
- },
23
- ]);
24
- },
25
- [goBack, t]
26
- );
25
+ const addingModbusDeviceFail = useCallback(async (message, channelName) => {
26
+ const channel = getPusher().subscribe(channelName);
27
+ channel.bind('change_modbus_address_completed', (messageRes) => {
28
+ setIsChangeAddressSuccess(messageRes.success);
29
+ });
30
+ }, []);
27
31
 
28
32
  const onReady = useCallback(
29
33
  async (channelName) => {
34
+ setChannelNameTemp(channelName);
30
35
  const { success, problem, data } = await axiosPost(
31
36
  API.CHIP.SCAN_SENSOR(chipId),
32
37
  {
33
38
  imei: qrData.imei,
34
39
  unit: unitId,
35
- station: stationId,
40
+ station: subUnit?.id,
36
41
  channel_name: channelName,
37
42
  }
38
43
  );
39
44
  if (!success) {
40
- addingModbusDeviceFail(JSON.stringify(problem || data));
45
+ addingModbusDeviceFail(JSON.stringify(problem || data), channelName);
41
46
  return;
42
47
  }
43
48
  setSensorId(data.id);
44
49
  },
45
- [chipId, addingModbusDeviceFail, qrData, stationId, unitId]
50
+ [chipId, addingModbusDeviceFail, qrData, subUnit, unitId]
46
51
  );
47
52
 
53
+ useEffect(() => {
54
+ if (isChangeAddressSuccess && channelNameTemp) {
55
+ setShowPopupTurnOnGuide();
56
+ getPusher().unsubscribe(channelNameTemp);
57
+ }
58
+ }, [isChangeAddressSuccess, channelNameTemp, setShowPopupTurnOnGuide]);
59
+
60
+ useEffect(() => {
61
+ if (isRecallChipScan && channelNameTemp) {
62
+ onReady(channelNameTemp);
63
+ }
64
+ }, [isRecallChipScan, channelNameTemp, onReady]);
65
+
48
66
  return (
49
67
  <ConnectingDevice
50
68
  title={t('connect_device')}
@@ -52,10 +70,14 @@ const ConnectingModbusDevice = ({ route }) => {
52
70
  onReady={onReady}
53
71
  fail={addingModbusDeviceFail}
54
72
  unitId={unitId}
55
- stationId={stationId}
56
- stationName={stationName}
73
+ subUnit={subUnit}
57
74
  chipId={chipId}
58
75
  sensorId={sensorId}
76
+ goBack={goBack}
77
+ showPopupTurnOnGuide={showPopupTurnOnGuide}
78
+ setHidePopupTurnOnGuide={setHidePopupTurnOnGuide}
79
+ setIsRecallChipScan={setIsRecallChipScan}
80
+ isChangeAddressSuccess={isChangeAddressSuccess}
59
81
  />
60
82
  );
61
83
  };