Commit d49738ca authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

change location

parent 0ee7c8a8
...@@ -7,9 +7,6 @@ import ActionType from '../redux/globalActionType'; ...@@ -7,9 +7,6 @@ import ActionType from '../redux/globalActionType';
import CurrencyFormat from 'react-currency-format'; import CurrencyFormat from 'react-currency-format';
import _ from 'lodash'; import _ from 'lodash';
import session from '../function/session'; import session from '../function/session';
import * as Location from 'expo-location';
import * as Permissions from 'expo-permissions';
import * as Device from 'expo-device';
class MenuSelection extends React.Component { class MenuSelection extends React.Component {
constructor(props) { constructor(props) {
...@@ -24,8 +21,6 @@ class MenuSelection extends React.Component { ...@@ -24,8 +21,6 @@ class MenuSelection extends React.Component {
order_list: [], order_list: [],
list_cart: [], list_cart: [],
indicator: true, indicator: true,
my_lat: 0,
my_long: 0
} }
} }
...@@ -34,22 +29,17 @@ class MenuSelection extends React.Component { ...@@ -34,22 +29,17 @@ class MenuSelection extends React.Component {
if (this.props.outlet_id != '') { if (this.props.outlet_id != '') {
this.getMenuList() this.getMenuList()
} else { } else {
this.setState({ Alert.alert('Device belum mendapatkan lokasi anda')
indicator: true
})
this._getPermissions()
this.getMenuList()
} }
// console.log("INI OUTLET : "+ this.props.outlet_id) // console.log("INI OUTLET : "+ this.props.outlet_id)
this._unsubscribe = this.props.navigation.addListener('focus', () => { this._unsubscribe = this.props.navigation.addListener('focus', () => {
if (this.props.outlet_id != '') { if (this.props.outlet_id != '') {
this.getMenuList()
} else {
this.setState({ this.setState({
indicator: true indicator:true
}) })
this._getPermissions()
this.getMenuList() this.getMenuList()
} else {
Alert.alert('Device belum mendapatkan lokasi anda')
} }
}); });
} }
...@@ -58,66 +48,35 @@ class MenuSelection extends React.Component { ...@@ -58,66 +48,35 @@ class MenuSelection extends React.Component {
this._unsubscribe(); this._unsubscribe();
} }
// _getOutletClosest() {
_getPermissions = async () => { // let params = {
let { status } = await Permissions.askAsync(Permissions.LOCATION); // session_id: this.props.session_id,
if (status !== 'granted') { // lat: this.state.my_lat,
Alert.alert('Akses tidak dizinkan!') // long: this.state.my_long
} else if (Platform.OS === 'android' && !Device.isDevice) { // }
// // console.log(params);
Alert.alert('Silahkan anda coba di real Device') // Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/outlet/get_closest', params).then((res) => {
} else {
this._getCurrentPosisition()
} // let outletId = res.data.data.outlet_id
} // let outletName = res.data.data.outlet_name
_getCurrentPosisition = async () => {
this.setState({ // let OutletChange = {
spinner: true, // outlet_id: outletId,
}) // name_outlet: outletName,
let location = await Location.getCurrentPositionAsync({ // }
accuracy: Location.Accuracy.Highest // this.props.setChangeOutletProps(OutletChange);
}) // this.setState({
// indicator: false
let latitude = location.coords.latitude; // })
let longitude = location.coords.longitude;
// }).catch(error => {
this.setState({ // const {navigation} = this.props
my_lat: latitude, // let response = error.response.data
my_long: longitude // session(response,navigation)
}) // Alert.alert(response.msg);
// })
this._getOutletClosest(); // }
}
_getOutletClosest() {
let params = {
session_id: this.props.session_id,
lat: this.state.my_lat,
long: this.state.my_long
}
// console.log(params);
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/outlet/get_closest', params).then((res) => {
let outletId = res.data.data.outlet_id
let outletName = res.data.data.outlet_name
let OutletChange = {
outlet_id: outletId,
name_outlet: outletName,
}
this.props.setChangeOutletProps(OutletChange);
this.setState({
indicator: false
})
}).catch(error => {
const { navigation } = this.props
let response = error.response.data
session(response, navigation)
Alert.alert(response.msg);
})
}
getMenuList() { getMenuList() {
let params = { let params = {
...@@ -167,9 +126,9 @@ class MenuSelection extends React.Component { ...@@ -167,9 +126,9 @@ class MenuSelection extends React.Component {
this.props.updateMenu(data.menu) this.props.updateMenu(data.menu)
}).catch(error => { }).catch(error => {
const { navigation } = this.props const {navigation} = this.props
let response = error.response.data let response = error.response.data
session(response, navigation) session(response,navigation)
Alert.alert(response.msg); Alert.alert(response.msg);
}) })
...@@ -301,18 +260,18 @@ class MenuSelection extends React.Component { ...@@ -301,18 +260,18 @@ class MenuSelection extends React.Component {
)} )}
</View> </View>
<View style={styles.shadow}> <View style={styles.shadow}>
{ {
this.state.indicator == true ? (<ActivityIndicator style={{ top: 10 }} size="large" color="#c9af6d" />) : ( this.state.indicator == true ? (<ActivityIndicator style={{ top: 10 }} size="large" color="#c9af6d" />):(
<View style={{ flexDirection: 'row', }}> <View style={{ flexDirection: 'row', }}>
<Text style={{ fontSize: 12, margin: 10 }}> Price Estimation / Item {this.props.order_quantity} </Text> <Text style={{ fontSize: 12, margin: 10 }}> Price Estimation / Item {this.props.order_quantity} </Text>
<Text style={{ fontSize: 12, margin: 10 }}> Ongkir {this.props.grabamount} </Text> <Text style={{ fontSize: 12, margin: 10 }}> Ongkir {this.props.grabamount} </Text>
<Text style={{ fontSize: 20, margin: 10, marginBottom: 10 }}> Rp. {this.props.order_total}</Text> <Text style={{ fontSize: 20, margin: 10, marginBottom: 10 }}> Rp. {this.props.order_total}</Text>
</View> </View>
) )
} }
<View> <View>
<Button title="VIEW CART" onPress={() => this.props.navigation.navigate('Shopping Cart')}></Button> <Button title="VIEW CART" onPress={() => this.props.navigation.navigate('Shopping Cart')}></Button>
</View> </View>
...@@ -380,13 +339,6 @@ const mapDispatchToProps = (dispacth) => { ...@@ -380,13 +339,6 @@ const mapDispatchToProps = (dispacth) => {
item: item item: item
} }
}), }),
setChangeOutletProps: (OutletChange) => dispacth({
type: ActionType.SET_CHANGE_OUTLET,
data: {
outlet_id: OutletChange.outlet_id,
name_outlet: OutletChange.name_outlet,
}
}),
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment