Browse Source

feat(utils)

master
farhantock 3 months ago
parent
commit
284ca72761
  1. 13
      src/services/api/request.js
  2. 2
      src/utils/camera.js
  3. 35
      src/utils/geolocation.js

13
src/services/api/request.js

@ -1,4 +1,5 @@
// NOTE: Function to get all API Request // NOTE: Function to get all API Request
import { store } from '../../appredux/store';
import { BASE_URL_API_V1, BASE_URL_API_V2, BASE_URL_IMAGE } from '../../config/ApiConst'; import { BASE_URL_API_V1, BASE_URL_API_V2, BASE_URL_IMAGE } from '../../config/ApiConst';
import RequestApi from './base'; import RequestApi from './base';
@ -214,4 +215,16 @@ export default class RequestModule extends RequestApi {
return result; return result;
} }
async login(param) {
const payload = JSON.stringify(param);
const url = `${BASE_URL_API_V1}/auth/user/login?isMobile=true`;
const fcm_token = store.getState().userReducer && store.getState().userReducer.fcmToken ? store.getState().userReducer.fcmToken : null;
param.fcm_token = fcm_token;
const result = await RequestApi.Hedaer()
.post(url, payload)
.then((res) => res)
.catch((err) => err.response);
return result;
}
} }

2
src/utils/camera.js

@ -67,8 +67,6 @@ const handleLaunchCamera = () => {
getCoords(loc => { getCoords(loc => {
if (loc) { if (loc) {
let imageObject = { let imageObject = {
"user_id": user_id,
"drop_point_id": selectedDropPoint?.id,
"image_uri": response.assets[0].uri, "image_uri": response.assets[0].uri,
"image_blob": response.assets[0].base64, "image_blob": response.assets[0].base64,
"lat": loc.lat, "lat": loc.lat,

35
src/utils/geolocation.js

@ -1,31 +1,25 @@
import { Alert, PermissionsAndroid, Platform, ToastAndroid } from 'react-native'; import { Alert, PermissionsAndroid, Platform, ToastAndroid } from 'react-native';
import Geolocation from 'react-native-geolocation-service'; import Geolocation from 'react-native-geolocation-service';
import { strings } from './i18n'; import { strings } from './i18n';
import moment from 'moment'; import moment from 'moment';
import { DATE_FORMAT } from './general'; import { DATE_FORMAT } from './general';
export const hasLocationPermission = async () => { export const hasLocationPermission = async () => {
if (Platform.OS === 'ios' || if (Platform.OS === 'ios' || (Platform.OS === 'android' && Platform.Version < 23)) {
(Platform.OS === 'android' && Platform.Version < 23)) {
return true; return true;
} }
const hasPermission = await PermissionsAndroid.check( const hasPermission = await PermissionsAndroid.check(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
// PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION
); );
if (hasPermission) return true; if (hasPermission) return true;
const status = await PermissionsAndroid.request( const status = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
// PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION
{ {
title: "NawakaraConnect Location Permission", title: "NeOps Location Permission",
message: "NawakaraConnect wants to enable location permission. Let NawakaraConnect collects the device's location to get current position of the device.", message: "NeOps wants to enable location permission. Let NeOps collect the device's location to get the current position of the device.",
// buttonNeutral: 'Ask Me Later',
buttonNegative: 'Deny', buttonNegative: 'Deny',
buttonPositive: 'Accept', buttonPositive: 'Accept',
} }
@ -43,12 +37,15 @@ export const hasLocationPermission = async () => {
} }
export const getCoords = async (callback) => { export const getCoords = async (callback) => {
if (typeof callback !== 'function') {
throw new TypeError('Callback must be a function');
}
const hasLocation = await hasLocationPermission(); const hasLocation = await hasLocationPermission();
if (!hasLocation) { if (!hasLocation) {
callback(null) callback({ lat: null, lon: null });
return return;
} }
Geolocation.getCurrentPosition( Geolocation.getCurrentPosition(
@ -57,22 +54,20 @@ export const getCoords = async (callback) => {
Alert.alert( Alert.alert(
strings('takePicture.fakeGPSDetected'), strings('takePicture.fakeGPSDetected'),
strings('takePicture.fakeGPSFailedMessage'), strings('takePicture.fakeGPSFailedMessage'),
[ [{ text: "OK" }]
{ text: "OK" }
]
); );
return false; callback({ lat: null, lon: null });
return;
} }
let lat = position.coords.latitude; let lat = position.coords.latitude;
let lon = position.coords.longitude; let lon = position.coords.longitude;
let timestamp = moment(position.timestamp).format(DATE_FORMAT); let timestamp = moment(position.timestamp).format('D MMMM YYYY HH:mm');
callback({ lat, lon, timestamp }) callback({ lat, lon, timestamp });
}, },
(error) => { (error) => {
// See error code charts below.
console.log('[Home] error Geolocation.getCurrentPosition', error.code, error.message); console.log('[Home] error Geolocation.getCurrentPosition', error.code, error.message);
// callback(null) callback({ lat: null, lon: null });
}, },
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 } { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
); );
} }

Loading…
Cancel
Save