Commit 4dfd8979 authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

delivery address (tambah fungsi hapus alamat)

parent fa14074c
...@@ -2,10 +2,10 @@ import React from 'react'; ...@@ -2,10 +2,10 @@ import React from 'react';
import { View, Text, StyleSheet, Button, FlatList, Alert, TextInput, Image, ScrollView, ActivityIndicator } from 'react-native'; import { View, Text, StyleSheet, Button, FlatList, Alert, TextInput, Image, ScrollView, ActivityIndicator } from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler'; import { TouchableOpacity } from 'react-native-gesture-handler';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { CheckBox, Icon } from 'react-native-elements'; import { CheckBox } from 'react-native-elements';
import Axios from 'axios'; import Axios from 'axios';
import ActionType from '../redux/globalActionType'; import ActionType from '../redux/globalActionType';
import { MaterialCommunityIcons, Ionicons } from '@expo/vector-icons'; import { MaterialCommunityIcons, Ionicons, EvilIcons } from '@expo/vector-icons';
import MyStatusBar from './MyStatusBar'; import MyStatusBar from './MyStatusBar';
import i18n from 'i18n-js'; import i18n from 'i18n-js';
...@@ -26,8 +26,17 @@ class DeliveryAddrees extends React.Component { ...@@ -26,8 +26,17 @@ class DeliveryAddrees extends React.Component {
} }
componentDidMount() { componentDidMount() {
this._unsubscribe = this.props.navigation.addListener('focus', () => {
this.setState({
indicator: true
})
this.getAddreess()
});
this.getAddreess() this.getAddreess()
// console.log("INI ADDRESS ID : " + this.props.addressId) }
componentWillUnmount() {
this._unsubscribe();
} }
onChangeAddress = data => { onChangeAddress = data => {
...@@ -39,8 +48,6 @@ class DeliveryAddrees extends React.Component { ...@@ -39,8 +48,6 @@ class DeliveryAddrees extends React.Component {
let params = { let params = {
session_id: this.props.session_id, session_id: this.props.session_id,
} }
// console.log(params)
Axios.post(this.props.BASE_URL + 'crm/v2/member/get_address', params).then(res => { Axios.post(this.props.BASE_URL + 'crm/v2/member/get_address', params).then(res => {
const dataAlamat = res.data.data; const dataAlamat = res.data.data;
console.log("INI DATA :" + JSON.stringify(dataAlamat)) console.log("INI DATA :" + JSON.stringify(dataAlamat))
...@@ -218,38 +225,72 @@ class DeliveryAddrees extends React.Component { ...@@ -218,38 +225,72 @@ class DeliveryAddrees extends React.Component {
} }
deleteAddress(id) {
let params = {
session_id: this.props.session_id,
address_id: id,
}
Axios.post(this.props.BASE_URL + 'crm/v2/member/delete_address', params).then(res => {
this.componentDidMount()
}).catch(error => {
let response = error.response.data;
Alert.alert('', response.msg)
})
}
handleDeleteAddress(id) {
Alert.alert(
"",
"Apakah Anda ingin menghapus Alamat ? ",
[
{
text: "Tidak",
onPress: () => console.log("Cancel Pressed"),
style: "cancel"
},
{ text: "Ya", onPress: () => this.deleteAddress(id) }
],
{ cancelable: false }
);
}
renderItem = ({ item }) => { renderItem = ({ item }) => {
return ( return (
<View style={styles.list_addrees}> <View style={styles.list_addrees}>
<TouchableOpacity onPress={() => this.onSave(item.address, item.id, item.name)}> <View style={{ flexDirection: 'row', flex: 1 }}>
<View style={{ flex: 1, flexDirection: 'row', margin: 5, }}> <View style={{ flex: 3 }}>
<View style={{ flex: 1, justifyContent: 'center' }}> <TouchableOpacity style={{ flex: 1, flexDirection: 'row', margin: 5 }} onPress={() => this.onSave(item.address, item.id, item.name)}>
<View> <View style={{ flex: 1.5, justifyContent: 'center' }}>
<CheckBox <View>
checkedIcon='dot-circle-o' <CheckBox
uncheckedIcon='circle-o' checkedIcon='dot-circle-o'
checked={this.state.checked} uncheckedIcon='circle-o'
checkedColor="#ccb46c" checked={this.state.checked}
uncheckedColor="#ccb46c" checkedColor="#ccb46c"
/> uncheckedColor="#ccb46c"
/>
</View>
<View>
<Text style={{ textAlign: 'center', color: '#ccb46c', fontFamily: 'Gotham-Light', marginRight: 20 }}>{i18n.t('selectaddress')}</Text>
</View>
</View> </View>
<View> <View style={{ flex: 3, justifyContent: 'center' }}>
<Text style={{ textAlign: 'center', color: '#ccb46c', fontFamily: 'Gotham-Light', marginRight: 20 }}>{i18n.t('selectaddress')}</Text> <View>
<Text style={{ fontFamily: 'Gotham-Black', color: '#838383', fontSize: 15, margin: 1 }}>{item.name}</Text>
</View>
<Text style={{ fontFamily: 'Gotham-Light', color: '#838383', fontSize: 15 }}>{item.address}</Text>
</View> </View>
</TouchableOpacity>
</View> </View>
<View style={{ flex: 3, justifyContent: 'center' }}> <View style={{ flex: 0.5 }}>
<View> <TouchableOpacity style={{ flex: 1, flexDirection: 'row', margin: 5 }} onPress={() => this.handleDeleteAddress(item.id)}>
<Text style={{ fontFamily: 'Gotham-Black', color: '#838383', fontSize: 15, margin: 1 }}>{item.name}</Text> <View style={{ justifyContent: 'center' }}>
<EvilIcons name="trash" size={40} color="black" />
</View> </View>
<Text style={{ fontFamily: 'Gotham-Light', color: '#838383', fontSize: 15 }}>{item.address}</Text> </TouchableOpacity>
</View>
</View> </View>
</TouchableOpacity> </View>
</View> </View>
); );
} }
render() { render() {
...@@ -279,7 +320,6 @@ class DeliveryAddrees extends React.Component { ...@@ -279,7 +320,6 @@ class DeliveryAddrees extends React.Component {
<Text style={{ fontFamily: 'Gotham-Black', textAlign: 'center', color: 'white', fontSize: 16 }}> {i18n.t('addaddress')} </Text> <Text style={{ fontFamily: 'Gotham-Black', textAlign: 'center', color: 'white', fontSize: 16 }}> {i18n.t('addaddress')} </Text>
</View> </View>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
<View style={styles.listAddress}> <View style={styles.listAddress}>
{this.state.indicator == true ? ( {this.state.indicator == true ? (
......
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