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

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

# Conflicts:
#	view/ShoppingCart.js
parents 696c03bf 30e1d19e
......@@ -29,7 +29,8 @@ const ActionType = {
SET_GRAB : 'SET_GRAB',
SET_ORDERS : 'SET_ORDERS',
SET_TYPE : 'SET_TYPE',
SET_TRANS_TYPE : 'SET_TRANS_TYPE'
SET_TRANS_TYPE : 'SET_TRANS_TYPE',
SET_RECALCULATE: 'SET_RECALCULATE'
}
......
......@@ -399,6 +399,15 @@ const rootReducer = (state = globalState, action) => {
order_item: new_items,
}
}
case ActionType.SET_RECALCULATE: {
return {
...state,
order_total: action.data.order_total,
order_quantity: action.data.order_quantity,
order_item: action.data.order_item
}
}
default:
return state;
}
......
......@@ -44,6 +44,9 @@ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { enableScreens } from 'react-native-screens';
import MenuDetail from './MenuDetail';
import OrderHistory from './OrderHistory'
import { TouchableOpacity } from 'react-native-gesture-handler';
import { StackActions } from '@react-navigation/native';
import { NavigationActions } from 'react-navigation';
enableScreens();
function Rewards() {
......@@ -73,9 +76,10 @@ function Outlets() {
const Tab = createBottomTabNavigator();
function HomePage() {
function HomePage({navigation}) {
return (
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarIcon: ({ focused, color, size }) => {
let iconName;
......@@ -98,12 +102,13 @@ function HomePage() {
// You can return any component that you like here!
return <Ionicons name={iconName} size={size} color={color} />;
},
})}
tabBarOptions={{ activeTintColor: 'cornflowerblue', inactiveTintColor: 'gray' }}
>
<Tab.Screen name="HOME" component={Home} />
<Tab.Screen name="HOME" component={Home} />
<Tab.Screen name="MENU" component={MenuSelection} />
<Tab.Screen name="REWARDS" component={Rewards} />
<Tab.Screen name="ORDER" component={TransactionHistory} />
......
......@@ -101,12 +101,20 @@ class DeliveryAddrees extends React.Component {
}
this.props.setAddress(setDataAddress);
let recalculateProps = {
order_total: 0,
order_quantity:0,
order_item:[]
}
this.props.setRecalculate(recalculateProps)
Alert.alert(
'',
'Apakah anda akan memilih alamat untuk pengiriman ?',
[
{text: 'OK', onPress: () => this.getRate() },
{text: 'OK', onPress: () => this.props.navigation.navigate("Menu Select") },
],
{ cancelable: false }
)
......@@ -120,7 +128,6 @@ class DeliveryAddrees extends React.Component {
<View style={styles.list_addrees}>
<TouchableOpacity onPress={()=> this.onSave(item.address,item.id)}>
<View style={{ margin: 5, }}>
<Text style={{ fontWeight: 'bold', fontSize: 20 }}>{item.id}</Text>
<Text style={{ fontWeight: 'bold', fontSize: 20 }}>{item.name}</Text>
</View>
<Text style={{ margin: 5 }}>
......@@ -152,19 +159,6 @@ class DeliveryAddrees extends React.Component {
renderItem={this.renderItem}
keyExtractor={item => item.id}
/>
{/*
<View style={styles.list_addrees}>
<View style={{ margin: 5, }}>
<Text style={{ fontWeight: 'bold', fontSize: 20 }}>Rumah</Text>
</View>
<Text style={{ margin: 5 }}>
Perkantoran Grenvil Maisonette Blok FB/16,
Tanjung Duren, Duri Kepa, Kebon Jeruk, RT.13/RW.9,
Duri Kepa, DKI Jakarta, Kota Jakarta Barat,
Daerah Khusus Ibukota Jakarta 11510
</Text>
</View> */}
{/* </ScrollView> */}
</View>
</View>
)
......@@ -232,6 +226,16 @@ const mapDispatchToProps = (dispacth) => {
// grabdestination: setGrabProps.grabdestination,
}
}),
setRecalculate: (recalculateProps) => dispacth({
type: ActionType.SET_RECALCULATE,
data: {
order_total : recalculateProps.order_total,
order_quantity: recalculateProps.order_quantity,
order_item: recalculateProps.order_item
}
}),
}
}
......
......@@ -115,7 +115,7 @@ class Home extends React.Component {
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
......@@ -132,6 +132,14 @@ class Home extends React.Component {
})
}
_pickup() {
let typeProps = {
type_pickup: true,
}
this.props.setTypePickup(typeProps);
this.props.navigation.navigate('Pickup Name');
}
render() {
return (
......@@ -178,7 +186,7 @@ class Home extends React.Component {
<TouchableOpacity style={styles.buttonDelivery} onPress={() => this.props.navigation.navigate('Delivery Address')}>
<Text style={{ textAlign: 'center', color: '#354175', fontWeight: 'bold' }}>{i18n.t('delivery')}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.buttonPickup} onPress={() => this.props.navigation.navigate('Pickup Name')}>
<TouchableOpacity style={styles.buttonPickup} onPress={() => this._pickup()}>
<Text style={{ textAlign: 'center', color: '#fff', fontWeight: 'bold' }}>{i18n.t('pickup')}</Text>
</TouchableOpacity>
</View>
......@@ -335,6 +343,14 @@ const mapDispatchToProps = (dispacth) => {
name_outlet: OutletChange.name_outlet,
}
}),
setTypePickup: (typeProps) => dispacth({
type: ActionType.SET_TYPE,
data: {
type_pickup: typeProps.type_pickup
}
}),
}
}
......
......@@ -2,6 +2,7 @@ import React from 'react';
import { View, Text, Alert, TextInput, StyleSheet, Button, ScrollView } from 'react-native';
import Axios from 'axios'
import { connect } from 'react-redux'
import Spinner from 'react-native-loading-spinner-overlay';
class MenuConfirmation extends React.Component {
constructor(props) {
super(props)
......@@ -12,7 +13,8 @@ class MenuConfirmation extends React.Component {
pointsused: 0,
ongkir: 0,
diskon: 0,
totalOrder: 0
totalOrder: 0,
spinner: false,
}
}
......@@ -29,6 +31,9 @@ class MenuConfirmation extends React.Component {
}
setOrder() {
this.setState({
spinner: true,
})
let params = {
session_id : this.props.session_id,
outlet_id : this.props.outlet_id,
......@@ -37,34 +42,49 @@ class MenuConfirmation extends React.Component {
order_item: this.props.order_item,
delivery_charge: this.props.grabamount,
voucher: [],
payment: {
balance: this.props.route.params.balanceUsed,
point: this.props.route.params.pointused
}
}
console.log("INI PARAMETER UNTUK ORDER : " + JSON.stringify())
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/transaction/booking', params).then(res => {
Alert.alert( 'Transaksi Anda Berhasil')
this.props.navigation.navigate('Order History');
this.setState({
spinner: false,
})
Alert.alert(
"Berhasil",
"Transaksi sudah berhasil, terimakasih sudah menggunakan excelso untuk ngopi",
[
{ text: "OK", onPress: () => this.props.navigation.reset({
routes: [{ name: 'Home' }]
})}
],
{ cancelable: false }
);
// let typeProps = {
// type_pickup: false,
// }
// this.props.setTypePickup(typeProps);
let typeProps = {
type_pickup: false,
}
this.props.setTypePickup(typeProps);
}).catch(error => {
let response = error.response.data;
// console.log('error')
Alert.alert(response.msg);
this.setState({
spinner: false,
})
})
}
setPickup() {
this.setState({
spinner: true,
})
let params = {
session_id : this.props.session_id,
outlet_id : this.props.outlet_id,
......@@ -81,18 +101,34 @@ class MenuConfirmation extends React.Component {
console.log("INI params : " + JSON.stringify(params) )
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/transaction/booking', params).then(res => {
Alert.alert( 'Transaksi Anda Berhasil')
this.props.navigation.navigate('Order History');
this.setState({
spinner: false,
})
Alert.alert(
"Berhasil",
"Transaksi sudah berhasil, terimakasih sudah menggunakan excelso untuk ngopi",
[
{ text: "OK", onPress: () => this.props.navigation.reset({
routes: [{ name: 'Home' }]
})}
],
{ cancelable: false }
);
let typeProps = {
type_pickup: false,
}
this.props.setTypePickup(typeProps);
}).catch(error => {
let response = error.response.data;
console.log('ini error ' + error)
// console.log('error')
Alert.alert(response.msg);
this.setState({
spinner: false,
})
})
}
......@@ -101,6 +137,11 @@ class MenuConfirmation extends React.Component {
let total = 0
return (
<ScrollView style={styles.container}>
<Spinner
visible={this.state.spinner}
textContent={'Sedang Proses...'}
textStyle={styles.spinnerTextStyle}
/>
{
this.props.order_item.map((item, index) => {
total = total + item.quantity * item.price
......@@ -192,11 +233,11 @@ class MenuConfirmation extends React.Component {
</View>
</View>
<View style={{ margin: 10 }}>
{/* {this.props.type_pickup == true ? (
{this.props.type_pickup == true ? (
<Button title='order' onPress={() => this.setPickup()}/>
):( */}
):(
<Button title='order' onPress={() => this.setOrder()}/>
{/* )} */}
)}
</View>
</ScrollView>
......@@ -265,5 +306,4 @@ const mapStateToProps = (state) => {
}
}
export default connect(mapStateToProps,mapDispatchToProps)(MenuConfirmation)
......@@ -30,7 +30,6 @@ class OrderHistory extends React.Component {
this.setState({
order_list: data
})
// console.log(this.state.order_list)
}).catch(error => {
let response = error.response.data;
Alert.alert(response.msg);
......@@ -49,7 +48,7 @@ class OrderHistory extends React.Component {
<Text>OUTLET : {item.outlet}</Text>
<Text>TGL TRANSAKSI : {item.trans_date}</Text>
<Text>TOTAL : {item.trans_total}</Text>
<Text>STATUS : {item.trans_status}</Text>
<Text>STATUS : {item.trans_status_display}</Text>
</Card>
</View>
......
......@@ -75,6 +75,12 @@ class PickupName extends React.Component {
type_pickup: true,
}
let recalculateProps = {
order_total: 0,
order_quantity:0,
order_item:[]
}
this.props.setRecalculate(recalculateProps)
this.props.setChangeOutletProps(OutletChange);
this.props.setTypePickup(typeProps);
this.props.navigation.navigate('Menu Select')
......@@ -180,6 +186,7 @@ class PickupName extends React.Component {
name_outlet: item.name,
}
this.props.setChangeOutletProps(OutletChange)
this.props.navigation.navigate('Home', { screen: 'MENU' });
}
......@@ -303,6 +310,16 @@ const mapDispatchToProps = (dispacth) => {
}
}),
setRecalculate: (recalculateProps) => dispacth({
type: ActionType.SET_RECALCULATE,
data: {
order_total : recalculateProps.order_total,
order_quantity: recalculateProps.order_quantity,
order_item: recalculateProps.order_item
}
}),
}
}
......
......@@ -25,8 +25,6 @@ class ShoppingCart extends React.Component {
pointsused: 0,
ongkir: 0,
diskon: 0,
isDelivery: false,
isPickUp: false,
// order_item: this.props.order_item,
grabtype: '',
grabamount: '',
......@@ -36,37 +34,44 @@ class ShoppingCart extends React.Component {
my_lat:0,
my_long:0,
indicator:true,
// dummyBalance : 155000,
// dummyPoint : 20000
}
}
componentDidMount() {
this.getRate()
this.getBalance()
console.log("INI REDUX PROPS BAGIAN ID : " + this.props.addressId)
console.log("INI REDUX PROPS BAGIAN ID : " + this.props.addressId)
}
checkChangeTrans(val) {
console.log('hai lg di sini')
console.log(val)
if (val == 'delivery') {
let typeProps = {
type_pickup: false,
}
this.props.setTypePickup(typeProps);
this.setState({
isDelivery: true,
isPickUp: false
checkedBalance: false,
checkedPoint: false,
checkedBalancePoint: false,
pointsused: 0,
balanceused: 0
})
console.log('ini delivery')
} else {
let typeProps = {
type_pickup: true,
}
this.props.setTypePickup(typeProps);
this.setState({
isPickUp: true,
isDelivery: false
checkedBalance: false,
checkedPoint: false,
checkedBalancePoint: false,
pointsused: 0,
balanceused: 0
})
console.log('ini pickup')
}
}
......@@ -142,38 +147,70 @@ class ShoppingCart extends React.Component {
checkedSelection(val) {
// console.log(val)
if (val == 'balance') {
this.setState({
checkedBalance: true,
checkedPoint: false,
checkedBalancePoint: false,
balanceused: this.props.order_total + this.props.grabamount,
pointsused: 0
})
if (this.props.type_pickup == true) {
this.setState({
checkedBalance: true,
checkedPoint: false,
checkedBalancePoint: false,
balanceused: this.props.order_total,
pointsused: 0
})
} else {
this.setState({
checkedBalance: true,
checkedPoint: false,
checkedBalancePoint: false,
balanceused: this.props.order_total + this.props.grabamount,
pointsused: 0
})
}
} else if (val == 'point') {
this.setState({
checkedBalance: false,
checkedPoint: true,
checkedBalancePoint: false,
pointsused: this.props.order_total + this.props.grabamount,
balanceused: 0
})
if (this.props.type_pickup == true) {
this.setState({
checkedBalance: false,
checkedPoint: true,
checkedBalancePoint: false,
pointsused: this.props.order_total,
balanceused: 0
})
} else {
this.setState({
checkedBalance: false,
checkedPoint: true,
checkedBalancePoint: false,
pointsused: this.props.order_total + this.props.grabamount,
balanceused: 0
})
}
} else {
this.setState({
checkedBalance: false,
checkedPoint: false,
checkedBalancePoint: true,
// balanceused : this.props.order_total - this.state.dummyPoint,
// pointsused : this.props.order_total,
})
if (this.state.kasproPoint - (this.props.order_total + this.props.grabamount) >= -1) {
this.setState({
pointsused: this.props.order_total + this.props.grabamount
})
if (this.props.type_pickup == true) {
if (this.state.kasproPoint - this.props.order_total >= -1) {
this.setState({
pointsused: this.props.order_total
})
} else {
this.setState({
balanceused: this.props.order_total - this.state.kasproPoint,
pointsused: this.state.kasproPoint
})
}
} else {
this.setState({
balanceused: (this.props.order_total + this.props.grabamount) - this.state.kasproPoint,
pointsused: this.state.kasproPoint
})
if (this.state.kasproPoint - (this.props.order_total + this.props.grabamount) >= -1) {
this.setState({
pointsused: this.props.order_total + this.props.grabamount
})
} else {
this.setState({
balanceused: (this.props.order_total + this.props.grabamount) - this.state.kasproPoint,
pointsused: this.state.kasproPoint
})
}
}
}
}
......@@ -216,8 +253,13 @@ class ShoppingCart extends React.Component {
})
}
checkOut(){
this.props.navigation.navigate('Confirm Your Order', { balanceUsed: this.state.balanceused, pointused: this.state.pointsused })
checkOut() {
if (this.state.checkedBalance == false && this.state.checkedPoint == false && this.state.checkedBalancePoint == false) {
Alert.alert('Error', 'Please insert payment methods')
} else {
this.props.navigation.navigate('Confirm Your Order', { balanceUsed: this.state.balanceused, pointused: this.state.pointsused })
}
}
getBalance() {
......@@ -251,16 +293,15 @@ class ShoppingCart extends React.Component {
</View>
<View style={{ alignItems: 'center' }}>
{
this.state.isDelivery == true ? (
<TouchableOpacity onPress={()=>this.props.navigation.navigate("Pickup Name")}>
<Card style={{ margin: 5, padding: 10 }}>
<Text style={{ textAlign: 'center' }}> Ambil pesanan kamu di</Text>
<Text style={{ textAlign: 'center' }}> {this.props.addressId}</Text>
<Text style={{ textAlign: 'center' }}>{this.props.name_outlet}</Text>
</Card>
this.props.type_pickup == true ? (
<TouchableOpacity >
<Card style={{ margin: 5, padding: 10 }}>
<Text style={{ textAlign: 'center' }}> Ambil pesanan kamu di</Text>
<Text style={{ textAlign: 'center', fontSize: 12, top: 5, fontWeight: 'bold' }}>Excelso {this.props.name_outlet}</Text>
</Card>
</TouchableOpacity>
) : (
<TouchableOpacity onPress={()=>this.props.navigation.navigate("Delivery Address")}>
......@@ -268,8 +309,8 @@ class ShoppingCart extends React.Component {
<Text style={{ textAlign: 'center' }}> Pesanan kamu dikirim ke</Text>
<Text style={{ textAlign: 'center' }}>{this.props.address}</Text>
</Card>
</TouchableOpacity>
)
}
</View>
......@@ -457,17 +498,17 @@ class ShoppingCart extends React.Component {
</View>
{this.props.type_pickup == true ? (
null
):(
<View style={{ flexDirection: 'row', marginTop: 10, justifyContent: 'space-between' }}>
<View>
<Text style={{ paddingLeft: 20, paddingTop: 10, color: 'gray' }}>Ongkos Kirim</Text>
</View>
<View style={{ paddingRight: 30, paddingTop: 10, alignItems: 'flex-end' }}>
<Text style={{ color: 'gray' }}>{this.props.grabamount}</Text>
</View>
</View>)}
) : (
<View style={{ flexDirection: 'row', marginTop: 10, justifyContent: 'space-between' }}>
<View>
<Text style={{ paddingLeft: 20, paddingTop: 10, color: 'gray' }}>Ongkos Kirim</Text>
</View>
<View style={{ paddingRight: 30, paddingTop: 10, alignItems: 'flex-end' }}>
<Text style={{ color: 'gray' }}>{this.props.grabamount}</Text>
</View>
</View>)}
<View style={{ flexDirection: 'row', marginTop: 10, justifyContent: 'space-between' }}>
<View>
<Text style={{ paddingLeft: 20, paddingTop: 10, color: 'gray' }}>Diskon</Text>
......@@ -482,13 +523,13 @@ class ShoppingCart extends React.Component {
</View>
{this.props.type_pickup == true ? (
<View style={{ marginTop: 15, paddingRight: 30, paddingTop: 10, alignItems: 'flex-end' }}>
<Text style={{ fontSize: 35, color: '#ccb46c' }}>{this.props.order_total + this.state.diskon}</Text>
</View>
): (
<View style={{ marginTop: 15, paddingRight: 30, paddingTop: 10, alignItems: 'flex-end' }}>
<Text style={{ fontSize: 35, color: '#ccb46c' }}>{this.props.order_total +this.props.grabamount + this.state.diskon }</Text>
</View>
)}
<Text style={{ fontSize: 35, color: '#ccb46c' }}>{this.props.order_total + this.state.diskon}</Text>
</View>
) : (
<View style={{ marginTop: 15, paddingRight: 30, paddingTop: 10, alignItems: 'flex-end' }}>
<Text style={{ fontSize: 35, color: '#ccb46c' }}>{this.props.order_total + this.props.grabamount + this.state.diskon}</Text>
</View>
)}
</View>
<View style={{ flexDirection: 'row', marginTop: 10, justifyContent: 'space-between' }}>
<View>
......@@ -499,7 +540,7 @@ class ShoppingCart extends React.Component {
</View>
</View>
<View style={{ margin: 20, }}>
<Button title='Checkout' color='#ccb46c' onPress={() => this.checkOut() } />
<Button title='Checkout' color='#ccb46c' onPress={() => this.checkOut()} />
</View>
</View>
</ScrollView>
......@@ -678,12 +719,20 @@ const mapDispatchToProps = (dispacth) => {
pointused: setOrdersProps.pointused,
}
}),
setTypePickup: (typeProps) => dispacth({
type: ActionType.SET_TYPE,
data: {
type_pickup: typeProps.type_pickup
}
}),
}
}
const mapStateToProps = (state) => {
return {
type_pickup : state.type_pickup,
type_pickup: state.type_pickup,
session_id: state.session_id,
outlet_id: state.outlet_id,
name_outlet: state.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