@eohjsc/react-native-smart-city 0.2.86 → 0.2.89

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 (126) hide show
  1. package/assets/images/Common/Calendar.svg +3 -0
  2. package/assets/images/Common/SmartPhone.svg +3 -0
  3. package/assets/images/Hanet/CaptureFaceID.svg +25 -0
  4. package/assets/images/Hanet/FaceFrame.svg +6 -0
  5. package/assets/images/brightnessBlack.svg +12 -0
  6. package/index.js +4 -0
  7. package/package.json +3 -3
  8. package/src/Images/SmartIr/AC.svg +14 -0
  9. package/src/Images/SmartIr/DIY.svg +3 -0
  10. package/src/Images/SmartIr/Fan.svg +10 -0
  11. package/src/Images/SmartIr/Fridge.svg +5 -0
  12. package/src/Images/SmartIr/Remote.svg +15 -0
  13. package/src/Images/SmartIr/SmartIr.svg +4 -0
  14. package/src/Images/SmartIr/TV.svg +10 -0
  15. package/src/Images/SmartIr/Union.svg +9 -0
  16. package/src/Images/SmartIr/WM.svg +11 -0
  17. package/src/Images/SmartIr/index.js +10 -0
  18. package/src/commons/ActionGroup/ColorPickerTemplate.js +51 -0
  19. package/src/commons/ActionGroup/ColorPickerTemplateStyles.js +17 -0
  20. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/AutoLockStyles.js +40 -0
  21. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/ButtonWrapper.js +65 -0
  22. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/ButtonWrapperStyles.js +43 -0
  23. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +48 -0
  24. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/index.js +57 -0
  25. package/src/commons/ActionGroup/{OnOffSmartLock.js → OnOffSmartLock/OnOffSmartLock.js} +5 -5
  26. package/src/commons/ActionGroup/{OnOffSmartLockStyle.js → OnOffSmartLock/OnOffSmartLockStyle.js} +1 -1
  27. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +48 -0
  28. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscodeStyles.js +42 -0
  29. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/PasscodeListStyles.js +49 -0
  30. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/index.js +66 -0
  31. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/ButtonWrapper.js +96 -0
  32. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/SetupGeneratePasscodeStyles.js +98 -0
  33. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +62 -0
  34. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/index.js +249 -0
  35. package/src/commons/ActionGroup/OnOffTemplate/index.js +4 -2
  36. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +2 -1
  37. package/src/commons/ActionGroup/SliderRangeTemplate.js +64 -0
  38. package/src/commons/ActionGroup/{LightActionTemplateStyles.js → SliderRangeTemplateStyles.js} +0 -8
  39. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +167 -186
  40. package/src/commons/ActionGroup/StatesGridActionTemplate.js +2 -1
  41. package/src/commons/ActionGroup/index.js +7 -4
  42. package/src/commons/BottomSheet/index.js +2 -1
  43. package/src/commons/Device/DisconnectedView.js +7 -1
  44. package/src/commons/Device/Hanet/ItemHanetDevice.js +109 -0
  45. package/src/commons/Device/HistoryChart.js +2 -2
  46. package/src/commons/Device/HorizontalBarChart.js +7 -0
  47. package/src/commons/Device/ItemDevice.js +18 -15
  48. package/src/commons/Device/LinearChart.js +14 -41
  49. package/src/commons/Device/__test__/DisconnectedView.test.js +13 -2
  50. package/src/commons/RowItem/index.js +12 -7
  51. package/src/commons/SubUnit/Favorites/index.js +2 -2
  52. package/src/commons/SubUnit/ShortDetail.js +39 -20
  53. package/src/commons/WheelDateTimePicker/index.js +18 -4
  54. package/src/configs/API.js +23 -1
  55. package/src/configs/Colors.js +1 -0
  56. package/src/configs/Constants.js +48 -0
  57. package/src/configs/SCConfig.js +1 -1
  58. package/src/context/actionType.ts +4 -0
  59. package/src/context/mockStore.ts +3 -0
  60. package/src/context/reducer.ts +20 -0
  61. package/src/iot/RemoteControl/Bluetooth.js +3 -22
  62. package/src/iot/RemoteControl/index.js +0 -1
  63. package/src/navigations/HanetCameraStack.js +41 -0
  64. package/src/navigations/SmartIrStack.js +31 -0
  65. package/src/navigations/SmartLockStack.js +51 -0
  66. package/src/navigations/UnitStack.js +46 -4
  67. package/src/screens/ActivityLog/hooks/index.js +1 -1
  68. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +1 -1
  69. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +79 -72
  70. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +155 -27
  71. package/src/screens/AddNewGateway/PlugAndPlay/__test__/ConnectWifiWarning.test.js +65 -0
  72. package/src/screens/AddNewGateway/PlugAndPlay/__test__/GatewayWifiList.test.js +26 -2
  73. package/src/screens/Device/__test__/detail.test.js +0 -10
  74. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +13 -2
  75. package/src/screens/Device/detail.js +118 -38
  76. package/src/screens/Device/hooks/useDisconnectedDevice.js +28 -16
  77. package/src/screens/GuestInfo/components/AccessScheduleItem.js +9 -2
  78. package/src/screens/GuestInfo/components/RecurringDetail.js +3 -2
  79. package/src/screens/GuestInfo/components/TemporaryDetail.js +3 -2
  80. package/src/screens/GuestInfo/styles/AccessScheduleItemStyles.js +3 -0
  81. package/src/screens/HanetCamera/CaptureFaceID.js +210 -0
  82. package/src/screens/HanetCamera/Detail.js +252 -0
  83. package/src/screens/HanetCamera/ManageAccess.js +173 -0
  84. package/src/screens/HanetCamera/MemberInfo.js +208 -0
  85. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +133 -0
  86. package/src/screens/HanetCamera/__test__/Detail.test.js +185 -0
  87. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +152 -0
  88. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +178 -0
  89. package/src/screens/HanetCamera/components/CheckinHeader.js +37 -0
  90. package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +151 -0
  91. package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +71 -0
  92. package/src/screens/HanetCamera/hooks/index.js +5 -0
  93. package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +116 -0
  94. package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +86 -0
  95. package/src/screens/HanetCamera/hooks/useStateAlertAction.js +62 -0
  96. package/src/screens/HanetCamera/styles/captureFaceIDStyles.js +50 -0
  97. package/src/screens/HanetCamera/styles/checkinHeaderStyles.js +24 -0
  98. package/src/screens/HanetCamera/styles/detailStyles.js +107 -0
  99. package/src/screens/HanetCamera/styles/manageAccessStyles.js +49 -0
  100. package/src/screens/HanetCamera/styles/memberInfoStyles.js +73 -0
  101. package/src/screens/HanetCamera/utils/Monitor.js +52 -0
  102. package/src/screens/Notification/__test__/NotificationItem.test.js +1 -0
  103. package/src/screens/Notification/components/NotificationItem.js +16 -0
  104. package/src/screens/SmartIr/__test__/ButtonsBottom.test.js +31 -0
  105. package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +80 -0
  106. package/src/screens/SmartIr/__test__/SelectBrand.test.js +65 -0
  107. package/src/screens/SmartIr/__test__/SelectDeviceType.test.js +57 -0
  108. package/src/screens/SmartIr/__test__/SmartIr.test.js +1 -0
  109. package/src/screens/SmartIr/components/GroupButtonByType/ButtonsBottom.js +45 -0
  110. package/src/screens/SmartIr/components/GroupButtonByType/ButtonsBottomStyles.js +31 -0
  111. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +208 -0
  112. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByTypeStyles.js +113 -0
  113. package/src/screens/SmartIr/components/SelectBrand.js +61 -0
  114. package/src/screens/SmartIr/components/SelectBrandStyles.js +14 -0
  115. package/src/screens/SmartIr/components/SelectDeviceType.js +96 -0
  116. package/src/screens/SmartIr/components/SelectDeviceTypeStyles.js +30 -0
  117. package/src/screens/SmartIr/index.js +8 -3
  118. package/src/screens/Unit/Detail.js +7 -11
  119. package/src/screens/Unit/__test__/Detail.test.js +0 -10
  120. package/src/screens/Unit/components/MyUnitDevice/index.js +2 -4
  121. package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +38 -9
  122. package/src/utils/I18n/translations/en.json +51 -1
  123. package/src/utils/I18n/translations/vi.json +51 -1
  124. package/src/utils/Route/index.js +14 -1
  125. package/src/commons/ActionGroup/LightActionTemplate.js +0 -103
  126. package/src/commons/ActionGroup/__test__/LightActionTemplate.test.js +0 -59
@@ -0,0 +1,208 @@
1
+ import React, { memo, useCallback, useState, useMemo } from 'react';
2
+ import { View, TouchableOpacity, Alert } from 'react-native';
3
+ import WrapHeaderScrollable from '../../../../commons/Sharing/WrapHeaderScrollable';
4
+ import { useTranslations } from '../../../../hooks/Common/useTranslations';
5
+ import SmartTiviActionTemplate from '../../../../commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate';
6
+ import Text from '../../../../commons/Text';
7
+ import { ModalCustom } from '../../../../commons/Modal';
8
+ import { IconOutline } from '@ant-design/icons-react-native';
9
+ import { Colors } from '../../../../configs';
10
+ import TextInput from '../../../../commons/Form/TextInput';
11
+ import { ButtonsBottom } from './ButtonsBottom';
12
+
13
+ import { Remote, SmartIr, Union } from '../../../../Images/SmartIr';
14
+
15
+ import styles from './GroupButtonByTypeStyles';
16
+
17
+ const GroupButtonByType = memo(({ route }) => {
18
+ const t = useTranslations();
19
+ const [groupButton] = useState({ id: 1, template: 'tivi' });
20
+ const [isLearn, setIsLearn] = useState(false);
21
+ const [isShowModal, setIsShowModal] = useState(false);
22
+ const [learnSuccess, setLearnSuccess] = useState(false);
23
+ const [select, setSelect] = useState(false);
24
+ const [text, setText] = useState('');
25
+
26
+ const GroupButtonTemplate = useCallback(() => {
27
+ switch (groupButton?.template) {
28
+ case 'tivi':
29
+ return <SmartTiviActionTemplate />;
30
+ default:
31
+ return <></>;
32
+ }
33
+ }, [groupButton]);
34
+ const rightButtonHeader = useCallback(
35
+ (type) => () => {
36
+ switch (type) {
37
+ case 'reload':
38
+ case 'more':
39
+ case 'done':
40
+ return Alert.alert(t('feature_under_development'));
41
+ default:
42
+ return <></>;
43
+ }
44
+ },
45
+ [t]
46
+ );
47
+ const rightComponent = useMemo(
48
+ () => (
49
+ <View style={styles.rightComponent}>
50
+ {!isLearn ? (
51
+ <>
52
+ <TouchableOpacity
53
+ onPress={rightButtonHeader('reload')}
54
+ style={[styles.headerButton]}
55
+ >
56
+ <IconOutline name={'reload'} size={27} color={Colors.Black} />
57
+ </TouchableOpacity>
58
+ <TouchableOpacity
59
+ onPress={rightButtonHeader('more')}
60
+ style={[styles.headerButton]}
61
+ >
62
+ <IconOutline name={'more'} size={27} color={Colors.Black} />
63
+ </TouchableOpacity>
64
+ </>
65
+ ) : (
66
+ <>
67
+ <TouchableOpacity
68
+ onPress={rightButtonHeader('done')}
69
+ style={[styles.headerButtonDone]}
70
+ >
71
+ <Text type="H4" bold color={Colors.Primary}>
72
+ {t('done')}
73
+ </Text>
74
+ </TouchableOpacity>
75
+ </>
76
+ )}
77
+ </View>
78
+ ),
79
+ [isLearn, rightButtonHeader, t]
80
+ );
81
+ const selectButton = useCallback(() => {
82
+ setSelect(true);
83
+ setIsShowModal(false);
84
+ }, []);
85
+ const nextButton = useCallback(() => {
86
+ setIsLearn(true);
87
+ setIsShowModal(true);
88
+ }, []);
89
+
90
+ const cancelButton = useCallback(() => {
91
+ setIsShowModal(false);
92
+ }, []);
93
+ const ApplyButton = useCallback(() => {
94
+ setIsLearn(false);
95
+ setIsShowModal(false);
96
+ setLearnSuccess(true);
97
+ setSelect(true);
98
+ }, []);
99
+
100
+ const ContentModal = useCallback(() => {
101
+ if (learnSuccess) {
102
+ return (
103
+ <View style={[styles.popoverStyle, styles.popoverLearn]}>
104
+ <View style={styles.paddingBottom16}>
105
+ <SmartIr />
106
+ </View>
107
+ <Union />
108
+ <View style={[styles.paddingBottom16, styles.paddingLeft16]}>
109
+ <Remote />
110
+ </View>
111
+ <View>
112
+ <Text color={Colors.Gray8}>{t('point_at_center')}</Text>
113
+ </View>
114
+ <View>
115
+ <Text color={Colors.Gray8}>
116
+ {t('press')}
117
+ <Text bold color={Colors.Primary}>
118
+ {t('remote_control')}
119
+ </Text>
120
+ {t('same_key')}
121
+ </Text>
122
+ </View>
123
+ <View>
124
+ <Text color={Colors.Gray8}>{`(20s ${t('remained')})`}</Text>
125
+ </View>
126
+ </View>
127
+ );
128
+ } else {
129
+ return (
130
+ <View style={[styles.popoverStyle, styles.popoverDetected]}>
131
+ <View style={styles.modalHeader}>
132
+ <Text semibold style={styles.modalHeaderText}>
133
+ {t('detected_signal')}
134
+ </Text>
135
+ </View>
136
+ <TextInput
137
+ defaultValue={text}
138
+ onChange={(value) => setText(value)}
139
+ textInputStyle={styles.textInputStyle}
140
+ wrapStyle={styles.textInputWrapStyle}
141
+ selectionColor={Colors.Primary}
142
+ />
143
+ <ButtonsBottom
144
+ onPressLeft={cancelButton}
145
+ onPressRight={ApplyButton}
146
+ textLeft={t('cancel')}
147
+ textRight={t('apply')}
148
+ colorTextLeft={Colors.Gray8}
149
+ colorTextRight={Colors.White}
150
+ leftButtonStyle={styles.leftButtonModal}
151
+ rightButtonStyle={styles.rightButtonModal}
152
+ />
153
+ </View>
154
+ );
155
+ }
156
+ }, [ApplyButton, cancelButton, learnSuccess, t, text]);
157
+
158
+ const AlertBottom = useCallback(() => {
159
+ return (
160
+ <View style={styles.alertBottom}>
161
+ <View style={styles.alertContent}>
162
+ {!isLearn ? (
163
+ <>
164
+ <Text>{t('make_sure_3_button_available')}</Text>
165
+ <ButtonsBottom
166
+ onPressLeft={selectButton}
167
+ onPressRight={nextButton}
168
+ textLeft={t('select_this_one')}
169
+ textRight={t('next_one')}
170
+ buttonStyle={styles.widthAlertBottom}
171
+ />
172
+ </>
173
+ ) : (
174
+ <Text color={Colors.Gray8}>
175
+ {t('please')}
176
+ <Text bold color={Colors.Primary}>
177
+ {t('long_press')}
178
+ </Text>
179
+ {t('the_button_to_study')}
180
+ </Text>
181
+ )}
182
+ </View>
183
+ </View>
184
+ );
185
+ }, [isLearn, nextButton, selectButton, t]);
186
+
187
+ return (
188
+ <View style={styles.container}>
189
+ <WrapHeaderScrollable
190
+ title={t('Tivi')}
191
+ headerAniStyle={styles.header}
192
+ styleScrollView={styles.scrollView}
193
+ rightComponent={rightComponent}
194
+ >
195
+ <View style={styles.wrapItem}>
196
+ <GroupButtonTemplate />
197
+ </View>
198
+ </WrapHeaderScrollable>
199
+ {!select && <AlertBottom />}
200
+
201
+ <ModalCustom isVisible={isShowModal}>
202
+ <ContentModal />
203
+ </ModalCustom>
204
+ </View>
205
+ );
206
+ });
207
+
208
+ export default GroupButtonByType;
@@ -0,0 +1,113 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { Colors, Constants } from '../../../../configs';
3
+ import { getStatusBarHeight } from 'react-native-iphone-x-helper';
4
+ export const heightHeader = 44 + 44 + getStatusBarHeight() + 10;
5
+
6
+ const flexCenter = {
7
+ justifyContent: 'center',
8
+ alignItems: 'center',
9
+ };
10
+
11
+ export default StyleSheet.create({
12
+ container: {
13
+ flex: 1,
14
+ },
15
+ header: {
16
+ borderBottomWidth: 0,
17
+ },
18
+ scrollView: {
19
+ backgroundColor: Colors.White,
20
+ position: 'relative',
21
+ },
22
+ wrapItem: {
23
+ flex: 1,
24
+ },
25
+ rightComponent: {
26
+ flexDirection: 'row',
27
+ paddingRight: 8,
28
+ },
29
+ headerButton: {
30
+ paddingHorizontal: 10,
31
+ },
32
+ headerButtonDone: {
33
+ paddingHorizontal: 10,
34
+ paddingTop: 8,
35
+ },
36
+ alertBottom: {
37
+ backgroundColor: Colors.White,
38
+ height: 120,
39
+ left: 0,
40
+ right: 0,
41
+ bottom: 0,
42
+ borderRadius: 10,
43
+ },
44
+ alertContent: {
45
+ flex: 1,
46
+ backgroundColor: Colors.Blue13,
47
+ ...flexCenter,
48
+ borderRadius: 10,
49
+ shadowColor: Colors.Shadow,
50
+ shadowOffset: {
51
+ width: 0,
52
+ height: 20,
53
+ },
54
+ shadowOpacity: 0.25,
55
+ shadowRadius: 4.84,
56
+ elevation: 5,
57
+ },
58
+ popoverStyle: {
59
+ justifyContent: 'center',
60
+ alignItems: 'center',
61
+ backgroundColor: Colors.White,
62
+ borderRadius: 10,
63
+ padding: 18,
64
+ },
65
+ popoverLearn: {
66
+ marginBottom: Constants.height / 2 - 136,
67
+ },
68
+ popoverDetected: {
69
+ justifyContent: 'flex-start',
70
+ alignItems: 'flex-start',
71
+ },
72
+ paddingBottom16: {
73
+ paddingBottom: 16,
74
+ },
75
+ paddingLeft16: {
76
+ paddingLeft: 16,
77
+ },
78
+ textInputStyle: {
79
+ paddingHorizontal: 0,
80
+ borderWidth: 0,
81
+ fontSize: 16,
82
+ marginTop: 0,
83
+ borderRadius: 1,
84
+ paddingTop: 10,
85
+ paddingBottom: 10,
86
+ },
87
+ textInputWrapStyle: {
88
+ width: '100%',
89
+ borderWidth: 0,
90
+ borderBottomWidth: 1,
91
+ borderBottomColor: Colors.Primary,
92
+ borderTopWidth: 1,
93
+ borderTopColor: Colors.Gray4,
94
+ marginBottom: 20,
95
+ marginHorizontal: 0,
96
+ },
97
+ titleModal: {
98
+ paddingTop: 8,
99
+ },
100
+ widthAlertBottom: {
101
+ width: Constants.width / 2 - 32,
102
+ },
103
+ rightButtonModal: {
104
+ width: Constants.width / 2 - 52,
105
+ backgroundColor: Colors.Primary,
106
+ },
107
+ leftButtonModal: {
108
+ width: Constants.width / 2 - 52,
109
+ backgroundColor: Colors.Gray1,
110
+ borderColor: Colors.Gray5,
111
+ borderWidth: 1,
112
+ },
113
+ });
@@ -0,0 +1,61 @@
1
+ import React, { memo, useCallback, useState } from 'react';
2
+ import { View, ScrollView } from 'react-native';
3
+ import { useNavigation } from '@react-navigation/native';
4
+ import { HeaderCustom } from '../../../commons/Header';
5
+ import { useTranslations } from '../../../hooks/Common/useTranslations';
6
+ import Routes from '../../../utils/Route';
7
+ import { RowItem } from '../../../commons/RowItem';
8
+ import { IconOutline } from '@ant-design/icons-react-native';
9
+ import { Colors } from '../../../configs';
10
+
11
+ import styles from './SelectBrandStyles';
12
+
13
+ const SelectDeviceType = memo(({ route }) => {
14
+ const t = useTranslations();
15
+ const { navigate } = useNavigation();
16
+ const tempBrand = [
17
+ { id: 1, name: 'Samsung' },
18
+ { id: 2, name: 'LG' },
19
+ { id: 3, name: 'Apple' },
20
+ ];
21
+ const [deviceBrand] = useState(tempBrand);
22
+
23
+ const handleOnPressItem = useCallback(
24
+ (item) => () => {
25
+ navigate(Routes.SmartIrStack, {
26
+ screen: Routes.GroupButtonByType,
27
+ params: {
28
+ device_type: item || {},
29
+ brand: item || {},
30
+ },
31
+ });
32
+ },
33
+ [navigate]
34
+ );
35
+
36
+ return (
37
+ <View style={styles.container}>
38
+ <HeaderCustom title={t('select_brand')} />
39
+ <ScrollView>
40
+ <View style={styles.listBrands}>
41
+ {!!deviceBrand &&
42
+ deviceBrand.map((item, index) => {
43
+ return (
44
+ <RowItem
45
+ onPress={handleOnPressItem(item)}
46
+ text={item?.name}
47
+ key={index.toString()}
48
+ isShowSubText={false}
49
+ rightComponent={
50
+ <IconOutline name="right" size={20} color={Colors.Gray7} />
51
+ }
52
+ />
53
+ );
54
+ })}
55
+ </View>
56
+ </ScrollView>
57
+ </View>
58
+ );
59
+ });
60
+
61
+ export default SelectDeviceType;
@@ -0,0 +1,14 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { Colors } from '../../../configs';
3
+
4
+ export default StyleSheet.create({
5
+ container: {
6
+ flex: 1,
7
+ backgroundColor: Colors.White,
8
+ },
9
+ listBrands: {
10
+ flex: 1,
11
+ paddingTop: 16,
12
+ paddingHorizontal: 16,
13
+ },
14
+ });
@@ -0,0 +1,96 @@
1
+ import React, { memo, useCallback, useState } from 'react';
2
+ import { View, TouchableOpacity, ScrollView } from 'react-native';
3
+ import { useNavigation } from '@react-navigation/native';
4
+ import Text from '../../../commons/Text';
5
+ import { HeaderCustom } from '../../../commons/Header';
6
+ import { useTranslations } from '../../../hooks/Common/useTranslations';
7
+ import { AC, DIY, Fan, Fridge, TV, WM } from '../../../Images/SmartIr';
8
+ import Routes from '../../../utils/Route';
9
+
10
+ import styles from './SelectDeviceTypeStyles';
11
+
12
+ const SelectDeviceType = memo(() => {
13
+ const t = useTranslations();
14
+ const { navigate } = useNavigation();
15
+ const tempDeviceType = [
16
+ { id: 1, icon: 'tv', name: 'TV' },
17
+ { id: 2, icon: 'fan', name: 'Fan' },
18
+ { id: 3, icon: 'ac', name: 'AC' },
19
+ { id: 4, icon: 'wm', name: 'wm' },
20
+ { id: 5, icon: 'fridge', name: 'Fridge' },
21
+ { id: 6, icon: 'diy', name: 'DIY' },
22
+ ];
23
+ const [deviceType] = useState(tempDeviceType);
24
+
25
+ const handleOnPressItem = useCallback(
26
+ (item) => () => {
27
+ navigate(Routes.SmartIrStack, {
28
+ screen: Routes.SelectBrand,
29
+ params: {
30
+ device_type: item || {},
31
+ },
32
+ });
33
+ },
34
+ [navigate]
35
+ );
36
+
37
+ const IconDevice = ({ icon, width, height }) => {
38
+ switch (icon) {
39
+ case 'tv':
40
+ return <TV width={width} height={height} />;
41
+ case 'fan':
42
+ return <Fan width={width} height={height} />;
43
+ case 'ac':
44
+ return <AC width={width} height={height} />;
45
+ case 'wm':
46
+ return <WM width={width} height={height} />;
47
+ case 'fridge':
48
+ return <Fridge width={width} height={height} />;
49
+ case 'diy':
50
+ return <DIY width={width} height={height} />;
51
+ default:
52
+ return <></>;
53
+ }
54
+ };
55
+ const ItemDevice = useCallback(
56
+ ({ onPress, buttonStyle, textStyle, wrapStyle, name, icon }) => {
57
+ return (
58
+ <TouchableOpacity
59
+ style={[styles.buttonItem, buttonStyle]}
60
+ onPress={onPress}
61
+ >
62
+ <View style={[styles.wrapItem, wrapStyle]}>
63
+ {!!icon && <IconDevice width={60} height={60} icon={icon} />}
64
+ {!!name && (
65
+ <Text style={[styles.textDevice, textStyle]}> {name} </Text>
66
+ )}
67
+ </View>
68
+ </TouchableOpacity>
69
+ );
70
+ },
71
+ []
72
+ );
73
+
74
+ return (
75
+ <View style={styles.container}>
76
+ <HeaderCustom title={t('select_device_type')} />
77
+ <ScrollView>
78
+ <View style={styles.listDevices}>
79
+ {!!deviceType &&
80
+ deviceType.map((item, index) => {
81
+ return (
82
+ <ItemDevice
83
+ onPress={handleOnPressItem(item)}
84
+ name={item?.name}
85
+ icon={item?.icon}
86
+ key={index.toString()}
87
+ />
88
+ );
89
+ })}
90
+ </View>
91
+ </ScrollView>
92
+ </View>
93
+ );
94
+ });
95
+
96
+ export default SelectDeviceType;
@@ -0,0 +1,30 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { Colors, Constants } from '../../../configs';
3
+
4
+ export default StyleSheet.create({
5
+ container: {
6
+ flex: 1,
7
+ backgroundColor: Colors.White,
8
+ },
9
+ wrapItem: {
10
+ justifyContent: 'center',
11
+ alignItems: 'center',
12
+ paddingTop: 34,
13
+ paddingBottom: 60,
14
+ paddingHorizontal: 52,
15
+ },
16
+ listDevices: {
17
+ paddingTop: 16,
18
+ flexDirection: 'row',
19
+ justifyContent: 'space-between',
20
+ flexWrap: 'wrap',
21
+ paddingHorizontal: 16,
22
+ },
23
+ buttonItem: {
24
+ width: Constants.width / 2 - 25,
25
+ borderRadius: 10,
26
+ borderWidth: 1,
27
+ borderColor: Colors.Gray4,
28
+ marginBottom: 15,
29
+ },
30
+ });
@@ -1,14 +1,19 @@
1
1
  import React, { memo, useCallback } from 'react';
2
- import { View, Alert } from 'react-native';
2
+ import { View } from 'react-native';
3
3
  import { useTranslations } from '../../hooks/Common/useTranslations';
4
4
  import ItemAddNew from '../../commons/Device/ItemAddNew';
5
+ import Routes from '../../utils/Route';
6
+ import { useNavigation } from '@react-navigation/native';
5
7
  import styles from './styles';
6
8
 
7
9
  const SmartIr = memo(({ item }) => {
8
10
  const t = useTranslations();
11
+ const { navigate } = useNavigation();
9
12
  const AddRemoteControl = useCallback(() => {
10
- Alert.alert(t('feature_under_development'));
11
- }, [t]);
13
+ navigate(Routes.SmartIrStack, {
14
+ screen: Routes.SelectDeviceType,
15
+ });
16
+ }, [navigate]);
12
17
  return (
13
18
  <View style={styles.container}>
14
19
  <ItemAddNew
@@ -2,7 +2,6 @@ import React, { useCallback, useContext, useEffect, useState } from 'react';
2
2
  import { AppState, RefreshControl, View } from 'react-native';
3
3
  import { useIsFocused } from '@react-navigation/native';
4
4
  import { useTranslations } from '../../hooks/Common/useTranslations';
5
- import { useNetInfo } from '@react-native-community/netinfo';
6
5
 
7
6
  import styles from './styles';
8
7
  import AddMenu from './AddMenu';
@@ -76,20 +75,18 @@ const UnitDetail = ({ route }) => {
76
75
  automates: [],
77
76
  });
78
77
  const [isGGHomeConnected, setIsGGHomeConnected] = useState(false);
79
- const [isNetworkConnected, setIsNetworkConnected] = useState(true);
80
78
  const [station, setStation] = useState({});
81
79
  const [indexStation, setIndexStation] = useState(0);
82
80
  const [showAdd, setShowAdd, setHideAdd] = useBoolean();
83
81
  const [isFullScreen, setIsFullScreen] = useState(false);
84
82
  const [dataFullScreen, setDataFullScreen] = useState();
83
+ const [serverDown, setServerDown] = useState(false);
85
84
 
86
85
  const { childRef, showingPopover, showPopoverWithRef, hidePopover } =
87
86
  usePopover();
88
87
 
89
88
  const { isOwner } = useIsOwnerOfUnit(unit.user_id);
90
89
 
91
- const netInfo = useNetInfo();
92
-
93
90
  const handleFullScreen = (data) => {
94
91
  setIsFullScreen(!isFullScreen);
95
92
  setDataFullScreen(data);
@@ -128,10 +125,13 @@ const UnitDetail = ({ route }) => {
128
125
  const fetchDetails = useCallback(async () => {
129
126
  getAutomates();
130
127
  await fetchWithCache(API.UNIT.UNIT_DETAIL(unitId), {}, (response) => {
131
- const { success, data } = response;
128
+ const { success, data, resp_status } = response;
132
129
  if (success) {
130
+ setServerDown(false);
133
131
  prepareData(data);
134
132
  setUnit(data);
133
+ } else if (resp_status >= 500) {
134
+ setServerDown(true);
135
135
  }
136
136
  });
137
137
  }, [setUnit, unitId, prepareData, getAutomates]);
@@ -192,10 +192,6 @@ const UnitDetail = ({ route }) => {
192
192
  };
193
193
  }, [handleAppStateChange]);
194
194
 
195
- useEffect(() => {
196
- setIsNetworkConnected(netInfo.isConnected);
197
- }, [netInfo.isConnected]);
198
-
199
195
  const handleGoogleHomeConnect = useCallback(
200
196
  async (options) => {
201
197
  let isConnected = await googleHomeConnect(options); // this may wrong if have multiple connection
@@ -311,7 +307,7 @@ const UnitDetail = ({ route }) => {
311
307
  isOwner={isOwner}
312
308
  favorites={favorites}
313
309
  wrapItemStyle={styles.wrapItemStyle}
314
- isNetworkConnected={isNetworkConnected}
310
+ serverDown={serverDown}
315
311
  isGGHomeConnected={isGGHomeConnected}
316
312
  />
317
313
  );
@@ -338,7 +334,7 @@ const UnitDetail = ({ route }) => {
338
334
  <ShortDetailSubUnit
339
335
  unit={unit}
340
336
  station={station}
341
- isNetworkConnected={isNetworkConnected}
337
+ serverDown={serverDown}
342
338
  isGGHomeConnected={isGGHomeConnected}
343
339
  />
344
340
  );
@@ -62,16 +62,6 @@ jest.mock('home-assistant-js-websocket', () => {
62
62
  };
63
63
  });
64
64
 
65
- jest.mock('@react-native-community/netinfo', () => {
66
- return {
67
- useNetInfo: () => {
68
- return {
69
- isConnected: true,
70
- };
71
- },
72
- };
73
- });
74
-
75
65
  jest.mock('axios');
76
66
 
77
67
  describe('Test UnitDetail', () => {
@@ -16,10 +16,8 @@ const MyUnitDevice = ({ sensor, unit }) => {
16
16
  navigate(Routes.UnitStack, {
17
17
  screen: Routes.DeviceDetail,
18
18
  params: {
19
- unit,
20
- sensor,
21
- title: sensor?.name,
22
- station: sensor?.station,
19
+ unitData: unit,
20
+ sensorData: sensor,
23
21
  },
24
22
  });
25
23
  }, [navigate, sensor, unit]);