// eslint-disable-next-line import/prefer-default-export
export function initFeedbackForm() {
$(document).ready(function () {
$('#submit').removeAttr('disabled');
$('#submit').click(function () {
$('.error').hide();
$('.error ul').empty();
var hasError = false;
var nameVal = $('#contactName').val();
if (nameVal == '') {
$('.error ul').append('
Please give us your name');
hasError = true;
}
var emailVal = $('#contactEmail').val();
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if (emailVal == '') {
$('.error ul').append('Please give us your email');
hasError = true;
}
if (!emailReg.test(emailVal)) {
$('.error ul').append('Please input a valid email');
hasError = true;
}
var msgVal = $('#message').val();
if (msgVal == '') {
$('.error ul').append('Please enter your message');
hasError = true;
}
var companyVal = $('#company').val();
if (hasError) {
$('.error').show();
} else {
$(this).attr('disabled', 'true');
$(this).attr('value', 'Sending...');
$.post('/feedback/send-mail', { contactName: nameVal, company: companyVal, contactEmail: emailVal, message: msgVal }, function (response) {
$('#feedbackForm').after('Thank you. Your email to FootyRoom has been sent
');
$('#submit').attr('value', 'Sent');
})
.fail(function (response) {
$('#feedbackForm').after('Whoops, looks like something went wrong. Try again later or report this to us.
');
$('#submit').attr('value', 'Sent');
});
}
return false;
});
});
}