import FormRecipient from "./generic/FormRecipient.js"; export default { name: 'SendContact', components: { FormRecipient }, data() { return { type: window.TYPEUSER, phone: '', card_name: '', card_phone: '', loading: false, } }, computed: { phone_id() { return this.phone + this.type; } }, methods: { openModal() { $('#modalSendContact').modal({ onApprove: function () { return false; } }).modal('show'); }, isValidForm() { if (this.type !== window.TYPESTATUS && !this.phone.trim()) { return false; } if (!this.card_name.trim()) { return false; } if (!this.card_phone.trim()) { return false; } return true; }, async handleSubmit() { try { this.loading = true; let response = await this.submitApi() showSuccessInfo(response) $('#modalSendContact').modal('hide'); } catch (err) { showErrorInfo(err) } finally { this.loading = false; } }, async submitApi() { if (!this.isValidForm() || this.loading) { return; } 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); } throw new Error(error.message); } finally { this.loading = false; } }, handleReset() { this.phone = ''; this.card_name = ''; this.card_phone = ''; this.type = window.TYPEUSER; }, }, template: `
Send
Send Contact
Send contact to user or group
` }