diff --git a/src/views/components/AccountAvatar.js b/src/views/components/AccountAvatar.js new file mode 100644 index 0000000..3509ecd --- /dev/null +++ b/src/views/components/AccountAvatar.js @@ -0,0 +1,112 @@ +export default { + name: 'AccountAvatar', + data() { + return { + type: 'user', + phone: '', + image: null, + loading: false, + is_preview: false, + is_community: false, + } + }, + computed: { + phone_id() { + return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}` + } + }, + 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 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 = 'user'; + } + }, + template: ` +
| Group ID | +Name | +Participants | +Created At | +Action | +
|---|---|---|---|---|
| {{ g.JID.split('@')[0] }} | +{{ g.Name }} | +{{ g.Participants.length }} | +{{ formatDate(g.GroupCreated) }} | ++ + | +
| Group ID | -Name | -Participants | -Created At | -Action | -
|---|---|---|---|---|
| [[ g.JID.split('@')[0] ]] | -[[ g.Name ]] | -[[ g.Participants.length ]] | -[[ formatDate(g.GroupCreated) ]] | -- - | -