8 changed files with 148 additions and 12 deletions
-
2src/config/settings.go
-
3src/internal/rest/group.go
-
4src/pkg/whatsapp/whatsapp.go
-
9src/services/group.go
-
2src/validations/group_validation.go
-
114src/views/components/GroupCreate.js
-
10src/views/components/GroupList.js
-
16src/views/index.html
@ -0,0 +1,114 @@ |
|||||
|
export default { |
||||
|
name: 'CreateGroup', |
||||
|
data() { |
||||
|
return { |
||||
|
loading: false, |
||||
|
title: '', |
||||
|
participants: ['', ''], |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
openModal() { |
||||
|
$('#modalGroupCreate').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) |
||||
|
$('#modalGroupCreate').modal('hide'); |
||||
|
} catch (err) { |
||||
|
showErrorInfo(err) |
||||
|
} |
||||
|
}, |
||||
|
async submitApi() { |
||||
|
this.loading = true; |
||||
|
try { |
||||
|
let response = await window.http.post(`/group`, { |
||||
|
title: this.title, |
||||
|
// convert participant become list of string
|
||||
|
participants: this.participants.filter(participant => participant !== '').map(participant => `${participant}`) |
||||
|
}) |
||||
|
this.handleReset(); |
||||
|
this.groups = response.data.results.data; |
||||
|
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.title = ''; |
||||
|
this.participants = ['', '']; |
||||
|
}, |
||||
|
}, |
||||
|
template: `
|
||||
|
<div class="green card" @click="openModal" style="cursor: pointer"> |
||||
|
<div class="content"> |
||||
|
<div class="header">Create Groups</div> |
||||
|
<div class="description"> |
||||
|
Add more friends to your group |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<!-- Modal AccountGroup --> |
||||
|
<div class="ui small modal" id="modalGroupCreate"> |
||||
|
<i class="close icon"></i> |
||||
|
<div class="header"> |
||||
|
|
||||
|
</div> |
||||
|
<div class="content"> |
||||
|
<form class="ui form"> |
||||
|
<div class="field"> |
||||
|
<label>Group Name</label> |
||||
|
<input v-model="title" type="text" |
||||
|
placeholder="Group Name..." |
||||
|
aria-label="Group Name"> |
||||
|
</div> |
||||
|
|
||||
|
<div class="field"> |
||||
|
<label>Participants</label> |
||||
|
<div style="display: flex; flex-direction: column; gap: 5px"> |
||||
|
<div class="ui action input" :key="index" v-for="(participant, index) in participants"> |
||||
|
<input type="number" placeholder="Phone Int Number (6289...)" v-model="participants[index]" |
||||
|
aria-label="list participant"> |
||||
|
<button class="ui button" @click="handleDeleteParticipant(index)" type="button"> |
||||
|
<i class="minus circle icon"></i> |
||||
|
</button> |
||||
|
</div> |
||||
|
<div class="field" style="display: flex; flex-direction: column; gap: 3px"> |
||||
|
<small>You do not need to include yourself as participant. it will be automatically included.</small> |
||||
|
<div> |
||||
|
<button class="mini ui primary button" @click="handleAddParticipant" type="button"> |
||||
|
<i class="plus icon"></i> Option |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</form> |
||||
|
</div> |
||||
|
<div class="actions"> |
||||
|
<div class="ui approve positive right labeled icon button" :class="{'loading': this.loading}" |
||||
|
@click="handleSubmit" type="button"> |
||||
|
Create |
||||
|
<i class="send icon"></i> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
`
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue