diff --git a/src/views/components/SendMessage.js b/src/views/components/SendMessage.js new file mode 100644 index 0000000..574b471 --- /dev/null +++ b/src/views/components/SendMessage.js @@ -0,0 +1,119 @@ +export default { + name: 'SendMessage', + data() { + return { + type: 'user', + phone: '', + text: '', + reply_id: '', + loading: false, + } + }, + computed: { + phone_id() { + return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}` + } + }, + methods: { + openModal() { + $('#modalSendMessage').modal({ + onApprove: function () { + return false; + } + }).modal('show'); + }, + async handleSubmit() { + try { + let response = await this.sendApi() + showSuccessInfo(response) + $('#modalSendMessage').modal('hide'); + } catch (err) { + showErrorInfo(err) + } + }, + async sendApi() { + this.loading = true; + try { + const payload = { + phone: this.phone_id, + message: this.text, + } + if (this.reply_id !== '') { + payload.reply_id = this.reply_id; + } + + let response = await http.post(`/send/message`, payload) + this.handleReset(); + return response.data.message; + } catch (error) { + if (error.response) { + throw new Error(error.response.data.message); + } else { + throw new Error(error.message); + } + } finally { + this.loading = false; + } + }, + handleReset() { + this.phone = ''; + this.text = ''; + this.type = 'user'; + this.reply_id = ''; + }, + }, + template: ` +
+
+ Send +
Send Message
+
+ Send any message to user or group +
+
+
+ + + + ` +} \ No newline at end of file diff --git a/src/views/index.html b/src/views/index.html index 2233ab2..a90d8a9 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -73,22 +73,14 @@
-
-
- Send -
Send Message
-
- Send any message to user or group -
-
-
- + + - +
@@ -169,49 +161,6 @@ - - -