import FormRecipient from "./generic/FormRecipient.js"; export default { name: 'SendVideo', components: { FormRecipient }, props: { maxVideoSize: { type: String, required: true, } }, data() { return { caption: '', view_once: false, compress: false, type: window.TYPEUSER, phone: '', loading: false, selectedFileName: null, is_forwarded: false } }, computed: { phone_id() { return this.phone + this.type; }, }, watch: { view_once(newValue) { // If view_once is set to true, set is_forwarded to false if (newValue === true) { this.is_forwarded = false; } } }, methods: { openModal() { $('#modalSendVideo').modal({ onApprove: function () { return false; } }).modal('show'); }, isShowAttributes() { return this.type !== window.TYPESTATUS; }, isValidForm() { let isValid = true; if (this.type !== window.TYPESTATUS && !this.phone.trim()) { isValid = false; } const fileInput = $("#file_video")[0]; if (!fileInput || !fileInput.files || !fileInput.files[0]) { console.log('fileInput', fileInput); isValid = false; } else { const videoFile = fileInput.files[0]; // Validate file type if (!videoFile.type.startsWith('video/')) { isValid = false; console.log('videoFile', videoFile); } } return isValid; }, async handleSubmit() { if (!this.isValidForm() || this.loading) { return; } try { let response = await this.submitApi() showSuccessInfo(response) $('#modalSendVideo').modal('hide'); } catch (err) { showErrorInfo(err) } }, async submitApi() { this.loading = true; try { let payload = new FormData(); payload.append("phone", this.phone_id) payload.append("caption", this.caption.trim()) payload.append("view_once", this.view_once) payload.append("compress", this.compress) payload.append("is_forwarded", this.is_forwarded) payload.append('video', $("#file_video")[0].files[0]) let response = await window.http.post(`/send/video`, 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.caption = ''; this.view_once = false; this.compress = false; this.phone = ''; this.selectedFileName = null; this.is_forwarded = false; $("#file_video").val(''); }, handleFileChange(event) { const file = event.target.files[0]; if (file) { this.selectedFileName = file.name; } } }, template: `
Send
Send Video
Send video
mp4
up to
{{ maxVideoSize }}
` }