submitSubstore
Manages all submission-related operations: draft save/update/load, submission to the API, and restoring state from a previously submitted request copy. All async operations expose their own loading and error state.
Table of contents
Draft state
Draft methods
Submission
Request copy
Draft state
isDraftEnabled
isDraftEnabled: boolean;Whether draft saving is currently available (user is authenticated and no form is loading).
true when authSubstore.isAuth is true and none of the configs in formSubstore.fromConfigs have isLoading === true. Use this to show/hide or enable/disable the draft save UI.
Related
authSubstore.isAuth— required to betrueformSubstore.fromConfigs—isLoadingon any config disables draftssaveOrUpdateDraft— the action gated by this flag
isDraftSave
isDraftSave: boolean;Whether the next draft action is a fresh save (true) versus an update to an existing draft (false).
true when draftId is undefined (no draft has been saved yet in this session). After a successful save, draftId is set and this flips to false for subsequent calls.
Related
draftId— determines the value of this flagsaveOrUpdateDraft— behaviour changes based on this flag
isLoadingDraft
isLoadingDraft: boolean;Whether a draft save or update operation is currently in progress.
Set to true for the duration of the saveOrUpdateDraft API call.
Related
errorDraft
errorDraft: string | undefined;Error message from the last failed draft operation, or undefined if none.
Set when saveOrUpdateDraft fails. Cleared on the next successful draft operation.
Related
draftId
draftId: number | undefined;ID of the most recently saved draft, or undefined if no draft has been saved yet.
Set after a successful call to saveOrUpdateDraft (save mode). Used by subsequent calls as the target for the update API endpoint.
Related
isDraftSave— flips tofalseonce this is setsaveOrUpdateDraft— sets this on successopenFromDraft— takes a draft ID as input
draftName
draftName: string;User-visible name for the draft configuration.
Editable via setDraftName. Sent to the API when calling saveOrUpdateDraft.
Related
setDraftName— settersavedDraftName— the last successfully persisted namesaveOrUpdateDraft— includes this in the payload
savedDraftName
savedDraftName: string | undefined;Name that was persisted on the last successful draft save or update.
undefined before any successful save. Use this to detect unsaved changes (when draftName !== savedDraftName).
Related
draftName— the current (possibly unsaved) namesaveOrUpdateDraft— updates this on success
draftData
draftData: Json | undefined;Arbitrary extra JSON payload attached to the draft (e.g., 3D configuration data).
This field is not interpreted by the SDK. Use it to round-trip any additional application state alongside the form configuration. Set via setDraftData.
Related
setDraftData— settersaveOrUpdateDraft— includes this in the API payload
Draft methods
setDraftName
setDraftName: (draftName: string) => voidUpdates the draft name.
Parameters
| Name | Type | Description |
|---|---|---|
draftName | string | New draft name |
Related
setDraftData
setDraftData: (draftData: Json) => voidUpdates the arbitrary extra draft payload.
Parameters
| Name | Type | Description |
|---|---|---|
draftData | Json | Any JSON-serialisable value |
Related
saveOrUpdateDraft
saveOrUpdateDraft: () => Promise<{ ok: boolean; type: "save" | "update" }>;Saves a new draft or updates the existing one and returns a result object indicating success and operation type.
The payload includes form submissions, contact name and email, dynamic request field values (contactDetailsSubstore.requestFieldsValues), configuration name, and 3D metadata. Name and email are required — the call returns { ok: false } if either is missing.
- When
isDraftSaveistrue(nodraftIdyet): calls the save API endpoint and setsdraftIdon success - When
isDraftSaveisfalse: calls the update API endpoint with the existingdraftId
Sets isLoadingDraft to true for the duration of the call. On failure, writes the error message to errorDraft.
Returns Promise<{ ok: boolean; type: "save" | "update" }>
| Field | Description |
|---|---|
ok | true if the operation succeeded |
type | "save" for a first-time save, "update" for a subsequent update |
Related
isDraftEnabled— gate before calling thisisDraftSave— determines save vs update modedraftId— set on success (save mode)draftName,draftData— included in the payloadisLoadingDraft,errorDraft— loading/error state
isLoadingOpenFromDraft
isLoadingOpenFromDraft: boolean;Whether a draft is currently being loaded into the store.
Set to true for the duration of openFromDraft.
Related
openFromDraft
openFromDraft: (draftId: number) => Promise<{ ok: boolean }>;Loads a draft by ID and restores the store state from it.
Fetches the draft from the API, then calls configsSubstore.setupFromPreConfig to re-populate the store with the saved configuration data. Also restores contact name, email, and dynamic request field values from the draft’s extra_fields. On success, sets draftId to the loaded draft’s ID, making the session draft-bound — a subsequent submit will use the draft-submit flow.
Parameters
| Name | Type | Description |
|---|---|---|
draftId | number | ID of the draft to load |
Returns Promise<{ ok: boolean }> — ok is true if the draft was loaded successfully.
Related
isLoadingOpenFromDraftdraftId— set to the loaded draft’s ID on successconfigsSubstore.setupFromPreConfig— called internally to restore state
Submission
submit
submit: () => Promise<SubmitResult>;
type SubmitResult = | { ok: true; pdfUrl: string | undefined; documentUrls: string[] } | { ok: false };Submits the current configuration to the API and returns a result object.
Builds the submission payload from:
configsSubstore.configs— config list and quantitiesvaluesSubstore.valuesConfigs— selected values and quantitiescontactDetailsSubstore.fixedContactDetails— name and emailcontactDetailsSubstore.requestFieldsValues— dynamic contact fieldsdocumentTemplatesSubstore.selectedTemplateIds— selected Carbone document templates
Requires both a selected country and language from localizationSubstore. Returns { ok: false } immediately if either is missing.
Draft-bound submission: When the user is authenticated (authSubstore.isAuth) and a draftId is active, submission routes through the draft-submit endpoint for that draft ID. On success the SDK clears the draft-bound state (draftId, savedDraftName, draftData, and related flags) while keeping the configuration name unchanged. If the user is not authenticated or no draftId is set, a normal (non-draft) submission is used instead.
On success, writes the returned URLs to submittedPdfUrl and submittedDocumentUrls.
Sets isLoadingSubmit to true during the call. On failure, writes to errorSubmit.
Returns Promise<SubmitResult>
| Field | When ok: true | Description |
|---|---|---|
pdfUrl | always present | Legacy PDF URL from the API response, if any |
documentUrls | always present | URLs of all generated documents (PDF, DOCX, etc.) |
Related
isSubmitEnabled— gate before calling thisisLoadingSubmit,errorSubmitsubmittedPdfUrl,submittedDocumentUrlsdocumentTemplatesSubstorecontactDetailsSubstore.fixedContactDetailsvaluesSubstore.valuesConfigsconfigsSubstore.configs
isSubmitEnabled
isSubmitEnabled: boolean;Whether contact details are valid and supporting data has finished loading.
true when:
- No form in
formSubstore.fromConfigshasisLoading === true contactDetailsSubstore.requestFieldsDatais not loadingdocumentTemplatesSubstore.templatesDatais not loading- All
fixedContactDetailsfields pass validation (no errors) - All
requestFieldsErrorsarefalse
Use this to enable/disable the submit button. Config completion (status === "completed") is not checked here — gate on that separately in your UI if needed.
Related
submit— the action gated by this flagcontactDetailsSubstore.fixedContactDetailscontactDetailsSubstore.requestFieldsErrorsdocumentTemplatesSubstore.templatesData
submittedPdfUrl
submittedPdfUrl: string | undefined;URL of the PDF generated by the last successful submission, or undefined before submit or when the API did not return one.
Set from the pdf_url field in the submit response. Prefer submittedDocumentUrls for the full list of generated documents.
Related
submittedDocumentUrls
submittedDocumentUrls: string[];URLs of all documents generated by the last successful submission (PDF, DOCX, ODT, XLSX, ODS, etc.).
Populated from the document_urls field in the submit response. Cleared at the start of each new submit attempt.
Related
isLoadingSubmit
isLoadingSubmit: boolean;Whether a form submission is currently in progress.
Set to true for the duration of the submit API call.
Related
errorSubmit
errorSubmit: string | undefined;Error message from the last failed submission, or undefined if none.
Set when submit fails. Cleared on the next successful submission attempt.
Related
Request copy
isLoadingOpenFromRequestCopy
isLoadingOpenFromRequestCopy: boolean;Whether a request copy is currently being loaded into the store.
Set to true for the duration of openFromRequestCopy.
Related
openFromRequestCopy
openFromRequestCopy: (requestId: number) => Promise<{ ok: boolean }>;Restores the store state from a previously submitted request by its ID.
Fetches the historical request from the API, then calls configsSubstore.setupFromPreConfig to re-populate the store with the same configuration data that was originally submitted. Also restores contact name, email, and dynamic request field values from the request’s extra_fields. Clears any draft-bound state so the session is not tied to a previous draft. Useful for “re-order” or “edit previous request” flows.
Parameters
| Name | Type | Description |
|---|---|---|
requestId | number | ID of the previously submitted request |
Returns Promise<{ ok: boolean }> — ok is true if the request was loaded successfully.
Related
isLoadingOpenFromRequestCopyconfigsSubstore.setupFromPreConfig— called internally to restore stateopenFromDraft— similar pattern for draft restoration