diff --git a/src/views/components/GroupAddParticipants.js b/src/views/components/GroupAddParticipants.js new file mode 100644 index 0000000..4d272fc --- /dev/null +++ b/src/views/components/GroupAddParticipants.js @@ -0,0 +1,119 @@ +export default { + name: 'AddParticipantsToGroup', + data() { + return { + loading: false, + group: '', + participants: ['', ''], + } + }, + computed: { + group_id() { + return `${this.group}@${window.TYPEGROUP}` + } + }, + methods: { + openModal() { + $('#modalGroupAddParticipant').modal({ + onApprove: function () { + return false; + } + }).modal('show'); + }, + handleAddParticipant() { + this.participants.push('') + }, + handleDeleteParticipant(index) { + this.participants.splice(index, 1) + }, + async handleSubmit() { + try { + let response = await this.submitApi() + showSuccessInfo(response) + $('#modalGroupAddParticipant').modal('hide'); + } catch (err) { + showErrorInfo(err) + } + }, + async submitApi() { + this.loading = true; + try { + let response = await window.http.post(`/group/participants`, { + group_id: this.group_id, + // convert participant become list of string + participants: this.participants.filter(participant => participant !== '').map(participant => `${participant}`) + }) + 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.group = ''; + this.participants = ['', '']; + }, + }, + template: ` +