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

nambah fitur edit alamat

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