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

nambah fitur edit alamat

parent 7cd27c8d
......@@ -51,6 +51,7 @@ const ActionType = {
SET_ACCOUNT_NUMBER:'SET_ACCOUNT_NUMBER',
SET_MEMBER:'SET_MEMBER',
SET_INBOX:'SET_INBOX',
SET_EDIT_ADDRESS: 'SET_EDIT_ADDRESS'
}
export default ActionType;
\ No newline at end of file
......@@ -100,7 +100,8 @@ const globalState = {
old_balance_claimed: true,
set_inbox :'',
email_confirm:false
email_confirm:false,
edit_address : false,
}
......@@ -163,6 +164,13 @@ const rootReducer = (state = globalState, action) => {
pointused: action.data.pointused,
}
}
case ActionType.SET_EDIT_ADDRESS: {
return {
...state,
edit_address: action.data.edit_address,
}
}
case ActionType.SET_PAGE: {
return {
...state,
......
......@@ -11,6 +11,7 @@ import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
import { connect } from 'react-redux';
import session from '../function/session';
import ActionType from '../redux/globalActionType';
class AddreesDetail extends React.Component {
......@@ -29,13 +30,15 @@ class AddreesDetail extends React.Component {
street: '',
city: '',
region: '',
name: '',
postalCode: '',
address: '',
address_edit :this.props.route.params.data_address.name,
description_edit :this.props.route.params.data_address.address,
address_d: '',
spinner: false,
indicator: true,
caretHidden: true,
data: [],
}
}
......@@ -57,6 +60,7 @@ class AddreesDetail extends React.Component {
}
}
//Current location (lokasi saat ini)
_getLocationAsync = async () => {
this.setState({
......@@ -172,13 +176,25 @@ class AddreesDetail extends React.Component {
}
validation() {
if (this.state.name == '') {
Alert.alert(i18n.t('alertLabelAddress'))
} else if (this.state.description == '') {
Alert.alert(i18n.t('alertDetailAddress'))
if (this.props.edit_address == true) {
if (this.state.address_edit == '') {
Alert.alert(i18n.t('','alertLabelAddress'))
} else if (this.state.description_edit == '') {
Alert.alert(i18n.t('','alertDetailAddress'))
} else {
this.saveAddress()
}
} else {
this.saveAddress()
if (this.state.name == '') {
Alert.alert(i18n.t('','alertLabelAddress'))
} else if (this.state.description == '') {
Alert.alert(i18n.t('','alertDetailAddress'))
} else {
this.saveAddress()
}
}
}
onChangeLocation = async (e) => {
......@@ -216,20 +232,34 @@ class AddreesDetail extends React.Component {
})
}
saveAddress() {
saveAddress() {
this.setState({
spinner: true,
})
const navigation = this.props.navigation
let name = ""
let description = ""
let address_id = ""
if (this.props.edit_address == true) {
name = this.state.address_edit
description = this.state.description_edit
address_id = this.props.route.params.data_address.id
} else {
name = this.state.name
description = this.state.description
address_id =""
}
let params = {
session_id: this.props.session_id,
address_id: '',
address: this.state.street + ' ' + this.state.city + ' ' + this.state.region + ' ' + this.state.postalCode,
name: this.state.name,
description: this.state.description,
name: name,
description: description,
lat: this.state.latitude,
address_id: address_id,
long: this.state.longitude
}
// console.log(params)
......@@ -244,10 +274,15 @@ class AddreesDetail extends React.Component {
spinner: false,
})
let setDataEditAddress = {
edit_address: false
}
this.props.editAddress(setDataEditAddress);
this.props.navigation.goBack()
this.props.route.params.onChangeAddress({ example: 'wakwaw' })
}).catch(error => {
})
.catch(error => {
let response = error.response.data;
const { navigation } = this.props
session(response, navigation)
......@@ -310,7 +345,7 @@ class AddreesDetail extends React.Component {
}}
/>
</View>
<View style={{ flex: 1, margin: 5 , display:'none'}} >
<View style={{ flex: 1, margin: 5, display: 'none' }} >
<TouchableOpacity onPress={() => this._searchLocation()}>
<Ionicons name="ios-search" size={32} color="#ccb46c" />
</TouchableOpacity>
......@@ -375,37 +410,51 @@ class AddreesDetail extends React.Component {
</View>
<View style={styles.field_name_addrees}>
<Text style={{ fontFamily: 'Gotham-Black', color: "#ccb46c", textAlign: 'center', fontSize: 18 }}>{i18n.t('address_name')}</Text>
<TextInput style={{ color: 'grey', fontFamily: 'Gotham-Black', height: 40, borderWidth: 1, padding: 5, flex: 1, margin: 10, borderRadius: 10, borderColor: 'grey', textAlign: 'center' }}
{this.props.edit_address == true ? (<TextInput style={{ color: 'grey', fontFamily: 'Gotham-Black', height: 40, borderWidth: 1, padding: 5, flex: 1, margin: 10, borderRadius: 10, borderColor: 'grey', textAlign: 'center' }}
onChangeText={(address_edit) => this.setState({ address_edit })}
caretHidden={this.state.caretHidden}
value={this.state.address_edit}
onFocus={() => this.setState({ caretHidden: false })}/>):
( <TextInput style={{ color: 'grey', fontFamily: 'Gotham-Black', height: 40, borderWidth: 1, padding: 5, flex: 1, margin: 10, borderRadius: 10, borderColor: 'grey', textAlign: 'center' }}
onChangeText={(name) => this.setState({ name })}
caretHidden={this.state.caretHidden}
onFocus={() => this.setState({ caretHidden: false })} />
onFocus={() => this.setState({ caretHidden: false })} />)}
</View>
<View style={styles.field_detail_addrees}>
<Text style={{ fontFamily: 'Gotham-Black', color: "#ccb46c", textAlign: 'center', fontSize: 18 }}>{i18n.t('address_fulladdress')}</Text>
{this.props.edit_address == true ? (
<TextInput
style={{ color: 'grey', fontFamily: 'Gotham-Black', textAlign: 'center', height: 70, borderWidth: 1, padding: 5, flex: 1, margin: 10, borderRadius: 10, borderColor: 'grey' }}
onChangeText={(description_edit) => this.setState({ description_edit })}
numberOfLines={10}
multiline={true}
value={this.state.description_edit}
caretHidden={this.state.caretHidden}
onFocus={() => this.setState({ caretHidden: false })} />):(
<TextInput
style={{ color: 'grey', fontFamily: 'Gotham-Black', textAlign: 'center', height: 70, borderWidth: 1, padding: 5, flex: 1, margin: 10, borderRadius: 10, borderColor: 'grey' }}
onChangeText={(description) => this.setState({ description })}
numberOfLines={10}
multiline={true}
caretHidden={this.state.caretHidden}
onFocus={() => this.setState({ caretHidden: false })} />
onFocus={() => this.setState({ caretHidden: false })} /> )}
<Text style={{ color: '#666666', textAlign: 'center', fontSize: 14, paddingBottom: 15 }}>{i18n.t('address_fulladdress_helptext')}</Text>
</View>
<View style={{ margin: 50, justifyContent: 'center' }}>
{
this.state.indicator == true ? (
<View style={{ height: 40, borderRadius: 10, backgroundColor: '#838383', justifyContent: 'center' }}>
<ActivityIndicator size="large" color="#c9af6d" />
</View>
) : (
// this.state.indicator == true ? (
// <View style={{ height: 40, borderRadius: 10, backgroundColor: '#838383', justifyContent: 'center' }}>
// <ActivityIndicator size="large" color="#c9af6d" />
// </View>
// ) : (
<TouchableOpacity onPress={() => this.validation()}>
<View style={{ height: 40, borderRadius: 10, backgroundColor: '#CFB368', justifyContent: 'center' }}>
<Text style={{ fontFamily: 'Gotham-Black', color: 'white', fontSize: 16, textAlign: 'center' }}>{i18n.t('addaddress')}</Text>
</View>
</TouchableOpacity>
)
// )
}
</View>
......@@ -479,10 +528,23 @@ const mapStateToProps = (state) => {
session_id: state.session_id,
language: state.language,
BASE_URL: state.BASE_URL,
edit_address: state.edit_address
}
}
const mapDispatchToProps = (dispacth) => {
return {
editAddress: (setDataEditAddress) => dispacth({
type: ActionType.SET_EDIT_ADDRESS,
data: {
edit_address:setDataEditAddress.edit_address
}
}),
}
}
export default connect(mapStateToProps)(AddreesDetail)
\ No newline at end of file
export default connect(mapStateToProps,mapDispatchToProps)(AddreesDetail)
\ No newline at end of file
......@@ -54,6 +54,7 @@ class DeliveryAddrees extends React.Component {
}
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))
let address = []
for (let i = 0; i < dataAlamat.length; i++) {
......@@ -73,6 +74,8 @@ class DeliveryAddrees extends React.Component {
data_alamat.push(b)
})
// console.log(this.state.data)
}).catch(error => {
let response = error.response.data;
......@@ -135,7 +138,16 @@ class DeliveryAddrees extends React.Component {
}
addAdreess() {
this.props.navigation.navigate('Address Detail', { 'data': 'sample', onChangeAddress: this.onChangeAddress })
this.props.navigation.navigate('Address Detail', {data_address : "", 'data': 'sample', onChangeAddress: this.onChangeAddress })
}
EditAdreess(data_address) {
this.props.navigation.navigate('Address Detail', { data_address : data_address,'data': 'sample', onChangeAddress: this.onChangeAddress })
let setDataEditAddress = {
edit_address: true
}
this.props.editAddress(setDataEditAddress);
}
......@@ -327,8 +339,8 @@ class DeliveryAddrees extends React.Component {
uncheckedColor="#ccb46c"
/>
</View>
<View>
<Text style={{ textAlign: 'center', color: '#ccb46c', fontFamily: 'Gotham-Light', marginRight: 20 }}>{i18n.t('selectaddress')}</Text>
<View style={{flex:3}}>
<Text style={{ textAlign: 'center', color: '#ccb46c', fontFamily: 'Gotham-Light', marginRight:5 }}>{i18n.t('selectaddress')}</Text>
</View>
</View>
<View style={{ flex: 3, justifyContent: 'center' }}>
......@@ -339,12 +351,27 @@ class DeliveryAddrees extends React.Component {
</View>
</TouchableOpacity>
</View>
<View style={{ flex: 1}}>
<TouchableOpacity style={{ flexDirection: 'row', justifyContent: "center" }} onPress={() =>this.EditAdreess(item)}>
<View style={{ alignSelf:'flex-end', marginTop: 20 }}>
{/* <EvilIcons name="pencil" size={40} color="#ccb46c" /> */}
</View>
</TouchableOpacity>
</View>
<View style={{ flex: 1 }}>
<TouchableOpacity style={{ flexDirection: 'row', justifyContent: "center" }} onPress={() =>this.EditAdreess(item)}>
<View style={{ alignSelf: "center", marginTop: 20 }}>
<EvilIcons name="pencil" size={40} color="#ccb46c" />
</View>
</TouchableOpacity>
</View>
<View style={{ flex: 1 }}>
<TouchableOpacity style={{ flex: 1, flexDirection: 'row', justifyContent: "center" }} onPress={() => this.handleDeleteAddress(item.id)}>
<View style={{ alignSelf: "center", marginTop: 20 }}>
<EvilIcons name="trash" size={40} color="#ccb46c" />
</View>
</TouchableOpacity>
</View>
</View>
</View>
......@@ -380,6 +407,7 @@ class DeliveryAddrees extends React.Component {
</View>
</TouchableOpacity>
</View>
<View style={styles.listAddress}>
{this.state.indicator == true ? (
<ActivityIndicator size="large" color="#c9af6d" />
......@@ -495,6 +523,13 @@ const mapDispatchToProps = (dispacth) => {
}
}),
editAddress: (setDataEditAddress) => dispacth({
type: ActionType.SET_EDIT_ADDRESS,
data: {
edit_address:setDataEditAddress.edit_address
}
}),
setGrab: (setGrabProps) => dispacth({
type: ActionType.SET_GRAB,
data: {
......
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