Skip to content
717 changes: 717 additions & 0 deletions src/components/PdfEditor/PdfEditor.spec.js

Large diffs are not rendered by default.

425 changes: 425 additions & 0 deletions src/components/Request/VisibleElements.spec.js

Large diffs are not rendered by default.

563 changes: 563 additions & 0 deletions src/components/RightSidebar/RequestSignatureTab.spec.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/components/RightSidebar/RequestSignatureTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -775,19 +775,22 @@ export default {

const file = this.filesStore.getFile()
const signerOrder = signer.signingOrder || 1
const signers = Array.isArray(file?.signers) ? file.signers : []

const hasPendingLowerOrder = file.signers.some(s => {
const hasPendingLowerOrder = signers.some(s => {
const otherOrder = s.signingOrder || 1
return otherOrder < signerOrder && !s.signed
})

return !hasPendingLowerOrder
},
hasAnyDraftSigner(file) {
return file.signers.some(signer => signer.status === 0)
const signers = Array.isArray(file?.signers) ? file.signers : []
return signers.some(signer => signer.status === 0)
},
hasSequentialDraftSigners(file) {
const signersNotSigned = file.signers.filter(s => !s.signed)
const signers = Array.isArray(file?.signers) ? file.signers : []
const signersNotSigned = signers.filter(s => !s.signed)
if (signersNotSigned.length === 0) {
return false
}
Expand All @@ -799,7 +802,8 @@ export default {
return Math.min(...signersNotSigned.map(s => s.signingOrder || 1))
},
hasOrderDraftSigners(file, order) {
return file.signers.some(signer => {
const signers = Array.isArray(file?.signers) ? file.signers : []
return signers.some(signer => {
const signerOrder = signer.signingOrder || 1
return signerOrder === order && signer.status === 0
})
Expand Down
80 changes: 44 additions & 36 deletions src/services/longPolling.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,63 @@ export const waitForFileStatusChange = async (fileId, currentStatus, timeout = 3
return response.data.ocs.data
}

export const startLongPolling = (fileId, initialStatus, onUpdate, shouldStop, onError = null) => {
let isRunning = true
let currentStatus = initialStatus
let errorCount = 0
const MAX_ERRORS = 5

const stopPolling = () => {
isRunning = false
}
export const createLongPolling = (options = {}) => {
return (fileId, initialStatus, onUpdate, shouldStop, onError = null) => {
let isRunning = true
let currentStatus = initialStatus
let errorCount = 0
const MAX_ERRORS = 5
const waitForStatusChange = options.waitForFileStatusChange || waitForFileStatusChange
const sleepFn = options.sleep || sleep

const stopPolling = () => {
isRunning = false
}

const poll = async () => {
while (isRunning) {
if (shouldStop && shouldStop()) {
break
}
const poll = async () => {
while (isRunning) {
if (shouldStop && shouldStop()) {
break
}

try {
const data = await waitForFileStatusChange(fileId, currentStatus, 30)
try {
const data = await waitForStatusChange(fileId, currentStatus, 30)

errorCount = 0
errorCount = 0

if (data.status !== currentStatus) {
currentStatus = data.status
onUpdate(data)
if (data.status !== currentStatus) {
currentStatus = data.status
onUpdate(data)

if (isTerminalStatus(data.status)) {
break
if (isTerminalStatus(data.status)) {
break
}
}
}
} catch (error) {
errorCount++
} catch (error) {
errorCount++

if (onError) {
onError(error)
}
if (onError) {
onError(error)
}

if (errorCount >= MAX_ERRORS) {
console.error('Long polling stopped after', MAX_ERRORS, 'consecutive errors')
break
}
if (errorCount >= MAX_ERRORS) {
console.error('Long polling stopped after', MAX_ERRORS, 'consecutive errors')
break
}

await sleep(3000)
await sleepFn(3000)
}
}
}
}

poll()
poll()

return stopPolling
}
}

return stopPolling
export const startLongPolling = (fileId, initialStatus, onUpdate, shouldStop, onError = null, options = {}) => {
return createLongPolling(options)(fileId, initialStatus, onUpdate, shouldStop, onError)
}

const isTerminalStatus = (status) => {
Expand Down
Loading
Loading