EditAddress.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import React, { Component } from 'react';
  2. import { View, Text, StyleSheet, TextInput } from 'react-native';
  3. import Button from '../../components/Button';
  4. export default class EditAddress extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. addressDto: userInfo.address ?? {}
  9. };
  10. }
  11. componentDidMount() {
  12. userInfo.editAddress = false;
  13. }
  14. saveInfo() {
  15. const dto = this.state.addressDto
  16. if (!dto.street) {
  17. toastShort('Please input street');
  18. return;
  19. }
  20. if (!dto.houseNumber) {
  21. toastShort('Please input unit number');
  22. return;
  23. }
  24. if (!dto.zipCode) {
  25. toastShort('Please input postal code');
  26. return;
  27. }
  28. userInfo.address = dto;
  29. userInfo.addressLine = dto.houseNumber + ', ' + dto.street + ', ' + dto.zipCode
  30. userInfo.editAddress = true;
  31. goBack();
  32. }
  33. render() {
  34. return (
  35. <View style={styles.container}>
  36. <View style={styles.formView}>
  37. <Text style={styles.label}>Street</Text>
  38. <TextInput
  39. style={styles.formInput}
  40. placeholder='Street name and number'
  41. placeholderTextColor={textPlacehoder}
  42. maxLength={50}
  43. defaultValue={this.state.addressDto?.street}
  44. onChangeText={text => this.state.addressDto.street = text}
  45. />
  46. </View>
  47. <View style={styles.formView}>
  48. <Text style={styles.label}>Unit Number</Text>
  49. <TextInput
  50. style={styles.formInput}
  51. placeholder='Unit number'
  52. placeholderTextColor={textPlacehoder}
  53. maxLength={15}
  54. defaultValue={this.state.addressDto?.houseNumber}
  55. onChangeText={text => this.state.addressDto.houseNumber = text}
  56. />
  57. </View>
  58. <View style={styles.formView}>
  59. <Text style={styles.label}>Postal Code</Text>
  60. <TextInput
  61. style={styles.formInput}
  62. placeholder='Postal Code'
  63. placeholderTextColor={textPlacehoder}
  64. maxLength={10}
  65. defaultValue={this.state.addressDto?.zipCode}
  66. onChangeText={text => this.state.addressDto.zipCode = text}
  67. />
  68. </View>
  69. <Text style={ui.flex1}></Text>
  70. <View style={styles.buttonView}>
  71. <Button
  72. text='Save'
  73. elevation={1.5}
  74. onClick={() => {
  75. this.saveInfo();
  76. }}/>
  77. </View>
  78. </View>
  79. );
  80. }
  81. }
  82. const styles = StyleSheet.create({
  83. container: {
  84. flex: 1,
  85. backgroundColor: 'white'
  86. },
  87. formView: {
  88. paddingTop: 16,
  89. paddingLeft: 16,
  90. paddingRight: 16,
  91. paddingBottom: 4
  92. },
  93. label: {
  94. color: '#333',
  95. fontSize: 14
  96. },
  97. formInput: {
  98. color: '#333',
  99. fontSize: 14,
  100. paddingBottom: 2,
  101. borderBottomColor: '#EEE',
  102. borderBottomWidth: 1
  103. },
  104. buttonView: {
  105. padding: 16,
  106. marginBottom: 16
  107. },
  108. })