import React, { Component } from "react";
import "./Contact-us.css";
import axios from 'axios'
import {
FieldFeedback,
FieldFeedbacks,
FormWithConstraints
} from 'react-form-with-constraints';
import Alert from 'react-bootstrap/Alert';
class ContactUs extends Component {
constructor(props) {
super(props);
this.state = {
firstname: "",
lastname: "",
email: "",
message: "",
agent: "",
house: "",
alertBad: false,
alertSucess: false,
time: false
};
}
render() {
return (
this.setState({ alertBad: false })} dismissible>
Message could not send.
There are some errors in your contact form.
this.setState({ alertSucess: false })} dismissible>
The message is successfully sent.
You contact form will be delivered to our support team.
)
}
onAgentChange(event) {
this.setState({ agent: event.target.value });
}
onHouseChange(event) {
this.setState({ house: event.target.value });
}
onFirstNameChange(event) {
this.setState({ firstname: event.target.value });
}
onLastNameChange(event) {
this.setState({ lastname: event.target.value });
}
onEmailChange(event) {
this.setState({ email: event.target.value });
}
onMessageChange(event) {
this.setState({ message: event.target.value });
}
handleChange = e => {
this.form.validateFields(e.target);
}
handleSubmit(event) {
event.preventDefault();
this.form.validateFields();
if (!this.form.isValid()) {
this.alertBad();
return;
} else {
this.alertSuccess();
axios({
method: "POST",
url: "http://localhost:3002/send",
data: this.state
}).then((response) => {
if (response.data.status === 'success') {
this.resetForm();
} else if (response.data.status === 'fail') {
return;
}
})
}
}
alertSuccess(){
this.setState({ alertBad: false, alertSucess: true })
}
alertBad(){
this.setState({ alertSucess: false, alertBad: true })
}
resetForm() {
this.setState({ firstname: '', lastname: '', email: '', message: '', agent: '', house: '' })
}
}
export default ContactUs;