import React, { Component } from 'react' import { View, Alert, TouchableOpacity, Platform } from 'react-native' import GetWidthHeightDevice from '../../components/GetWidthHeightDevice' import { CustomInput } from '../../components/CustomInput' import { CustomPicker } from '../../components/CustomPicker' import { CustomButton } from '../../components/CustomButton' import Text from '../../components/Text'; import { Picker, Right } from 'native-base' import moment from 'moment' import CustomDatePicker from './CustomDatePicker'; import {postReserveRoom} from '../../api/UserApi'; import {withNavigation} from 'react-navigation'; import IndicatorLoading from '../../components/IndicatorLoading'; import { t } from '../../utils/i18n' class PersonRoomReservationScreen extends Component { constructor(props) { super(props) this.state = { isLoading:false, room_id: this.props.roomDetail.id, activeIndex: 0, user:{}, } this.sendReserve = this.sendReserve.bind(this) } componentDidMount = () => { this.setState({ user: { ...this.state.user, type: 'customer', gender: 'ชาย', room_type: this.props.roomDetail.type_name, project_name: this.props.roomDetail.project.name } }) }; sendReserve() { var email_validate = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ if (email_validate.test(this.state.user.email) !== true){ Alert.alert(null, t('email_format_invalid')) return } postReserveRoom(this.state.room_id,this.state.user) .then(res => { console.log('response ---------> ',res.data) }) .then(() => { Alert.alert( t('booking_success'),null, [ { text: t('ok'), onPress: () => this.props.navigation.navigate('HomeScreen') }, ] ) }) } handleDatePickedBirthDay = (date) => { console.log("A date birth day has been picked: ", date); this.setState({ user: { ...this.state.user, birth_date: moment(date).format('DD-MM-YYYY') } }) }; handleDatePickedCheckIn = (date) => { console.log("A date check-in has been picked: ", date); this.setState({ user: { ...this.state.user, check_in_date: moment(date).format('DD-MM-YYYY') } }) }; render() { let width_device = GetWidthHeightDevice.WidthDevice return ( {t('profile')} { let input = e.nativeEvent.text this.setState({ user: { ...this.state.user, name: input } }) }}/> { let input = e.nativeEvent.text this.setState({ user: { ...this.state.user, email: input } }) }}/> { let input = e.nativeEvent.text this.setState({ user: { ...this.state.user, phone: input } }) }}/> {t('gender')} { Platform.OS == 'ios' ? { this.setState({ user: { ...this.state.user, gender: e } }) }}> : { this.setState({ user: { ...this.state.user, gender: e } }) }}> } = 400 ? styles.row : styles.row_minSize}> { if(this.state.user.name != null && this.state.user.email != null && this.state.user.phone != null && this.state.user.birth_date != null && this.state.user.check_in_date){ Alert.alert( t('booking_submit'), t('booking_confirm'), [ { text: t('cancel'), style: 'cancel' }, { text: t('ok'), onPress: () => this.sendReserve() }, ], { cancelable: false } ) }else{ Alert.alert(t('error_occurred'), t('required_field')) } }} title={t('book_room')} /> ) } } const styles = { container: { flex: 1, flexDirection: 'column', height: GetWidthHeightDevice.HeightDevice, }, row: { flexDirection: 'row', marginBottom: 7, height: 48, }, row_grow_first: { flexGrow: 1, marginRight: 5, width: '9%' }, row_grow_first_minSize: { flexGrow: 1, marginBottom: 5, width: '100%', }, row_grow: { flexGrow: 1, }, form: { height: '100%', flex: 1, padding: 15, paddingTop: 5, paddingBottom: 0, }, row_minSize: { flexDirection: 'column', marginBottom: 5, }, box_form_reservation: { marginLeft: 15, marginRight: 15, }, input_reservation: { marginLeft: 15, marginRight: 15, }, contentContainer: { paddingVertical: 5 }, headerTitle: { color: 'white', marginVertical: 5 }, buttons: { paddingHorizontal: 15, paddingVertical: 10 }, custom_input: { backgroundColor: 'rgba(255,255,255,0.3)', borderRadius: 30, height: 48, color: 'white' } } export default withNavigation(PersonRoomReservationScreen)