From 284ca72761834ad88224025e0fe608a187f9c387 Mon Sep 17 00:00:00 2001 From: farhantock Date: Tue, 18 Jun 2024 13:44:19 +0700 Subject: [PATCH] feat(utils) --- src/services/api/request.js | 13 +++++++++++++ src/utils/camera.js | 2 -- src/utils/geolocation.js | 35 +++++++++++++++-------------------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/services/api/request.js b/src/services/api/request.js index b44ac6c..2db69b9 100644 --- a/src/services/api/request.js +++ b/src/services/api/request.js @@ -1,4 +1,5 @@ // 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 RequestApi from './base'; @@ -214,4 +215,16 @@ export default class RequestModule extends RequestApi { 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; + } + } diff --git a/src/utils/camera.js b/src/utils/camera.js index 22b1056..a97daea 100644 --- a/src/utils/camera.js +++ b/src/utils/camera.js @@ -67,8 +67,6 @@ const handleLaunchCamera = () => { getCoords(loc => { if (loc) { let imageObject = { - "user_id": user_id, - "drop_point_id": selectedDropPoint?.id, "image_uri": response.assets[0].uri, "image_blob": response.assets[0].base64, "lat": loc.lat, diff --git a/src/utils/geolocation.js b/src/utils/geolocation.js index a9e8c88..27178a8 100644 --- a/src/utils/geolocation.js +++ b/src/utils/geolocation.js @@ -1,31 +1,25 @@ - import { Alert, PermissionsAndroid, Platform, ToastAndroid } from 'react-native'; import Geolocation from 'react-native-geolocation-service'; import { strings } from './i18n'; import moment from 'moment'; import { DATE_FORMAT } from './general'; - export const hasLocationPermission = async () => { - if (Platform.OS === 'ios' || - (Platform.OS === 'android' && Platform.Version < 23)) { + if (Platform.OS === 'ios' || (Platform.OS === 'android' && Platform.Version < 23)) { return true; } const hasPermission = await PermissionsAndroid.check( PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION - // PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION ); if (hasPermission) return true; const status = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, - // PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION { - title: "NawakaraConnect Location Permission", - message: "NawakaraConnect wants to enable location permission. Let NawakaraConnect collects the device's location to get current position of the device.", - // buttonNeutral: 'Ask Me Later', + title: "NeOps Location Permission", + message: "NeOps wants to enable location permission. Let NeOps collect the device's location to get the current position of the device.", buttonNegative: 'Deny', buttonPositive: 'Accept', } @@ -43,12 +37,15 @@ export const hasLocationPermission = async () => { } export const getCoords = async (callback) => { + if (typeof callback !== 'function') { + throw new TypeError('Callback must be a function'); + } const hasLocation = await hasLocationPermission(); if (!hasLocation) { - callback(null) - return + callback({ lat: null, lon: null }); + return; } Geolocation.getCurrentPosition( @@ -57,22 +54,20 @@ export const getCoords = async (callback) => { Alert.alert( strings('takePicture.fakeGPSDetected'), strings('takePicture.fakeGPSFailedMessage'), - [ - { text: "OK" } - ] + [{ text: "OK" }] ); - return false; + callback({ lat: null, lon: null }); + return; } let lat = position.coords.latitude; let lon = position.coords.longitude; - let timestamp = moment(position.timestamp).format(DATE_FORMAT); - callback({ lat, lon, timestamp }) + let timestamp = moment(position.timestamp).format('D MMMM YYYY HH:mm'); + callback({ lat, lon, timestamp }); }, (error) => { - // See error code charts below. console.log('[Home] error Geolocation.getCurrentPosition', error.code, error.message); - // callback(null) + callback({ lat: null, lon: null }); }, { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 } ); -} \ No newline at end of file +}