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: ` +
+
+ Group +
Add Participants
+
+ Add multiple participants +
+
+
+ + + + ` +} \ No newline at end of file diff --git a/src/views/index.html b/src/views/index.html index 17cc325..75723e0 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -81,6 +81,7 @@ +
@@ -141,6 +142,7 @@ import GroupList from "./components/GroupList.js"; import GroupCreate from "./components/GroupCreate.js"; import GroupJoinWithLink from "./components/GroupJoinWithLink.js"; + import GroupAddParticipants from "./components/GroupAddParticipants.js"; import AccountAvatar from "./components/AccountAvatar.js"; import AccountUserInfo from "./components/AccountUserInfo.js"; import AccountPrivacy from "./components/AccountPrivacy.js"; @@ -169,7 +171,7 @@ AppLogin, AppLogout, AppReconnect, SendMessage, SendImage, SendFile, SendVideo, SendContact, SendLocation, SendAudio, SendPoll, MessageUpdate, MessageReact, MessageRevoke, - GroupList, GroupCreate, GroupJoinWithLink, + GroupList, GroupCreate, GroupJoinWithLink, GroupAddParticipants, AccountAvatar, AccountUserInfo, AccountPrivacy }, delimiters: ['[[', ']]'],