diff --git a/src/views/components/SendContact.js b/src/views/components/SendContact.js new file mode 100644 index 0000000..e3fbf25 --- /dev/null +++ b/src/views/components/SendContact.js @@ -0,0 +1,118 @@ +export default { + name: 'SendContact', + data() { + return { + type: 'user', + phone: '', + card_name: '', + card_phone: '', + loading: false, + } + }, + computed: { + phone_id() { + return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}` + } + }, + methods: { + openModal() { + $('#modalSendContact').modal({ + onApprove: function () { + return false; + } + }).modal('show'); + }, + async handleSubmit() { + try { + this.loading = true; + let response = await this.sendApi() + showSuccessInfo(response) + $('#modalSendContact').modal('hide'); + } catch (err) { + showErrorInfo(err) + } finally { + this.loading = false; + } + }, + async sendApi() { + this.loading = true; + try { + const payload = { + phone: this.phone_id, + contact_name: this.card_name, + contact_phone: this.card_phone + } + let response = await window.http.post(`/send/contact`, 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.card_name = ''; + this.card_phone = ''; + this.type = 'user'; + }, + }, + template:` +
+
+ Send +
Send Contact
+
+ Send contact to user or group +
+
+
+ + + + ` +} \ No newline at end of file diff --git a/src/views/components/SendFile.js b/src/views/components/SendFile.js new file mode 100644 index 0000000..f8ba014 --- /dev/null +++ b/src/views/components/SendFile.js @@ -0,0 +1,123 @@ +export default { + name: 'SendFile', + props: { + maxFileSize: { + type: String, + required: true, + } + }, + data() { + return { + caption: '', + type: 'user', + phone: '', + loading: false, + } + }, + computed: { + phone_id() { + return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}` + } + }, + methods: { + openModal() { + $('#modalSendFile').modal({ + onApprove: function () { + return false; + } + }).modal('show'); + }, + async handleSubmit() { + try { + let response = await this.sendApi() + showSuccessInfo(response) + $('#modalSendFile').modal('hide'); + } catch (err) { + showErrorInfo(err) + } + }, + async sendApi() { + this.loading = true; + try { + let payload = new FormData(); + payload.append("caption", this.caption) + payload.append("phone", this.phone_id) + payload.append("file", $("#file")[0].files[0]) + let response = await http.post(`/send/file`, 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.caption = ''; + this.phone = ''; + this.type = 'user'; + $("#file").val(''); + }, + }, + template: ` +
+
+ Send +
Send File
+
+ Send any file up to +
{{ maxFileSize }}
+
+
+
+ + + + ` +} \ No newline at end of file diff --git a/src/views/components/SendVideo.js b/src/views/components/SendVideo.js new file mode 100644 index 0000000..65b9285 --- /dev/null +++ b/src/views/components/SendVideo.js @@ -0,0 +1,146 @@ +export default { + name: 'SendVideo', + // define props + props: { + maxVideoSize: { + type: String, + required: true, + } + }, + data() { + return { + caption: '', + view_once: false, + compress: false, + type: 'user', + phone: '', + loading: false, + } + }, + computed: { + phone_id() { + return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}` + } + }, + methods: { + openModal() { + $('#modalSendVideo').modal({ + onApprove: function () { + return false; + } + }).modal('show'); + }, + async handleSubmit() { + try { + let response = await this.sendApi() + showSuccessInfo(response) + $('#modalSendVideo').modal('hide'); + } catch (err) { + showErrorInfo(err) + } + }, + async sendApi() { + this.loading = true; + try { + let payload = new FormData(); + payload.append("phone", this.phone_id) + payload.append("caption", this.caption) + payload.append("view_once", this.view_once) + payload.append("compress", this.compress) + payload.append("video", $("#file")[0].files[0]) + let response = await window.http.post(`/send/video`, 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.caption = ''; + this.view_once = false; + this.compress = false; + this.phone = ''; + this.type = 'user'; + $("#file").val(''); + }, + }, + template: ` +
+
+ Send +
Send Video
+
+ Send video +
mp4
+ up to +
{{ maxVideoSize }}
+
+
+
+ + + + ` +} \ No newline at end of file diff --git a/src/views/index.html b/src/views/index.html index 9cfcc3c..548ee09 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -12,7 +12,7 @@ - + Whatsapp API Multi Device {{ .AppVersion }} @@ -93,37 +93,10 @@ -
-
- Send -
Send File
-
- Send any file up to -
{{ .MaxFileSize }}
-
-
-
-
-
- Send -
Send Video
-
- Send video -
mp4
- up to -
{{ .MaxVideoSize }}
-
-
-
-
-
- Send -
Send Contact
-
- Send contact to user or group -
-
-
+ + + + @@ -309,152 +282,6 @@ - - - - - - - - -