You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

contactUsSection.vue 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <div>
  3. <h4 align="left" class="contactHeader">Send us a message</h4>
  4. <div class="form">
  5. <div v-if="boolValidationError" class="row">
  6. <div class="col">
  7. <alert :text="errorMessage" :type="errorOccurred" />
  8. </div>
  9. </div>
  10. <div class="row">
  11. <div class="form-group col-md-6">
  12. <float-label label="Name" style="width: 100%;">
  13. <input
  14. type="text"
  15. id="name"
  16. class="form-control uniInput my-2"
  17. v-model="name"
  18. v-bind:class="{
  19. 'is-valid': name,
  20. 'is-invalid': !requiredField(name) && nameLoad,
  21. }"
  22. v-on:keyup="nameLoad = true"
  23. v-on:blur="nameLoad = true"
  24. placeholder="Name"
  25. />
  26. <div class="invalid-feedback">Name is required!</div>
  27. </float-label>
  28. </div>
  29. <div class="form-group col-md-6">
  30. <float-label label="Email" style="width: 100%;">
  31. <input
  32. type="email"
  33. id="contactemail"
  34. v-model="contactemail"
  35. class="form-control uniInput my-2"
  36. v-bind:class="{
  37. 'is-valid': contactemail,
  38. 'is-invalid': !validEmail(contactemail) && contactemailLoad,
  39. }"
  40. v-on:keyup="contactemailLoad = true"
  41. v-on:blur="contactemailLoad = true"
  42. placeholder="Email"
  43. />
  44. <div class="invalid-feedback">Valid email address is required!</div>
  45. </float-label>
  46. </div>
  47. <div class="form-group col-md-6">
  48. <float-label label="Phone Number" style="width: 100%;">
  49. <input
  50. type="text"
  51. id="phone"
  52. v-model="phone"
  53. class="form-control uniInput my-2"
  54. v-bind:class="{ 'is-valid': phone }"
  55. placeholder="Phone Number"
  56. />
  57. </float-label>
  58. </div>
  59. <div class="form-group col-md-6">
  60. <float-label label="Property" style="width: 100%;">
  61. <input
  62. type="text"
  63. id="property"
  64. v-model="property"
  65. class="form-control uniInput my-2"
  66. v-bind:class="{ 'is-valid': property }"
  67. placeholder="Property"
  68. />
  69. </float-label>
  70. </div>
  71. </div>
  72. <div class="form-group">
  73. <label v-if="!mailSource" class="uniSelectLabel" for="SourceSelect">
  74. Heard About
  75. </label>
  76. <float-label label="Heard About" style="width: 100%;">
  77. <select
  78. id="SourceSelect"
  79. class="form-control uniSelect"
  80. v-model="mailSource"
  81. @change="sourceSelect()"
  82. v-bind:class="{
  83. 'is-valid': mailSource,
  84. 'is-invalid': !requiredField(mailSource) && mailSourceLoad,
  85. }"
  86. v-on:keyup="mailSourceLoad = true"
  87. v-on:blur="mailSourceLoad = true"
  88. >
  89. <option
  90. v-for="(source, s) in contactUsSources"
  91. :key="s"
  92. :value="source"
  93. >
  94. {{ source.description }}
  95. </option>
  96. </select>
  97. <div class="invalid-feedback">
  98. Please select a source!
  99. </div>
  100. </float-label>
  101. </div>
  102. <div class="form-group">
  103. <float-label label="Message" style="width: 100%;">
  104. <textarea
  105. type="text"
  106. id="message"
  107. rows="5"
  108. class="form-control uniInput my-2"
  109. v-model="message"
  110. v-bind:class="{
  111. 'is-valid': message,
  112. 'is-invalid': !requiredField(message) && messageLoad,
  113. }"
  114. v-on:keyup="messageLoad = true"
  115. v-on:blur="messageLoad = true"
  116. placeholder="Message"
  117. ></textarea>
  118. <div class="invalid-feedback">Message is required!</div>
  119. </float-label>
  120. </div>
  121. <div class="text-center">
  122. <button class="btn-white-border" @click="sendMail()">Send</button>
  123. </div>
  124. <div v-if="boolSent">
  125. <alert :text="alertMsg" :type="'SUCCESS'" />
  126. </div>
  127. </div>
  128. </div>
  129. </template>
  130. <script>
  131. /* eslint-disable */
  132. import { mapState, mapActions } from 'vuex'
  133. import axios from 'axios'
  134. import alert from '../shared/alert'
  135. export default {
  136. components: {
  137. alert,
  138. },
  139. data() {
  140. return {
  141. sourceObj: {},
  142. source: '',
  143. mailSource: '',
  144. mailSourceId: '',
  145. alertMsg: 'Sent! You can expect a reply soon!',
  146. name: '',
  147. contactemail: '',
  148. phone: '',
  149. property: '',
  150. message: '',
  151. boolSent: false,
  152. errorOccurred: '',
  153. errorMessage: '',
  154. boolValidationError: false,
  155. nameLoad: false,
  156. contactemailLoad: false,
  157. messageLoad: false,
  158. mailSourceLoad: false,
  159. }
  160. },
  161. mounted() {
  162. this.boolSent = false
  163. console.log('Email')
  164. console.log(this.contactemail)
  165. this.getContactUsSources()
  166. },
  167. computed: {
  168. ...mapState('contactUsSources', ['contactUsSources']),
  169. },
  170. methods: {
  171. ...mapActions('contactUsSources', ['getContactUsSources']),
  172. sourceSelect() {
  173. console.log('sourceSelect')
  174. console.log(this.mailSource.id)
  175. console.log(this.mailSource)
  176. this.mailSourceId = this.mailSource ? this.mailSource.id : 1
  177. },
  178. async sendMail() {
  179. if (this.validatePage()) {
  180. var mailObj = {
  181. name: this.name,
  182. email: this.contactemail,
  183. phone: this.phone,
  184. property: this.property,
  185. message: this.message,
  186. mailSourceId: this.mailSourceId,
  187. }
  188. await axios
  189. .post('/api/mail/0', mailObj)
  190. .then((response) => {
  191. //console.log('Response');
  192. //console.log(response);
  193. this.boolSent = true
  194. })
  195. .catch((err) => {
  196. this.boolValidationError = true
  197. this.errorOccurred = 'ERROR'
  198. this.errorMessage = 'Server Error: CONNECTION_REFUSED'
  199. if (err) {
  200. //console.log('Error');
  201. //console.log(err.response.status);
  202. if (err.response.status) {
  203. this.boolSent = true
  204. this.boolValidationError = false
  205. } else {
  206. this.boolSent = false
  207. }
  208. } else {
  209. console.log('no err')
  210. boolSent = false
  211. }
  212. })
  213. this.name = ''
  214. this.contactemail = ''
  215. this.phone = ''
  216. this.property = ''
  217. this.message = ''
  218. this.mailSource = ''
  219. this.nameLoad = false
  220. this.contactemailLoad = false
  221. this.messageLoad = false
  222. this.mailSourceLoad = false
  223. }
  224. },
  225. countDownChanged(dismissCountDown) {
  226. this.dismissCountDown = dismissCountDown
  227. },
  228. validatePage: function () {
  229. //console.log('validatePage')
  230. if (this.name && this.contactemail && this.mailSource) {
  231. this.errorOccurred = ''
  232. this.errorMessage = ''
  233. this.boolValidationError = false
  234. return true
  235. } else {
  236. this.boolValidationError = true
  237. this.nameLoad = true
  238. this.contactemailLoad = true
  239. this.mailSourceLoad = true
  240. this.messageLoad = true
  241. this.errorOccurred = 'ERROR'
  242. this.errorMessage = 'Please check form and correct all input fields!'
  243. return false
  244. }
  245. },
  246. requiredField: function (tfield) {
  247. if (tfield) {
  248. return true
  249. } else {
  250. return false
  251. }
  252. },
  253. validEmail: function (temail) {
  254. var re = /(.+)@(.+){2,}\.(.+){2,}/
  255. return re.test(temail.toLowerCase())
  256. },
  257. },
  258. }
  259. </script>
  260. <style lang="scss" scoped></style>