@eohjsc/react-native-smart-city 0.2.59 → 0.2.63

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/README.md +115 -68
  2. package/assets/images/Map/MarkerGeolocation.svg +4 -0
  3. package/package.json +3 -3
  4. package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -2
  5. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +1 -1
  6. package/src/commons/ActionGroup/__test__/MenuActionAddSchedule.test.js +71 -0
  7. package/src/commons/ActionGroup/hooks/AccessScheduleDetailStyles.js +41 -0
  8. package/src/commons/ActionGroup/hooks/MenuActionAddSchedule.js +110 -0
  9. package/src/commons/ActionGroup/hooks/MenuActionAddScheduleStyle.js +69 -0
  10. package/src/commons/ActionGroup/hooks/RecurringDetail.js +97 -0
  11. package/src/commons/DateTimeRangeChange/DateTimeButton.js +7 -2
  12. package/src/commons/Device/HistoryChart.js +80 -81
  13. package/src/commons/Device/HorizontalBarChart.js +48 -31
  14. package/src/commons/Device/LinearChart.js +28 -1
  15. package/src/commons/Form/CurrencyInput.js +1 -0
  16. package/src/commons/FourButtonFilterHistory/__test__/FourButtonFilterHistory.test.js +48 -0
  17. package/src/commons/FourButtonFilterHistory/index.js +72 -0
  18. package/src/commons/FourButtonFilterHistory/styles.js +22 -0
  19. package/src/commons/ImagePicker/index.js +27 -33
  20. package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +11 -1
  21. package/src/commons/MediaPlayerDetail/index.js +14 -5
  22. package/src/commons/SubUnit/OneTap/OneTapStyles.js +20 -1
  23. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +151 -40
  24. package/src/commons/SubUnit/OneTap/index.js +64 -12
  25. package/src/commons/UnitSummary/AirQuality/index.js +9 -7
  26. package/src/commons/UnitSummary/ConfigHistoryChart.js +2 -1
  27. package/src/configs/API.js +3 -0
  28. package/src/configs/Constants.js +15 -0
  29. package/src/iot/RemoteControl/Bluetooth.js +6 -3
  30. package/src/iot/RemoteControl/GoogleHome.js +6 -3
  31. package/src/iot/RemoteControl/Internet.js +1 -0
  32. package/src/iot/RemoteControl/LG.js +2 -1
  33. package/src/iot/RemoteControl/index.js +13 -6
  34. package/src/navigations/SharedStack.js +11 -9
  35. package/src/navigations/UnitStack.js +26 -2
  36. package/src/screens/ActivityLog/ItemLog.js +3 -3
  37. package/src/screens/ActivityLog/__test__/ItemLog.test.js +5 -2
  38. package/src/screens/ActivityLog/hooks/index.js +2 -1
  39. package/src/screens/ActivityLog/index.js +0 -1
  40. package/src/screens/AddLocationMaps/index.js +4 -2
  41. package/src/screens/AddNewAction/SelectSensorDevices.js +18 -11
  42. package/src/screens/AddNewAction/Styles/SelectSensorDevicesStyles.js +5 -1
  43. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +6 -1
  44. package/src/screens/Automate/MultiUnits.js +7 -4
  45. package/src/screens/Automate/__test__/MultiUnits.test.js +1 -1
  46. package/src/screens/Automate/__test__/index.test.js +12 -0
  47. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +61 -0
  48. package/src/screens/ConfirmUnitDeletion/index.js +64 -0
  49. package/src/screens/ConfirmUnitDeletion/styles.js +37 -0
  50. package/src/screens/Device/__test__/detail.test.js +3 -2
  51. package/src/screens/Device/detail.js +48 -15
  52. package/src/screens/Device/hooks/useDisconnectedDevice.js +2 -1
  53. package/src/screens/Device/styles.js +3 -3
  54. package/src/screens/EmergencySetting/__test__/DropDownItem.test.js +59 -0
  55. package/src/screens/EmergencySetting/__test__/index.test.js +27 -0
  56. package/src/screens/EmergencySetting/components/DropDownItem.js +54 -0
  57. package/src/screens/EmergencySetting/index.js +92 -0
  58. package/src/screens/EmergencySetting/styles/DropDownItem.js +38 -0
  59. package/src/screens/EmergencySetting/styles.js +25 -0
  60. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +126 -0
  61. package/src/screens/MoveToAnotherSubUnit/index.js +88 -0
  62. package/src/screens/MoveToAnotherSubUnit/styles/MoveToAnotherSubUnitStyles.js +50 -0
  63. package/src/screens/ScriptDetail/Styles/indexStyles.js +0 -1
  64. package/src/screens/ScriptDetail/index.js +1 -0
  65. package/src/screens/SubUnit/AddSubUnit.js +3 -3
  66. package/src/screens/SubUnit/AddSubUnitStyles.js +0 -2
  67. package/src/screens/SubUnit/EditSubUnit.js +16 -7
  68. package/src/screens/SubUnit/EditSubUnitStyles.js +2 -3
  69. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +2 -2
  70. package/src/screens/TDSGuide/index.js +1 -1
  71. package/src/screens/Unit/ChooseLocation.js +3 -7
  72. package/src/screens/Unit/ChooseLocationStyles.js +5 -8
  73. package/src/screens/Unit/Detail.js +16 -6
  74. package/src/screens/Unit/ManageUnit.js +20 -26
  75. package/src/screens/Unit/SmartAccount.js +25 -41
  76. package/src/screens/Unit/SmartAccountItem.js +2 -1
  77. package/src/screens/Unit/SmartAccountStyles.js +0 -1
  78. package/src/screens/Unit/__test__/ManageUnit.test.js +0 -6
  79. package/src/screens/Unit/__test__/SmartAccount.test.js +24 -0
  80. package/src/screens/Unit/__test__/SmartAccountItem.test.js +72 -0
  81. package/src/screens/UnitSummary/components/3PPowerConsumption/index.js +58 -59
  82. package/src/screens/UnitSummary/components/PowerConsumption/index.js +26 -22
  83. package/src/screens/UnitSummary/components/Temperature/ItemTemperature/index.js +2 -2
  84. package/src/screens/UnitSummary/components/Temperature/index.js +15 -14
  85. package/src/screens/UnitSummary/components/UvIndex/index.js +6 -5
  86. package/src/screens/UnitSummary/components/WaterQuality/index.js +9 -7
  87. package/src/screens/UnitSummary/index.js +11 -7
  88. package/src/screens/WaterQualityGuide/index.js +1 -0
  89. package/src/utils/Apis/axios.js +4 -4
  90. package/src/utils/I18n/translations/en.json +20 -2
  91. package/src/utils/I18n/translations/vi.json +21 -2
  92. package/src/utils/Route/index.js +3 -0
  93. package/src/utils/Utils.js +4 -0
  94. package/src/commons/ThreeButtonHistory/CalendarHeader.js +0 -35
  95. package/src/commons/ThreeButtonHistory/CalendarHeaderStyles.js +0 -17
  96. package/src/commons/ThreeButtonHistory/SelectMonth.js +0 -53
  97. package/src/commons/ThreeButtonHistory/SelectMonthStyles.js +0 -29
  98. package/src/commons/ThreeButtonHistory/__test__/SelectMonth.test.js +0 -37
  99. package/src/commons/ThreeButtonHistory/__test__/ThreeButtonHistory.test.js +0 -240
  100. package/src/commons/ThreeButtonHistory/index.js +0 -310
  101. package/src/commons/ThreeButtonHistory/styles.js +0 -65
@@ -0,0 +1,50 @@
1
+ import { Colors } from '../../../configs';
2
+ import { StyleSheet } from 'react-native';
3
+
4
+ export default StyleSheet.create({
5
+ container: {
6
+ paddingHorizontal: 16,
7
+ },
8
+ wrap: {
9
+ flex: 1,
10
+ backgroundColor: Colors.White,
11
+ },
12
+ rowSubUnit: {
13
+ flexDirection: 'row',
14
+ alignItems: 'center',
15
+ },
16
+ wrapText: {
17
+ flex: 1,
18
+ marginRight: 24,
19
+ marginLeft: 16,
20
+ paddingVertical: 16,
21
+ borderBottomWidth: 1,
22
+ borderBottomColor: Colors.Gray4,
23
+ },
24
+ content: {
25
+ margin: 16,
26
+ },
27
+ textLeft: {
28
+ borderColor: Colors.Gray9,
29
+ fontWeight: 'bold',
30
+ fontSize: 16,
31
+ },
32
+ textRight: {
33
+ borderColor: Colors.Gray7,
34
+ fontSize: 14,
35
+ },
36
+ separator: {
37
+ height: 1,
38
+ width: '100%',
39
+ borderBottomWidth: 1,
40
+ borderColor: Colors.Gray4,
41
+ marginBottom: 16,
42
+ },
43
+ bottomButtonView: {
44
+ paddingTop: 24,
45
+ paddingBottom: 32,
46
+ backgroundColor: Colors.White,
47
+ borderColor: Colors.ShadownTransparent,
48
+ borderTopWidth: 1,
49
+ },
50
+ });
@@ -151,7 +151,6 @@ export default StyleSheet.create({
151
151
  borderBottomWidth: 2,
152
152
  borderBottomColor: Colors.Primary,
153
153
  fontSize: 16,
154
- lineHeight: 24,
155
154
  color: Colors.Gray9,
156
155
  },
157
156
  titleItem: {
@@ -492,6 +492,7 @@ const ScriptDetail = ({ route }) => {
492
492
  onChange={(text) => setInputName(text)}
493
493
  defaultValue={scriptName}
494
494
  textInputStyle={styles.textInput}
495
+ maxLength={64}
495
496
  />
496
497
  )}
497
498
  </AlertAction>
@@ -29,11 +29,11 @@ import styles from './AddSubUnitStyles';
29
29
  const MAX_FILE_SIZE_BYTES = 1.5 * 1024 * 1024; // 1.5mb
30
30
 
31
31
  const prepareImageToUpload = async (image) => {
32
- if (!image || image.fileSize < MAX_FILE_SIZE_BYTES) {
32
+ if (!image || image.size < MAX_FILE_SIZE_BYTES) {
33
33
  return image;
34
34
  }
35
35
  const result = await ImageResizer.createResizedImage(
36
- image.uri,
36
+ image.path,
37
37
  1280,
38
38
  1280,
39
39
  'JPEG',
@@ -214,7 +214,7 @@ const AddSubUnit = ({ route }) => {
214
214
  </Text>
215
215
  {wallpaper ? (
216
216
  <Image
217
- source={{ uri: wallpaper.uri }}
217
+ source={{ uri: wallpaper.uri || wallpaper.path }}
218
218
  style={styles.wallpaper}
219
219
  />
220
220
  ) : (
@@ -33,8 +33,6 @@ export default StyleSheet.create({
33
33
  borderBottomWidth: 1,
34
34
  borderBottomColor: Colors.Primary,
35
35
  paddingLeft: 0,
36
- fontSize: 16,
37
- lineHeight: 24,
38
36
  margin: 0,
39
37
  padding: 0,
40
38
  },
@@ -4,7 +4,7 @@ import { connect } from 'react-redux';
4
4
  import { useIsFocused, useNavigation } from '@react-navigation/native';
5
5
  import { useTranslations } from '../../hooks/Common/useTranslations';
6
6
 
7
- import { Colors, API, Device } from '../../configs';
7
+ import { Colors, API } from '../../configs';
8
8
  import { ToastBottomHelper } from '../../utils/Utils';
9
9
  import {
10
10
  axiosPatch,
@@ -84,9 +84,11 @@ const EditSubUnit = ({ route }) => {
84
84
  },
85
85
  [unit.id, station.id, t]
86
86
  );
87
+
87
88
  const updateBackground = useCallback(
88
89
  async (headers) => {
89
- const formData = createFormData(imageUrl, ['background']);
90
+ const formData = createFormData({ background: imageUrl }, ['background']);
91
+
90
92
  const { success } = await axiosPatch(
91
93
  API.SUB_UNIT.MANAGE_SUB_UNIT(unit.id, station.id),
92
94
  formData,
@@ -146,9 +148,9 @@ const EditSubUnit = ({ route }) => {
146
148
  const options = {
147
149
  mediaType: 'photo',
148
150
  maxWidth: 1024,
149
- quality: 0.8,
150
- includeBase64: Device.isIOS,
151
- saveToPhotos: true,
151
+ compressImageMaxWidth: 1280,
152
+ compressImageMaxHeight: 720,
153
+ compressImageQuality: 0.8,
152
154
  };
153
155
 
154
156
  const contactsName = listContacts.map((item) => item.name);
@@ -193,7 +195,7 @@ const EditSubUnit = ({ route }) => {
193
195
  <Image
194
196
  style={styles.image}
195
197
  source={{
196
- uri: resourcePath.uri,
198
+ uri: resourcePath.uri || resourcePath.path,
197
199
  }}
198
200
  resizeMode="cover"
199
201
  />
@@ -231,7 +233,14 @@ const EditSubUnit = ({ route }) => {
231
233
  onPress={onPressRemove}
232
234
  style={styles.removeButton}
233
235
  >
234
- <Text style={styles.removeText}>{t('remove_sub_unit')}</Text>
236
+ <Text
237
+ type={'H4'}
238
+ semibold
239
+ color={Colors.Red}
240
+ style={styles.removeText}
241
+ >
242
+ {t('remove_sub_unit')}
243
+ </Text>
235
244
  </TouchableOpacity>
236
245
  </View>
237
246
  </View>
@@ -46,9 +46,8 @@ export default StyleSheet.create({
46
46
  paddingBottom: 16 + getBottomSpace(),
47
47
  },
48
48
  removeText: {
49
- fontSize: 16,
50
- lineHeight: 24,
51
- color: Colors.Gray6,
49
+ borderBottomWidth: 1,
50
+ borderBottomColor: Colors.Red,
52
51
  },
53
52
  backgroundContainer: {
54
53
  alignItems: 'center',
@@ -381,7 +381,7 @@ describe('Test EditSubUnit', () => {
381
381
  const imagePicker = instance.findByType(ImagePicker);
382
382
  const image = instance.findByType(Image);
383
383
  expect(image.props.source).toEqual({
384
- uri: '',
384
+ uri: undefined,
385
385
  });
386
386
  await act(async () => {
387
387
  await imagePicker.props.setImageUrl({ uri: 'path' });
@@ -413,7 +413,7 @@ describe('Test EditSubUnit', () => {
413
413
  const imagePicker = instance.findByType(ImagePicker);
414
414
  const image = instance.findByType(Image);
415
415
  expect(image.props.source).toEqual({
416
- uri: '',
416
+ uri: undefined,
417
417
  });
418
418
  await act(async () => {
419
419
  await imagePicker.props.setImageUrl({ uri: 'path' });
@@ -9,7 +9,7 @@ import useTitleHeader from '../../hooks/Common/useTitleHeader';
9
9
 
10
10
  const TDSGuide = memo(() => {
11
11
  const t = useTranslations();
12
- useTitleHeader(t('tds_infomation'));
12
+ useTitleHeader(t('tds_information'));
13
13
 
14
14
  return (
15
15
  <View style={styles.container}>
@@ -3,15 +3,14 @@ import React, { memo, useCallback, useRef, useState } from 'react';
3
3
  import { View } from 'react-native';
4
4
  import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';
5
5
  import { useNavigation } from '@react-navigation/native';
6
- import { IconFill, IconOutline } from '@ant-design/icons-react-native';
7
-
6
+ import MarkerGeolocation from '../../../assets/images/Map/MarkerGeolocation.svg';
8
7
  import BottomButtonView from '../../commons/BottomButtonView';
9
8
  import { useTranslations } from '../../hooks/Common/useTranslations';
10
9
 
11
10
  navigator.geolocation = require('@react-native-community/geolocation');
12
11
 
13
12
  import styles from './ChooseLocationStyles';
14
- import { API, Colors } from '../../configs';
13
+ import { API } from '../../configs';
15
14
  import { axiosGet } from '../../utils/Apis/axios';
16
15
  import { SCConfig } from '../../configs';
17
16
 
@@ -81,10 +80,7 @@ const ChooseLocation = memo(({ route }) => {
81
80
  onRegionChangeComplete={onRegionChange}
82
81
  />
83
82
  <View style={styles.wrapMarker}>
84
- <>
85
- <IconFill name="environment" size={27} color={Colors.Blue10} />
86
- <IconOutline name="close" size={14} color={Colors.Gray9} />
87
- </>
83
+ <MarkerGeolocation />
88
84
  </View>
89
85
  <BottomButtonView
90
86
  rowButton
@@ -16,14 +16,11 @@ export default StyleSheet.create({
16
16
  backgroundColor: Colors.White,
17
17
  },
18
18
  wrapMarker: {
19
- flex: 1,
20
- alignItems: 'center',
21
- justifyContent: 'center',
19
+ zIndex: 3,
22
20
  position: 'absolute',
23
- top: 0,
24
- bottom: 0,
25
- left: 0,
26
- right: 0,
27
- paddingBottom: 24,
21
+ marginTop: -37,
22
+ marginLeft: -11,
23
+ left: '50%',
24
+ top: '50%',
28
25
  },
29
26
  });
@@ -39,7 +39,7 @@ const UnitDetail = ({ route }) => {
39
39
  const [appState, setAppState] = useState(AppState.currentState);
40
40
  const [listMenuItem, setListMenuItem] = useState([]);
41
41
  const [listStation, setListStation] = useState([]);
42
- const [oneTap, setOneTap] = useState([]);
42
+ const [listAutomate, setListAutomate] = useState([]);
43
43
  const [favorites, setFavorites] = useState({
44
44
  devices: [],
45
45
  automates: [],
@@ -106,12 +106,23 @@ const UnitDetail = ({ route }) => {
106
106
  await fetchWithCache(
107
107
  API.UNIT.AUTOMATE(unitId),
108
108
  {
109
- params: { type: AUTOMATE_TYPE.ONE_TAP },
109
+ params: { type: AUTOMATE_TYPE.ALL },
110
110
  },
111
111
  (response) => {
112
112
  const { success, data } = response;
113
113
  if (success) {
114
- setOneTap([...data]);
114
+ setListAutomate([
115
+ {
116
+ text: t(AUTOMATE_TYPE.SCENARIO),
117
+ data: data.filter((item) => item.type === AUTOMATE_TYPE.ONE_TAP),
118
+ type: AUTOMATE_TYPE.ONE_TAP,
119
+ },
120
+ {
121
+ text: t(AUTOMATE_TYPE.AUTOMATION),
122
+ data: data.filter((item) => item.type !== AUTOMATE_TYPE.ONE_TAP),
123
+ type: AUTOMATE_TYPE.AUTOMATION,
124
+ },
125
+ ]);
115
126
  setFavorites((prevData) => ({
116
127
  ...prevData,
117
128
  automates: data.filter((item) => item.script.is_star),
@@ -119,7 +130,7 @@ const UnitDetail = ({ route }) => {
119
130
  }
120
131
  }
121
132
  );
122
- }, [unitId]);
133
+ }, [t, unitId]);
123
134
 
124
135
  const onRefresh = useCallback(() => {
125
136
  fetchDetails();
@@ -264,8 +275,7 @@ const UnitDetail = ({ route }) => {
264
275
  return (
265
276
  <SubUnitAutomate
266
277
  isOwner={isOwner}
267
- type={AUTOMATE_TYPE.ONE_TAP}
268
- automates={oneTap}
278
+ listAutomate={listAutomate}
269
279
  unit={unit}
270
280
  wrapItemStyle={styles.wrapItemStyle}
271
281
  />
@@ -3,14 +3,10 @@ import { View, TouchableOpacity, Image, Platform } from 'react-native';
3
3
  import Animated from 'react-native-reanimated';
4
4
  import { useTranslations } from '../../hooks/Common/useTranslations';
5
5
 
6
- import { Colors, API, Device, Images } from '../../configs';
6
+ import { Colors, API, Images } from '../../configs';
7
7
  import Routes from '../../utils/Route';
8
8
  import { ToastBottomHelper } from '../../utils/Utils';
9
- import {
10
- createFormData,
11
- axiosPatch,
12
- axiosDelete,
13
- } from '../../utils/Apis/axios';
9
+ import { createFormData, axiosPatch } from '../../utils/Apis/axios';
14
10
  import useBoolean from '../../hooks/Common/useBoolean';
15
11
  import useKeyboardAnimated from '../../hooks/Explore/useKeyboardAnimated';
16
12
 
@@ -77,8 +73,8 @@ const ManageUnit = ({ route }) => {
77
73
  const [showImagePicker, setShowImagePicker] = useState(false);
78
74
 
79
75
  const updateUnit = useCallback(
80
- async (bodyData, headers) => {
81
- const formData = createFormData(bodyData, ['background']);
76
+ async (headers) => {
77
+ const formData = createFormData({ background: imageUrl }, ['background']);
82
78
 
83
79
  const { success, data } = await axiosPatch(
84
80
  API.UNIT.MANAGE_UNIT(unit.id),
@@ -90,7 +86,7 @@ const ManageUnit = ({ route }) => {
90
86
  ToastBottomHelper.success(t('unit_updated_successfully'));
91
87
  }
92
88
  },
93
- [unit.id, t]
89
+ [unit.id, t, imageUrl]
94
90
  );
95
91
 
96
92
  const updateLocation = useCallback(
@@ -120,24 +116,22 @@ const ManageUnit = ({ route }) => {
120
116
 
121
117
  useEffect(() => {
122
118
  if (imageUrl) {
123
- updateUnit(
124
- { background: imageUrl },
125
- {
126
- headers: { 'Content-Type': 'multipart/form-data' },
127
- }
128
- );
119
+ updateUnit({
120
+ headers: { 'Content-Type': 'multipart/form-data' },
121
+ });
129
122
  }
130
123
  }, [imageUrl, updateUnit]);
131
124
 
132
125
  const [showRemove, setshowRemove, setHideRemove] = useBoolean();
133
126
  const goRemove = useCallback(async () => {
134
- const { success } = await axiosDelete(API.UNIT.MANAGE_UNIT(unit.id));
135
- if (success) {
136
- setHideRemove(true);
137
- ToastBottomHelper.success(t('unit_deleted_successfully'));
138
- navigation.navigate(Routes.Dashboard);
139
- }
140
- }, [unit.id, setHideRemove, t, navigation]);
127
+ navigation.navigate(Routes.UnitStack, {
128
+ screen: Routes.ConfirmUnitDeletion,
129
+ params: {
130
+ unit,
131
+ },
132
+ });
133
+ setHideRemove(true);
134
+ }, [setHideRemove, navigation, unit]);
141
135
 
142
136
  const goToManageSubUnit = useCallback(() => {
143
137
  navigation.navigate(Routes.UnitStack, {
@@ -158,9 +152,9 @@ const ManageUnit = ({ route }) => {
158
152
  const options = {
159
153
  mediaType: 'photo',
160
154
  maxWidth: 1024,
161
- quality: 0.8,
162
- includeBase64: Device.isIOS,
163
- saveToPhotos: true,
155
+ compressImageMaxWidth: 1280,
156
+ compressImageMaxHeight: 720,
157
+ compressImageQuality: 0.8,
164
158
  };
165
159
 
166
160
  return (
@@ -202,7 +196,7 @@ const ManageUnit = ({ route }) => {
202
196
  <View style={styles.boxImage}>
203
197
  <Image
204
198
  source={{
205
- uri: unit.background,
199
+ uri: unitData.background,
206
200
  }}
207
201
  borderRadius={10}
208
202
  style={styles.image}
@@ -7,17 +7,16 @@ import React, {
7
7
  useState,
8
8
  memo,
9
9
  } from 'react';
10
- import { View } from 'react-native';
10
+ import { TouchableOpacity, View } from 'react-native';
11
11
  import styles from './SmartAccountStyles';
12
12
  import { API, Colors } from '../../configs';
13
13
  import Routes from '../../utils/Route';
14
14
  import { useNavigation } from '@react-navigation/native';
15
15
  import { axiosDelete, axiosGet } from '../../utils/Apis/axios';
16
16
  import { SmartAccountItem } from './SmartAccountItem';
17
- import { usePopover, useBoolean } from '../../hooks/Common';
18
- import { AlertAction, MenuActionMore } from '../../commons';
17
+ import { usePopover } from '../../hooks/Common';
18
+ import { MenuActionMore } from '../../commons';
19
19
  import { useTranslations } from '../../hooks/Common/useTranslations';
20
- import { useStateAlertRemove } from '../Unit/hook/useStateAlertRemove';
21
20
 
22
21
  const ListSmartAccount = ({ route }) => {
23
22
  const { unitId } = route?.params || {};
@@ -38,10 +37,6 @@ const ListSmartAccount = ({ route }) => {
38
37
  const { childRef, showingPopover, showPopoverWithRef, hidePopover } =
39
38
  usePopover();
40
39
 
41
- const [lockShowing, acquireLockShowing, releaseLockShowing] = useBoolean();
42
- const { stateAlertRemove, onShowRemoveAlert, hideAlertAction } =
43
- useStateAlertRemove();
44
-
45
40
  useEffect(() => {
46
41
  getAllSmartAccounts();
47
42
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -55,21 +50,7 @@ const ListSmartAccount = ({ route }) => {
55
50
  [showPopoverWithRef]
56
51
  );
57
52
 
58
- const onItemClick = useCallback(
59
- (item) => {
60
- if (!smartAccountRef?.current) {
61
- return;
62
- }
63
- if (item.action === 'delete') {
64
- acquireLockShowing();
65
- onShowRemoveAlert(smartAccountRef.current.brand)();
66
- }
67
- },
68
- [acquireLockShowing, onShowRemoveAlert]
69
- );
70
-
71
53
  const deleteSmartAccount = useCallback(async () => {
72
- hideAlertAction();
73
54
  if (!smartAccountRef?.current) {
74
55
  return;
75
56
  }
@@ -78,10 +59,22 @@ const ListSmartAccount = ({ route }) => {
78
59
  API.SMART_ACCOUNT.REMOVE_SMART_ACCOUNT(id)
79
60
  );
80
61
  success && getAllSmartAccounts();
81
- }, [hideAlertAction, getAllSmartAccounts]);
62
+ }, [getAllSmartAccounts]);
63
+
64
+ const onItemClick = useCallback(
65
+ (item) => {
66
+ if (!smartAccountRef?.current) {
67
+ return;
68
+ }
69
+ if (item.action === 'remove') {
70
+ deleteSmartAccount();
71
+ }
72
+ },
73
+ [deleteSmartAccount]
74
+ );
82
75
 
83
76
  const listMenuItem = useMemo(() => {
84
- return [{ action: 'delete', text: t('delete') }];
77
+ return [{ action: 'remove', text: t('remove_account') }];
85
78
  }, [t]);
86
79
 
87
80
  const gotoSmartAccountDetail = useCallback(
@@ -104,33 +97,24 @@ const ListSmartAccount = ({ route }) => {
104
97
  headerAniStyle={styles.headerAniStyle}
105
98
  >
106
99
  <View style={styles.wrapContent}>
107
- {data.map((item) => {
100
+ {data.map((item, index) => {
108
101
  return (
109
- <SmartAccountItem
110
- gotoSmartAccountDetail={gotoSmartAccountDetail}
111
- item={item}
112
- onShowMenuMore={onShowMenuMore}
113
- />
102
+ <TouchableOpacity key={index}>
103
+ <SmartAccountItem
104
+ gotoSmartAccountDetail={gotoSmartAccountDetail}
105
+ item={item}
106
+ onShowMenuMore={onShowMenuMore}
107
+ />
108
+ </TouchableOpacity>
114
109
  );
115
110
  })}
116
111
  </View>
117
- <AlertAction
118
- visible={stateAlertRemove.visible && !lockShowing}
119
- hideModal={hideAlertAction}
120
- title={stateAlertRemove.title}
121
- message={stateAlertRemove.message}
122
- leftButtonTitle={stateAlertRemove.leftButton}
123
- leftButtonClick={hideAlertAction}
124
- rightButtonTitle={stateAlertRemove.rightButton}
125
- rightButtonClick={deleteSmartAccount}
126
- />
127
112
  <MenuActionMore
128
113
  isVisible={showingPopover}
129
114
  hideMore={hidePopover}
130
115
  listMenuItem={listMenuItem}
131
116
  childRef={childRef}
132
117
  onItemClick={onItemClick}
133
- hideComplete={releaseLockShowing}
134
118
  />
135
119
  </WrapHeaderScrollable>
136
120
  </View>
@@ -23,6 +23,7 @@ export const SmartAccountItem = memo(
23
23
  <TouchableOpacity
24
24
  style={styles.wrapText}
25
25
  onPress={onPressGotoSmartAccountDetail}
26
+ testID={TESTID.SMART_ACCOUNT_ITEM}
26
27
  >
27
28
  <FImage
28
29
  source={{ uri: item?.logo }}
@@ -39,7 +40,7 @@ export const SmartAccountItem = memo(
39
40
  </View>
40
41
  </TouchableOpacity>
41
42
  <TouchableOpacity
42
- testID={TESTID.ITEM_QUICK_ACTION_PRESS}
43
+ testID={TESTID.SMART_ACCOUNT_ITEM_PRESSMORE}
43
44
  onPress={onPressMore}
44
45
  ref={buttonMoreRef}
45
46
  >
@@ -26,7 +26,6 @@ export default StyleSheet.create({
26
26
  },
27
27
  wrapText: {
28
28
  flexDirection: 'row',
29
- alignItems: 'space-around',
30
29
  },
31
30
  icon: {
32
31
  width: 48,
@@ -3,7 +3,6 @@ import { act, create } from 'react-test-renderer';
3
3
  import axios from 'axios';
4
4
 
5
5
  import { ToastBottomHelper } from '../../../utils/Utils';
6
- import API from '../../../configs/API';
7
6
  import { TESTID } from '../../../configs/Constants';
8
7
 
9
8
  import ManageUnit from '../ManageUnit';
@@ -131,7 +130,6 @@ describe('Test Manage Unit', () => {
131
130
  });
132
131
 
133
132
  test('remove Unit success', async () => {
134
- const spyToast = jest.spyOn(ToastBottomHelper, 'success');
135
133
  await act(async () => {
136
134
  tree = create(wrapComponent(route));
137
135
  });
@@ -165,11 +163,7 @@ describe('Test Manage Unit', () => {
165
163
  await bottomButton.props.onPress();
166
164
  });
167
165
 
168
- expect(axios.delete).toBeCalledWith(API.UNIT.MANAGE_UNIT(1));
169
166
  expect(mockedDispatch).not.toBeCalled();
170
- expect(spyToast).toBeCalled();
171
- spyToast.mockReset();
172
- spyToast.mockRestore();
173
167
  });
174
168
 
175
169
  test('rename Unit sucess', async () => {
@@ -6,6 +6,7 @@ import { SCProvider } from '../../../context';
6
6
  import { mockSCStore } from '../../../context/mockStore';
7
7
  import ListSmartAccount from '../SmartAccount';
8
8
  import { SmartAccountItem } from '../SmartAccountItem';
9
+ import { MenuActionMore } from '../../../commons';
9
10
 
10
11
  const wrapComponent = (route, navigation) => (
11
12
  <SCProvider initState={mockSCStore({})}>
@@ -13,6 +14,17 @@ const wrapComponent = (route, navigation) => (
13
14
  </SCProvider>
14
15
  );
15
16
 
17
+ const mockedNavigate = jest.fn();
18
+
19
+ jest.mock('@react-navigation/native', () => {
20
+ return {
21
+ ...jest.requireActual('@react-navigation/native'),
22
+ useNavigation: () => ({
23
+ goBack: mockedNavigate,
24
+ }),
25
+ };
26
+ });
27
+
16
28
  jest.mock('react', () => {
17
29
  return {
18
30
  ...jest.requireActual('react'),
@@ -55,4 +67,16 @@ describe('Test SmartAccount', () => {
55
67
  const smartAccountItem = instance.findAllByType(SmartAccountItem);
56
68
  expect(smartAccountItem.length).toEqual(3);
57
69
  });
70
+
71
+ test('test render SmartAccountItem', async () => {
72
+ await act(async () => {
73
+ tree = await renderer.create(wrapComponent());
74
+ });
75
+ const instance = tree.root;
76
+ const menuActionMore = instance.findByType(MenuActionMore);
77
+ await act(async () => {
78
+ menuActionMore.props.onItemClick();
79
+ });
80
+ expect(menuActionMore.props.isVisible).toEqual(false);
81
+ });
58
82
  });