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

nambahin pengecekan di delivery dan pickup

parent d5772b63
...@@ -83,6 +83,8 @@ class DeliveryAddrees extends React.Component { ...@@ -83,6 +83,8 @@ class DeliveryAddrees extends React.Component {
}) })
} }
getRate(address_id) { getRate(address_id) {
// console.log('ADdress id : ' + address_id) // console.log('ADdress id : ' + address_id)
...@@ -160,55 +162,58 @@ class DeliveryAddrees extends React.Component { ...@@ -160,55 +162,58 @@ class DeliveryAddrees extends React.Component {
onSave(address, id, name) { onSave(address, id, name) {
if (this.props.value_voucher !== "") {
let setDataAddress = { this.handleVoucherSelect()
address: address, } else {
addressId: id, let setDataAddress = {
home_address: name address: address,
} addressId: id,
home_address: name
this.props.setAddress(setDataAddress);
let params = {
session_id: this.props.session_id,
address_id: id,
}
Axios.post(this.props.BASE_URL + 'crm/v2/delivery/rate', params).then(res => {
let setGrabProps = {
// grabdestination: this.state.grabdestination,
// grabamount: this.state.grabamount,
grabamount: res.data.data.amount
}
let OutletChange = {
outlet_id: res.data.data.outlet_id,
name_outlet: res.data.data.outlet_name,
} }
this.props.setGrab(setGrabProps); this.props.setAddress(setDataAddress);
this.props.setChangeOutletProps(OutletChange);
this.props.setTypePickup(false) let params = {
session_id: this.props.session_id,
if (this.props.route.params.from == 'shoppingCart') { address_id: id,
this.props.navigation.navigate('Shopping Cart', { outlet_change: true, outlet_id: res.data.data.outlet_id })
} else {
this.props.navigation.navigate('Home', {
screen: 'MENU',
params: { user: 'janeT' },
});
} }
Axios.post(this.props.BASE_URL + 'crm/v2/delivery/rate', params).then(res => {
let setGrabProps = {
// grabdestination: this.state.grabdestination,
// grabamount: this.state.grabamount,
grabamount: res.data.data.amount
}
let OutletChange = {
outlet_id: res.data.data.outlet_id,
name_outlet: res.data.data.outlet_name,
}
this.props.setGrab(setGrabProps);
this.props.setChangeOutletProps(OutletChange);
this.props.setTypePickup(false)
if (this.props.route.params.from == 'shoppingCart') {
this.props.navigation.navigate('Shopping Cart', { outlet_change: true, outlet_id: res.data.data.outlet_id })
} else {
this.props.navigation.navigate('Home', {
screen: 'MENU',
params: { user: 'janeT' },
});
}
}).catch(error => {
let response = error.response.data;
console.log('ini error ' + response.msg)
Alert.alert('', response.msg)
})
}
}).catch(error => {
let response = error.response.data;
console.log('ini error ' + response.msg)
Alert.alert('', response.msg)
})
// let recalculateProps = { // let recalculateProps = {
// order_total: 0, // order_total: 0,
// order_quantity:0, // order_quantity:0,
...@@ -226,7 +231,6 @@ class DeliveryAddrees extends React.Component { ...@@ -226,7 +231,6 @@ class DeliveryAddrees extends React.Component {
// { cancelable: false } // { cancelable: false }
// ) // )
} }
deleteAddress(id) { deleteAddress(id) {
...@@ -242,6 +246,64 @@ class DeliveryAddrees extends React.Component { ...@@ -242,6 +246,64 @@ class DeliveryAddrees 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())
}
})
}
handleDeleteAddress(id) { handleDeleteAddress(id) {
Alert.alert( Alert.alert(
"", "",
...@@ -394,8 +456,30 @@ const mapStateToProps = (state) => { ...@@ -394,8 +456,30 @@ const mapStateToProps = (state) => {
session_id: state.session_id, session_id: state.session_id,
addressId: state.addressId, addressId: state.addressId,
language: state.language, language: state.language,
outlet_detailadress: state.outlet_detailadress,
home_address: state.home_address,
type_pickup: state.type_pickup,
value_voucher: state.value_voucher,
voucher: state.voucher,
session_id: state.session_id,
outlet_id: state.outlet_id,
name_outlet: state.name_outlet,
value_voucher: state.value_voucher,
voucher: state.voucher,
order_quantity: state.order_quantity,
order_total: state.order_total,
order_item: state.order_item,
quantity: state.quantity,
address: state.address,
addressId: state.addressId,
grabtype: state.grabtype,
grabamount: state.grabamount,
grabpickup: state.grabpickup,
grabdropoff: state.grabdropoff,
grabdestination: state.grabdestination,
BASE_URL: state.BASE_URL BASE_URL: state.BASE_URL
} }
} }
...@@ -445,6 +529,9 @@ const mapDispatchToProps = (dispacth) => { ...@@ -445,6 +529,9 @@ const mapDispatchToProps = (dispacth) => {
type_pickup: type type_pickup: type
} }
}), }),
removeVoucher: () => dispacth({
type: ActionType.REMOVE_VOUCHER
}),
} }
} }
......
...@@ -44,15 +44,15 @@ class Home extends React.Component { ...@@ -44,15 +44,15 @@ class Home extends React.Component {
member_since: "", member_since: "",
old_balance: 0, old_balance: 0,
expired: '', expired: '',
card_number: '' card_number: ''
} }
} }
componentDidMount() { componentDidMount() {
this.loadAll() this.loadAll()
} }
loadAll(){ loadAll() {
this.CheckInbox() this.CheckInbox()
const screenWidth = Math.round(Dimensions.get('window').width); const screenWidth = Math.round(Dimensions.get('window').width);
...@@ -95,7 +95,7 @@ class Home extends React.Component { ...@@ -95,7 +95,7 @@ class Home extends React.Component {
let params = Object.assign(requestParams, { let params = Object.assign(requestParams, {
session_id: this.props.session_id, session_id: this.props.session_id,
}) })
Axios.post( this.props.BASE_URL + 'crm/v2/inbox/unread_count', params).then(respon => { Axios.post(this.props.BASE_URL + 'crm/v2/inbox/unread_count', params).then(respon => {
let res = respon.data.unread_count let res = respon.data.unread_count
this.setState({ this.setState({
...@@ -139,7 +139,7 @@ class Home extends React.Component { ...@@ -139,7 +139,7 @@ class Home extends React.Component {
this._getCurrentPosisition() this._getCurrentPosisition()
} }
} }
_getCurrentPosisition = async () => { _getCurrentPosisition = async () => {
let location = await Location.getCurrentPositionAsync({ let location = await Location.getCurrentPositionAsync({
accuracy: Location.Accuracy.Highest accuracy: Location.Accuracy.Highest
}) })
...@@ -188,7 +188,7 @@ class Home extends React.Component { ...@@ -188,7 +188,7 @@ class Home extends React.Component {
let params = Object.assign(requestParams, { let params = Object.assign(requestParams, {
session_id: this.props.session_id, session_id: this.props.session_id,
}) })
this.setState({indicatorProfileCard: true}) this.setState({ indicatorProfileCard: true })
Axios.post(this.props.BASE_URL + 'crm/v2/member/get_profile', params).then(res => { Axios.post(this.props.BASE_URL + 'crm/v2/member/get_profile', params).then(res => {
const dataCard = res.data const dataCard = res.data
...@@ -269,15 +269,23 @@ class Home extends React.Component { ...@@ -269,15 +269,23 @@ class Home extends React.Component {
} }
}).catch(error => { }).catch(error => {
let response = error.response.data let response = error.response.data
Alert.alert("Error", response.msg) Alert.alert("Error", response.msg)
}) })
} }
_pickup() { _pickup() {
let typeProps = {
type_pickup: true,
}
this.props.setTypePickup(typeProps);
this.props.navigation.navigate('Pickup Name', { from: 'home' }); this.props.navigation.navigate('Pickup Name', { from: 'home' });
} }
_delivery() { _delivery() {
let typeProps = {
type_pickup: false,
}
this.props.setTypePickup(typeProps);
this.props.navigation.navigate('Delivery Address', { from: 'home' }); this.props.navigation.navigate('Delivery Address', { from: 'home' });
} }
...@@ -296,32 +304,32 @@ class Home extends React.Component { ...@@ -296,32 +304,32 @@ class Home extends React.Component {
} }
handleClaimCredit() { handleClaimCredit() {
this.setState({spinner: true}) this.setState({ spinner: true })
this.setState({old_balance_claimed: true}) /** set jadi true dulu buat hilangkan bagian claim credit */ this.setState({ old_balance_claimed: true }) /** set jadi true dulu buat hilangkan bagian claim credit */
this.setState({indicatorProfileCard: true}) /** atau sekalian dibuat loading aja bagian profilecardnya */ this.setState({ indicatorProfileCard: true }) /** atau sekalian dibuat loading aja bagian profilecardnya */
let params = Object.assign(requestParams, { let params = Object.assign(requestParams, {
session_id: this.props.session_id, session_id: this.props.session_id,
}) })
console.log("start processing claim_old_balance") console.log("start processing claim_old_balance")
Axios.post(this.props.BASE_URL + 'crm/v2/card/claim_old_balance', params).then(res => { Axios.post(this.props.BASE_URL + 'crm/v2/card/claim_old_balance', params).then(res => {
console.log("success processing claim_old_balance") console.log("success processing claim_old_balance")
this.setState({spinner: false}) this.setState({ spinner: false })
this._account() this._account()
// Alert.alert(i18n.t('success'), i18n.t('alertclaimcredit')) // Alert.alert(i18n.t('success'), i18n.t('alertclaimcredit'))
}).catch(error => { }).catch(error => {
console.log("failed processing claim_old_balance") console.log("failed processing claim_old_balance")
this._account() this._account()
let response = error.response.data let response = error.response.data
Alert.alert( Alert.alert(
"Error", "Error",
response.msg, response.msg,
[ [
{ {
text: 'OK', onPress: () => this.setState({spinner: false}) text: 'OK', onPress: () => this.setState({ spinner: false })
} }
] ]
); );
}) })
} }
...@@ -337,7 +345,7 @@ class Home extends React.Component { ...@@ -337,7 +345,7 @@ class Home extends React.Component {
style: 'cancel', style: 'cancel',
}, },
{ {
text: i18n.t('alertyes'), onPress: () => { text: i18n.t('alertyes'), onPress: () => {
this.handleClaimCredit() this.handleClaimCredit()
} }
}, },
...@@ -356,7 +364,7 @@ class Home extends React.Component { ...@@ -356,7 +364,7 @@ class Home extends React.Component {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Spinner visible={this.state.spinner} textContent={'Loading...'} textStyle={{ color: "white" }} /> <Spinner visible={this.state.spinner} textContent={'Loading...'} textStyle={{ color: "white" }} />
{Platform.OS === 'ios' ? ( {Platform.OS === 'ios' ? (
<CustomIosStatusBar color='#CFB368' /> <CustomIosStatusBar color='#CFB368' />
...@@ -506,7 +514,7 @@ class Home extends React.Component { ...@@ -506,7 +514,7 @@ class Home extends React.Component {
</Card> </Card>
) )
} }
{ {
this.state.indicatorProfileCard == true ? ( this.state.indicatorProfileCard == true ? (
<View style={styles.card}> <View style={styles.card}>
...@@ -515,7 +523,7 @@ class Home extends React.Component { ...@@ -515,7 +523,7 @@ class Home extends React.Component {
</Card> </Card>
</View> </View>
) : ) :
//jika member belum punya account kaspro //jika member belum punya account kaspro
this.state.account_number == "" ? ( this.state.account_number == "" ? (
<View style={styles.card}> <View style={styles.card}>
...@@ -542,7 +550,7 @@ class Home extends React.Component { ...@@ -542,7 +550,7 @@ class Home extends React.Component {
<Text style={{ fontSize: 10, fontFamily: 'Gotham-Light' }}>{i18n.t('cardnumber')}</Text> <Text style={{ fontSize: 10, fontFamily: 'Gotham-Light' }}>{i18n.t('cardnumber')}</Text>
</View> </View>
<View style={{ flex: 0.5 }}> <View style={{ flex: 0.5 }}>
<Text style={{ fontSize: 10, textAlign: 'right', fontFamily: 'Gotham-Light' }}> <Text style={{ fontSize: 10, textAlign: 'right', fontFamily: 'Gotham-Light' }}>
{i18n.t('expired')} {this.state.expired} {i18n.t('expired')} {this.state.expired}
</Text> </Text>
</View> </View>
...@@ -563,7 +571,7 @@ class Home extends React.Component { ...@@ -563,7 +571,7 @@ class Home extends React.Component {
</View> </View>
</View> </View>
{/* <View style={styles.line2}></View> */} {/* <View style={styles.line2}></View> */}
<View style={{ flexDirection: 'row', flex: 1, display:'none' }}> <View style={{ flexDirection: 'row', flex: 1, display: 'none' }}>
<View style={{ flex: 0.3, justifyContent: 'center' }}> <View style={{ flex: 0.3, justifyContent: 'center' }}>
{/* <Text>{i18n.t('balance')}</Text> */} {/* <Text>{i18n.t('balance')}</Text> */}
<Text style={{ fontSize: 14, fontFamily: 'Gotham-Light' }}>{i18n.t('point')} : </Text> <Text style={{ fontSize: 14, fontFamily: 'Gotham-Light' }}>{i18n.t('point')} : </Text>
...@@ -572,7 +580,7 @@ class Home extends React.Component { ...@@ -572,7 +580,7 @@ class Home extends React.Component {
<Text style={{ fontSize: 14, fontFamily: 'Gotham-Black', color: 'gray' }}>IDR {this.state.point}</Text> <Text style={{ fontSize: 14, fontFamily: 'Gotham-Black', color: 'gray' }}>IDR {this.state.point}</Text>
</View> </View>
</View> </View>
</Card> </Card>
{this.state.old_balance_claimed == false ? ( {this.state.old_balance_claimed == false ? (
this.state.old_balance == 0 ? (null) : this.state.old_balance == 0 ? (null) :
(<Card style={{ padding: 10, margin: 10, alignContent: 'center' }}> (<Card style={{ padding: 10, margin: 10, alignContent: 'center' }}>
...@@ -590,7 +598,7 @@ class Home extends React.Component { ...@@ -590,7 +598,7 @@ class Home extends React.Component {
) : (null)} ) : (null)}
</View> </View>
) : ) :
/** If gak punya kaspro, dan sudah expired */ /** If gak punya kaspro, dan sudah expired */
this.state.account_number == "" && this.state.is_expired == true ? ( this.state.account_number == "" && this.state.is_expired == true ? (
<View style={styles.card}> <View style={styles.card}>
...@@ -621,7 +629,7 @@ class Home extends React.Component { ...@@ -621,7 +629,7 @@ class Home extends React.Component {
</View> </View>
</View> </View>
{/* <View style={styles.line2}></View> */} {/* <View style={styles.line2}></View> */}
<View style={{ flexDirection: 'row', flex: 1, display:'none' }}> <View style={{ flexDirection: 'row', flex: 1, display: 'none' }}>
<View style={{ flex: 0.3, justifyContent: 'center' }}> <View style={{ flex: 0.3, justifyContent: 'center' }}>
{/* <Text>{i18n.t('balance')}</Text> */} {/* <Text>{i18n.t('balance')}</Text> */}
<Text style={{ fontSize: 14, fontFamily: 'Gotham-Light' }}>{i18n.t('point')} : </Text> <Text style={{ fontSize: 14, fontFamily: 'Gotham-Light' }}>{i18n.t('point')} : </Text>
...@@ -655,17 +663,17 @@ class Home extends React.Component { ...@@ -655,17 +663,17 @@ class Home extends React.Component {
</Card>) </Card>)
) : (null)} ) : (null)}
</View> </View>
) : ) :
/** punya kaspro ( expired atau tidak ) */ /** punya kaspro ( expired atau tidak ) */
( (
<View style={styles.card}> <View style={styles.card}>
<Card style={{ padding: 20, margin: 10, alignContent: 'center' }}> <Card style={{ padding: 20, margin: 10, alignContent: 'center' }}>
<View style={{ flexDirection: 'row', flex: 1, paddingBottom: 5 }}> <View style={{ flexDirection: 'row', flex: 1, paddingBottom: 5 }}>
<View style={{ flex: 0.5 }}> <View style={{ flex: 0.5 }}>
<Text style={{ fontSize: 10, fontFamily: 'Gotham-Light' }}>{i18n.t('cardnumber')}</Text> <Text style={{ fontSize: 10, fontFamily: 'Gotham-Light' }}>{i18n.t('cardnumber')}</Text>
</View> </View>
<View style={{ flex: 0.5 }}> <View style={{ flex: 0.5 }}>
<Text style={{ fontSize: 10, textAlign: 'right', fontFamily: 'Gotham-Light', color: this.state.expired ? "red" : "" }}> <Text style={{ fontSize: 10, textAlign: 'right', fontFamily: 'Gotham-Light', color: this.state.expired ? "red" : "" }}>
{i18n.t('expired')} {this.state.expired} {i18n.t('expired')} {this.state.expired}
</Text> </Text>
...@@ -686,7 +694,7 @@ class Home extends React.Component { ...@@ -686,7 +694,7 @@ class Home extends React.Component {
</View> </View>
</View> </View>
{/* <View style={styles.line2}></View> */} {/* <View style={styles.line2}></View> */}
<View style={{ flexDirection: 'row', flex: 1, display:'none' }}> <View style={{ flexDirection: 'row', flex: 1, display: 'none' }}>
<View style={{ flex: 0.3, justifyContent: 'center' }}> <View style={{ flex: 0.3, justifyContent: 'center' }}>
<Text style={{ fontSize: 14, fontFamily: 'Gotham-Light' }}>{i18n.t('point')} : </Text> <Text style={{ fontSize: 14, fontFamily: 'Gotham-Light' }}>{i18n.t('point')} : </Text>
</View> </View>
...@@ -904,7 +912,14 @@ const mapDispatchToProps = (dispacth) => { ...@@ -904,7 +912,14 @@ const mapDispatchToProps = (dispacth) => {
session_id: configProps.session_id session_id: configProps.session_id
} }
}), }),
setTypePickup: (typeProps) => dispacth({
type: ActionType.SET_TYPE,
data: {
type_pickup: typeProps.type_pickup
}
}),
} }
} }
......
...@@ -273,7 +273,6 @@ class MenuSelection extends React.Component { ...@@ -273,7 +273,6 @@ class MenuSelection extends React.Component {
Alert.alert("", error.toString()) Alert.alert("", error.toString())
} }
}) })
} }
renderTabBar = ({ item }) => { renderTabBar = ({ item }) => {
......
...@@ -39,6 +39,64 @@ class PickupName extends React.Component { ...@@ -39,6 +39,64 @@ class PickupName 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())
}
})
}
_getPermissions = async () => { _getPermissions = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION); let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') { if (status !== 'granted') {
...@@ -70,30 +128,36 @@ class PickupName extends React.Component { ...@@ -70,30 +128,36 @@ class PickupName extends React.Component {
getOutletDetail(id, name, address) { getOutletDetail(id, name, address) {
let OutletChange = { if (this.props.value_voucher !== "") {
outlet_id: id, this.handleVoucherSelect()
name_outlet: name,
outlet_detailadress: address }else{
} let OutletChange = {
outlet_id: id,
// let recalculateProps = { name_outlet: name,
// order_total: 0, outlet_detailadress: address
// order_quantity:0, }
// order_item:[]
// } // let recalculateProps = {
// this.props.setRecalculate(recalculateProps) // order_total: 0,
this.props.setChangeOutletProps(OutletChange); // order_quantity:0,
this.props.setTypePickup(true); // order_item:[]
// }
if (this.props.route.params.from == 'shoppingCart') { // this.props.setRecalculate(recalculateProps)
this.props.navigation.navigate('Shopping Cart', { outlet_change: true, outlet_id: id }) this.props.setChangeOutletProps(OutletChange);
} else { this.props.setTypePickup(true);
this.props.navigation.navigate('Home', { if (this.props.route.params.from == 'shoppingCart') {
screen: 'MENU', this.props.navigation.navigate('Shopping Cart', { outlet_change: true, outlet_id: id })
params: { user: 'jane' }, } else {
})
this.props.navigation.navigate('Home', {
screen: 'MENU',
params: { user: 'jane' },
})
}
} }
} }
getOutlet() { getOutlet() {
...@@ -192,11 +256,13 @@ class PickupName extends React.Component { ...@@ -192,11 +256,13 @@ class PickupName extends React.Component {
} }
select(item) { select(item) {
let OutletChange = {
outlet_id: item.id, let OutletChange = {
name_outlet: item.name, outlet_id: item.id,
} name_outlet: item.name,
this.props.setChangeOutletProps(OutletChange) }
this.props.setChangeOutletProps(OutletChange)
this.props.navigation.navigate('Home', { screen: 'MENU' }); this.props.navigation.navigate('Home', { screen: 'MENU' });
} }
...@@ -391,6 +457,9 @@ const mapDispatchToProps = (dispacth) => { ...@@ -391,6 +457,9 @@ const mapDispatchToProps = (dispacth) => {
} }
}), }),
removeVoucher: () => dispacth({
type: ActionType.REMOVE_VOUCHER
}),
} }
} }
...@@ -402,7 +471,30 @@ const mapStateToProps = (state) => { ...@@ -402,7 +471,30 @@ const mapStateToProps = (state) => {
name_outlet: state.name_outlet, name_outlet: state.name_outlet,
outlet_detailadress: state.outlet_detailadress, outlet_detailadress: state.outlet_detailadress,
language: state.language, language: state.language,
BASE_URL: state.BASE_URL value_voucher: state.value_voucher,
voucher: state.voucher,
outlet_detailadress: state.outlet_detailadress,
home_address: state.home_address,
type_pickup: state.type_pickup,
value_voucher: state.value_voucher,
voucher: state.voucher,
session_id: state.session_id,
outlet_id: state.outlet_id,
name_outlet: state.name_outlet,
value_voucher: state.value_voucher,
voucher: state.voucher,
order_quantity: state.order_quantity,
order_total: state.order_total,
order_item: state.order_item,
quantity: state.quantity,
address: state.address,
addressId: state.addressId,
grabtype: state.grabtype,
grabamount: state.grabamount,
grabpickup: state.grabpickup,
grabdropoff: state.grabdropoff,
grabdestination: state.grabdestination,
BASE_URL: state.BASE_URL,
} }
} }
......
...@@ -9,6 +9,7 @@ import requestParams from '../helper/requestParams'; ...@@ -9,6 +9,7 @@ import requestParams from '../helper/requestParams';
import ActionType from '../redux/globalActionType'; import ActionType from '../redux/globalActionType';
import MyStatusBar from './MyStatusBar'; import MyStatusBar from './MyStatusBar';
import i18n from 'i18n-js'; import i18n from 'i18n-js';
import Spinner from 'react-native-loading-spinner-overlay';
class RewardDetail extends React.Component { class RewardDetail extends React.Component {
constructor(props) { constructor(props) {
...@@ -25,6 +26,7 @@ class RewardDetail extends React.Component { ...@@ -25,6 +26,7 @@ class RewardDetail extends React.Component {
value: '', value: '',
cur_time: '', cur_time: '',
exp_time: '', exp_time: '',
spinner: false
} }
} }
...@@ -33,14 +35,14 @@ class RewardDetail extends React.Component { ...@@ -33,14 +35,14 @@ class RewardDetail extends React.Component {
} }
detailReward() { detailReward() {
let params = Object.assign(requestParams,{ let params = Object.assign(requestParams, {
session_id: this.props.session_id, session_id: this.props.session_id,
reward_id: this.props.route.params.rewardId reward_id: this.props.route.params.rewardId
}) })
Axios.post(this.props.BASE_URL+'crm/v2/reward/get_detail', params).then(res => { Axios.post(this.props.BASE_URL + 'crm/v2/reward/get_detail', params).then(res => {
let exp_time = new Date(res.data.reward.expire_time) let exp_time = new Date(res.data.reward.expire_time)
let cur_time = new Date() let cur_time = new Date()
let expire_date = moment(res.data.reward.expire_time).format('DD MMMM YYYY') let expire_date = moment(res.data.reward.expire_time).format('DD MMMM YYYY')
this.setState({ this.setState({
...@@ -66,14 +68,62 @@ class RewardDetail extends React.Component { ...@@ -66,14 +68,62 @@ class RewardDetail extends React.Component {
} }
useVoucher() { handleVoucherSelect() {
let voucherProps = { //SPINNER ON
value_voucher: this.state.value, this.setState({
voucher: this.state.value 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.route.params.rewardId,
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 => {
let voucherProps = {
value_voucher: res.data.reward,
voucher: res.data.reward
}
this.props.setVoucher(voucherProps);
this.setState({
spinner: false,
})
this.props.navigation.navigate('Home', { screen: 'MENU' })
this.props.setVoucher(voucherProps); }).catch(error => {
this.props.navigation.navigate('Home', { screen: 'MENU' }) try {
let response = error.response.data;
Alert.alert(
'',
response.msg,
[
{ text: "OK", onPress: () => this.setState({spinner: false}) }
],
);
// FUNGSI REDUX UNTUK HAPUS VOUCHER
this.props.removeVoucher()
} catch (error) {
Alert.alert("", error.toString())
}
})
}
useVoucher() {
this.handleVoucherSelect()
} }
...@@ -86,6 +136,7 @@ class RewardDetail extends React.Component { ...@@ -86,6 +136,7 @@ class RewardDetail extends React.Component {
console.log(this.state.content) console.log(this.state.content)
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Spinner visible={this.state.spinner} textContent={'Loading...'} textStyle={{ color: "white" }} />
<MyStatusBar /> <MyStatusBar />
<ScrollView> <ScrollView>
<View style={styles.images}> <View style={styles.images}>
...@@ -125,9 +176,9 @@ class RewardDetail extends React.Component { ...@@ -125,9 +176,9 @@ class RewardDetail extends React.Component {
<View style={styles.content}> <View style={styles.content}>
{this.state.cur_time > this.state.exp_time ? ( {this.state.cur_time > this.state.exp_time ? (
<View style={{ flex: 1, height: 50, marginRight: 70, marginLeft: 70, justifyContent: 'center' }}> <View style={{ flex: 1, height: 50, marginRight: 70, marginLeft: 70, justifyContent: 'center' }}>
<View style={{ height: 40, borderRadius: 10, backgroundColor: 'red' }}> <View style={{ height: 40, borderRadius: 10, backgroundColor: 'red' }}>
<Text style={{ fontFamily: 'Gotham-Black', color: 'white', fontSize: 16, textAlign: 'center', margin: 11 }}>{i18n.t('expiredLabel')}</Text> <Text style={{ fontFamily: 'Gotham-Black', color: 'white', fontSize: 16, textAlign: 'center', margin: 11 }}>{i18n.t('expiredLabel')}</Text>
</View> </View>
</View> </View>
) )
: this.state.used == 0 ? ( : this.state.used == 0 ? (
...@@ -250,6 +301,9 @@ const mapDispatchToProps = (dispacth) => { ...@@ -250,6 +301,9 @@ const mapDispatchToProps = (dispacth) => {
} }
}), }),
removeVoucher: () => dispacth({
type: ActionType.REMOVE_VOUCHER
}),
} }
} }
...@@ -260,6 +314,27 @@ const mapStateToProps = (state) => { ...@@ -260,6 +314,27 @@ const mapStateToProps = (state) => {
lat: state.lat, lat: state.lat,
long: state.long, long: state.long,
BASE_URL: state.BASE_URL, BASE_URL: state.BASE_URL,
outlet_detailadress: state.outlet_detailadress,
home_address: state.home_address,
type_pickup: state.type_pickup,
value_voucher: state.value_voucher,
voucher: state.voucher,
session_id: state.session_id,
outlet_id: state.outlet_id,
name_outlet: state.name_outlet,
value_voucher: state.value_voucher,
voucher: state.voucher,
order_quantity: state.order_quantity,
order_total: state.order_total,
order_item: state.order_item,
quantity: state.quantity,
address: state.address,
addressId: state.addressId,
grabtype: state.grabtype,
grabamount: state.grabamount,
grabpickup: state.grabpickup,
grabdropoff: state.grabdropoff,
grabdestination: state.grabdestination,
} }
} }
......
...@@ -18,7 +18,9 @@ class RewardSelect extends React.Component { ...@@ -18,7 +18,9 @@ class RewardSelect extends React.Component {
} }
componentDidMount() { componentDidMount() {
// console.log("INI URL NYA :"+this.props.BASE_URL);
console.log(" DATA PROPS : "+this.props.type_pickup);
this.getRewardsList() this.getRewardsList()
this._unsubscribe = this.props.navigation.addListener('focus', () => { this._unsubscribe = this.props.navigation.addListener('focus', () => {
this.getRewardsList() this.getRewardsList()
...@@ -35,13 +37,12 @@ class RewardSelect extends React.Component { ...@@ -35,13 +37,12 @@ class RewardSelect extends React.Component {
// value_voucher: this.state.value, // value_voucher: this.state.value,
// voucher: this.state.code // voucher: this.state.code
// } // }
// this.props.setVoucher(voucherProps); // this.props.setVoucher(voucherProps);
// this.props.navigation.navigate('Home', { screen: 'MENU' }) // this.props.navigation.navigate('Home', { screen: 'MENU' })
// } // }
handleSelect(item) { handleSelect(item) {
let type_trans = "" let type_trans = ""
if (this.props.type_pickup == true) { if (this.props.type_pickup == true) {
type_trans = 'Pickup' type_trans = 'Pickup'
...@@ -56,7 +57,7 @@ class RewardSelect extends React.Component { ...@@ -56,7 +57,7 @@ class RewardSelect extends React.Component {
reward_id: item.id, reward_id: item.id,
delivery_charge: this.props.grabamount, delivery_charge: this.props.grabamount,
} }
console.log(params) // console.log(params)
Axios.post(this.props.BASE_URL + 'crm/v2/reward/get_value', params).then(res => { Axios.post(this.props.BASE_URL + 'crm/v2/reward/get_value', params).then(res => {
// console.log(res.data.reward) // console.log(res.data.reward)
let detail = res.data.reward let detail = res.data.reward
......
...@@ -88,15 +88,12 @@ class ShoppingCart extends React.Component { ...@@ -88,15 +88,12 @@ class ShoppingCart extends React.Component {
} }
checkChangeTrans(val) { checkChangeTrans(val) {
if (val == 'delivery') { if (val == 'delivery') {
// let typeProps = { // let typeProps = {
// type_pickup: false, // type_pickup: false,
// } // }
// this.props.setTypePickup(typeProps); // this.props.setTypePickup(typeProps);
if (this.props.value_voucher !== "") {
this.handleVoucherSelect()
}
this.setState({ this.setState({
checkedBalance: false, checkedBalance: false,
checkedPoint: false, checkedPoint: false,
...@@ -105,15 +102,20 @@ class ShoppingCart extends React.Component { ...@@ -105,15 +102,20 @@ class ShoppingCart extends React.Component {
balanceused: 0 balanceused: 0
}) })
let typeProps = {
type_pickup: false,
}
this.props.setTypePickup(typeProps);
this.props.navigation.navigate("Delivery Address", { from: 'shoppingCart' }) this.props.navigation.navigate("Delivery Address", { from: 'shoppingCart' })
} else { } else {
// let typeProps = {
// type_pickup: true, let typeProps = {
// } type_pickup: true,
// this.props.setTypePickup(typeProps);
if (this.props.value_voucher !== "") {
this.handleVoucherSelect()
} }
this.props.setTypePickup(typeProps);
this.setState({ this.setState({
checkedBalance: false, checkedBalance: false,
checkedPoint: false, checkedPoint: false,
...@@ -122,6 +124,7 @@ class ShoppingCart extends React.Component { ...@@ -122,6 +124,7 @@ class ShoppingCart extends React.Component {
balanceused: 0 balanceused: 0
}) })
this.props.navigation.navigate('Pickup Name', { from: 'shoppingCart' }) this.props.navigation.navigate('Pickup Name', { from: 'shoppingCart' })
} }
} }
...@@ -158,13 +161,18 @@ class ShoppingCart extends React.Component { ...@@ -158,13 +161,18 @@ class ShoppingCart extends React.Component {
state_add_remove_voucher: false state_add_remove_voucher: false
}) })
this.props.removeVoucher() this.props.removeVoucher()
this.setState({
spinner: false,
})
} else{ } else{
let voucherProps = { let voucherProps = {
value_voucher: res.data.reward, value_voucher: res.data.reward,
voucher: res.data.reward voucher: res.data.reward
} }
this.props.setVoucher(voucherProps); this.props.setVoucher(voucherProps);
this.setState({
spinner: false,
})
} }
this.setState({ this.setState({
...@@ -174,10 +182,11 @@ class ShoppingCart extends React.Component { ...@@ -174,10 +182,11 @@ class ShoppingCart extends React.Component {
}).catch(error => { }).catch(error => {
try { try {
let response = error.response.data let response = error.response.data
Alert.alert("", response.msg) console.log("RESPONSE : "+ response)
this.setState({ // Alert.alert("", response.msg)
spinner: false, // this.setState({
}) // spinner: false,
// })
// FUNGSI REDUX UNTUK HAPUS VOUCHER // FUNGSI REDUX UNTUK HAPUS VOUCHER
this.props.removeVoucher() this.props.removeVoucher()
} catch (error) { } catch (error) {
...@@ -187,7 +196,6 @@ class ShoppingCart extends React.Component { ...@@ -187,7 +196,6 @@ class ShoppingCart extends React.Component {
} }
handleRemoveVoucher() { handleRemoveVoucher() {
//panggil spiner //panggil spiner
if (this.props.value_voucher !== "") { if (this.props.value_voucher !== "") {
...@@ -204,9 +212,7 @@ class ShoppingCart extends React.Component { ...@@ -204,9 +212,7 @@ class ShoppingCart extends React.Component {
balanceused: 0, balanceused: 0,
state_add_remove_voucher: true state_add_remove_voucher: true
}) })
// this.props.removeVoucher() // this.props.removeVoucher()
} }
handleAddVoucher() { handleAddVoucher() {
......
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