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';
import { View, Text, StyleSheet, Button, FlatList, Alert, TextInput, Image, ScrollView, ActivityIndicator } from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler';
import { connect } from 'react-redux';
import { CheckBox, Icon } from 'react-native-elements';
import { CheckBox } from 'react-native-elements';
import Axios from 'axios';
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 i18n from 'i18n-js';
......@@ -26,8 +26,17 @@ class DeliveryAddrees extends React.Component {
}
componentDidMount() {
this._unsubscribe = this.props.navigation.addListener('focus', () => {
this.setState({
indicator: true
})
this.getAddreess()
});
this.getAddreess()
// console.log("INI ADDRESS ID : " + this.props.addressId)
}
componentWillUnmount() {
this._unsubscribe();
}
onChangeAddress = data => {
......@@ -39,8 +48,6 @@ class DeliveryAddrees extends React.Component {
let params = {
session_id: this.props.session_id,
}
// console.log(params)
Axios.post(this.props.BASE_URL + 'crm/v2/member/get_address', params).then(res => {
const dataAlamat = res.data.data;
console.log("INI DATA :" + JSON.stringify(dataAlamat))
......@@ -218,13 +225,42 @@ 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 }) => {
return (
<View style={styles.list_addrees}>
<TouchableOpacity onPress={() => this.onSave(item.address, item.id, item.name)}>
<View style={{ flex: 1, flexDirection: 'row', margin: 5, }}>
<View style={{ flex: 1, justifyContent: 'center' }}>
<View style={{ flexDirection: 'row', flex: 1 }}>
<View style={{ flex: 3 }}>
<TouchableOpacity style={{ flex: 1, flexDirection: 'row', margin: 5 }} onPress={() => this.onSave(item.address, item.id, item.name)}>
<View style={{ flex: 1.5, justifyContent: 'center' }}>
<View>
<CheckBox
checkedIcon='dot-circle-o'
......@@ -237,7 +273,6 @@ class DeliveryAddrees extends React.Component {
<View>
<Text style={{ textAlign: 'center', color: '#ccb46c', fontFamily: 'Gotham-Light', marginRight: 20 }}>{i18n.t('selectaddress')}</Text>
</View>
</View>
<View style={{ flex: 3, justifyContent: 'center' }}>
<View>
......@@ -245,11 +280,17 @@ class DeliveryAddrees extends React.Component {
</View>
<Text style={{ fontFamily: 'Gotham-Light', color: '#838383', fontSize: 15 }}>{item.address}</Text>
</View>
</TouchableOpacity>
</View>
<View style={{ flex: 0.5 }}>
<TouchableOpacity style={{ flex: 1, flexDirection: 'row', margin: 5 }} onPress={() => this.handleDeleteAddress(item.id)}>
<View style={{ justifyContent: 'center' }}>
<EvilIcons name="trash" size={40} color="black" />
</View>
</TouchableOpacity>
</View>
</View>
</View>
);
}
render() {
......@@ -279,7 +320,6 @@ class DeliveryAddrees extends React.Component {
<Text style={{ fontFamily: 'Gotham-Black', textAlign: 'center', color: 'white', fontSize: 16 }}> {i18n.t('addaddress')} </Text>
</View>
</TouchableOpacity>
</View>
<View style={styles.listAddress}>
{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