import FormRecipient from "./generic/FormRecipient.js"; export default { name: 'Send', components: { FormRecipient }, data() { return { phone: '', type: window.TYPEUSER, loading: false, selectedFileName: null, is_forwarded: false } }, computed: { phone_id() { return this.phone + this.type; } }, methods: { openModal() { $('#modalAudioSend').modal({ onApprove: function () { return false; } }).modal('show'); }, isValidForm() { if (this.type !== window.TYPEUSER && !this.phone.trim()) { return false; } if (!this.selectedFileName) { return false; } return true; }, async handleSubmit() { if (!this.isValidForm() || this.loading) { return; } try { let response = await this.submitApi() showSuccessInfo(response) $('#modalAudioSend').modal('hide'); } catch (err) { showErrorInfo(err) } }, async submitApi() { this.loading = true; try { let payload = new FormData(); payload.append("phone", this.phone_id) payload.append("is_forwarded", this.is_forwarded) payload.append("audio", $("#file_audio")[0].files[0]) const response = await window.http.post(`/send/audio`, payload) this.handleReset(); return response.data.message; } catch (error) { if (error.response) { throw new Error(error.response.data.message); } throw new Error(error.message); } finally { this.loading = false; } }, handleReset() { this.phone = ''; this.type = window.TYPEUSER; this.is_forwarded = false; $("#file_audio").val(''); this.selectedFileName = null; }, handleFileChange(event) { const file = event.target.files[0]; if (file) { this.selectedFileName = file.name; } } }, template: `
Send
Send Audio
Send audio to user or group
` }