@@ -251,48 +251,105 @@ defineOptions({
251251 this .signStore .clearSigningErrors ()
252252
253253 try {
254- const payload : SubmitSignaturePayload = {
254+ const basePayload : SubmitSignaturePayload = {
255255 method: methodConfig .method ,
256256 }
257257
258258 if (methodConfig .token ) {
259- payload .token = methodConfig .token
259+ basePayload .token = methodConfig .token
260260 }
261261
262- if (this .elements ?.length > 0 ) {
263- if (this .canCreateSignature ) {
264- payload .elements = this .elements .flatMap ((row ) => typeof row .elementId === ' number'
265- ? [{
266- documentElementId: row .elementId ,
267- profileNodeId: row .type ? this .signatureElementsStore .signs [row .type ]?.file .nodeId : undefined ,
268- }]
269- : [])
270- } else {
271- payload .elements = this .elements .flatMap ((row ) => typeof row .elementId === ' number'
272- ? [{
273- documentElementId: row .elementId ,
274- }]
275- : [])
262+ const myEnvelopeSigners = this .signStore .document ?.nodeType === ' envelope'
263+ ? (this .signStore .document ?.signers ?? [])
264+ .filter ((s ): s is NonNullable <typeof s > & { signRequestId: number ; sign_request_uuid: string } =>
265+ s .me === true && typeof s .sign_request_uuid === ' string' )
266+ : []
267+
268+ if (myEnvelopeSigners .length > 0 ) {
269+ let anySigningInProgress = false
270+ let lastResult: SignResult | null = null
271+
272+ for (const signer of myEnvelopeSigners ) {
273+ const filePayload: SubmitSignaturePayload = { ... basePayload }
274+ const fileElements = (this .elements ?? []).filter ((el ) => el .signRequestId === signer .signRequestId )
275+ if (fileElements .length > 0 ) {
276+ if (this .canCreateSignature ) {
277+ filePayload .elements = fileElements .flatMap ((row ) => typeof row .elementId === ' number'
278+ ? [{
279+ documentElementId: row .elementId ,
280+ profileNodeId: row .type ? this .signatureElementsStore .signs [row .type ]?.file .nodeId : undefined ,
281+ }]
282+ : [])
283+ } else {
284+ filePayload .elements = fileElements .flatMap ((row ) => typeof row .elementId === ' number'
285+ ? [{
286+ documentElementId: row .elementId ,
287+ }]
288+ : [])
289+ }
290+ }
291+
292+ lastResult = await this .signStore .submitSignature (filePayload , signer .sign_request_uuid , {
293+ documentId: this .signStore .document .id ,
294+ })
295+
296+ if (lastResult .status === ' signingInProgress' ) {
297+ anySigningInProgress = true
298+ }
276299 }
277- }
278300
279- const result = await this .signStore .submitSignature (payload , this .signRequestUuid , {
280- documentId: this .signStore .document .id ,
281- })
301+ if (lastResult ?.status === ' signed' ) {
302+ this .actionHandler .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
303+ this .sidebarStore .hideSidebar ()
304+ this .$emit (' signed' , {
305+ ... lastResult .data ,
306+ signRequestUuid: myEnvelopeSigners [0 ].sign_request_uuid ,
307+ })
308+ } else if (anySigningInProgress ) {
309+ this .actionHandler .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
310+ this .$emit (' signing-started' , {
311+ signRequestUuid: myEnvelopeSigners [0 ].sign_request_uuid ,
312+ async: true ,
313+ })
314+ }
315+ } else {
316+ const payload: SubmitSignaturePayload = { ... basePayload }
317+
318+ if (this .elements ?.length > 0 ) {
319+ if (this .canCreateSignature ) {
320+ payload .elements = this .elements .flatMap ((row ) => typeof row .elementId === ' number'
321+ ? [{
322+ documentElementId: row .elementId ,
323+ profileNodeId: row .type ? this .signatureElementsStore .signs [row .type ]?.file .nodeId : undefined ,
324+ }]
325+ : [])
326+ } else {
327+ payload .elements = this .elements .flatMap ((row ) => typeof row .elementId === ' number'
328+ ? [{
329+ documentElementId: row .elementId ,
330+ }]
331+ : [])
332+ }
333+ }
282334
283- if (result .status === ' signingInProgress' ) {
284- this .actionHandler .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
285- this .$emit (' signing-started' , {
286- signRequestUuid: this .signRequestUuid ,
287- async: true ,
288- })
289- } else if (result .status === ' signed' ) {
290- this .actionHandler .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
291- this .sidebarStore .hideSidebar ()
292- this .$emit (' signed' , {
293- ... result .data ,
294- signRequestUuid: this .signRequestUuid ,
335+ const result = await this .signStore .submitSignature (payload , this .signRequestUuid , {
336+ documentId: this .signStore .document .id ,
295337 })
338+
339+ if (result .status === ' signingInProgress' ) {
340+ this .actionHandler .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
341+ this .$emit (' signing-started' , {
342+ signRequestUuid: this .signRequestUuid ,
343+ async: true ,
344+ })
345+ } else if (result .status === ' signed' ) {
346+ this .actionHandler .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
347+ this .sidebarStore .hideSidebar ()
348+ this .$emit (' signed' , {
349+ ... result .data ,
350+ signRequestUuid: this .signRequestUuid ,
351+ })
352+ }
296353 }
297354 } catch (error : unknown ) {
298355 const signError = typeof error === ' object' && error !== null ? error as SignSubmissionError : {}
@@ -611,53 +668,111 @@ let submitSignature = async (methodConfig: SignatureMethodConfig = {}) => {
611668 signStore .clearSigningErrors ()
612669
613670 try {
614- const payload : SubmitSignaturePayload = {
671+ const basePayload : SubmitSignaturePayload = {
615672 method: methodConfig .method ,
616673 }
617674
618675 if (methodConfig .token ) {
619- payload .token = methodConfig .token
676+ basePayload .token = methodConfig .token
620677 }
621678
622- if (elements .value .length > 0 ) {
623- if (canCreateSignature .value ) {
624- payload .elements = elements .value .flatMap ((row ) => typeof row .elementId === ' number'
625- ? [{
626- documentElementId: row .elementId ,
627- profileNodeId: row .type ? signatureElementsStore .signs [row .type ]?.file .nodeId : undefined ,
628- }]
629- : [])
630- } else {
631- payload .elements = elements .value .flatMap ((row ) => typeof row .elementId === ' number'
632- ? [{
633- documentElementId: row .elementId ,
634- }]
635- : [])
679+ const myEnvelopeSigners = signStore .document ?.nodeType === ' envelope'
680+ ? (signStore .document ?.signers ?? [])
681+ .filter ((s ): s is NonNullable <typeof s > & { signRequestId: number ; sign_request_uuid: string } =>
682+ s .me === true && typeof s .sign_request_uuid === ' string' )
683+ : []
684+
685+ if (myEnvelopeSigners .length > 0 ) {
686+ let anySigningInProgress = false
687+ let lastResult: SignResult | null = null
688+
689+ for (const signer of myEnvelopeSigners ) {
690+ const filePayload: SubmitSignaturePayload = { ... basePayload }
691+ const fileElements = elements .value .filter ((el ) => el .signRequestId === signer .signRequestId )
692+ if (fileElements .length > 0 ) {
693+ if (canCreateSignature .value ) {
694+ filePayload .elements = fileElements .flatMap ((row ) => typeof row .elementId === ' number'
695+ ? [{
696+ documentElementId: row .elementId ,
697+ profileNodeId: row .type ? signatureElementsStore .signs [row .type ]?.file .nodeId : undefined ,
698+ }]
699+ : [])
700+ } else {
701+ filePayload .elements = fileElements .flatMap ((row ) => typeof row .elementId === ' number'
702+ ? [{
703+ documentElementId: row .elementId ,
704+ }]
705+ : [])
706+ }
707+ }
708+
709+ lastResult = await signStore .submitSignature (filePayload , signer .sign_request_uuid , {
710+ documentId: signStore .document .id ,
711+ })
712+
713+ if (lastResult .status === ' signingInProgress' ) {
714+ anySigningInProgress = true
715+ }
636716 }
637- }
638717
639- const result = await signStore .submitSignature (
640- payload ,
641- signRequestUuid .value ,
642- {
643- documentId: signStore .document .id ,
644- },
645- )
718+ ensureServices ()
719+ if (lastResult ?.status === ' signed' ) {
720+ actionHandler ! .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
721+ sidebarStore .hideSidebar ()
722+ emit (' signed' , {
723+ ... lastResult .data ,
724+ signRequestUuid: myEnvelopeSigners [0 ].sign_request_uuid ,
725+ })
726+ } else if (anySigningInProgress ) {
727+ actionHandler ! .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
728+ emit (' signing-started' , {
729+ signRequestUuid: myEnvelopeSigners [0 ].sign_request_uuid ,
730+ async: true ,
731+ })
732+ }
733+ } else {
734+ const payload: SubmitSignaturePayload = { ... basePayload }
735+
736+ if (elements .value .length > 0 ) {
737+ if (canCreateSignature .value ) {
738+ payload .elements = elements .value .flatMap ((row ) => typeof row .elementId === ' number'
739+ ? [{
740+ documentElementId: row .elementId ,
741+ profileNodeId: row .type ? signatureElementsStore .signs [row .type ]?.file .nodeId : undefined ,
742+ }]
743+ : [])
744+ } else {
745+ payload .elements = elements .value .flatMap ((row ) => typeof row .elementId === ' number'
746+ ? [{
747+ documentElementId: row .elementId ,
748+ }]
749+ : [])
750+ }
751+ }
646752
647- ensureServices ()
648- if (result .status === ' signingInProgress' ) {
649- actionHandler ! .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
650- emit (' signing-started' , {
651- signRequestUuid: signRequestUuid .value ,
652- async: true ,
653- })
654- } else if (result .status === ' signed' ) {
655- actionHandler ! .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
656- sidebarStore .hideSidebar ()
657- emit (' signed' , {
658- ... result .data ,
659- signRequestUuid: signRequestUuid .value ,
660- })
753+ const result = await signStore .submitSignature (
754+ payload ,
755+ signRequestUuid .value ,
756+ {
757+ documentId: signStore .document .id ,
758+ },
759+ )
760+
761+ ensureServices ()
762+ if (result .status === ' signingInProgress' ) {
763+ actionHandler ! .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
764+ emit (' signing-started' , {
765+ signRequestUuid: signRequestUuid .value ,
766+ async: true ,
767+ })
768+ } else if (result .status === ' signed' ) {
769+ actionHandler ! .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
770+ sidebarStore .hideSidebar ()
771+ emit (' signed' , {
772+ ... result .data ,
773+ signRequestUuid: signRequestUuid .value ,
774+ })
775+ }
661776 }
662777 } catch (error : unknown ) {
663778 const signError = isSignSubmissionError (error ) ? error : {}
0 commit comments