EditAddress.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. maxLength={50}
  42. defaultValue={this.state.addressDto?.street}
  43. onChangeText={text => this.state.addressDto.street = text}
  44. />
  45. </View>
  46. <View style={styles.formView}>
  47. <Text style={styles.label}>Unit Number</Text>
  48. <TextInput
  49. style={styles.formInput}
  50. placeholder='Unit number'
  51. maxLength={15}
  52. defaultValue={this.state.addressDto?.houseNumber}
  53. onChangeText={text => this.state.addressDto.houseNumber = text}
  54. />
  55. </View>
  56. <View style={styles.formView}>
  57. <Text style={styles.label}>Postal Code</Text>
  58. <TextInput
  59. style={styles.formInput}
  60. placeholder='Postal Code'
  61. maxLength={10}
  62. defaultValue={this.state.addressDto?.zipCode}
  63. onChangeText={text => this.state.addressDto.zipCode = text}
  64. />
  65. </View>
  66. <Text style={ui.flex1}></Text>
  67. <View style={styles.buttonView}>
  68. <Button
  69. text='Save'
  70. elevation={1.5}
  71. onClick={() => {
  72. this.saveInfo();
  73. }}/>
  74. </View>
  75. </View>
  76. );
  77. }
  78. }
  79. const styles = StyleSheet.create({
  80. container: {
  81. flex: 1,
  82. backgroundColor: 'white'
  83. },
  84. formView: {
  85. paddingTop: 16,
  86. paddingLeft: 16,
  87. paddingRight: 16,
  88. paddingBottom: 4
  89. },
  90. label: {
  91. color: '#333',
  92. fontSize: 14
  93. },
  94. formInput: {
  95. color: '#333',
  96. fontSize: 14,
  97. paddingBottom: 2,
  98. borderBottomColor: '#EEE',
  99. borderBottomWidth: 1
  100. },
  101. buttonView: {
  102. padding: 16,
  103. marginBottom: 16
  104. },
  105. })