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';
import { withTranslation } from "react-i18next";
class ContactUs extends Component {
constructor(props) {
super(props);
this.state = {
firstname: "",
lastname: "",
email: "",
message: "",
agent: "",
house: "",
alertBad: false,
alertSucess: false,
time: false
};
}
render() {
const { t } = this.props;
return (
this.setState({ alertBad: false })} dismissible>
{t("Danger1")}
{t("Danger2")}
this.setState({ alertSucess: false })} dismissible>
{t("Success1")}
{t("Success2")}
)
}
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 withTranslation()(ContactUs);