Commit 4aff7651 authored by Afid's avatar Afid

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

# Conflicts:
#	redux/globalActionType.js
#	redux/globalReducer.js
#	view/Item.js
#	view/ItemShopingCart.js
parents e1aa0de1 1b3ca2f8
{
"expo": {
"name": "Excelso_update v1_malam",
"name": "Excelso_update v1.06062020",
"slug": "excelso-pro",
"privacy": "public",
"sdkVersion": "36.0.0",
......
......@@ -33,7 +33,10 @@ const ActionType = {
SET_RECALCULATE: 'SET_RECALCULATE',
SET_ORDER_FINISH: 'SET_ORDER_FINISH',
UPDATE_MENU: 'UPDATE_MENU',
CHANGE_QUANTITY: 'CHANGE_QUANTITY'
CHANGE_QUANTITY: 'CHANGE_QUANTITY',
SET_TRANS_ID:'SET_TRANS_ID',
CHANGE_TO_CHART:'CHANGE_TO_CHART'
}
export default ActionType;
\ No newline at end of file
......@@ -76,6 +76,8 @@ const globalState = {
balanceUsed:'',
pointused:'',
trans_id:''
}
const rootReducer = (state = globalState, action) => {
......@@ -265,6 +267,12 @@ const rootReducer = (state = globalState, action) => {
addressId:action.data.addressId
}
}
case ActionType.SET_TRANS_ID: {
return {
...state,
trans_id: action.data.trans_id
}
}
case ActionType.SET_LOGOUT: {
return {
...state,
......@@ -332,6 +340,64 @@ const rootReducer = (state = globalState, action) => {
}
}
case ActionType.CHANGE_TO_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) {
update = old_data
if (update.quantity == NaN) {
update.quantity = 1
}
console.log('Update : ' + JSON.stringify(update))
data = { ...old_data, ...update }
}
updated_data.push(data)
}
order_item = updated_data
} else {
// addcd ..
order_item = [...state.order_item]
}
let quantity = state.order_quantity
let menu_item = []
for (let i = 0; i < state.menu_item.length; i++) {
const row = state.menu_item[i];
if (row.id == addedItem.id) {
let is_exist = order_item.find(item => addedItem.id == item.id)
if (is_exist) {
row.qty = is_exist.quantity
}
}
menu_item.push(row)
}
return {
...state,
menu_item: menu_item,
order_item: order_item,
order_quantity: quantity,
}
}
case ActionType.REDUCE_QUANTITY_ITEM: {
let addedItem = action.data.item
......
import * as React from 'react';
import { createStackNavigator } from '@react-navigation/stack';
import { createStackNavigator, HeaderBackButton } from '@react-navigation/stack';
import { connect } from 'react-redux';
import { View, Text } from 'react-native';
import ActionType from '../redux/globalActionType';
......@@ -125,7 +125,6 @@ class Auth extends React.Component {
}
render() {
return (
<Stack.Navigator>
{
......@@ -170,7 +169,8 @@ class Auth extends React.Component {
<Stack.Screen name="Card Info" component={CardInfo} />
<Stack.Screen name="Shopping Cart" component={ShoppingCart} />
<Stack.Screen name="Order History" component={OrderHistory} />
<Stack.Screen name="Order Detail" component={OrderDetail} />
<Stack.Screen name="Order Detail" component={OrderDetail} options={({ navigation, route }) => ({ headerLeft: props => <HeaderBackButton {...props} onPress={()=>navigation.navigate('Home',{screen:'ORDER'})}/>,
})}/>
</>
)
......
......@@ -284,7 +284,7 @@ class Home extends React.Component {
<TouchableOpacity style={styles.submitUpgradePemium} activeOpacity={.5} onPress={this.onPress}>
<Text style={{ textAlign: 'center', bottom: 5, color: 'white' }}>TOP BALANCE </Text>
</TouchableOpacity>
<Text>APP.V2.APRIL</Text>
<Text>UPDATE SORE </Text>
<View style={{ height: 60 }}></View>
</View>
</View>
......
......@@ -6,46 +6,44 @@ import ActionType from '../redux/globalActionType';
class Item extends React.Component {
handleChangeQuantity = (item, quantity) => {
this.props.changeQuantity({item: item, quantity: quantity})
this.props.changeQuantity({ item: item, quantity: quantity })
}
render() {
const { item } = this.props
// console.log("ini id itemnya "+item.id)
return (
<View style={{ flex: 1, margin: 10 }} key={item.id} ref={this.props._scrollView}>
<ScrollView ref={view => this._scrollView = view}>
{item.code == 'CATEGORY' ? (
<Text style={{ fontSize: 20, color: '#c9af6d' }}>{item.name}</Text>
): (
<Text style={{ fontSize: 20, color: '#c9af6d' }}>{item.name}</Text>
) : (
<View style={{ flexDirection: 'row' }}>
<View >
<Image source={{ uri: item.image }} style={{ height: 100, width: 100, borderRadius: 5, top: 5 }}></Image>
</View>
<View >
<Text style={{ fontSize: 20, margin: 5, marginRight: 10, fontWeight: 'bold' }}>{item.name}</Text>
<Text style={{ fontSize: 15, margin: 5, marginRight: 10 }}>Rp. {item.price}</Text>
<View style={{ flexDirection: 'row', flex: 1 }}>
<View style={styles.shadowEdit}></View>
<View style={styles.shadowAdd}>
<TouchableOpacity onPress={() => this.props.handleMin()}>
<Text style={{ fontSize: 20, margin: 2 }}> - </Text>
</TouchableOpacity>
<TextInput
style={{ height: 25, padding: 2, textAlign: 'center', margin: 2 }}
keyboardType={'numeric'}
onChangeText={(qty) => this.handleChangeQuantity(item, qty)}>{item.qty}</TextInput>
<TouchableOpacity onPress={() => this.props.handleAdd()}>
<Text style={{ fontSize: 20, margin: 2 }}> + </Text>
</TouchableOpacity>
<View style={{ flexDirection: 'row' }}>
<View >
<Image source={{ uri: item.image }} style={{ height: 100, width: 100, borderRadius: 5, top: 5 }}></Image>
</View>
<View >
<Text style={{ fontSize: 20, margin: 5, marginRight: 10, fontWeight: 'bold' }}>{item.name}</Text>
<Text style={{ fontSize: 15, margin: 5, marginRight: 10 }}>Rp. {item.price}</Text>
<View style={{ flexDirection: 'row', flex: 1 }}>
<View style={styles.shadowEdit}></View>
<View style={styles.shadowAdd}>
<TouchableOpacity onPress={() => this.props.handleMin()}>
<Text style={{ fontSize: 20, margin: 2 }}> - </Text>
</TouchableOpacity>
<TextInput
style={{ height: 25, padding: 2, textAlign: 'center', margin: 2 }}
keyboardType={'numeric'}
onChangeText={(qty) => this.handleChangeQuantity(item, qty)}>{item.qty}</TextInput>
<TouchableOpacity onPress={() => this.props.handleAdd()}>
<Text style={{ fontSize: 20, margin: 2 }}> + </Text>
</TouchableOpacity>
</View>
</View>
</View>
</View>
</View>
</View>
)}
)}
</ScrollView>
</View>
)
......@@ -104,6 +102,23 @@ const styles = StyleSheet.create({
}
})
const mapDispatchToProps = (dispacth) => {
return {
setChangeQuantity: (item) => dispacth({
type: ActionType.CHANGE_TO_CHART,
data: {
item: item
}
}),
changeQuantity: (params) => dispacth({
type: ActionType.CHANGE_QUANTITY,
data: {
item: params.item,
new_quantity: params.quantity
}
}),
}
}
const mapStateToProps = (state) => {
// console.log(state)
return {
......@@ -115,16 +130,4 @@ const mapStateToProps = (state) => {
}
}
const mapDispatchToProps = (dispacth) => {
return {
changeQuantity: (params) => dispacth({
type: ActionType.CHANGE_QUANTITY,
data: {
item: params.item,
new_quantity: params.quantity
}
}),
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Item)
......@@ -10,11 +10,10 @@ class ItemShoping extends React.Component {
console.log('new quantity : ' + quantity)
this.props.changeQuantity({item: item, quantity: quantity})
}
render() {
const { item } = this.props
return (
<View style={{ flex: 1, margin: 10 }} key={item.id}>
{/* <Text style={{ fontSize: 20, color: '#c9af6d' }}>{item.name}</Text> */}
<View style={{ flexDirection: 'row' }}>
......
......@@ -59,10 +59,15 @@ class MenuConfirmation extends React.Component {
console.log('BOOK : ' + JSON.stringify(params))
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/transaction/booking', params).then(res => {
let data_order = res.data.data.id
this.setState({
spinner: false,
})
let transIdProps = {
trans_id : data_order
}
this.props.setTransId(transIdProps);
Alert.alert(
"Berhasil",
"Transaksi sudah berhasil, terimakasih sudah menggunakan excelso untuk ngopi",
......@@ -85,10 +90,7 @@ class MenuConfirmation extends React.Component {
orderSuccess = () => {
this.props.setOrderFinish()
this.props.navigation.navigate('Home', {
screen: 'ORDER',
params: { user: 'janei' },
});
this.props.navigation.navigate('Order Detail');
// this.props.navigation.reset({
// routes: [{ name: 'Home' }]
// })
......@@ -236,6 +238,12 @@ const mapDispatchToProps = (dispacth) => {
return {
setOrderFinish: () => dispacth({
type: ActionType.SET_ORDER_FINISH
}),
setTransId: (transIdProps) => dispacth({
type: ActionType.SET_TRANS_ID,
data: {
trans_id: transIdProps.trans_id,
}
})
}
}
......
......@@ -24,6 +24,8 @@ class MenuSelection extends React.Component {
order_list: [],
list_cart: [],
indicator: true,
my_lat: 0,
my_long: 0
}
}
......@@ -36,17 +38,16 @@ class MenuSelection extends React.Component {
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()
}
});
}
......@@ -166,9 +167,9 @@ class MenuSelection extends React.Component {
})
}).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);
})
......@@ -300,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>
......@@ -390,26 +391,3 @@ const mapDispatchToProps = (dispacth) => {
}
export default connect(mapStateToProps, mapDispatchToProps)(MenuSelection)
import React from 'react';
import { View, Text, TextInput, StyleSheet, ScrollView, Alert, TouchableOpacity } from 'react-native';
import { View, Text, TextInput, StyleSheet, ScrollView, Alert, TouchableOpacity,BackHandler } from 'react-native';
import { Card } from 'react-native-shadow-cards'
import { connect } from 'react-redux';
import Axios from 'axios';
import session from '../function/session';
class OrderDetail extends React.Component {
constructor(props) {
super(props)
this.handleBackButtonClick = this.handleBackButtonClick.bind(this)
this.state = {
trans_type_display:'',
outlet:'',
......@@ -15,20 +17,34 @@ class OrderDetail extends React.Component {
trans_status_display:'',
transaction_detail:[],
}
}
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonClick);
this.getDetailTrans()
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButtonClick);
}
handleBackButtonClick() {
this.props.navigation.navigate('Home',{screen:'ORDER'});
return true;
}
getDetailTrans() {
let params = {
session_id: this.props.session_id,
transaction_id: this.props.route.params.idTrans
transaction_id: this.props.trans_id
}
console.log("PARAMETER : " + JSON.stringify(params))
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/transaction/detail', params).then(res => {
let data = res.data
// console.log("INI OUTLET "+ data.outlet)
......@@ -43,8 +59,15 @@ class OrderDetail extends React.Component {
})
}).catch(error => {
let response = error.response.data;
const { navigation } = this.props
let response = error.response.data
session(response, navigation)
Alert.alert(response.msg);
this.setState({
indicator: false,
})
// let response = error.response.data;
// Alert.alert(response.msg);
})
}
......@@ -110,6 +133,7 @@ const mapStateToProps = (state) => {
return {
session_id: state.session_id,
trans_id : state.trans_id
}
}
......
......@@ -107,6 +107,11 @@ class ShoppingCart extends React.Component {
}
}
onChange(params){
console.log(params);
}
handleMin(item, index) {
this.setState({
checkedBalance: false,
......@@ -277,6 +282,9 @@ class ShoppingCart extends React.Component {
}
getRate() {
let params = {
......@@ -323,6 +331,10 @@ class ShoppingCart extends React.Component {
}
onChange(){
}
checkOut() {
if (this.props.order_item.length == 0){
Alert.alert('Error', 'Please choose your order first')
......@@ -399,6 +411,7 @@ class ShoppingCart extends React.Component {
item={item}
handleAdd={() => this.handleAdd(item, index)}
handleMin={() => this.handleMin(item, index)}
onChange={()=> this.onChange(item,index)}
/>
)}
keyExtractor={item => item.id}
......
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