Skip to content

Commit 4fb5186

Browse files
committed
feat: add UI to add files to envelope
Add button and functionality to add multiple PDF files to an envelope: - Add 'Add file to envelope' button in sidebar - Support multiple file selection - Upload via multipart/form-data - Show capability-based visibility check - Display API response messages - Clean error handling without duplicate toasts Signed-off-by: Vitor Mattos <[email protected]>
1 parent 3fbc56e commit 4fb5186

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

src/Components/RightSidebar/RequestSignatureTab.vue

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@
116116
</NcButton>
117117
</div>
118118
<div class="button-group">
119+
<NcButton v-if="isEnvelope && canAddFilesToEnvelope"
120+
wide
121+
variant="secondary"
122+
@click="addFileToEnvelope">
123+
<template #icon>
124+
<FilePlus :size="20" />
125+
</template>
126+
{{ t('libresign', 'Add file to envelope') }}
127+
</NcButton>
119128
<NcButton v-if="filesStore.canValidate()"
120129
wide
121130
variant="secondary"
@@ -236,6 +245,7 @@ import ChartGantt from 'vue-material-design-icons/ChartGantt.vue'
236245
import Delete from 'vue-material-design-icons/Delete.vue'
237246
import Draw from 'vue-material-design-icons/Draw.vue'
238247
import FileDocument from 'vue-material-design-icons/FileDocument.vue'
248+
import FilePlus from 'vue-material-design-icons/FilePlus.vue'
239249
import Information from 'vue-material-design-icons/Information.vue'
240250
import MessageText from 'vue-material-design-icons/MessageText.vue'
241251
import OrderNumericAscending from 'vue-material-design-icons/OrderNumericAscending.vue'
@@ -297,6 +307,7 @@ export default {
297307
Delete,
298308
Draw,
299309
FileDocument,
310+
FilePlus,
300311
IdentifySigner,
301312
Information,
302313
MessageText,
@@ -519,6 +530,17 @@ export default {
519530
fileName() {
520531
return this.filesStore.getFile()?.name ?? ''
521532
},
533+
isEnvelope() {
534+
return this.filesStore.getFile()?.nodeType === 'envelope'
535+
},
536+
canAddFilesToEnvelope() {
537+
const file = this.filesStore.getFile()
538+
if (!file || file.status !== SIGN_STATUS.DRAFT) {
539+
return false
540+
}
541+
const capabilities = getCapabilities()
542+
return capabilities?.libresign?.config?.envelope?.['is-available'] === true
543+
},
522544
size() {
523545
return window.matchMedia('(max-width: 512px)').matches ? 'full' : 'normal'
524546
},
@@ -873,6 +895,48 @@ export default {
873895
this.signStore.setDocumentToSign(this.filesStore.getFile())
874896
this.$router.push({ name: 'SignPDF', params: { uuid } })
875897
},
898+
addFileToEnvelope() {
899+
const input = document.createElement('input')
900+
input.type = 'file'
901+
input.accept = '.pdf'
902+
input.multiple = true
903+
input.onchange = (e) => {
904+
const files = e.target.files
905+
if (!files || files.length === 0) return
906+
907+
this.hasLoading = true
908+
const envelope = this.filesStore.getFile()
909+
const formData = new FormData()
910+
911+
for (const file of files) {
912+
formData.append('files[]', file)
913+
}
914+
915+
axios.post(
916+
generateOcsUrl('/apps/libresign/api/v1/file/{uuid}/add-file', { uuid: envelope.uuid }),
917+
formData,
918+
{
919+
headers: {
920+
'Content-Type': 'multipart/form-data',
921+
},
922+
}
923+
)
924+
.then(({ data }) => {
925+
showSuccess(data.ocs.data.message)
926+
})
927+
.catch((error) => {
928+
if (error.response?.data?.ocs?.data?.message) {
929+
showError(error.response.data.ocs.data.message)
930+
} else {
931+
showError(t('libresign', 'Failed to add files to envelope'))
932+
}
933+
})
934+
.finally(() => {
935+
this.hasLoading = false
936+
})
937+
}
938+
input.click()
939+
},
876940
async save() {
877941
this.hasLoading = true
878942
try {

0 commit comments

Comments
 (0)