import FormRecipient from "./generic/FormRecipient.js"; export default { name: 'AccountUserCheck', components: { FormRecipient }, data() { return { type: window.TYPEUSER, phone: '', isOnWhatsApp: null, loading: false, } }, computed: { phone_id() { return this.phone + this.type; } }, methods: { async openModal() { this.handleReset(); $('#modalUserCheck').modal('show'); }, isValidForm() { return this.phone.trim() !== ''; }, async handleSubmit() { if (!this.isValidForm() || this.loading) { return; } try { await this.submitApi(); showSuccessInfo("Check completed") } catch (err) { showErrorInfo(err) } }, async submitApi() { this.loading = true; try { let response = await window.http.get(`/user/check?phone=${this.phone_id}`) this.isOnWhatsApp = response.data.results.is_on_whatsapp; } 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.isOnWhatsApp = null; this.type = window.TYPEUSER; } }, template: `