Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Components/Request/IdentifySigner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export default {
})

try {
await this.filesStore.saveWithVisibleElements({ visibleElements: [] })
await this.filesStore.saveOrUpdateSignatureRequest({})
} catch (error) {
console.error('Error saving signer:', error)
}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Request/VisibleElements.vue
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export default {
const visibleElements = this.buildVisibleElements()

try {
const response = await this.filesStore.saveWithVisibleElements({ visibleElements })
const response = await this.filesStore.saveOrUpdateSignatureRequest({ visibleElements })
showSuccess(t('libresign', response.message))
this.closeModal()
this.loading = false
Expand Down
11 changes: 5 additions & 6 deletions src/Components/RightSidebar/RequestSignatureTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,7 @@ export default {
this.debouncedSave = debounce(async () => {
try {
const file = this.filesStore.getFile()
await this.filesStore.saveWithVisibleElements({
visibleElements: [],
await this.filesStore.saveOrUpdateSignatureRequest({
signatureFlow: file?.signatureFlow,
})
} catch (error) {
Expand Down Expand Up @@ -874,9 +873,9 @@ export default {
}
return s
})
await this.filesStore.updateSignatureRequest({
visibleElements: [],
await this.filesStore.saveOrUpdateSignatureRequest({
signers,
status: 1,
})
showSuccess(t('libresign', 'Signature requested'))
this.showConfirmRequestSigner = false
Expand Down Expand Up @@ -910,7 +909,7 @@ export default {
async save() {
this.hasLoading = true
try {
await this.filesStore.saveWithVisibleElements({ visibleElements: [] })
await this.filesStore.saveOrUpdateSignatureRequest({})
emit('libresign:show-visible-elements')
} catch (error) {
if (error.response?.data?.ocs?.data?.message) {
Expand All @@ -927,7 +926,7 @@ export default {
async confirmRequest() {
this.hasLoading = true
try {
const response = await this.filesStore.updateSignatureRequest({ visibleElements: [], status: 1 })
const response = await this.filesStore.saveOrUpdateSignatureRequest({ status: 1 })
showSuccess(t('libresign', response.message))
this.showConfirmRequest = false
} catch (error) {
Expand Down
77 changes: 2 additions & 75 deletions src/store/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,81 +509,7 @@ export const useFilesStore = function(...args) {
filesSorted() {
return this.ordered.map(key => this.files[key])
},
async saveWithVisibleElements({ visibleElements = [], signers = null, uuid = null, fileId = null, signatureFlow = null }) {
const file = this.getFile()

let flowValue = signatureFlow || file.signatureFlow
if (typeof flowValue === 'number') {
const flowMap = { 0: 'none', 1: 'parallel', 2: 'ordered_numeric' }
flowValue = flowMap[flowValue] || 'parallel'
}

const config = {
url: generateOcsUrl('/apps/libresign/api/v1/request-signature'),
method: uuid || file.uuid ? 'patch' : 'post',
data: {
name: file?.name,
users: signers || file.signers || [],
visibleElements,
status: 0,
signatureFlow: flowValue,
},
}

if (uuid || file.uuid) {
config.data.uuid = uuid || file.uuid
} else if (file.id) {
config.data.file = { fileId: file.id }
} else if (file.files) {
config.data.files = file.files
} else if (!isNaN(file.nodeId)) {
config.data.file = { nodeId: file.nodeId }
}

if (file.settings) {
if (config.data.file) {
config.data.file.settings = file.settings
} else if (config.data.files) {
config.data.settings = file.settings
}
}

const { data } = await axios(config)
const responseFile = data?.ocs?.data

if (file.nodeType === 'envelope' && typeof file.nodeId === 'string' && responseFile.nodeId !== file.nodeId) {
delete this.files[file.nodeId]
const index = this.ordered.indexOf(file.nodeId)
if (index !== -1) {
this.ordered.splice(index, 1)
}
}

if (responseFile.nodeId) {
const nodeId = responseFile.nodeId
const existingFile = this.files[file.nodeId] || this.files[nodeId]
if (existingFile?.settings) {
responseFile.settings = { ...existingFile.settings, ...responseFile.settings }
}
set(this.files, nodeId, responseFile)
this.addUniqueIdentifierToAllSigners(this.files[nodeId].signers)
if (!this.ordered.includes(nodeId)) {
this.ordered.push(nodeId)
}
if (this.selectedNodeId === file.nodeId) {
this.selectedNodeId = nodeId
}
} else {
this.addFile(responseFile)
}
const eventName = (!uuid && !file.uuid) ? 'libresign:file:created' : 'libresign:file:updated'
emit(eventName, {
path: responseFile.settings?.path,
nodeId: responseFile.nodeId,
})
return data.ocs.data
},
async updateSignatureRequest({ visibleElements = [], signers = null, uuid = null, fileId = null, status = 1, signatureFlow = null }) {
async saveOrUpdateSignatureRequest({ visibleElements = [], signers = null, uuid = null, fileId = null, status = 0, signatureFlow = null } = {}) {
const file = this.getFile()

let flowValue = signatureFlow || file.signatureFlow
Expand Down Expand Up @@ -621,6 +547,7 @@ export const useFilesStore = function(...args) {
config.data.settings = file.settings
}
}

const { data } = await axios(config)
const responseFile = data?.ocs?.data

Expand Down
Loading