Hopefully Eightpieces is less buggish now
[vchess.git] / client / src / components / ContactForm.vue
index 392d319..b7aea94 100644 (file)
@@ -1,42 +1,51 @@
 <template lang="pug">
 div
-  input#modalContact.modal(type="checkbox" @change="trySetEnterTime($event)")
-  div(role="dialog" data-checkbox="modalContact")
+  input#modalContact.modal(
+    type="checkbox"
+    @change="trySetEnterTime($event)"
+  )
+  div#contactDiv(
+    role="dialog"
+    data-checkbox="modalContact"
+  )
     .card
       label.modal-close(for="modalContact")
-      h3.section {{ st.tr["Contact form"] }}
-      form(@submit.prevent="trySendMessage()" @keyup.enter="trySendMessage()")
-        fieldset
-          label(for="userEmail") {{ st.tr["Email"] }}
-          input#userEmail(type="email")
-        fieldset
-          label(for="mailSubject") {{ st.tr["Subject"] }}
-          input#mailSubject(type="text")
-        fieldset
-          label(for="mailContent") {{ st.tr["Content"] }} *
-          br
-          textarea#mailContent
+      a#discordLink(href="https://discord.gg/a9ZFKBe")
+        span {{ st.tr["Discord invitation"] }}
+        img(src="/images/icons/discord.svg")
+      fieldset
+        label(for="userEmail") {{ st.tr["Email"] }}
+        input#userEmail(type="email" :value="st.user.email")
+      fieldset
+        label(for="mailSubject") {{ st.tr["Subject"] }}
+        input#mailSubject(type="text")
+      fieldset
+        textarea#mailContent(:placeholder="st.tr['Your message']")
       button(@click="trySendMessage()") {{ st.tr["Send"] }}
       #dialog.text-center {{ st.tr[infoMsg] }}
 </template>
 
 <script>
-import { ajax } from "../utils/ajax";
+import { ajax } from "@/utils/ajax";
 import { store } from "@/store";
 import { checkNameEmail } from "@/data/userCheck";
+import { processModalClick } from "@/utils/modalClick.js";
 export default {
   name: "my-contact-form",
   data: function() {
     return {
       enterTime: Number.MAX_SAFE_INTEGER, //for a basic anti-bot strategy
       st: store.state,
-      infoMsg: "",
+      infoMsg: ""
     };
   },
+  mounted: function() {
+    document.getElementById("contactDiv")
+      .addEventListener("click", processModalClick);
+  },
   methods: {
     trySetEnterTime: function(event) {
-      if (!!event.target.checked)
-      {
+      if (event.target.checked) {
         this.enterTime = Date.now();
         this.infoMsg = "";
       }
@@ -44,36 +53,42 @@ export default {
     trySendMessage: function() {
       // Basic anti-bot strategy:
       const exitTime = Date.now();
-      if (exitTime - this.enterTime < 5000)
-        return;
+      if (exitTime - this.enterTime < 5000) return;
       let email = document.getElementById("userEmail");
       let subject = document.getElementById("mailSubject");
       let content = document.getElementById("mailContent");
-      const error = checkNameEmail({email: email});
-      if (!!error)
-        return alert(error);
-      if (content.value.trim().length == 0)
-        return alert(this.st.tr["Empty message"]);
-      if (subject.value.trim().length == 0 && !confirm(this.st.tr["No subject. Send anyway?"]))
+      let error = checkNameEmail({ email: email });
+      if (!error && content.value.trim().length == 0)
+        error = this.st.tr["Empty message"];
+      if (error) {
+        alert(error);
+        return;
+      }
+      if (
+        subject.value.trim().length == 0 &&
+        !confirm(this.st.tr["No subject. Send anyway?"])
+      )
         return;
-
       // Message sending:
       ajax(
         "/messages",
         "POST",
         {
-          email: email.value,
-          subject: subject.value,
-          content: content.value,
-        },
-        () => {
-          this.infoMsg = "Email sent!";
-          subject.value = "";
-          content.value = "";
+          nocredentials: true,
+          data: {
+            email: email.value,
+            subject: subject.value,
+            content: content.value
+          },
+          success: () => {
+            this.infoMsg = "Email sent!";
+            subject.value = "";
+            content.value = "";
+          }
         }
       );
-    },
-  },
+    }
+  }
 };
 </script>
 
@@ -81,9 +96,21 @@ export default {
 [type="checkbox"].modal+div .card
   max-width: 767px
   max-height: 100%
+
 textarea#mailContent
   width: 100%
   min-height: 100px
+
+#discordLink
+  display: block
+  margin-top: 10px
+  text-align: center
+  font-size: 1.3em
+  & > img
+    height: 1.5em
+    display: inline-block
+    margin-left: 5px
+
 #dialog
   padding: 5px
   color: blue