Commit 6102760c authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

ini rdux grab dan order

parent 630880ee
...@@ -25,7 +25,9 @@ const ActionType = { ...@@ -25,7 +25,9 @@ const ActionType = {
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', REDUCE_QUANTITY_ITEM :'REDUCE_QUANTITY_ITEM',
SET_ADDRESS :'SET_ADDRESS' SET_ADDRESS :'SET_ADDRESS',
SET_GRAB : 'SET_GRAB',
SET_ORDERS : 'SET_ORDERS'
} }
......
...@@ -60,7 +60,16 @@ const globalState = { ...@@ -60,7 +60,16 @@ const globalState = {
address:'', address:'',
addressId:'' addressId:'',
grabtype:'',
grabamount:'',
grabpickup:'',
grabdropoff:'',
grabdestination:'',
balanceUsed:'',
pointused:'',
} }
const rootReducer = (state = globalState, action) => { const rootReducer = (state = globalState, action) => {
...@@ -79,6 +88,24 @@ const rootReducer = (state = globalState, action) => { ...@@ -79,6 +88,24 @@ const rootReducer = (state = globalState, action) => {
isEmailverif: action.data.isEmailverif, isEmailverif: action.data.isEmailverif,
} }
} }
case ActionType.SET_GRAB: {
return {
...state,
grabtype: action.data.grabtype,
grabamount: action.data.grabamount,
grabpickup: action.data.grabpickup,
grabdropoff: action.data.grabdropoff,
grabdestination: action.data.grabdestination,
}
}
case ActionType.SET_ORDERS: {
return {
...state,
balanceUsed: action.data.balanceUsed,
pointused: action.data.pointused,
}
}
case ActionType.SET_PAGE: { case ActionType.SET_PAGE: {
return { return {
...state, ...state,
......
...@@ -16,6 +16,16 @@ class MenuConfirmation extends React.Component { ...@@ -16,6 +16,16 @@ class MenuConfirmation extends React.Component {
} }
} }
componentDidMount(){
console.log(" DESTINASI : "+ this.props.grabdestination)
console.log("ONGKIR"+ this.props.grabamount)
console.log("drop off"+this.props.grabdropoff)
console.log("pickup"+this.props.grabpickup)
console.log("type" +this.props.grabtype)
console.log("BALANCED" +this.props.balanceUsed)
console.log("POINT" +this.props.pointsused)
}
render() { render() {
console.log(this.props) console.log(this.props)
let total = 0 let total = 0
...@@ -136,7 +146,14 @@ const mapStateToProps = (state) => { ...@@ -136,7 +146,14 @@ const mapStateToProps = (state) => {
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 address: state.address,
grabtype: state.grabtype,
grabamount: state.grabamount,
grabpickup: state.grabpickup,
grabdropoff:state.grabdropoff,
grabdestination:state.grabdestination,
balanceUsed: state.balanceUsed,
pointused: state.pointsused,
} }
} }
......
...@@ -28,7 +28,12 @@ class ShoppingCart extends React.Component { ...@@ -28,7 +28,12 @@ class ShoppingCart extends React.Component {
diskon: 0, diskon: 0,
isDelivery: false, isDelivery: false,
isPickUp: false, isPickUp: false,
order_item: this.props.order_item order_item: this.props.order_item,
grabtype: '',
grabamount: '',
grabpickup: '',
grabdropoff: '',
grabdestination: '',
// dummyBalance : 155000, // dummyBalance : 155000,
// dummyPoint : 20000 // dummyPoint : 20000
} }
...@@ -55,70 +60,70 @@ class ShoppingCart extends React.Component { ...@@ -55,70 +60,70 @@ class ShoppingCart extends React.Component {
handleMin(item, index) { handleMin(item, index) {
const list_order_item = this.props.order_item; const list_order_item = this.props.order_item;
let is_xist = list_order_item.find(row => row.id == item.id) let is_xist = list_order_item.find(row => row.id == item.id)
if (is_xist) { if (is_xist) {
if (is_xist.quantity != 0) { if (is_xist.quantity != 0) {
const order_item = { const order_item = {
id: item.id, id: item.id,
name: item.name, name: item.name,
price: item.price, price: item.price,
} }
this.props.reduceQuantityItem(order_item) this.props.reduceQuantityItem(order_item)
let quantity = 0 let quantity = 0
for (let i = 0; i < list_order_item.length; i++) { for (let i = 0; i < list_order_item.length; i++) {
const row = list_order_item[i]; const row = list_order_item[i];
const qty = list_order_item[i]; const qty = list_order_item[i];
if (row.id == item.id) { if (row.id == item.id) {
quantity = row.quantity quantity = row.quantity
} }
const listMenu = [...this.state.listMenu] const listMenu = [...this.state.listMenu]
listMenu[index].qty = quantity listMenu[index].qty = quantity
this.setState({ this.setState({
listMenu listMenu
}) })
}
} else if (is_xist.quantity == 0) {
const order_item = {
id: item.id,
name: item.name,
price: item.price,
}
this.props.removeFromChart(order_item)
} }
} else if (is_xist.quantity == 0) {
const order_item = {
id: item.id,
name: item.name,
price: item.price,
}
this.props.removeFromChart(order_item)
}
} }
} }
handleAdd(item, index) { handleAdd(item, index) {
const order_item = { const order_item = {
id: item.id, id: item.id,
code:item.code, code: item.code,
name: item.name, name: item.name,
description: item.description, description: item.description,
note:'jangan garing', note: 'jangan garing',
price: parseInt(item.price), price: parseInt(item.price),
} }
this.props.addToChart(order_item) this.props.addToChart(order_item)
const list_order_item = this.props.order_item; const list_order_item = this.props.order_item;
let is_xist = list_order_item.find(row => row.id == item.id) let is_xist = list_order_item.find(row => row.id == item.id)
let quantity = 0 let quantity = 0
if (is_xist) { if (is_xist) {
quantity = is_xist.quantity quantity = is_xist.quantity
} }
const listMenu = [...this.state.listMenu] const listMenu = [...this.state.listMenu]
listMenu[index].qty = quantity listMenu[index].qty = quantity
this.setState({ this.setState({
listMenu listMenu
}) })
} }
checkedSelection(val) { checkedSelection(val) {
// console.log(val) // console.log(val)
...@@ -167,57 +172,57 @@ class ShoppingCart extends React.Component { ...@@ -167,57 +172,57 @@ class ShoppingCart extends React.Component {
this.getMenuList() this.getMenuList()
this.getBalance() this.getBalance()
// this.getRate() this.getRate()
} }
getMenuList() { getMenuList() {
let params = { let params = {
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
}) })
let last_category = '' let last_category = ''
let list_menu = [] let list_menu = []
for (let i = 0; i < data.menu.length; i++) { for (let i = 0; i < data.menu.length; i++) {
const row = data.menu[i]; const row = data.menu[i];
// cari sudah ada belum di redux // cari sudah ada belum di redux
let is_xist = this.props.order_item.find(item => row.id == item.id) let is_xist = this.props.order_item.find(item => row.id == item.id)
if (is_xist) { if (is_xist) {
row['qty'] = is_xist.quantity row['qty'] = is_xist.quantity
} else { } else {
row['qty'] = 0 row['qty'] = 0
} }
if (last_category != row.category.name) { if (last_category != row.category.name) {
let category = { let category = {
"id": row.category.id, "id": row.category.id,
"name": row.category.name, "name": row.category.name,
"code": "CATEGORY" "code": "CATEGORY"
} }
list_menu.push(category) list_menu.push(category)
list_menu.push(row) list_menu.push(row)
last_category = row.category.name last_category = row.category.name
} else { } else {
list_menu.push(row) list_menu.push(row)
}
} }
} this.setState({
this.setState({ listMenu: list_menu
listMenu: list_menu })
})
}) })
} }
getRate() { getRate() {
...@@ -229,10 +234,37 @@ class ShoppingCart extends React.Component { ...@@ -229,10 +234,37 @@ class ShoppingCart extends React.Component {
order_item: this.props.order_item order_item: this.props.order_item
} }
console.log("INI PARAMETER : " + JSON.stringify(params) ); console.log("INI PARAMETER : " + JSON.stringify(params));
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/delivery/rate', params).then(res => { Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/delivery/rate', params).then(res => {
console.log("INI : " + JSON.stringify( res.data)) console.log("INI LHO CUY : " + JSON.stringify(res.data.data.destination.address))
this.setState({
grabtype: res.data.data.quotes[0].service.type,
grabamount: res.data.data.quotes[0].amount,
grabpickup: res.data.data.quotes[0].estimatedTimeline.pickup,
grabdropoff: res.data.data.quotes[0].estimatedTimeline.dropoff,
grabdestination: res.data.data.destination.address,
})
let setGrabProps = {
grabtype: this.state.grabtype,
grabamount: this.state.grabamount,
grabpickup: this.state.grabpickup,
grabdropoff: this.state.grabdropoff,
grabdestination: this.state.grabdestination,
}
this.props.setGrab(setGrabProps);
let setOrdersProps = {
balanceUsed: this.state.balanceused,
pointused: this.state.pointsused,
}
this.props.setOrder(setOrdersProps);
}).catch(error => { }).catch(error => {
console.log('ini error ' + error) console.log('ini error ' + error)
}) })
...@@ -499,7 +531,7 @@ class ShoppingCart extends React.Component { ...@@ -499,7 +531,7 @@ class ShoppingCart extends React.Component {
</View> </View>
</View> </View>
<View style={{ margin: 20, }}> <View style={{ margin: 20, }}>
<Button title='Checkout' color='#ccb46c' onPress={() => this.getRate()} /> <Button title='Checkout' color='#ccb46c' onPress={() => this.props.navigation.navigate('Confirm Your Order', { balanceUsed: this.state.balanceused, pointused: this.state.pointsused })} />
</View> </View>
</View> </View>
</ScrollView> </ScrollView>
...@@ -661,6 +693,24 @@ const mapDispatchToProps = (dispacth) => { ...@@ -661,6 +693,24 @@ const mapDispatchToProps = (dispacth) => {
item: item item: item
} }
}), }),
setGrab: (setGrabProps) => dispacth({
type: ActionType.SET_GRAB,
data: {
grabtype: setGrabProps.grabtype,
grabamount: setGrabProps.grabamount,
grabpickup: setGrabProps.grabpickup,
grabdropoff: setGrabProps.grabdropoff,
grabdestination: setGrabProps.grabdestination,
}
}),
setOrder: (setOrdersProps) => dispacth({
type: ActionType.SET_ORDERS,
data: {
balanceUsed: setOrdersProps.balanceUsed,
pointused: setOrdersProps.pointsused,
}
}),
} }
} }
......
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