fix: handle completion when already signed (#3159)

Previously attempting to complete a document which is already completed
you'd get a generic error toast. Now when completing a document that you
have already completed you are redirected to the completed page.

Handles cases where two mutations managed to fire racing eachother.
This commit is contained in:
Lucas Smith
2026-08-10 09:25:41 +10:00
committed by GitHub
parent d6cf3fec4b
commit fc95ee9ead
5 changed files with 77 additions and 18 deletions
@@ -182,12 +182,16 @@ export type TCompleteDocumentWithTokenMutationSchema = z.infer<typeof ZCompleteD
* Discriminated response: SES envelopes return `{ status: 'SIGNED' }` after
* the in-place completion; TSP (AES/QES) envelopes return
* `{ status: 'REDIRECT', redirectUrl }` pointing at the credential-scope
* OAuth authorize endpoint. Frontend callers can branch on `status` —
* existing callers ignored the response and remain compatible.
* OAuth authorize endpoint. `{ status: 'ALREADY_SIGNED' }` is returned when
* the recipient had already signed prior to this request (retries, stale
* tabs, concurrent submissions) so callers can notify the user instead of
* erroring. Frontend callers can branch on `status` — existing callers
* ignored the response and remain compatible.
*/
export const ZCompleteDocumentWithTokenResponseSchema = z.discriminatedUnion('status', [
z.object({ status: z.literal('REDIRECT'), redirectUrl: z.string() }),
z.object({ status: z.literal('SIGNED') }),
z.object({ status: z.literal('ALREADY_SIGNED') }),
]);
export type TCompleteDocumentWithTokenResponseSchema = z.infer<typeof ZCompleteDocumentWithTokenResponseSchema>;