whatsapp-multi-devicewhatsapp-apiwhatsapprestgolanggogolang-whatsapp-apigolang-whatsappbotwhatsapp-web-multi-devicewhatsapp-api-gorest-api
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.4 KiB
115 lines
3.4 KiB
import FormRecipient from "./generic/FormRecipient.js";
|
|
|
|
export default {
|
|
name: 'DeleteMessage',
|
|
components: {
|
|
FormRecipient
|
|
},
|
|
data() {
|
|
return {
|
|
type: window.TYPEUSER,
|
|
phone: '',
|
|
message_id: '',
|
|
loading: false,
|
|
}
|
|
},
|
|
computed: {
|
|
phone_id() {
|
|
return this.phone + this.type;
|
|
}
|
|
},
|
|
methods: {
|
|
openModal() {
|
|
$('#modalMessageDelete').modal({
|
|
onApprove: function () {
|
|
return false;
|
|
}
|
|
}).modal('show');
|
|
},
|
|
isValidForm() {
|
|
if (this.type !== window.TYPESTATUS && !this.phone.trim()) {
|
|
return false;
|
|
}
|
|
|
|
if (!this.message_id.trim()) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
},
|
|
async handleSubmit() {
|
|
if (!this.isValidForm() || this.loading) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
let response = await this.submitApi()
|
|
showSuccessInfo(response)
|
|
$('#modalMessageDelete').modal('hide');
|
|
} catch (err) {
|
|
showErrorInfo(err)
|
|
}
|
|
},
|
|
async submitApi() {
|
|
this.loading = true;
|
|
try {
|
|
const payload = {phone: this.phone_id, message: this.new_message}
|
|
|
|
let response = await window.http.post(`/message/${this.message_id}/delete`, payload)
|
|
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.type = window.TYPEUSER;
|
|
this.phone = '';
|
|
this.message_id = '';
|
|
this.new_message = '';
|
|
this.loading = false;
|
|
},
|
|
},
|
|
template: `
|
|
<div class="red card" @click="openModal()" style="cursor: pointer">
|
|
<div class="content">
|
|
<a class="ui red right ribbon label">Message</a>
|
|
<div class="header">Delete Message</div>
|
|
<div class="description">
|
|
Delete your sent message
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal MessageDelete -->
|
|
<div class="ui small modal" id="modalMessageDelete">
|
|
<i class="close icon"></i>
|
|
<div class="header">
|
|
Delete Message
|
|
</div>
|
|
<div class="content">
|
|
<form class="ui form">
|
|
<FormRecipient v-model:type="type" v-model:phone="phone"/>
|
|
|
|
<div class="field">
|
|
<label>Message ID</label>
|
|
<input v-model="message_id" type="text" placeholder="Please enter your message id"
|
|
aria-label="message id">
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="actions">
|
|
<button class="ui approve positive right labeled icon button" :class="{'loading': this.loading, 'disabled': !isValidForm() || loading}"
|
|
@click.prevent="handleSubmit">
|
|
Delete
|
|
<i class="send icon"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
`
|
|
}
|