Skip to content

Commit a7adf8c

Browse files
authored
Merge pull request #6673 from LibreSign/refactor/extract-logic-to-choose-the-action
refactor: extract logic to choose the action
2 parents a18f826 + 3abf550 commit a7adf8c

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

src/helpers/SigningActionHelper.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2026 LibreCode coop and LibreCode contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
/**
7+
* Determine the primary action to execute based on current signing state
8+
* @param {Object} signStore - Sign store instance
9+
* @param {Object} signMethodsStore - SignMethods store instance
10+
* @param {Boolean} needCreateSignature - Whether signature needs to be created
11+
* @param {Boolean} needIdentificationDocuments - Whether identification documents are needed
12+
* @returns {Object|null} - Action object with action name and callback or null if unable to sign
13+
*/
14+
export function getPrimarySigningAction(signStore, signMethodsStore, needCreateSignature, needIdentificationDocuments) {
15+
if (signMethodsStore.needCertificate()) {
16+
return { action: 'uploadCertificate' }
17+
}
18+
19+
if (signMethodsStore.needCreatePassword()) {
20+
return { action: 'createPassword' }
21+
}
22+
23+
if (needCreateSignature) {
24+
return { action: 'createSignature' }
25+
}
26+
27+
if (needIdentificationDocuments) {
28+
return { action: 'documents' }
29+
}
30+
31+
if (signStore.errors.length > 0) {
32+
return null
33+
}
34+
35+
return { action: 'sign' }
36+
}

src/views/SignPDF/_partials/Sign.vue

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ import { useSignatureElementsStore } from '../../../store/signatureElements.js'
175175
import { useSignMethodsStore } from '../../../store/signMethods.js'
176176
import { useIdentificationDocumentStore } from '../../../store/identificationDocument.js'
177177
import { FILE_STATUS } from '../../../constants.js'
178+
import { getPrimarySigningAction } from '../../../helpers/SigningActionHelper.js'
178179
179180
export default {
180181
name: 'Sign',
@@ -255,19 +256,13 @@ export default {
255256
return getCapabilities()?.libresign?.config?.['sign-elements']?.['can-create-signature'] === true
256257
},
257258
ableToSign() {
258-
if (this.signMethodsStore.needCreatePassword()) {
259-
return false
260-
}
261-
if (this.needCreateSignature) {
262-
return false
263-
}
264-
if (this.needIdentificationDocuments) {
265-
return false
266-
}
267-
if (this.signStore.errors.length > 0) {
268-
return false
269-
}
270-
return true
259+
const primaryAction = getPrimarySigningAction(
260+
this.signStore,
261+
this.signMethodsStore,
262+
this.needCreateSignature,
263+
this.needIdentificationDocuments
264+
)
265+
return primaryAction?.action === 'sign'
271266
},
272267
signRequestUuid() {
273268
const doc = this.signStore.document || {}

0 commit comments

Comments
 (0)