Commit 3b481e0a authored by Trisno's avatar Trisno

Merge branch 'master' of ssh://repo.cs.co.id:2222/wahyu/bahanoprek

# Conflicts:
#	view/ShoppingCart.js
parents 987b2cca 03e4a898
import * as Location from 'expo-location';
import * as Permissions from 'expo-permissions';
import * as Device from 'expo-device';
export default _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
})
console.log("MY LAT : " + this.state.my_lat)
console.log("MY LONG : " + this.state.my_long)
this.getOutlet()
}
function getOutlet() {
this.setState({
spinner: true,
})
let params = {
session_id: this.props.session_id
}
Axios.post("https://excelsocrm.ravintoladev.com/crm/v2/outlet/get_list", params).then(res => {
let dataOutlets = res.data.outlets;
for (let i = 0; i < dataOutlets.length; i++) {
dataOutlets[i]['distance'] = this.distance(dataOutlets[i]['lat'], dataOutlets[i]['long']);
let address = dataOutlets[i]['address'];
if (dataOutlets[i]['city'] !== '') {
if (address !== '') {
address = address + ', ' + dataOutlets[i]['city'];
} else {
address = dataOutlets[i]['city'];
}
}
if (dataOutlets[i]['province']) {
if (address !== '') {
address = address + ', ' + dataOutlets[i]['province'];
} else {
address = dataOutlets[i]['province'];
}
}
if (dataOutlets[i]['postal_code']) {
if (address !== '') {
address = address + ' ' + dataOutlets[i]['postal_code'];
} else {
address = dataOutlets[i]['postal_code'];
}
}
dataOutlets[i]['full_address'] = address;
}
this.setState({
dataOutlets: dataOutlets,
data_before_search: dataOutlets,
})
this.setState({
spinner: false,
})
}).catch(error => {
let response = error.response.data;
Alert.alert(response.msg);
this.setState({
spinner: false,
})
})
}
function toRad(value) {
return value * Math.PI / 180;
}
function distance(locationLat, locationLong) {
let R = 6371;
let dLat = this.toRad(locationLat - this.state.my_lat); // Javascript functions in radians
let dLon = this.toRad(locationLong - this.state.my_long);
let a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(this.toRad(this.state.my_lat)) * Math.cos(this.toRad(locationLat)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
let d = R * c;
return Math.round(d * 10) / 10;
}
...@@ -24,6 +24,8 @@ const ActionType = { ...@@ -24,6 +24,8 @@ const ActionType = {
SET_CHANGE_SHOP:'SET_CHANGE_SHOP', SET_CHANGE_SHOP:'SET_CHANGE_SHOP',
ADD_TO_CHART:'ADD_TO_CHART', ADD_TO_CHART:'ADD_TO_CHART',
REMOVE_FROM_CHART:'REMOVE_FROM_CHART', REMOVE_FROM_CHART:'REMOVE_FROM_CHART',
REDUCE_QUANTITY_ITEM :'REDUCE_QUANTITY_ITEM',
SET_ADDRESS :'SET_ADDRESS'
} }
......
...@@ -56,7 +56,9 @@ const globalState = { ...@@ -56,7 +56,9 @@ const globalState = {
order_item: [], order_item: [],
order_quantity: 0, order_quantity: 0,
order_total: 0 order_total: 0,
address:''
} }
const rootReducer = (state = globalState, action) => { const rootReducer = (state = globalState, action) => {
...@@ -200,6 +202,13 @@ const rootReducer = (state = globalState, action) => { ...@@ -200,6 +202,13 @@ const rootReducer = (state = globalState, action) => {
...state ...state
} }
} }
case ActionType.SET_ADDRESS:{
return{
...state,
address: action.data.address
}
}
case ActionType.SET_LOGOUT:{ case ActionType.SET_LOGOUT:{
return{ return{
...state, ...state,
...@@ -213,15 +222,19 @@ const rootReducer = (state = globalState, action) => { ...@@ -213,15 +222,19 @@ const rootReducer = (state = globalState, action) => {
let order_item = [] let order_item = []
if (is_exist) { if (is_exist) {
// update // update
addedItem.quantity += 1
console.log('Update : ' + JSON.stringify(addedItem))
updated_data = [] updated_data = []
for (let i = 0; i < state.order_item.length; i++) { for (let i = 0; i < state.order_item.length; i++) {
const old_data = state.order_item[i]; const old_data = state.order_item[i];
const data = old_data; const data = old_data;
if (old_data.id == addedItem.id) { if (old_data.id == addedItem.id) {
data = {...old_data, ...addedItem} update = old_data
if (update.quantity == NaN){
update.quantity = 1
}
update.quantity += 1
console.log('Update : ' + JSON.stringify(update))
data = {...old_data, ...update}
} }
...@@ -245,6 +258,80 @@ const rootReducer = (state = globalState, action) => { ...@@ -245,6 +258,80 @@ const rootReducer = (state = globalState, action) => {
order_total: total order_total: total
} }
} }
case ActionType.REDUCE_QUANTITY_ITEM:{
let addedItem = action.data.item
let is_exist = state.order_item.find(item => addedItem.id == item.id)
let order_item = []
if (is_exist) {
// update
updated_data = []
for (let i = 0; i < state.order_item.length; i++) {
const old_data = state.order_item[i];
const data = old_data;
if (old_data.id == addedItem.id) {
update = old_data
if (update.quantity == NaN){
update.quantity = 1
}
update.quantity -= 1
console.log('Update : ' + JSON.stringify(update))
data = {...old_data, ...update}
}
updated_data.push(data)
}
order_item = updated_data
} else {
// add
addedItem.quantity = 1
console.log('Baru : ' + JSON.stringify(addedItem))
order_item = [...state.order_item, addedItem]
}
let quantity = state.order_quantity - 1
let total = parseInt(state.order_total) - parseInt(addedItem.price)
return{
...state,
order_item: order_item,
order_quantity: quantity,
order_total: total
}
}
case ActionType.REMOVE_FROM_CHART:{
let addedItem = action.data.item
let is_exist = state.order_item.find(item => addedItem.id == item.id)
let order_item = []
if (is_exist) {
// update
updated_data = []
for (let i = 0; i < state.order_item.length; i++) {
const old_data = state.order_item[i];
const data = old_data;
if (old_data.id != addedItem.id) {
updated_data.push(data)
quantity += data.quantity
total += (data.quantity * data.price)
}
}
order_item = updated_data
}
return{
...state,
order_item: order_item,
order_quantity: quantity,
order_total: total
}
}
default: default:
......
import React from 'react'; import React from 'react';
import { View, Text, StyleSheet, Button, FlatList } from 'react-native'; import { View, Text, StyleSheet, Button, FlatList, Alert } from 'react-native';
import { ScrollView } from 'react-native-gesture-handler'; import { ScrollView, TouchableOpacity } from 'react-native-gesture-handler';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import Axios from 'axios'; import Axios from 'axios';
import ActionType from '../redux/globalActionType';
class DeliveryAddrees extends React.Component { class DeliveryAddrees extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {
data:[] data: []
} }
} }
componentDidMount() { componentDidMount() {
this.getAddreess() this.getAddreess()
console.log(this.props) console.log(this.props)
} }
onChangeAddress = data => { onChangeAddress = data => {
...@@ -22,7 +23,7 @@ class DeliveryAddrees extends React.Component { ...@@ -22,7 +23,7 @@ class DeliveryAddrees extends React.Component {
this.getAddreess() this.getAddreess()
} }
getAddreess(){ getAddreess() {
let params = { let params = {
session_id: this.props.session_id, session_id: this.props.session_id,
} }
...@@ -50,27 +51,51 @@ class DeliveryAddrees extends React.Component { ...@@ -50,27 +51,51 @@ class DeliveryAddrees extends React.Component {
}) })
} }
addAdreess(){ addAdreess() {
this.props.navigation.navigate('Address Detail', { 'data': 'sample', onChangeAddress: this.onChangeAddress }) this.props.navigation.navigate('Address Detail', { 'data': 'sample', onChangeAddress: this.onChangeAddress })
} }
render() {
function Item({ name,description,address }) { onSave(address) {
return (
<View style={styles.list_addrees}> Alert.alert(
'',
'Apakah anda akan memilih alamat untuk pengiriman ?',
[
{text: 'OK', onPress: () => this.props.navigation.navigate('Menu Select')},
],
{ cancelable: false }
)
let setDataAddress = {
address : address
}
this.props.setAddress(setDataAddress);
}
renderItem = ({item})=>{
return (
<View style={styles.list_addrees}>
<TouchableOpacity onPress={()=> this.onSave(item.address)}>
<View style={{ margin: 5, }}> <View style={{ margin: 5, }}>
<Text style={{ fontWeight: 'bold', fontSize: 20 }}>{name}</Text> <Text style={{ fontWeight: 'bold', fontSize: 20 }}>{item.name}</Text>
</View> </View>
<Text style={{ margin: 5 }}> <Text style={{ margin: 5 }}>
{address} {item.address}
</Text> </Text>
<Text style={{ margin: 5 }}> <Text style={{ margin: 5 }}>
Patokan : {description} Patokan : {item.description}
</Text> </Text>
</View> </TouchableOpacity>
); </View>
} );
}
render() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<View style={styles.header}> <View style={styles.header}>
...@@ -84,7 +109,7 @@ class DeliveryAddrees extends React.Component { ...@@ -84,7 +109,7 @@ class DeliveryAddrees extends React.Component {
<FlatList <FlatList
data={this.state.data} data={this.state.data}
renderItem={({ item }) => <Item name={item.name} description = {item.description} address = {item.address} /> } renderItem={this.renderItem}
keyExtractor={item => item.id} keyExtractor={item => item.id}
/> />
{/* {/*
...@@ -144,5 +169,18 @@ const mapStateToProps = (state) => { ...@@ -144,5 +169,18 @@ const mapStateToProps = (state) => {
} }
} }
export default connect(mapStateToProps)(DeliveryAddrees) const mapDispatchToProps = (dispacth) => {
return {
setAddress: (setDataAddress) => dispacth({
type: ActionType.SET_ADDRESS,
data: {
address: setDataAddress.address,
}
}),
}
}
export default connect(mapStateToProps,mapDispatchToProps)(DeliveryAddrees)
// import { BASE_URL_GET_CARAOUSEL, BASE_URL_CHANGE_PASSWORD } from '../model/Base_Model';
// import Swiper from 'react-native-swiper';
import * as React from 'react'; import * as React from 'react';
import { View, Text, StyleSheet, StatusBar, ScrollView, TouchableOpacity, Alert ,Button} from 'react-native'; import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Alert } from 'react-native';
import { SliderBox } from "react-native-image-slider-box"; import { SliderBox } from "react-native-image-slider-box";
import { IndicatorViewPager, PagerDotIndicator, PagerTabIndicator } from '@shankarmorwal/rn-viewpager';
import { Card } from 'react-native-shadow-cards'; import { Card } from 'react-native-shadow-cards';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import Axios from 'axios'; import Axios from 'axios';
import ActionType from '../redux/globalActionType';
import Account from './Account';
import TopUpInfo from './TopUpInfo';
// import SmsConfirmation from './SmsConfirmation';
import i18n from 'i18n-js'; import i18n from 'i18n-js';
import _ from 'lodash';
class Home extends React.Component { class Home extends React.Component {
...@@ -20,20 +16,28 @@ class Home extends React.Component { ...@@ -20,20 +16,28 @@ class Home extends React.Component {
this.state = { this.state = {
data_baner: [], data_baner: [],
images: [], images: [],
balance:"", balance: "",
point:"", point: "",
account_number:"" account_number: "",
my_lat: 0,
my_long: 0,
} }
} }
componentDidMount() { componentDidMount() {
this._renderCarousell() this._renderCarousell()
this._account() this._account()
console.log("INI SESSION"+this.props.session_id)
} }
_renderCarousell() { //fungsi untuk get current posisi
clear = () => {
this.state.search.clear();
};
_renderCarousell() {
Axios.get('https://excelsocrm.ravintoladev.com/cms/v2/list/promotions-carousel').then(respon => { Axios.get('https://excelsocrm.ravintoladev.com/cms/v2/list/promotions-carousel').then(respon => {
// console.log(respon); // console.log(respon);
const dataCarousell = respon.data.contents; const dataCarousell = respon.data.contents;
...@@ -51,30 +55,29 @@ class Home extends React.Component { ...@@ -51,30 +55,29 @@ class Home extends React.Component {
}) })
} }
_account(){ _account() {
let params = { let params = {
session_id: this.props.session_id session_id: this.props.session_id
} }
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/member/get_profile', params).then(res => {
console.log('ini res ' + JSON.stringify(res.data))
const dataCard = res.data
let point = dataCard.kaspro_point
let balance = dataCard.kaspro_balance
let expire = dataCard.expire_date
let account_number = dataCard.kaspro_account_number
this.setState({ Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/member/get_profile', params).then(res => {
point: point, const dataCard = res.data
balance: balance, let point = dataCard.kaspro_point
account_number: account_number, let balance = dataCard.kaspro_balance
expire_date:expire, let expire = dataCard.expire_date
}) let account_number = dataCard.kaspro_account_number
console.log(this.state.expire_date) this.setState({
}).catch(error => { point: point,
console.log('ini error ' + error) balance: balance,
account_number: account_number,
expire_date: expire,
}) })
console.log(this.state.expire_date)
}).catch(error => {
console.log('ini error ' + error)
})
} }
render() { render() {
...@@ -145,49 +148,49 @@ class Home extends React.Component { ...@@ -145,49 +148,49 @@ class Home extends React.Component {
{ {
this.state.account_number === "" ? ( this.state.account_number === "" ? (
<View style={styles.card}> <View style={styles.card}>
<Card style={{ padding: 10, margin: 10, alignContent: 'center' }}>
<Text style={{textAlign:"center"} }> Anda belum aktivasi kartu</Text>
<Text>
{/* {i18n.t('yourCardNumber')} | {this.state.expire_date}{'\n'} */}
</Text>
<Text style={{ textAlign: "center", fontSize: 40, color: '#c9af6d' }}>
{/* {this.state.account_number} */}
</Text>
<View style={styles.line}></View>
<Text style={{ textAlign: 'left', fontWeight: 'bold' }}> {'\n'}
{/* {i18n.t('balance')} {this.state.balance}{'\n'} */}
</Text>
<View style={styles.line}></View>
<Text style={{ textAlign: 'left', fontWeight: 'bold' }}>{'\n'}
{/* {i18n.t('point')} {this.state.point} */}
</Text>
</Card>
</View>
):(
<View style={styles.card}> <Card style={{ padding: 10, margin: 10, alignContent: 'center' }}>
<Card style={{ padding: 10, margin: 10, alignContent: 'center' }}> <Text style={{ textAlign: "center" }}> Anda belum aktivasi kartu</Text>
<Text> <Text>
{i18n.t('yourCardNumber')} | {this.state.expire_date}{'\n'} {/* {i18n.t('yourCardNumber')} | {this.state.expire_date}{'\n'} */}
</Text> </Text>
<Text style={{ textAlign: "center", fontSize: 40, color: '#c9af6d' }}> <Text style={{ textAlign: "center", fontSize: 40, color: '#c9af6d' }}>
{this.state.account_number} {/* {this.state.account_number} */}
</Text> </Text>
<View style={styles.line}></View> <View style={styles.line}></View>
<Text style={{ textAlign: 'left', fontWeight: 'bold' }}> {'\n'} <Text style={{ textAlign: 'left', fontWeight: 'bold' }}> {'\n'}
{i18n.t('balance')} {this.state.balance}{'\n'} {/* {i18n.t('balance')} {this.state.balance}{'\n'} */}
</Text> </Text>
<View style={styles.line}></View> <View style={styles.line}></View>
<Text style={{ textAlign: 'left', fontWeight: 'bold' }}>{'\n'} <Text style={{ textAlign: 'left', fontWeight: 'bold' }}>{'\n'}
{i18n.t('point')} {this.state.point} {/* {i18n.t('point')} {this.state.point} */}
</Text> </Text>
</Card> </Card>
{/* <Button title="upgrade premium" onPress={()=>this.props.navigation.navigate("Upgrade Premium")}></Button> */} </View>
</View> ) : (
)
<View style={styles.card}>
<Card style={{ padding: 10, margin: 10, alignContent: 'center' }}>
<Text>
{i18n.t('yourCardNumber')} | {this.state.expire_date}{'\n'}
</Text>
<Text style={{ textAlign: "center", fontSize: 40, color: '#c9af6d' }}>
{this.state.account_number}
</Text>
<View style={styles.line}></View>
<Text style={{ textAlign: 'left', fontWeight: 'bold' }}> {'\n'}
{i18n.t('balance')} {this.state.balance}{'\n'}
</Text>
<View style={styles.line}></View>
<Text style={{ textAlign: 'left', fontWeight: 'bold' }}>{'\n'}
{i18n.t('point')} {this.state.point}
</Text>
</Card>
{/* <Button title="upgrade premium" onPress={()=>this.props.navigation.navigate("Upgrade Premium")}></Button> */}
</View>
)
} }
<View style={{height:60}}></View> <View style={{ height: 60 }}></View>
</View> </View>
</View> </View>
</ScrollView> </ScrollView>
......
import React from 'react'; import React from 'react';
import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, TextInput } from 'react-native'; import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, TextInput } from 'react-native';
import { connect } from 'react-redux';
export default class Item extends React.Component { class Item extends React.Component {
render() { render() {
const { item } = this.props const { item } = this.props
// console.log('ini props nya item : ' + JSON.stringify(item)) // console.log('ini props nya item : ' + JSON.stringify(item))
const { description, name, image, price, qty, } = item const { description, name, image, price, qty, } = item
return ( return (
<View style={{ flex: 1, margin: 10 }}> <View style={{ flex: 1, margin: 10 }}>
<Text style={{ fontSize: 20, color: '#c9af6d' }}>{item.category.name}</Text> <ScrollView ref={view => this._scrollView = view}>
{/* <Text style={{ fontSize: 20, color: '#c9af6d' }}>{item.category.name}</Text> */}
<View style={{ flexDirection: 'row' }}> <View style={{ flexDirection: 'row' }}>
<View > <View >
<Image source={{ uri: item.image }} style={{ height: 100, width: 100, borderRadius: 5, top: 5 }}></Image> <Image source={{ uri: item.image }} style={{ height: 100, width: 100, borderRadius: 5, top: 5 }}></Image>
...@@ -19,16 +21,14 @@ export default class Item extends React.Component { ...@@ -19,16 +21,14 @@ export default class Item extends React.Component {
<View style={{ flexDirection: 'row', flex: 1 }}> <View style={{ flexDirection: 'row', flex: 1 }}>
<View style={styles.shadowEdit}></View> <View style={styles.shadowEdit}></View>
<View style={styles.shadowAdd}> <View style={styles.shadowAdd}>
<TouchableOpacity> <TouchableOpacity onPress={() => this.props.handleMin()}>
<Text style={{ fontSize: 20, margin: 2 }}> - </Text> <Text style={{ fontSize: 20, margin: 2 }}> - </Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity onPress={() => this.props.handleRemove()}>
<TextInput <TextInput
style={{ height: 25, padding: 2,textAlign:'center',margin:2 }} style={{ height: 25, padding: 2,textAlign:'center',margin:2 }}
autoCapitalize="none"> autoCapitalize="none">
{item.qty} {item.qty}
</TextInput> </TextInput>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.props.handleAdd()}> <TouchableOpacity onPress={() => this.props.handleAdd()}>
<Text style={{ fontSize: 20, margin: 2 }}> + </Text> <Text style={{ fontSize: 20, margin: 2 }}> + </Text>
</TouchableOpacity> </TouchableOpacity>
...@@ -36,6 +36,7 @@ export default class Item extends React.Component { ...@@ -36,6 +36,7 @@ export default class Item extends React.Component {
</View> </View>
</View> </View>
</View> </View>
</ScrollView>
</View> </View>
) )
} }
...@@ -92,3 +93,16 @@ const styles = StyleSheet.create({ ...@@ -92,3 +93,16 @@ const styles = StyleSheet.create({
marginTop: 10, marginTop: 10,
} }
}) })
const mapStateToProps = (state) => {
console.log(state)
return {
session_id: state.session_id,
outlet_id: state.outlet_id,
order_quantity : state.order_quantity,
order_total : state.order_total,
quantity: state.quantity,
}
}
export default connect(mapStateToProps)(Item)
import React from 'react'; import React from 'react';
import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, FlatList, Button, Alert, StatusBar } from 'react-native'; import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, FlatList, Button, Alert, StatusBar, SafeAreaView, SectionList } from 'react-native';
import Axios from 'axios'; import Axios from 'axios';
import Item from './Item'; import Item from './Item';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import ActionType from '../redux/globalActionType'; import ActionType from '../redux/globalActionType';
import CurrencyFormat from 'react-currency-format'; import CurrencyFormat from 'react-currency-format';
import Constants from "expo-constants";
import { Ionicons, MaterialCommunityIcons, MaterialIcons, AntDesign } from '@expo/vector-icons'; import { Ionicons, MaterialCommunityIcons, MaterialIcons, AntDesign } from '@expo/vector-icons';
// import { range } from 'lodash'; // import { range } from 'lodash';
import _ from 'lodash'; import _ from 'lodash';
...@@ -14,11 +15,12 @@ class MenuSelection extends React.Component { ...@@ -14,11 +15,12 @@ class MenuSelection extends React.Component {
super(props) super(props)
this.state = { this.state = {
listCategory: [], listCategory: [],
list_category:[],
listMenu: [], listMenu: [],
list_orders: [], list_orders: [],
outlet_id: '', outlet_id: '',
qty: 1, qty: 1,
order_list:[], order_list: [],
list_cart: [], list_cart: [],
} }
} }
...@@ -35,13 +37,16 @@ class MenuSelection extends React.Component { ...@@ -35,13 +37,16 @@ class MenuSelection extends React.Component {
outlet_id: "dec1abbb-95d0-46ae-a6cd-2bf306590f15" outlet_id: "dec1abbb-95d0-46ae-a6cd-2bf306590f15"
} }
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/menu/get_list', params).then(res => { Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/menu/get_list', params).then(res => {
let data = res.data.data let data = res.data.data
this.setState({ this.setState({
listCategory: data.category, listCategory: data.category,
listMenu: data.menu listMenu: data.menu
}) })
this.state.listMenu.map((i) => ( this.state.listMenu.map((i) => (
i.qty = 0 i.qty = 0
)) ))
}).catch(error => { }).catch(error => {
let response = error.response.data; let response = error.response.data;
...@@ -50,12 +55,10 @@ class MenuSelection extends React.Component { ...@@ -50,12 +55,10 @@ class MenuSelection extends React.Component {
renderTabBar = ({ item }) => { renderTabBar = ({ item }) => {
return ( return (
<View style={{ margin: 10 }}> <View style={{ margin: 10 }}>
<ScrollView horizontal={true} ref={'scrollview'}> <TouchableOpacity onPress={() => this.scrollToItem()}>
<TouchableOpacity onPress={() => this.scroll(item)}>
<Image style={{ height: 50, width: 50, borderRadius: 25 }} source={{ uri: item.image }} /> <Image style={{ height: 50, width: 50, borderRadius: 25 }} source={{ uri: item.image }} />
<Text>{item.name}</Text> <Text>{item.name}</Text>
</TouchableOpacity> </TouchableOpacity>
</ScrollView>
</View> </View>
) )
} }
...@@ -64,50 +67,96 @@ class MenuSelection extends React.Component { ...@@ -64,50 +67,96 @@ class MenuSelection extends React.Component {
} }
refresh() { refresh() {
this.setState({ isFetching: true }, function () { this.getMenuList() }); this.setState({ isFetching: true }, function () { this.getMenuList() });
} }
handleRemove(item, index) { // handleRemove(item, index) {
const listMenu = [...this.state.listMenu] // const listMenu = [...this.state.listMenu]
if (listMenu[index].qty !== 0) { // if (listMenu[index].qty !== 0) {
listMenu[index].qty -= 1 // listMenu[index].qty -= 1
this.setState({ // this.setState({
listMenu // listMenu
}) // })
} // }
// }
scrollToItem = () => {
// let newData = []
// newData.push(this.state.listMenu)
// console.log("DATA " + JSON.stringify(newData))
// newData.map((item => {
// let abc = item[0].category
// }))
this.props._scrollView.scrollTo({ y: 1 * 100});
} }
handleAdd(item) { handleAdd(item, index) {
const order_item = { const order_item = {
id: item.id, id: item.id,
name: item.name, name: item.name,
price: item.price, price: item.price,
image: item.image
} }
this.props.addToChart(order_item) this.props.addToChart(order_item)
const list_order_item = this.props.order_item;
let quantity = 0
for (let i = 0; i < list_order_item.length; i++) {
const row = list_order_item[i];
if (row.id == item.id) {
quantity = row.quantity
}
}
const listMenu = [...this.state.listMenu]
listMenu[index].qty = quantity
this.setState({
listMenu
})
} }
handleMin(item, index) {
const order_item = {
id: item.id,
name: item.name,
price: item.price,
render() { }
const { list_orders } = this.state;
let totalQuantity = 0;
let totalPrice = 0;
list_orders.forEach((item) => { this.props.reduceQuantityItem(order_item)
totalQuantity += item.qty; const list_order_item = this.props.order_item;
totalPrice += item.qty * item.price; let quantity = 0
}) if (quantity != 0) {
quantity = quantity - 1
for (let i = 0; i < list_order_item.length; i++) {
const row = list_order_item[i];
if (row.id == item.id) {
quantity = row.quantity
}
}
const listMenu = [...this.state.listMenu]
listMenu[index].qty = quantity
this.setState({
listMenu
})
}
}
render() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<StatusBar hidden={true} /> <StatusBar hidden={true} />
<View style={{ flex: 0.7, height: 90, flexDirection: 'row', borderWidth: 1, }}> <View style={{ flex: 0.7, height: 90, flexDirection: 'row', borderWidth: 1, }}>
<FlatList style={{ flexDirection: 'row' }} <FlatList horizontal={true} style={{ flexDirection: 'row' }}
data={this.state.listCategory} data={this.state.listCategory}
renderItem={this.renderTabBar} renderItem={this.renderTabBar}
keyExtractor={item => item.id} keyExtractor= {(item) => item.id}
numColumns={5}
/> />
</View> </View>
<View style={{ flex: 3 }}> <View style={{ flex: 3 }}>
...@@ -116,9 +165,8 @@ class MenuSelection extends React.Component { ...@@ -116,9 +165,8 @@ class MenuSelection extends React.Component {
renderItem={({ item, index }) => ( renderItem={({ item, index }) => (
<Item navigation={this.props.navigation} <Item navigation={this.props.navigation}
item={item} item={item}
handleAdd={() => this.handleAdd(item)} handleAdd={() => this.handleAdd(item, index)}
handleRemove={() => this.handleRemove(item, index)} handleMin={() => this.handleMin(item, index)}
refreshing={this.state.isFetching}
/> />
)} )}
keyExtractor={item => item.id} keyExtractor={item => item.id}
...@@ -126,8 +174,8 @@ class MenuSelection extends React.Component { ...@@ -126,8 +174,8 @@ class MenuSelection extends React.Component {
</View> </View>
<View style={styles.shadow}> <View style={styles.shadow}>
<View style={{ flexDirection: 'row', }}> <View style={{ flexDirection: 'row', }}>
<Text style={{ fontSize: 12, margin: 10 }}> Price Estimation / Item {this.state.qty} </Text> <Text style={{ fontSize: 12, margin: 10 }}> Price Estimation / Item {this.props.order_quantity} </Text>
<Text style={{ fontSize: 20, margin: 10, marginBottom: 10 }}> Rp. {totalPrice}</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>
...@@ -166,12 +214,18 @@ const mapStateToProps = (state) => { ...@@ -166,12 +214,18 @@ const mapStateToProps = (state) => {
return { return {
session_id: state.session_id, session_id: state.session_id,
outlet_id: state.outlet_id, outlet_id: state.outlet_id,
qty: state.qty, order_item: state.order_item,
totalOrder: state.totalOrder, order_quantity: state.order_quantity,
totalQty: state.totalQty, order_total: state.order_total,
quantity: state.quantity, quantity: state.quantity,
orders: state.orders, address: state.address
cart_shop: state.cart_shop // qty: state.qty,
// totalOrder: state.totalOrder,
// totalQty: state.totalQty,
// orders: state.orders,
// cart_shop: state.cart_shop,
} }
} }
...@@ -190,6 +244,13 @@ const mapDispatchToProps = (dispacth) => { ...@@ -190,6 +244,13 @@ const mapDispatchToProps = (dispacth) => {
item: item item: item
} }
}), }),
//REDUCE QUANTITY ITEM
reduceQuantityItem: (item) => dispacth({
type: ActionType.REDUCE_QUANTITY_ITEM,
data: {
item: item
}
}),
} }
} }
......
...@@ -9,6 +9,8 @@ import { MaterialCommunityIcons, Ionicons } from '@expo/vector-icons'; ...@@ -9,6 +9,8 @@ import { MaterialCommunityIcons, Ionicons } from '@expo/vector-icons';
import _ from 'lodash'; import _ from 'lodash';
import * as Location from 'expo-location'; import * as Location from 'expo-location';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import * as Permissions from 'expo-permissions';
import * as Device from 'expo-device';
class PickupName extends React.Component { class PickupName extends React.Component {
constructor(props) { constructor(props) {
...@@ -28,10 +30,22 @@ class PickupName extends React.Component { ...@@ -28,10 +30,22 @@ class PickupName extends React.Component {
} }
componentDidMount() { componentDidMount() {
this._getCurrentPosisition()
this._getPermissions()
} }
_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 () => { _getCurrentPosisition = async () => {
this.setState({ this.setState({
spinner: true, spinner: true,
...@@ -54,9 +68,6 @@ class PickupName extends React.Component { ...@@ -54,9 +68,6 @@ class PickupName extends React.Component {
this.props.navigation.navigate('Outlet Detail',{id:id}) this.props.navigation.navigate('Outlet Detail',{id:id})
} }
getOutlet() { getOutlet() {
this.setState({ this.setState({
spinner: true, spinner: true,
...@@ -111,7 +122,6 @@ class PickupName extends React.Component { ...@@ -111,7 +122,6 @@ class PickupName extends React.Component {
}) })
} }
toRad(value) { toRad(value) {
return value * Math.PI / 180; return value * Math.PI / 180;
} }
......
...@@ -40,7 +40,6 @@ class ShoppingCart extends React.Component { ...@@ -40,7 +40,6 @@ class ShoppingCart extends React.Component {
} }
} }
plusQty(item, index) { plusQty(item, index) {
this.setState({ this.setState({
...@@ -147,6 +146,7 @@ class ShoppingCart extends React.Component { ...@@ -147,6 +146,7 @@ class ShoppingCart extends React.Component {
</TouchableOpacity> </TouchableOpacity>
</View> </View>
<View style={styles.order}> <View style={styles.order}>
{this.props.order_item.map((item, i) => { {this.props.order_item.map((item, i) => {
return ( return (
<View style={{ flex: 1, margin: 10 }} key={i}> <View style={{ flex: 1, margin: 10 }} key={i}>
...@@ -176,10 +176,10 @@ class ShoppingCart extends React.Component { ...@@ -176,10 +176,10 @@ class ShoppingCart extends React.Component {
</View> </View>
</View> </View>
</View> </View>
) )
})} })}
</View> </View>
<View style={styles.voucher}> <View style={styles.voucher}>
<TouchableOpacity> <TouchableOpacity>
...@@ -340,6 +340,7 @@ class ShoppingCart extends React.Component { ...@@ -340,6 +340,7 @@ class ShoppingCart extends React.Component {
<Text style={{ paddingLeft: 20, paddingTop: 15, color: 'gray' }}>Harga</Text> <Text style={{ paddingLeft: 20, paddingTop: 15, color: 'gray' }}>Harga</Text>
</View> </View>
<View> <View>
<Text style={{ paddingRight: 150, paddingTop: 15, color: 'gray' }}>{this.props.order_total}</Text> <Text style={{ paddingRight: 150, paddingTop: 15, color: 'gray' }}>{this.props.order_total}</Text>
</View> </View>
</View> </View>
...@@ -364,6 +365,7 @@ class ShoppingCart extends React.Component { ...@@ -364,6 +365,7 @@ class ShoppingCart extends React.Component {
<Text style={{ fontSize: 35, color: '#ccb46c' }}>Total</Text> <Text style={{ fontSize: 35, color: '#ccb46c' }}>Total</Text>
</View> </View>
<View style={{ marginTop: 15, paddingRight: 60, paddingTop: 10 }}> <View style={{ marginTop: 15, paddingRight: 60, paddingTop: 10 }}>
<Text style={{ fontSize: 35, color: '#ccb46c' }}>{this.props.order_total}</Text> <Text style={{ fontSize: 35, color: '#ccb46c' }}>{this.props.order_total}</Text>
</View> </View>
</View> </View>
...@@ -372,7 +374,7 @@ class ShoppingCart extends React.Component { ...@@ -372,7 +374,7 @@ class ShoppingCart extends React.Component {
<Text style={{ paddingLeft: 20, paddingTop: 10, color: 'gray' }}>Tujuan</Text> <Text style={{ paddingLeft: 20, paddingTop: 10, color: 'gray' }}>Tujuan</Text>
</View> </View>
<View> <View>
<Text style={{ color: '#ccb46c', paddingRight: 150, paddingTop: 10 }}>undefined</Text> <Text style={{ color: '#ccb46c', paddingRight: 150, paddingTop: 10 }}>{this.props.address}</Text>
</View> </View>
</View> </View>
<View style={{ margin: 20, }}> <View style={{ margin: 20, }}>
...@@ -515,16 +517,19 @@ const styles = StyleSheet.create({ ...@@ -515,16 +517,19 @@ const styles = StyleSheet.create({
}) })
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
console.log(state)
return { return {
session_id: state.session_id, session_id: state.session_id,
outlet_id: state.outlet_id, outlet_id: state.outlet_id,
order_quantity: state.order_quantity, order_quantity: state.order_quantity,
order_total: state.order_total, order_total: state.order_total,
order_item: state.order_item, order_item: state.order_item,
quantity: state.quantity, quantity: state.quantity,
address: state.address
} }
} }
export default connect(mapStateToProps)(ShoppingCart)
\ No newline at end of file export default connect(mapStateToProps)(ShoppingCart)
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