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 {
}
componentDidMount() {
this._account();
this._getPermissions()
this._renderCarousell()
this._account();
this._unsubscribe = this.props.navigation.addListener('focus', () => {
this.setState({
indicator:true,
})
this._account();
this._getPermissions()
this._renderCarousell()
this._account();
});
}
......
......@@ -7,6 +7,9 @@ import ActionType from '../redux/globalActionType';
import CurrencyFormat from 'react-currency-format';
import _ from 'lodash';
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 {
constructor(props) {
......@@ -21,26 +24,32 @@ class MenuSelection extends React.Component {
order_list: [],
list_cart: [],
indicator: true,
my_lat: 0,
my_long: 0
}
}
componentDidMount() {
if (this.props.outlet_id != '') {
this.getMenuList()
} else {
Alert.alert('Device belum mendapatkan lokasi anda')
this.setState({
indicator: true
})
this._getPermissions()
this.getMenuList()
}
// console.log("INI OUTLET : "+ this.props.outlet_id)
this._unsubscribe = this.props.navigation.addListener('focus', () => {
if (this.props.outlet_id != '') {
this.getMenuList()
} else {
this.setState({
indicator:true
indicator: true
})
this._getPermissions()
this.getMenuList()
} else {
Alert.alert('Device belum mendapatkan lokasi anda')
}
});
}
......@@ -50,35 +59,65 @@ class MenuSelection extends React.Component {
}
// _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);
// })
// }
_getPermissions = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
Alert.alert('Akses tidak dizinkan!')
} else if (Platform.OS === 'android' && !Device.isDevice) {
Alert.alert('Silahkan anda coba di real Device')
} else {
this._getCurrentPosisition()
}
}
_getCurrentPosisition = async () => {
this.setState({
spinner: true,
})
let location = await Location.getCurrentPositionAsync({
accuracy: Location.Accuracy.Highest
})
let latitude = location.coords.latitude;
let longitude = location.coords.longitude;
this.setState({
my_lat: latitude,
my_long: longitude
})
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() {
let params = {
......@@ -128,9 +167,9 @@ class MenuSelection extends React.Component {
this.props.updateMenu(data.menu)
}).catch(error => {
const {navigation} = this.props
const { navigation } = this.props
let response = error.response.data
session(response,navigation)
session(response, navigation)
Alert.alert(response.msg);
})
......@@ -262,18 +301,18 @@ class MenuSelection extends React.Component {
)}
</View>
<View style={styles.shadow}>
{
this.state.indicator == true ? (<ActivityIndicator style={{ top: 10 }} size="large" color="#c9af6d" />):(
<View style={{ flexDirection: 'row', }}>
{
this.state.indicator == true ? (<ActivityIndicator style={{ top: 10 }} size="large" color="#c9af6d" />) : (
<View style={{ flexDirection: 'row', }}>
<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: 20, margin: 10, marginBottom: 10 }}> Rp. {this.props.order_total}</Text>
</View>
)
}
<Text style={{ fontSize: 20, margin: 10, marginBottom: 10 }}> Rp. {this.props.order_total}</Text>
</View>
)
}
<View>
<Button title="VIEW CART" onPress={() => this.props.navigation.navigate('Shopping Cart')}></Button>
</View>
......@@ -341,6 +380,13 @@ const mapDispatchToProps = (dispacth) => {
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