@eohjsc/react-native-smart-city 0.2.99 → 0.3.2

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 (224) hide show
  1. package/README.md +1 -1
  2. package/package.json +6 -4
  3. package/react-native-smart-city.podspec +1 -0
  4. package/src/commons/Action/ItemQuickAction.js +11 -2
  5. package/src/commons/Action/__test__/ItemQuickAction.test.js +11 -6
  6. package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
  7. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +31 -20
  8. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
  9. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
  10. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +24 -0
  11. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +14 -0
  12. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +1 -1
  13. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +3 -2
  14. package/src/commons/ActionGroup/StatesGridActionTemplate.js +8 -4
  15. package/src/commons/ActionGroup/TimerActionTemplate.js +2 -2
  16. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +0 -1
  17. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
  18. package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +45 -48
  19. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
  20. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
  21. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
  22. package/src/commons/ActionGroup/__test__/index.test.js +137 -2
  23. package/src/commons/Automate/ItemAutomate.js +1 -3
  24. package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
  25. package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
  26. package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +7 -3
  27. package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +8 -11
  28. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
  29. package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +3 -2
  30. package/src/commons/ConnectingProcess/index.js +72 -25
  31. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
  32. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
  33. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
  34. package/src/commons/Device/ConnectedViewHeader.js +1 -1
  35. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
  36. package/src/commons/Device/HistoryChart.js +3 -3
  37. package/src/commons/Device/ItemDevice.js +15 -11
  38. package/src/commons/Device/LinearChart.js +15 -0
  39. package/src/commons/Device/SonosSpeaker/index.js +1 -1
  40. package/src/commons/Explore/__test__/CityItem.test.js +33 -54
  41. package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +19 -14
  42. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +0 -3
  43. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +0 -3
  44. package/src/commons/FieldTemplate/ScheduleField/index.js +2 -2
  45. package/src/commons/Header/HeaderCustom.js +2 -1
  46. package/src/commons/HorizontalPicker/index.js +2 -2
  47. package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +0 -6
  48. package/src/commons/MediaPlayerDetail/index.js +24 -55
  49. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
  50. package/src/commons/SubUnit/Favorites/index.js +2 -3
  51. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
  52. package/src/commons/SubUnit/OneTap/index.js +1 -2
  53. package/src/commons/SubUnit/ShortDetail.js +25 -9
  54. package/src/commons/SubUnit/__test__/Item.test.js +0 -1
  55. package/src/commons/SubUnit/__test__/ShortDetail.test.js +8 -1
  56. package/src/commons/Unit/SharedUnit.js +1 -0
  57. package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
  58. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +2 -13
  59. package/src/commons/UnitSummary/ConfigHistoryChart.js +22 -13
  60. package/src/commons/WheelDateTimePicker/index.js +2 -2
  61. package/src/configs/API.js +85 -144
  62. package/src/configs/Constants.js +24 -0
  63. package/src/configs/SCConfig.js +2 -0
  64. package/src/context/actionType.ts +8 -0
  65. package/src/context/mockStore.ts +10 -0
  66. package/src/context/reducer.ts +38 -2
  67. package/src/hooks/Common/index.js +2 -0
  68. package/src/hooks/Common/useGGHomeDeviceConnected.js +16 -0
  69. package/src/hooks/Common/useGetIdUser.js +1 -5
  70. package/src/hooks/Common/useSensorsStatus.js +4 -4
  71. package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +198 -0
  72. package/src/hooks/IoT/__test__/useRemoteControl.test.js +198 -0
  73. package/src/hooks/IoT/index.js +4 -0
  74. package/src/hooks/IoT/useGGHomeConnection.js +91 -0
  75. package/src/hooks/IoT/useRemoteControl.js +79 -0
  76. package/src/hooks/index.js +4 -0
  77. package/src/hooks/useReceiveNotifications.js +9 -5
  78. package/src/iot/Monitor.js +3 -2
  79. package/src/iot/RemoteControl/Bluetooth.js +1 -1
  80. package/src/iot/RemoteControl/GoogleHome.js +75 -49
  81. package/src/iot/RemoteControl/Internet.js +1 -1
  82. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +95 -48
  83. package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
  84. package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
  85. package/src/iot/RemoteControl/index.js +52 -52
  86. package/src/screens/ActivityLog/__test__/index.test.js +38 -23
  87. package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
  88. package/src/screens/ActivityLog/hooks/index.js +1 -1
  89. package/src/screens/ActivityLog/index.js +2 -2
  90. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
  91. package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
  92. package/src/screens/AddLocationMaps/index.js +5 -4
  93. package/src/screens/AddNewAction/SelectAction.js +8 -8
  94. package/src/screens/AddNewAction/SetupSensor.js +7 -7
  95. package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
  96. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
  97. package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
  98. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -33
  99. package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
  100. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +21 -21
  101. package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
  102. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +23 -17
  103. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +3 -3
  104. package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
  105. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
  106. package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
  107. package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
  108. package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
  109. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
  110. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +9 -23
  111. package/src/screens/AllCamera/index.js +4 -4
  112. package/src/screens/Automate/MultiUnits.js +8 -8
  113. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
  114. package/src/screens/Automate/__test__/index.test.js +7 -12
  115. package/src/screens/Automate/index.js +3 -3
  116. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
  117. package/src/screens/ConfirmUnitDeletion/index.js +7 -1
  118. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
  119. package/src/screens/Device/EditDevice/index.js +2 -2
  120. package/src/screens/Device/__test__/detail.test.js +32 -85
  121. package/src/screens/Device/components/DetailHistoryChart.js +1 -1
  122. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +1 -0
  123. package/src/screens/Device/components/SensorDisplayItem.js +5 -2
  124. package/src/screens/Device/detail.js +53 -22
  125. package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
  126. package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
  127. package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
  128. package/src/screens/EditActionsList/index.js +1 -1
  129. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +1 -1
  130. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
  131. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +18 -14
  132. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +30 -31
  133. package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
  134. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
  135. package/src/screens/GuestInfo/__test__/index.test.js +13 -40
  136. package/src/screens/HanetCamera/Detail.js +1 -1
  137. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
  138. package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
  139. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
  140. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
  141. package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +3 -2
  142. package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
  143. package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
  144. package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +11 -11
  145. package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +11 -11
  146. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
  147. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
  148. package/src/screens/ManageAccess/hooks/index.js +7 -4
  149. package/src/screens/ManageAccess/index.js +1 -1
  150. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
  151. package/src/screens/MoveToAnotherSubUnit/index.js +5 -5
  152. package/src/screens/Notification/__test__/Notification.test.js +14 -25
  153. package/src/screens/Notification/__test__/NotificationItem.test.js +8 -7
  154. package/src/screens/Notification/components/NotificationItem.js +17 -20
  155. package/src/screens/Notification/index.js +9 -2
  156. package/src/screens/PlayBackCamera/Timer.js +2 -2
  157. package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
  158. package/src/screens/PlayBackCamera/index.js +22 -6
  159. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
  160. package/src/screens/ScanChipQR/hooks/index.js +15 -16
  161. package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
  162. package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
  163. package/src/screens/ScriptDetail/index.js +16 -11
  164. package/src/screens/SelectUnit/__test__/index.test.js +11 -54
  165. package/src/screens/SelectUnit/index.js +4 -2
  166. package/src/screens/SetSchedule/index.js +9 -9
  167. package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
  168. package/src/screens/Sharing/Components/SensorItem.js +10 -12
  169. package/src/screens/Sharing/InfoMemberUnit.js +1 -1
  170. package/src/screens/Sharing/SelectPermission.js +121 -76
  171. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
  172. package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
  173. package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
  174. package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
  175. package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
  176. package/src/screens/SideMenuDetail/__test__/index.test.js +12 -23
  177. package/src/screens/SideMenuDetail/index.js +2 -3
  178. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +3 -2
  179. package/src/screens/SubUnit/Detail.js +1 -2
  180. package/src/screens/SubUnit/ManageSubUnit.js +12 -7
  181. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +21 -67
  182. package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
  183. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
  184. package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +27 -1
  185. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +48 -45
  186. package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
  187. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
  188. package/src/screens/Unit/ChooseLocation.js +7 -14
  189. package/src/screens/Unit/Detail.js +30 -75
  190. package/src/screens/Unit/ManageUnit.js +1 -0
  191. package/src/screens/Unit/SelectAddress.js +34 -21
  192. package/src/screens/Unit/SmartAccount.js +4 -4
  193. package/src/screens/Unit/Summaries.js +17 -1
  194. package/src/screens/Unit/__test__/CheckSendEmail.test.js +24 -29
  195. package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
  196. package/src/screens/Unit/__test__/Detail.test.js +99 -200
  197. package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
  198. package/src/screens/Unit/__test__/SelectAddress.test.js +84 -51
  199. package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
  200. package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
  201. package/src/screens/Unit/__test__/Summaries.test.js +100 -0
  202. package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
  203. package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
  204. package/src/screens/Unit/components/SharedUnit/index.js +1 -0
  205. package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
  206. package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +50 -0
  207. package/src/screens/Unit/styles.js +4 -0
  208. package/src/screens/UnitSummary/__test__/index.test.js +70 -41
  209. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +31 -2
  210. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
  211. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +2 -13
  212. package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +0 -1
  213. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
  214. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +11 -2
  215. package/src/screens/UnitSummary/components/RunningDevices/index.js +7 -10
  216. package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
  217. package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +10 -2
  218. package/src/screens/UnitSummary/index.js +15 -1
  219. package/src/utils/Apis/axios.js +46 -31
  220. package/src/utils/Converter/time.js +0 -18
  221. package/src/utils/I18n/translations/en.json +4 -1
  222. package/src/utils/I18n/translations/vi.json +5 -1
  223. package/src/utils/Permission/common.js +67 -0
  224. package/src/utils/Utils.js +11 -7
@@ -22,11 +22,11 @@ const Item = memo((props) => {
22
22
  <View size={14} color={Colors.Gray8} style={styles.textTitleX}>
23
23
  <Text>{title}</Text>
24
24
  {waterType && (
25
- <TouchableOpacity onPress={goToDetail}>
25
+ <TouchableOpacity onPress={goToDetail} style={styles.buttonInfo}>
26
26
  <IconOutline
27
27
  style={styles.row}
28
28
  name="info-circle"
29
- size={14}
29
+ size={20}
30
30
  color={Colors.Black}
31
31
  />
32
32
  </TouchableOpacity>
@@ -79,4 +79,12 @@ const styles = StyleSheet.create({
79
79
  row: {
80
80
  flexDirection: 'row',
81
81
  },
82
+ buttonInfo: {
83
+ width: 40,
84
+ height: 40,
85
+ justifyContent: 'center',
86
+ alignItems: 'center',
87
+ marginTop: -10,
88
+ marginRight: -10,
89
+ },
82
90
  });
@@ -3,9 +3,10 @@ import { View, StyleSheet } from 'react-native';
3
3
  import { useNavigation } from '@react-navigation/native';
4
4
  import { TouchableOpacity } from 'react-native';
5
5
  import { IconOutline } from '@ant-design/icons-react-native';
6
- import { useTranslations } from '../../hooks/Common/useTranslations';
7
6
  import moment from 'moment';
8
7
 
8
+ import { useTranslations } from '../../hooks/Common/useTranslations';
9
+ import { useReceiveNotifications } from '../../hooks';
9
10
  import { API, Colors } from '../../configs';
10
11
  import Routes from '../../utils/Route';
11
12
  import { axiosGet } from '../../utils/Apis/axios';
@@ -139,6 +140,19 @@ const UnitSummary = memo(({ route }) => {
139
140
  fetchSummaryDetail();
140
141
  }, [fetchSummaryDetail]);
141
142
 
143
+ const { dataNotification } = useReceiveNotifications();
144
+
145
+ useEffect(() => {
146
+ if (dataNotification) {
147
+ const { params = {} } = dataNotification;
148
+ const { summary_id } = params;
149
+ if (summary_id && summary_id === summaryId) {
150
+ fetchSummaryDetail();
151
+ }
152
+ }
153
+ // eslint-disable-next-line react-hooks/exhaustive-deps
154
+ }, [dataNotification]);
155
+
142
156
  const UnitSummaryDetail = getComponentAndGuide();
143
157
  const ComponentName = UnitSummaryDetail?.componentName;
144
158
  const GuideName = UnitSummaryDetail?.guideName;
@@ -1,35 +1,33 @@
1
- import axios from 'axios';
2
- import { deleteData, getData, storeData } from '../Storage';
1
+ import { create } from 'apisauce';
2
+ import { getData, storeData } from '../Storage';
3
3
  import { ToastBottomHelper } from '../Utils';
4
4
  import NetInfo from '@react-native-community/netinfo';
5
5
 
6
- export const replaceParams = (apiURL, params) => {
7
- let _result = apiURL;
8
- if (typeof params === 'object') {
9
- Object.keys(params).forEach((key) => {
10
- _result = _result.replace(`{${key}}`, params[key]);
11
- });
12
- }
13
- return _result;
14
- };
6
+ const api = create({
7
+ headers: {
8
+ 'Content-Type': 'application/json',
9
+ },
10
+ timeout: 30000,
11
+ });
15
12
 
16
13
  const parseErrorResponse = async (error) => {
17
14
  let message;
18
15
  let data = {};
19
- if (
20
- error.response &&
21
- error.response.data &&
22
- error.response.data instanceof Object
23
- ) {
24
- data = error.response.data;
25
- const firstKey = Object.keys(error.response.data)[0];
26
- message = error.response.data[firstKey];
16
+ if (error.data instanceof Array) {
17
+ message = error.data[0];
18
+ } else if (error.data instanceof Object) {
19
+ data = error.data;
20
+ const firstKey = Object.keys(error.data)[0];
21
+ message = error.data[firstKey];
27
22
 
28
23
  if (message instanceof Array) {
29
24
  message = message[0];
30
25
  }
26
+ if (message?.message) {
27
+ message = message.message;
28
+ }
31
29
  } else {
32
- message = error.message;
30
+ message = error.data || error.problem;
33
31
  }
34
32
 
35
33
  if (typeof message === 'string') {
@@ -50,7 +48,7 @@ const parseErrorResponse = async (error) => {
50
48
  error,
51
49
  message,
52
50
  data,
53
- resp_status: error?.response?.status,
51
+ resp_status: error?.status || error?.response?.status,
54
52
  };
55
53
  };
56
54
 
@@ -75,6 +73,7 @@ export async function fetchWithCache(url, config = {}, updateMethod) {
75
73
  if (cacheResponse) {
76
74
  updateMethod(cacheResponse);
77
75
  }
76
+ // eslint-disable-next-line no-empty
78
77
  } catch {}
79
78
  const response = await axiosGet(url, config, true);
80
79
  if (!response.cache) {
@@ -83,25 +82,34 @@ export async function fetchWithCache(url, config = {}, updateMethod) {
83
82
  }
84
83
 
85
84
  export async function axiosGet(URL, config = {}, cache = false) {
86
- const cacheKey = `@CACHE_REQUEST_${URL}`;
87
85
  let response;
88
86
  try {
89
- response = await axios.get(URL, config);
87
+ response = await api.get(URL, config.params, config);
90
88
  } catch (error) {
91
89
  if (cache) {
92
- // only network error or server error
93
- if (!error.response || error.response.status >= 500) {
90
+ if (error.message === 'Network Error') {
91
+ return (
92
+ (await axiosCache(URL, 500)) || (await parseErrorResponse(error))
93
+ );
94
+ }
95
+ if (!error?.response || error?.response?.status >= 500) {
94
96
  return (
95
- (await axiosCache(URL, error.response.status)) ||
97
+ (await axiosCache(URL, error?.response?.status)) ||
96
98
  (await parseErrorResponse(error))
97
99
  );
98
- } else {
99
- await deleteData(cacheKey);
100
100
  }
101
101
  }
102
102
  return await parseErrorResponse(error);
103
103
  }
104
- const { data } = response;
104
+ const { data, problem } = response;
105
+ if (problem === 'NETWORK_ERROR') {
106
+ if (cache) {
107
+ return (
108
+ (await axiosCache(URL, 500)) || (await parseErrorResponse(response))
109
+ );
110
+ }
111
+ return await parseErrorResponse(response);
112
+ }
105
113
  if (response.status === 200) {
106
114
  if (cache) {
107
115
  await storeData(`@CACHE_REQUEST_${URL}`, JSON.stringify(data));
@@ -121,18 +129,23 @@ export async function axiosGet(URL, config = {}, cache = false) {
121
129
  async function axiosCall(method, ...args) {
122
130
  let response;
123
131
  try {
124
- response = await axios[method](...args);
132
+ response = await api[method](...args);
125
133
  } catch (error) {
126
134
  return await parseErrorResponse(error);
127
135
  }
128
136
 
129
- const { data } = response;
137
+ const { data, problem } = response;
138
+ if (problem) {
139
+ return await parseErrorResponse(response);
140
+ }
141
+
130
142
  if (response.status >= 200 && response.status < 300) {
131
143
  return {
132
144
  success: true,
133
145
  data,
134
146
  };
135
147
  }
148
+ await parseErrorResponse(response);
136
149
 
137
150
  return {
138
151
  success: false,
@@ -186,3 +199,5 @@ export function createFormData(data, list_file_field) {
186
199
 
187
200
  return formData;
188
201
  }
202
+
203
+ export default api;
@@ -1,24 +1,6 @@
1
1
  import t from '../../hooks/Common/useTranslations';
2
2
  import moment from 'moment';
3
3
 
4
- export const transformDatetime = (data = {}, listFieldName = []) => {
5
- listFieldName.forEach((name) => {
6
- const value = data[name];
7
- const isArray = Array.isArray(value);
8
-
9
- if (!data.hasOwnProperty(name)) {
10
- return;
11
- }
12
-
13
- if (isArray) {
14
- data[name] = value.map((item) => (item ? moment(item) : item));
15
- return;
16
- }
17
-
18
- data[name] = value ? moment(value) : value;
19
- });
20
- };
21
-
22
4
  export const timeDifference = (current, previous, symbol = false) => {
23
5
  let msPerMinute = 60 * 1000;
24
6
  let msPerHour = msPerMinute * 60;
@@ -986,5 +986,8 @@
986
986
  "note": "Note",
987
987
  "back": "Back",
988
988
  "invaild_data": "Invaild data",
989
- "This {name} was removed!" : "This {name} was removed!"
989
+ "This {name} was removed!" : "This {name} was removed!",
990
+ "camera_request_permission": "Camera request permission",
991
+ "camera_request_permission_des": "To use camera, please unlock camera permission",
992
+ "location_require_message": "EoH needs your location permission to get current location."
990
993
  }
@@ -986,5 +986,9 @@
986
986
  "note": "Lưu ý ",
987
987
  "back": "Quay lại",
988
988
  "invaild_data": "Dữ liệu không hợp lệ",
989
- "This {name} was removed!" : "{Name} này đã bị xóa!"
989
+ "This {name} was removed!" : "{Name} này đã bị xóa!",
990
+ "location_perm_denied": "Ứng dụng không cho phép truy cập vị trí.",
991
+ "camera_request_permission": "Quyền yêu cầu máy ảnh",
992
+ "camera_request_permission_des": "Để sử dụng máy ảnh, vui lòng mở khóa quyền đối với máy ảnh",
993
+ "location_require_message": "Eoh cần quyền truy cập vị trí của bạn để lấy vị trí hiện tại."
990
994
  }
@@ -0,0 +1,67 @@
1
+ /* eslint-disable promise/prefer-await-to-then */
2
+ /* eslint-disable promise/prefer-await-to-callbacks */
3
+
4
+ import {
5
+ check,
6
+ openSettings,
7
+ PERMISSIONS,
8
+ request,
9
+ RESULTS,
10
+ } from 'react-native-permissions';
11
+ import AlertAsync from 'react-native-alert-async';
12
+ import t from '../../hooks/Common/useTranslations';
13
+ import { Platform } from 'react-native';
14
+
15
+ const isAndroid = Platform.OS === 'android';
16
+
17
+ export const OpenSetting = async (alertTitle, alertMessage) => {
18
+ await AlertAsync(alertTitle, alertMessage, [
19
+ {
20
+ text: t('cancel'),
21
+ onPress: () => {},
22
+ style: 'cancel',
23
+ },
24
+ {
25
+ text: t('ok'),
26
+ onPress: () => {
27
+ openSettings().then();
28
+ },
29
+ },
30
+ ]);
31
+ };
32
+
33
+ export const permitPermissionFunction = (keyPermission, callback) => {
34
+ if (keyPermission) {
35
+ check(keyPermission).then((result) => {
36
+ switch (result) {
37
+ case RESULTS.DENIED:
38
+ case RESULTS.LIMITED:
39
+ request(keyPermission).then((res) => callback(res));
40
+ break;
41
+ case RESULTS.BLOCKED:
42
+ case RESULTS.GRANTED:
43
+ callback(result);
44
+ break;
45
+ default:
46
+ break;
47
+ }
48
+ });
49
+ }
50
+ };
51
+
52
+ export const keyPermission = {
53
+ SMS_RECEIVE: PERMISSIONS.ANDROID.RECEIVE_SMS,
54
+ LOCATION: isAndroid
55
+ ? PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
56
+ : PERMISSIONS.IOS.LOCATION_WHEN_IN_USE,
57
+ CAMERA: isAndroid ? PERMISSIONS.ANDROID.CAMERA : PERMISSIONS.IOS.CAMERA,
58
+ SELECT_PHOTO: isAndroid
59
+ ? PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE
60
+ : PERMISSIONS.IOS.PHOTO_LIBRARY,
61
+ };
62
+
63
+ export const GEOLOCATION_ERROR = {
64
+ PERMISSION_DENIED: 1,
65
+ POSITION_UNAVAILABLE: 2,
66
+ TIMEOUT: 3,
67
+ };
@@ -1,21 +1,21 @@
1
- import { PixelRatio, Linking } from 'react-native';
1
+ import { PixelRatio, Linking, Alert } from 'react-native';
2
2
  import Toast from 'react-native-toast-message';
3
3
  import validator from 'validator';
4
- import axios from 'axios';
5
4
  import { Constants } from '../configs';
5
+ import api from './Apis/axios';
6
6
 
7
7
  export const setAxiosDefaultAuthToken = (token) => {
8
- axios.defaults.headers.common.Accept = 'application/json';
9
- axios.defaults.headers.common.Authorization = `Token ${token}`;
8
+ api.setHeaders({ Authorization: `Token ${token}` });
10
9
  };
11
10
 
12
11
  export const setAxiosDefaultLanguage = (language) => {
13
- axios.defaults.headers.common['Accept-Language'] =
14
- language || Constants.LANGUAGE.DEFAULT;
12
+ api.setHeaders({
13
+ 'Accept-Language': language || Constants.LANGUAGE.DEFAULT,
14
+ });
15
15
  };
16
16
 
17
17
  export const deleteDefaultAuthToken = () => {
18
- delete axios.defaults.headers.common.Authorization;
18
+ delete api.headers.Authorization;
19
19
  };
20
20
 
21
21
  export const validateEmail = (text) => {
@@ -129,6 +129,10 @@ export const object_Ids = (data) => {
129
129
  return listObject;
130
130
  };
131
131
 
132
+ export const notImplemented = (t) => {
133
+ Alert.alert(t('feature_under_development'));
134
+ };
135
+
132
136
  export default {
133
137
  validateEmail,
134
138
  isObjectEmpty,