Advertisement
enkf

Untitled

Feb 3rd, 2020
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { View, StyleSheet, Text, TouchableOpacity, Platform, TextInput, SafeAreaView } from 'react-native';
  3. import { Button, Left } from 'native-base';
  4. import Icon from 'react-native-vector-icons/FontAwesome';
  5. import Axios from 'axios';
  6. import DateTimePickerModal from 'react-native-modal-datetime-picker';
  7. import AsyncStorage from '@react-native-community/async-storage';
  8.  
  9. class Bookings extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. isDateTimePickerVisible: false,
  14. date: '',
  15. time: ''
  16.  
  17. }
  18. }
  19.  
  20. async handleSubmit () {
  21. // console.log(this.state)
  22. const resToken = await AsyncStorage.getItem('token')
  23. const token = JSON.parse(resToken);
  24. Axios({
  25. method: 'post',
  26. url: 'http://192.168.56.1/vzuu/public/api/bookings',
  27. headers: {
  28. 'Accept': 'application/json',
  29. 'Content-Type': 'application/json',
  30. 'Authorization': 'Bearer ' + token.data.success.token,
  31. },
  32. data: {
  33. 'date': this.state.date,
  34. 'time': this.state.time,
  35. },
  36. })
  37. .then(function (response) {
  38. console.log(response.data);
  39. })
  40. .catch(function (error) {
  41. console.log(error);
  42. });
  43. this.setState({ date: '', time:''});
  44. }
  45.  
  46. showDateTimePicker = () => {
  47. this.setState({ isDateTimePickerVisible: true });
  48. };
  49.  
  50. hideDateTimePicker = () => {
  51. this.setState({ isDateTimePickerVisible: false });
  52. };
  53.  
  54. handleDatePicked = date => {
  55. console.log("A date has been picked: ", date);
  56. this.setState({date: date})
  57. this.hideDateTimePicker();
  58. };
  59.  
  60.  
  61. render() {
  62. return(
  63. <View style={{ marginHorizontal: 17, paddingTop: 15 }}>
  64. <View style={{marginTop: 30}}></View>
  65. <Text style={[styles.text, { textAlign: 'left' }, { color: '#000' }, { fontSize: 18}]}>
  66. Date
  67. </Text>
  68. <View style={{marginTop: 20}}></View>
  69. <TouchableOpacity onPress={this.showDateTimePicker}>
  70. <Icon name="calendar" size={24} color="#DC143C" />
  71. </TouchableOpacity>
  72. <TextInput style={{color: '#000000', fontSize: 12 }} underlineColorAndroid="#E91E63" value={this.state.date} />
  73. <DateTimePickerModal
  74. underlineColorAndroid="#E91E63"
  75. isVisible={this.state.isDateTimePickerVisible}
  76. onConfirm={this.handleDatePicked}
  77. onCancel={this.hideDateTimePicker}
  78. mode={'date'}
  79. is24Hour={false}
  80. locale="en_GB"
  81. onDateChange={date => this.setState({ date: date })} value={this.state.date} />
  82.  
  83. {/* <View style={{marginTop: 30}}></View>
  84. <Text style={[styles.text, { textAlign: 'left' }, { color: '#000' }, { fontSize: 18}]}>
  85. Time
  86. </Text>
  87. <View style={{marginTop: 20}}></View>
  88. <TouchableOpacity onPress={this.showDateTimePicker}>
  89. <Icon name="clock" size={24} color="#DC143C" />
  90. </TouchableOpacity>
  91. <TextInput style={{color: '#000000', fontSize: 12 }} underlineColorAndroid="#E91E63" value={this.state.time}/>
  92. <DateTimePickerModal
  93. underlineColorAndroid="#E91E63"
  94. isVisible={this.state.isDateTimePickerVisible}
  95. onConfirm={this.handleDatePicked}
  96. onCancel={this.hideDateTimePicker}
  97. mode={'time'}
  98. is24Hour={false}
  99. locale="en_GB"
  100. onDateChange={time => this.setState({ time: time })} value={this.state.time} /> */}
  101.  
  102. <View style={{ paddingTop: 30}}>
  103. <SafeAreaView style={styles.container}>
  104. <View style={{ flexDirection: 'row' }}>
  105. <Left>
  106. <View style={{paddingTop: 15 }}>
  107. <Button small rounded danger onPress={this.handleSubmit}>
  108. <Text style={{ color: '#fff' }}> Send </Text>
  109. </Button>
  110. </View>
  111. </Left>
  112. </View>
  113. </SafeAreaView>
  114. </View>
  115. </View>
  116. )
  117.  
  118. }
  119. }
  120.  
  121. export default Bookings;
  122. const styles = StyleSheet.create({
  123. container: {
  124. flex: 1,
  125. justifyContent: 'center',
  126. alignItems: 'center'
  127.  
  128. }
  129. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement