mirror of
https://github.com/PotentiaRobotics/website.git
synced 2025-04-20 20:30:18 -04:00
Added error handling
This commit is contained in:
parent
cac2bbda6a
commit
25f25b6fda
|
@ -16,15 +16,16 @@ const GlobalStyle = createGlobalStyle`
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
||||||
class ContactForm extends Component {
|
class ContactForm extends Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
name: '',
|
name: '',
|
||||||
email: '',
|
email: '',
|
||||||
subject: '',
|
subject: '',
|
||||||
message: ''
|
message: '',
|
||||||
|
error:''
|
||||||
};
|
};
|
||||||
|
|
||||||
this.handleNameChange = this.handleNameChange.bind(this);
|
this.handleNameChange = this.handleNameChange.bind(this);
|
||||||
|
@ -33,6 +34,7 @@ class ContactForm extends Component {
|
||||||
this.handleMessageChange = this.handleMessageChange.bind(this);
|
this.handleMessageChange = this.handleMessageChange.bind(this);
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNameChange(event) {
|
handleNameChange(event) {
|
||||||
this.setState({
|
this.setState({
|
||||||
name: event.target.value
|
name: event.target.value
|
||||||
|
@ -58,6 +60,17 @@ class ContactForm extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleSubmit(event) {
|
async handleSubmit(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
var i = 0;
|
||||||
|
for (let key in this.state) {
|
||||||
|
if (this.state[key] === '' && i<4) {
|
||||||
|
this.setState({error: `You must provide a ${key}`});
|
||||||
|
return
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
this.setState({error: ``});
|
||||||
|
|
||||||
alert('You will get and email from us shortly!');
|
alert('You will get and email from us shortly!');
|
||||||
alert('These are the details you have submitted!');
|
alert('These are the details you have submitted!');
|
||||||
alert(this.state.name);
|
alert(this.state.name);
|
||||||
|
@ -65,8 +78,6 @@ class ContactForm extends Component {
|
||||||
alert(this.state.subject);
|
alert(this.state.subject);
|
||||||
alert(this.state.message);
|
alert(this.state.message);
|
||||||
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
emailjs.sendForm('service_5ggwj8d', 'template_jirc6zm', event.target, 'user_XtSzEFFNtc4C6IEpGN9JS')
|
emailjs.sendForm('service_5ggwj8d', 'template_jirc6zm', event.target, 'user_XtSzEFFNtc4C6IEpGN9JS')
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
console.log(result.text);
|
console.log(result.text);
|
||||||
|
@ -106,6 +117,11 @@ class ContactForm extends Component {
|
||||||
name="message"
|
name="message"
|
||||||
onChange={this.handleMessageChange}
|
onChange={this.handleMessageChange}
|
||||||
/>
|
/>
|
||||||
|
<StyledError>
|
||||||
|
<p>{this.state.error}</p>
|
||||||
|
<p></p>
|
||||||
|
</StyledError>
|
||||||
|
|
||||||
<StyledButton type="submit">Send Message</StyledButton>
|
<StyledButton type="submit">Send Message</StyledButton>
|
||||||
</StyledForm>
|
</StyledForm>
|
||||||
</StyledFormWrapper>
|
</StyledFormWrapper>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user