Commit 0ee7c8a8 authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

tambah di menu

parent 6f339910
...@@ -31,16 +31,18 @@ class Home extends React.Component { ...@@ -31,16 +31,18 @@ class Home extends React.Component {
} }
componentDidMount() { componentDidMount() {
this._account();
this._getPermissions() this._getPermissions()
this._renderCarousell() this._renderCarousell()
this._account();
this._unsubscribe = this.props.navigation.addListener('focus', () => { this._unsubscribe = this.props.navigation.addListener('focus', () => {
this.setState({ this.setState({
indicator:true, indicator:true,
}) })
this._account();
this._getPermissions() this._getPermissions()
this._renderCarousell() this._renderCarousell()
this._account();
}); });
} }
......
...@@ -7,6 +7,9 @@ import ActionType from '../redux/globalActionType'; ...@@ -7,6 +7,9 @@ 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) {
...@@ -21,26 +24,32 @@ class MenuSelection extends React.Component { ...@@ -21,26 +24,32 @@ class MenuSelection extends React.Component {
order_list: [], order_list: [],
list_cart: [], list_cart: [],
indicator: true, indicator: true,
my_lat: 0,
my_long: 0
} }
} }
componentDidMount() { componentDidMount() {
if (this.props.outlet_id != '') { if (this.props.outlet_id != '') {
this.getMenuList() this.getMenuList()
} else { } else {
Alert.alert('Device belum mendapatkan lokasi anda') this.setState({
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')
} }
}); });
} }
...@@ -50,35 +59,65 @@ class MenuSelection extends React.Component { ...@@ -50,35 +59,65 @@ class MenuSelection extends React.Component {
} }
// _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 = {
...@@ -128,9 +167,9 @@ class MenuSelection extends React.Component { ...@@ -128,9 +167,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);
}) })
...@@ -262,18 +301,18 @@ class MenuSelection extends React.Component { ...@@ -262,18 +301,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>
...@@ -341,6 +380,13 @@ const mapDispatchToProps = (dispacth) => { ...@@ -341,6 +380,13 @@ 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