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

ini

parent 0881d4c0
......@@ -22,6 +22,7 @@ const ActionType = {
SET_CHANGE_CAMERA_ID:'SET_CHANGE_CAMERA_ID',
SET_CHANGE_OUTLET:'SET_CHANGE_OUTLET',
SET_CHANGE_SHOP:'SET_CHANGE_SHOP',
ADD_TO_CHART:'ADD_TO_CHART',
}
......
......@@ -53,6 +53,10 @@ const globalState = {
quantity:0,
orders :0,
cart_shop:[],
order_item: [],
order_quantity: 0,
order_total: 0
}
const rootReducer = (state = globalState, action) => {
......@@ -192,16 +196,8 @@ const rootReducer = (state = globalState, action) => {
}
}
case ActionType.SET_CHANGE_SHOP:{
let is_exists = cart_shop.find(item => item.id === action.data.id)
if (is_exists) {
// update
} else {
// add
}
return{
...state
}
}
case ActionType.SET_LOGOUT:{
......@@ -210,6 +206,26 @@ const rootReducer = (state = globalState, action) => {
session_id:action.data.session_id,
}
}
case ActionType.ADD_TO_CHART:{
let addedItem = action.data.order_item
let is_exist = cart_shop.find(item => addedItem.id == item.id)
if (is_exist) {
// update
addedItem.quantity += 1
} else {
// add
addedItem.quantity = 1
}
let quantity = order_quantity + 1
let total = order_total + addedItem.price
return{
...state,
order_item: [...state.order_item, addedItem],
order_quantity: quantity,
order_total: total
}
}
default:
......
......@@ -79,25 +79,13 @@ class MenuSelection extends React.Component {
}
handleAdd(item, index) {
// const listMenu = [...this.state.listMenu]
// listMenu[index].qty += 1
const order = {
handleAdd(item) {
const order_item = {
id: item.id,
name: item.name,
price: item.price,
quantity: 1
}
this.state.list_orders.push(order);
this.setState({
listMenu
})
let InsertCart = {
cart_shop: this.state.list_orders
}
this.props.setCartInsert(InsertCart)
this.props.addToChart(order_item)
}
......@@ -128,7 +116,7 @@ class MenuSelection extends React.Component {
renderItem={({ item, index }) => (
<Item navigation={this.props.navigation}
item={item}
handleAdd={() => this.handleAdd(item, index)}
handleAdd={() => this.handleAdd(item)}
handleRemove={() => this.handleRemove(item, index)}
refreshing={this.state.isFetching}
/>
......@@ -190,10 +178,16 @@ const mapStateToProps = (state) => {
const mapDispatchToProps = (dispacth) => {
return {
setCartInsert: (InsertCart) => dispacth({
setCartInsert: (data) => dispacth({
type: ActionType.SET_CHANGE_SHOP,
data: {
cart_shop: InsertCart.cart_shop
id: data.cart_shop
}
}),
addToChart: (order_item) => dispacth({
type: ActionType.ADD_TO_CHART,
data: {
order_item: order_item
}
}),
}
......
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