import { NumberFormatLocale } from './funcoes.js'; import FormRecipient from "./generic/FormRecipient.js"; export default { name: 'AccountAvatar', components: { FormRecipient }, data() { return { type: window.TYPEUSER, phone: '', image: null, loading: false, is_preview: false, is_community: false, } }, computed: { phone_id() { return NumberFormatLocale(this.phone) + this.type; } }, methods: { async openModal() { this.handleReset(); $('#modalUserAvatar').modal('show'); }, async handleSubmit() { try { await this.submitApi(); showSuccessInfo("Avatar fetched") } catch (err) { showErrorInfo(err) } }, async submitApi() { this.loading = true; try { let response = await window.http.get(`/user/avatar?phone=${this.phone_id}&is_preview=${this.is_preview}&is_community=${this.is_community}`) this.image = response.data.results.url; } 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.image = null; this.type = window.TYPEUSER; } }, template: `