@eohjsc/react-native-smart-city 0.7.25 → 0.7.26

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 (38) hide show
  1. package/package.json +1 -1
  2. package/src/Images/Common/search-menu.svg +7 -0
  3. package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplateStyle.js +2 -1
  4. package/src/commons/ActionGroup/OneBigButtonTemplateStyle.js +1 -2
  5. package/src/commons/ActionGroup/SliderRangeTemplate.js +1 -3
  6. package/src/commons/ActionGroup/TerminalBoxTemplate.js +1 -4
  7. package/src/commons/ActionGroup/TextBoxTemplate.js +1 -5
  8. package/src/commons/ActionGroup/ThreeButtonTemplate/components/ThreeButtonDefaultStyles.js +1 -1
  9. package/src/commons/ActionGroup/__test__/index.test.js +51 -0
  10. package/src/commons/ActionGroup/index.js +4 -0
  11. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +0 -10
  12. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +114 -48
  13. package/src/commons/Dashboard/MyUnit/index.js +74 -27
  14. package/src/commons/Dashboard/MyUnit/styles.js +16 -1
  15. package/src/commons/DateTimeRangeChange/index.js +1 -1
  16. package/src/commons/SelectUnit/index.js +19 -5
  17. package/src/commons/SelectUnit/styles.js +0 -1
  18. package/src/commons/Widgets/IFrame/IFrameStyles.js +1 -0
  19. package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfigStyles.js +1 -0
  20. package/src/configs/API.js +4 -0
  21. package/src/configs/Constants.js +3 -0
  22. package/src/context/reducer.ts +0 -5
  23. package/src/navigations/UnitStack.js +8 -0
  24. package/src/screens/Device/__test__/sensorDisplayItem.test.js +27 -0
  25. package/src/screens/Device/components/DonutChart.js +5 -14
  26. package/src/screens/Device/components/SensorDisplayItem.js +92 -61
  27. package/src/screens/Device/components/VisualChart.js +0 -12
  28. package/src/screens/Device/styles.js +16 -0
  29. package/src/screens/SubUnit/AddSubUnit.js +18 -8
  30. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +5 -3
  31. package/src/screens/Unit/GoToDetailUnit.js +30 -0
  32. package/src/screens/Unit/__test__/GoToDetailUnit.test.js +103 -0
  33. package/src/utils/I18n/translations/en.js +1 -0
  34. package/src/utils/I18n/translations/vi.js +1 -0
  35. package/src/utils/Route/index.js +1 -0
  36. package/src/utils/Storage.js +0 -2
  37. package/src/utils/Utils.js +2 -1
  38. package/src/utils/Functions/preloadImages.js +0 -38
@@ -13,11 +13,14 @@ import _TextInput from '../../commons/Form/TextInput';
13
13
  import Text from '../../commons/Text';
14
14
  import { API, Colors } from '../../configs';
15
15
  import { AccessibilityLabel } from '../../configs/Constants';
16
- import { useSCContextSelector } from '../../context';
17
16
  import useKeyboardShow from '../../hooks/Common/useKeyboardShow';
18
17
  import { useTranslations } from '../../hooks/Common/useTranslations';
19
18
  import { replace } from '../../navigations/utils';
20
- import { axiosPost, createFormData } from '../../utils/Apis/axios';
19
+ import {
20
+ axiosPost,
21
+ createFormData,
22
+ fetchWithCache,
23
+ } from '../../utils/Apis/axios';
21
24
  import { useBackendPermission } from '../../utils/Permission/backend';
22
25
  import Routes from '../../utils/Route';
23
26
  import { ToastBottomHelper } from '../../utils/Utils';
@@ -29,7 +32,6 @@ const AddSubUnit = ({ route }) => {
29
32
  const { dismissKeyboard } = useKeyboardShow();
30
33
  const { navigate, goBack, dispatch } = useNavigation();
31
34
  const permissions = useBackendPermission();
32
- const myUnits = useSCContextSelector((state) => state.myUnits);
33
35
 
34
36
  const {
35
37
  unit,
@@ -42,11 +44,15 @@ const AddSubUnit = ({ route }) => {
42
44
  const [wallpaper, setWallpaper] = useState('');
43
45
  const [imageUrl, setImageUrl] = useState('');
44
46
  const [showImagePicker, setShowImagePicker] = useState(false);
47
+ const [unitDetail, setUnitDetail] = useState({});
45
48
  let awaitCreate = useRef(false);
46
49
 
47
- const unitChoose = useMemo(() => {
48
- return myUnits?.find((item) => item?.id === unit?.id);
49
- }, [myUnits, unit?.id]);
50
+ const fetchUnitDetail = useCallback(async () => {
51
+ await fetchWithCache(API.UNIT.UNIT_DETAIL(unit?.id), {}, (response) => {
52
+ const { success, data } = response;
53
+ success && setUnitDetail(data);
54
+ });
55
+ }, [unit?.id]);
50
56
 
51
57
  const cleanData = () => {
52
58
  setRoomName('');
@@ -133,7 +139,7 @@ const AddSubUnit = ({ route }) => {
133
139
  } else {
134
140
  awaitCreate.current = false;
135
141
  if (
136
- unitChoose?.stations?.length >= permissions?.max_stations_per_unit
142
+ unitDetail?.stations?.length >= permissions?.max_stations_per_unit
137
143
  ) {
138
144
  ToastBottomHelper.error(
139
145
  t('reach_max_stations_per_unit', {
@@ -159,7 +165,7 @@ const AddSubUnit = ({ route }) => {
159
165
  goBack,
160
166
  navigate,
161
167
  route.params,
162
- unitChoose?.stations?.length,
168
+ unitDetail?.stations?.length,
163
169
  permissions?.max_stations_per_unit,
164
170
  ]);
165
171
 
@@ -174,6 +180,10 @@ const AddSubUnit = ({ route }) => {
174
180
  }
175
181
  }, [imageUrl]);
176
182
 
183
+ useEffect(() => {
184
+ fetchUnitDetail();
185
+ }, [fetchUnitDetail]);
186
+
177
187
  const onChangeRoomName = useCallback(
178
188
  (value) => {
179
189
  setRoomName(value);
@@ -295,6 +295,11 @@ describe('Test AddSubUnit', () => {
295
295
  isInsideUnit: false,
296
296
  };
297
297
  const spyToastError = jest.spyOn(ToastBottomHelper, 'error');
298
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
299
+ id: 1,
300
+ name: 'unit 1',
301
+ stations: [{ id: 1, name: 'station' }],
302
+ });
298
303
  mock.onPost(API.SUB_UNIT.CREATE_SUB_UNIT(1)).reply(400, {});
299
304
  await act(async () => {
300
305
  tree = await create(
@@ -308,9 +313,6 @@ describe('Test AddSubUnit', () => {
308
313
  },
309
314
  },
310
315
  },
311
- myUnits: [
312
- { id: 1, name: 'unit 1', stations: [{ id: 1, name: 'station' }] },
313
- ],
314
316
  })
315
317
  );
316
318
  });
@@ -0,0 +1,30 @@
1
+ import { useNavigation } from '@react-navigation/native';
2
+ import React, { useCallback } from 'react';
3
+
4
+ import Routes from '../../utils/Route';
5
+ import SelectUnit from '../../commons/SelectUnit';
6
+ import { useTranslations } from '../../hooks/Common/useTranslations';
7
+
8
+ const GoToDetailUnit = () => {
9
+ const t = useTranslations();
10
+ const navigation = useNavigation();
11
+
12
+ const goToDetail = useCallback(
13
+ (item) => {
14
+ navigation.navigate(Routes.UnitDetail, {
15
+ unitId: item.id,
16
+ });
17
+ },
18
+ [navigation]
19
+ );
20
+
21
+ return (
22
+ <SelectUnit
23
+ title={t('text_select_a_unit')}
24
+ subTitle={t('text_select_go_to_unit_detail')}
25
+ onPressNext={goToDetail}
26
+ />
27
+ );
28
+ };
29
+
30
+ export default GoToDetailUnit;
@@ -0,0 +1,103 @@
1
+ import { useNavigation } from '@react-navigation/native';
2
+ import React from 'react';
3
+ import renderer, { act } from 'react-test-renderer';
4
+ import MockAdapter from 'axios-mock-adapter';
5
+
6
+ import { SCProvider } from '../../../context';
7
+ import { mockSCStore } from '../../../context/mockStore';
8
+ import GoToDetailUnit from '../GoToDetailUnit';
9
+ import { Search } from '../../../commons/DevMode';
10
+ import { AccessibilityLabel } from '../../../configs/Constants';
11
+ import Routes from '../../../utils/Route';
12
+ import api from '../../../utils/Apis/axios';
13
+ import { API } from '../../../configs';
14
+
15
+ const wrapComponent = () => (
16
+ <SCProvider initState={mockSCStore({})}>
17
+ <GoToDetailUnit />
18
+ </SCProvider>
19
+ );
20
+
21
+ const mock = new MockAdapter(api.axiosInstance);
22
+
23
+ describe('Test GoToDetailUnit', () => {
24
+ let tree;
25
+ const data = [
26
+ {
27
+ id: 1,
28
+ name: 'Name 1',
29
+ },
30
+ {
31
+ id: 2,
32
+ name: 'Name 2',
33
+ },
34
+ ];
35
+
36
+ const mockedNavigate = useNavigation().navigate;
37
+ beforeEach(() => {
38
+ mockedNavigate.mockReset();
39
+ mock.resetHistory();
40
+ });
41
+
42
+ it('test render and navigate', async () => {
43
+ mock.onGet(API.SHARE.UNITS()).reply(200, data);
44
+ await act(async () => {
45
+ tree = await renderer.create(wrapComponent());
46
+ });
47
+
48
+ const instance = tree.root;
49
+ const unitItems = instance.findAllByProps({
50
+ accessibilityLabel: AccessibilityLabel.ITEM_UNIT,
51
+ });
52
+ expect(unitItems).toHaveLength(2);
53
+ const selectUnit = instance.findByProps({
54
+ accessibilityLabel: `${AccessibilityLabel.SELECT_UNIT_SELECT}-1`,
55
+ });
56
+ await act(async () => {
57
+ await selectUnit.props.onPress();
58
+ });
59
+ const rightClick = instance.findByProps({
60
+ accessibilityLabelPrefix: AccessibilityLabel.PREFIX.SELECT_UNIT,
61
+ });
62
+ await act(async () => {
63
+ await rightClick.props.onRightClick();
64
+ });
65
+
66
+ expect(global.mockedNavigate).toHaveBeenCalledWith(Routes.UnitDetail, {
67
+ unitId: 1,
68
+ });
69
+ });
70
+
71
+ it('test filter unit by name', async () => {
72
+ mock.onGet(API.SHARE.UNITS()).reply(200, data);
73
+ await act(async () => {
74
+ tree = await renderer.create(wrapComponent());
75
+ });
76
+
77
+ const instance = tree.root;
78
+ const search = instance.findByType(Search);
79
+ await act(() => {
80
+ search.props.onSearch('Name 2');
81
+ });
82
+ const unitItems = instance.findAllByProps({
83
+ accessibilityLabel: AccessibilityLabel.ITEM_UNIT,
84
+ });
85
+ expect(unitItems).toHaveLength(1);
86
+ const selectUnit = instance.findByProps({
87
+ accessibilityLabel: `${AccessibilityLabel.SELECT_UNIT_SELECT}-2`,
88
+ });
89
+ await act(async () => {
90
+ await selectUnit.props.onPress();
91
+ });
92
+ const rightClick = instance.findByProps({
93
+ accessibilityLabelPrefix: AccessibilityLabel.PREFIX.SELECT_UNIT,
94
+ });
95
+ await act(async () => {
96
+ await rightClick.props.onRightClick();
97
+ });
98
+
99
+ expect(global.mockedNavigate).toHaveBeenCalledWith(Routes.UnitDetail, {
100
+ unitId: 2,
101
+ });
102
+ });
103
+ });
@@ -382,6 +382,7 @@ export default {
382
382
  select_a_sub_unit_want_add_device:
383
383
  'Select a sub-unit that you want to add this device in',
384
384
  text_select_a_unit_have_device: 'Select a unit that has this device',
385
+ text_select_go_to_unit_detail: 'Select a unit to view details',
385
386
  text_select_permissions: 'Select permissions',
386
387
  text_select_permissions_desc: 'Select permissions will be grant',
387
388
  text_read_config: 'Read configs',
@@ -435,6 +435,7 @@ export default {
435
435
  text_select_a_gateway: 'Chọn một gateway',
436
436
  text_select_a_unit_desc: 'Chọn 1 địa điểm bạn muốn thêm thành viên',
437
437
  text_select_a_unit_have_device: 'Chọn một địa điểm có thiết bị này',
438
+ text_select_go_to_unit_detail: 'Chọn địa điểm để xem chi tiết',
438
439
  select_a_sub_unit_want_add_device:
439
440
  'Chọn một đơn vị con mà bạn muốn thêm thiết bị này vào',
440
441
  text_select_permissions: 'Chọn hành động',
@@ -49,6 +49,7 @@ const Routes = {
49
49
  Dashboard: 'Dashboard',
50
50
  Shared: 'Shared',
51
51
  UnitDetail: 'UnitDetail',
52
+ GoToDetailUnit: 'GoToDetailUnit',
52
53
  DrawerMain: 'DrawerMain',
53
54
  ConnectDevices: 'ConnectDevices',
54
55
  SharedStack: 'SharedStack',
@@ -4,8 +4,6 @@ export const STORAGE_KEY = {
4
4
  FIREBASE_APP_CONFIG: 'app_config',
5
5
  FIREBASE_EXCHANGE_RATES: 'exchange_rates',
6
6
  FIREBASE_REVIEW_COMMENT_VIDEO: 'review_comment_video',
7
- IS_FIRST_TIME_LOAD_MY_UNITS: 'IS_FIRST_TIME_LOAD_MY_UNITS',
8
- IS_FIRST_TIME_LOAD_MY_SHARE_UNIT: 'IS_FIRST_TIME_LOAD_MY_SHARE_UNIT',
9
7
  };
10
8
 
11
9
  export const storeData = async (key, value) => {
@@ -231,7 +231,8 @@ export const PIN_MAPPING = {
231
231
  },
232
232
  };
233
233
 
234
- export const keyExtractor = (item, index) => (item?.id || index).toString();
234
+ export const keyExtractor = (item, index) =>
235
+ item?.id ? `id-${item.id}` : `index-${index}`;
235
236
 
236
237
  export default {
237
238
  validateEmail,
@@ -1,38 +0,0 @@
1
- import FastImage from 'react-native-fast-image';
2
- import { API } from '../../configs';
3
- import { axiosGet } from '../Apis/axios';
4
- import { getData, STORAGE_KEY, storeData } from '../Storage';
5
-
6
- export const preloadImagesFromUnits = async (units, storeKey) => {
7
- const isFirstTime = await getData(storeKey);
8
- if (units?.length && !isFirstTime) {
9
- await storeData(storeKey, 'true');
10
- const results = await Promise.all(
11
- units.map(async (item) => {
12
- const unitId =
13
- storeKey === STORAGE_KEY.IS_FIRST_TIME_LOAD_MY_UNITS
14
- ? item?.id
15
- : item?.unit?.id;
16
- if (unitId) {
17
- const { success, data } = await axiosGet(
18
- API.UNIT.UNIT_DETAIL(unitId),
19
- {},
20
- true
21
- );
22
- return success && data;
23
- }
24
- })
25
- );
26
-
27
- const icons = results
28
- .map((item) => item?.stations?.map((i) => i?.background) || [])
29
- .flat()
30
- .filter(Boolean);
31
- FastImage.preload(
32
- icons.map((uri) => ({
33
- uri,
34
- priority: FastImage.priority.high,
35
- }))
36
- );
37
- }
38
- };