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

Voucher Percentage : Modifikasi fungsi voucher menjadi voucher percentage

parent e87354e9
...@@ -15,6 +15,7 @@ import i18n from 'i18n-js'; ...@@ -15,6 +15,7 @@ import i18n from 'i18n-js';
import Constants from 'expo-constants'; import Constants from 'expo-constants';
import requestParams from '../helper/requestParams'; import requestParams from '../helper/requestParams';
import CustomIosStatusBar from './CustomIosStatusBar'; import CustomIosStatusBar from './CustomIosStatusBar';
import Spinner from 'react-native-loading-spinner-overlay';
class MenuSelection extends React.Component { class MenuSelection extends React.Component {
constructor(props) { constructor(props) {
...@@ -219,6 +220,63 @@ class MenuSelection extends React.Component { ...@@ -219,6 +220,63 @@ class MenuSelection extends React.Component {
} }
handleVoucherSelect() {
//SPINNER ON
this.setState({
spinner: true,
})
//CEK TYPE TRANSAKSINYA DELIVERY OR PICKUP, DICEK UNTUK DI MASUKAN DI PARAMATER PEMANGGILAN API
let type_trans = ""
if (this.props.type_pickup == true) {
type_trans = 'Pickup'
} else {
type_trans = 'Delivery'
}
let params = {
session_id: this.props.session_id,
trans_type: type_trans,
order_item: this.props.order_item,
reward_id: this.props.voucher.id,
delivery_charge: this.props.grabamount,
}
// MULAI DISINI PEMANGGILAN API DI MULAI, KALAU BERHASIL SET VALUE VOUCHER NYA DAN SPINER DIMATIKAN, KALAU GAGAL CABUT SESSION VOUCHER DAN SPINNER DI MATIKAN
Axios.post(this.props.BASE_URL + 'crm/v2/reward/get_value', params).then(res => {
if (this.state.state_add_remove_voucher == true) {
this.setState({
state_add_remove_voucher: false
})
this.props.removeVoucher()
} else {
let voucherProps = {
value_voucher: res.data.reward,
voucher: res.data.reward
}
this.props.setVoucher(voucherProps);
}
this.setState({
spinner: false,
})
}).catch(error => {
try {
let response = error.response.data
Alert.alert("", response.msg)
this.setState({
spinner: false,
})
// FUNGSI REDUX UNTUK HAPUS VOUCHER
this.props.removeVoucher()
} catch (error) {
Alert.alert("", error.toString())
}
})
}
renderTabBar = ({ item }) => { renderTabBar = ({ item }) => {
return ( return (
<View style={{ flex: 0.5 }}> <View style={{ flex: 0.5 }}>
...@@ -269,6 +327,9 @@ class MenuSelection extends React.Component { ...@@ -269,6 +327,9 @@ class MenuSelection extends React.Component {
} }
let res = this.props.addToChart(order_item) let res = this.props.addToChart(order_item)
if (this.props.value_voucher !== "") {
this.handleVoucherSelect()
}
// console.log('After add : ' + JSON.stringify(res)) // console.log('After add : ' + JSON.stringify(res))
// const list_order_item = this.props.order_item; // const list_order_item = this.props.order_item;
...@@ -325,6 +386,9 @@ class MenuSelection extends React.Component { ...@@ -325,6 +386,9 @@ class MenuSelection extends React.Component {
} }
} }
if (this.props.value_voucher !== "") {
this.handleVoucherSelect()
}
} }
scrollToIndex = (item) => { scrollToIndex = (item) => {
...@@ -360,6 +424,7 @@ class MenuSelection extends React.Component { ...@@ -360,6 +424,7 @@ class MenuSelection extends React.Component {
render() { render() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Spinner visible={this.state.spinner} textContent={'Loading...'} textStyle={{ color: "white" }} />
{Platform.OS === 'ios' ? ( {Platform.OS === 'ios' ? (
<CustomIosStatusBar color='#CFB368' /> <CustomIosStatusBar color='#CFB368' />
) : ( ) : (
...@@ -471,6 +536,8 @@ const mapStateToProps = (state) => { ...@@ -471,6 +536,8 @@ const mapStateToProps = (state) => {
os_version: state.os_version, os_version: state.os_version,
os_name: state.os_name, os_name: state.os_name,
app_version: state.app_version, app_version: state.app_version,
value_voucher: state.value_voucher,
voucher: state.voucher,
} }
} }
...@@ -501,6 +568,15 @@ const mapDispatchToProps = (dispacth) => { ...@@ -501,6 +568,15 @@ const mapDispatchToProps = (dispacth) => {
name_outlet: OutletChange.name_outlet, name_outlet: OutletChange.name_outlet,
} }
}), }),
setVoucher: (voucherProps) => dispacth({
type: ActionType.SET_VOUCHER,
data: {
voucher: voucherProps.voucher,
value_voucher: voucherProps.value_voucher,
}
}),
} }
} }
......
This diff is collapsed.
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