Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lub2code committed Oct 23, 2019
1 parent 0a5606a commit 973ef7f
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 94 deletions.
6 changes: 2 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import firebase from 'react-native-firebase';
import Geolocation from 'react-native-geolocation-service';
import { connect } from 'react-redux';

import api from './config/api';
import AppNavigator from './Navigations/index';
import { set_coords } from './redux/actions/GeolocationAction';
import { update_last_location } from './redux/actions/CallApiAction';

const AppContainer = createAppContainer(AppNavigator);

Expand Down Expand Up @@ -160,8 +159,7 @@ class App extends Component {

this.watchId = Geolocation.watchPosition(
position => {
dispatch(set_coords(position.coords));
return fetch(api.update_last_Location + position.coords.latitude + '/' + position.coords.longitude);
dispatch(update_last_location(position.coords));
},
error => {
// this.setState({ location: error });
Expand Down
119 changes: 75 additions & 44 deletions src/Page/RegisterParcel.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { connect } from 'react-redux';

import colors from '../config/colors';
import key from '../config/api_keys';
import api from '../config/api';
import { getDeviceType } from '../utils/deviceType';
import { add_address, register_new_request } from '../redux/actions/CallApiAction';

Expand Down Expand Up @@ -691,6 +690,11 @@ class RegisterParcel extends Component {
if (item.avatarSource == null || item.avatarSource === '') {
error_cnt++;
}
if (error_cnt > 0) {
this.refs.toast.show('Please, insert all fields.', 3500);
this.setState({ sendingNewRequest: false });
return;
}
body.items.push({
// id: null,
receiverAddressID: item.parcel_address_name,
Expand Down Expand Up @@ -724,24 +728,19 @@ class RegisterParcel extends Component {
// }
});
});
console.log('new transport request', body);

if (error_cnt > 0) {
this.refs.toast.show('Please, insert all fields.', 3500);
this.setState({ sendingNewRequest: false });
return;
}

const dispatch = this.props.dispatch;
try {
await dispatch(register_new_request(body));
this.refs.toast.show('Success', 3500);
this.props.navigation.navigate('WholeRoute');
} catch (error) {
console.log;
this.refs.toast.show('Failed', 3500);
if (error_cnt === 0) {
console.log('new transport request', body);

const dispatch = this.props.dispatch;
try {
await dispatch(register_new_request(body));
this.refs.toast.show('Success', 3500);
this.props.navigation.navigate('WholeRoute');
} catch (error) {
console.log;
this.refs.toast.show('Failed', 3500);
}
}

this.setState({ sendingNewRequest: false });
});
} catch (error) {
Expand Down Expand Up @@ -803,13 +802,17 @@ class RegisterParcel extends Component {
<View style={styles.container}>
<Header
backgroundColor={colors.headerColor}
containerStyle={{ marginTop: Platform.OS === 'ios' ? 0 : -24 }}
containerStyle={styles.header_container}
centerComponent={{ text: 'Register transport request', style: { color: '#fff' } }}
leftComponent={<Icon name="menu" style={{ color: '#fff' }} onPress={() => this.props.navigation.openDrawer()} />}
leftComponent={
<View style={styles.icon_container}>
<Icon name="menu" style={styles.icon} onPress={() => this.props.navigation.openDrawer()} />
</View>
}
/>
<Toast
ref="toast"
style={{ backgroundColor: '#000' }}
style={styles.white}
position="top"
positionValue={100}
fadeInDuration={750}
Expand Down Expand Up @@ -926,7 +929,7 @@ class RegisterParcel extends Component {
<Input
label="Address Name/ID"
value={this.state.sender_address_name}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={this.state.sender_address_name == null || this.state.sender_address_name == '' ? error_msg : ''}
onChangeText={sender_address_name => this.setState({ sender_address_name })}
/>
Expand All @@ -938,7 +941,7 @@ class RegisterParcel extends Component {
label="E-mail"
keyboardType="email-address"
value={this.state.sender_email}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={this.state.sender_email == null || this.state.sender_email == '' ? error_msg : ''}
onChangeText={sender_email => this.setState({ sender_email })}
/>
Expand All @@ -948,7 +951,7 @@ class RegisterParcel extends Component {
label="Phone"
keyboardType="numeric"
value={this.state.sender_phone}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={this.state.sender_phone == null || this.state.sender_phone == '' ? error_msg : ''}
onChangeText={sender_phone => this.setState({ sender_phone })}
/>
Expand All @@ -968,7 +971,7 @@ class RegisterParcel extends Component {
label="Nr."
keyboardType="numeric"
value={this.state.sender_street_nr}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={this.state.sender_street_nr == null || this.state.sender_street_nr == '' ? error_msg : ''}
onChangeText={sender_street_nr => this.setState({ sender_street_nr })}
/>
Expand All @@ -979,7 +982,7 @@ class RegisterParcel extends Component {
<Input
label="City"
value={this.state.sender_city}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={this.state.sender_city == null || this.state.sender_city == '' ? error_msg : ''}
onChangeText={sender_city => this.setState({ sender_city })}
/>
Expand All @@ -991,7 +994,7 @@ class RegisterParcel extends Component {
label="Postal Code"
keyboardType="numeric"
value={this.state.sender_postal_code}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={this.state.sender_postal_code == null || this.state.sender_postal_code == '' ? error_msg : ''}
onChangeText={sender_postal_code => this.setState({ sender_postal_code })}
/>
Expand All @@ -1000,7 +1003,7 @@ class RegisterParcel extends Component {
<Input
label="Country"
value={this.state.sender_country}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={this.state.sender_country == null || this.state.sender_country == '' ? error_msg : ''}
onChangeText={sender_country => this.setState({ sender_country })}
/>
Expand Down Expand Up @@ -1085,7 +1088,7 @@ class RegisterParcel extends Component {
/>
</View>
</View>
<View style={{ alignItems: 'flex-end' }}>
<View style={styles.savebutton_row}>
<TouchableOpacity
disabled={this.state.savingSenderAddress}
style={[styles.save_addressContainer, styles.addressButton]}
Expand All @@ -1099,7 +1102,7 @@ class RegisterParcel extends Component {
</View>
)}
</View>
<Divider style={{ backgroundColor: '#000' }} />
<Divider style={styles.white} />
{this.state.parcels.map((item, index) => {
return (
<View key={index}>
Expand Down Expand Up @@ -1230,7 +1233,7 @@ class RegisterParcel extends Component {
<Input
label="Address Name/ID"
value={item.parcel_address_name}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={item.parcel_address_name == null || item.parcel_address_name == '' ? error_msg : ''}
onChangeText={parcel_address_name =>
this.setState(state => {
Expand All @@ -1249,7 +1252,7 @@ class RegisterParcel extends Component {
label="E-mail"
keyboardType="email-address"
value={item.parcel_email}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={item.parcel_email == null || item.parcel_email == '' ? error_msg : ''}
onChangeText={parcel_email =>
this.setState(state => {
Expand All @@ -1266,7 +1269,7 @@ class RegisterParcel extends Component {
label="Phone"
keyboardType="numeric"
value={item.parcel_phone}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={item.parcel_phone == null || item.parcel_phone == '' ? error_msg : ''}
onChangeText={parcel_phone =>
this.setState(state => {
Expand All @@ -1284,7 +1287,7 @@ class RegisterParcel extends Component {
<Input
label="Street"
value={item.parcel_street}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={item.parcel_street == null || item.parcel_street == '' ? error_msg : ''}
onChangeText={parcel_street =>
this.setState(state => {
Expand Down Expand Up @@ -1318,7 +1321,7 @@ class RegisterParcel extends Component {
<Input
label="City"
value={item.parcel_city}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={item.parcel_city == null || item.parcel_city == '' ? error_msg : ''}
onChangeText={parcel_city =>
this.setState(state => {
Expand All @@ -1337,7 +1340,7 @@ class RegisterParcel extends Component {
label="Postal Code"
keyboardType="numeric"
value={item.parcel_postal_code}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={item.parcel_postal_code == null || item.parcel_postal_code == '' ? error_msg : ''}
onChangeText={parcel_postal_code =>
this.setState(state => {
Expand All @@ -1353,7 +1356,7 @@ class RegisterParcel extends Component {
<Input
label="Country"
value={item.parcel_country}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={item.parcel_country == null || item.parcel_country == '' ? error_msg : ''}
onChangeText={parcel_country =>
this.setState(state => {
Expand Down Expand Up @@ -1414,7 +1417,7 @@ class RegisterParcel extends Component {
/>
</View>
</View>
<View style={{ alignItems: 'flex-end' }}>
<View style={styles.savebutton_row}>
<TouchableOpacity
disabled={this.state.savingParcelAddress}
style={[styles.save_addressContainer, styles.addressButton]}
Expand All @@ -1426,7 +1429,7 @@ class RegisterParcel extends Component {
<View style={{ flex: 1, flexDirection: 'row', justifyContent: 'center', marginBottom: 20 }}>
<Picker
selectedValue={item.selectedCountry}
style={{ height: 50, width: 100, margin: 10 }}
style={styles.picker}
onValueChange={(itemValue, itemIndex) =>
this.setState(state => {
var parcels = this.state.parcels;
Expand All @@ -1441,7 +1444,7 @@ class RegisterParcel extends Component {
</Picker>
<Picker
selectedValue={item.selectedParcelType}
style={{ height: 50, width: 100, margin: 10 }}
style={styles.picker}
onValueChange={(itemValue, itemIndex) =>
this.setState(state => {
var parcels = this.state.parcels;
Expand All @@ -1456,7 +1459,7 @@ class RegisterParcel extends Component {
</Picker>
<Picker
selectedValue={item.selectedCurrency}
style={{ height: 50, width: 100, margin: 10 }}
style={styles.picker}
onValueChange={(itemValue, itemIndex) =>
this.setState(state => {
var parcels = this.state.parcels;
Expand All @@ -1470,7 +1473,7 @@ class RegisterParcel extends Component {
})}
</Picker>
</View>
<View style={{ marginLeft: 20, marginRight: 20, marginTop: 120 }}>
<View style={styles.instrunce}>
<CheckBox
title="Insurance"
checked={item.insurance}
Expand Down Expand Up @@ -1504,7 +1507,7 @@ class RegisterParcel extends Component {
label="ParcelPrice"
keyboardType="numeric"
value={item.parcel_price}
errorStyle={{ color: 'red' }}
errorStyle={styles.error}
errorMessage={item.parcel_price == null || item.parcel_price == '' ? error_msg : ''}
onChangeText={parcel_price =>
this.setState(state => {
Expand Down Expand Up @@ -1554,6 +1557,15 @@ RegisterParcel.propTypes = {
};

const styles = StyleSheet.create({
header_container: {
marginTop: Platform.OS === 'ios' ? 0 : -24,
},
icon_container: {
width: 50,
},
icon: {
color: '#fff',
},
container: {
flex: 1,
},
Expand Down Expand Up @@ -1622,11 +1634,14 @@ const styles = StyleSheet.create({
addressButton: {
backgroundColor: '#007bff',
},
savebutton_row: {
alignItems: 'flex-end',
},
save_addressContainer: {
alignItems: 'center',
height: 38,
width: 150,
justifyContent: 'center',
alignItems: 'center',
borderRadius: 5,
margin: 20,
},
Expand Down Expand Up @@ -1680,6 +1695,22 @@ const styles = StyleSheet.create({
backgroundColor: colors.subScreen,
height: 300,
},
error: {
color: 'red',
},
picker: {
height: 50,
width: 100,
margin: 10,
},
instrunce: {
marginLeft: 20,
marginRight: 20,
marginTop: 120,
},
white: {
color: 'white',
},
});

const mapStatetoProps = ({ login: { person_info }, geolocation: { coords, geo_code }, countries, parcels, currencies }) => ({
Expand Down
8 changes: 2 additions & 6 deletions src/Page/RequestDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ class RequestDetail extends Component {
<Text style={styles.subTitle}>GPS</Text>
<View style={styles.row}>
<View style={styles.col}>
<Input label="Longitude" disabled={true} keyboardType="numeric" disabled={true} value={item.receiverLatitude.toString()} />
<Input label="Longitude" disabled={true} keyboardType="numeric" value={item.receiverLatitude.toString()} />
</View>
<View style={styles.col}>
<Input disabled={true} label="Latitude" keyboardType="numeric" disabled={true} value={item.receiverLongitude.toString()} />
<Input disabled={true} label="Latitude" keyboardType="numeric" value={item.receiverLongitude.toString()} />
</View>
</View>
<Text style={styles.label_data}>Loading Time</Text>
Expand Down Expand Up @@ -376,10 +376,6 @@ const styles = StyleSheet.create({
lable_button: {
color: 'white',
},
textfield: {
height: 48,
marginTop: 10,
},
avatarContainer: {
borderColor: '#9B9B9B',
borderWidth: 1 / PixelRatio.get(),
Expand Down
Loading

0 comments on commit 973ef7f

Please sign in to comment.