Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace submissionService

Helper functions for handling form submissions

import { submissionService } from '@oneblink/apps'

Index

Type aliases

BaseFormSubmission: { externalId?: string; jobId?: string; previousFormSubmissionApprovalId?: string; taskCompletion?: { redirectUrl: string; task: Task; taskAction: TaskAction; taskGroup: TaskGroup | undefined; taskGroupInstance: TaskGroupInstance | undefined } }

Type declaration

  • Optional externalId?: string

    The id of the Forms App submitting for

  • Optional jobId?: string

    The id of the job to submit

  • Optional previousFormSubmissionApprovalId?: string

    The id of the previous form submission approval id. Only used when the form submission is in response to CLARIFICATION_REQUIRED approval.

  • Optional taskCompletion?: { redirectUrl: string; task: Task; taskAction: TaskAction; taskGroup: TaskGroup | undefined; taskGroupInstance: TaskGroupInstance | undefined }

    Will have a value if the user was attempting to complete a scheduled task via a form submission

    • redirectUrl: string

      The URL to redirect the user to after completing the task via form submission

    • task: Task

      The task

    • taskAction: TaskAction

      The task action

    • taskGroup: TaskGroup | undefined

      The task group

    • taskGroupInstance: TaskGroupInstance | undefined

      The task group instance

DraftSubmission: DraftSubmissionInput & { createdAt: string; formSubmissionDraftId: string }
DraftSubmissionInput: NewDraftSubmission & BaseFormSubmission & { formsAppId: number; title: string }
FormSubmission: NewFormSubmission & BaseFormSubmission & { formSubmissionDraftId?: string; formsAppId?: number; preFillFormDataId: string | null }
FormSubmissionResult: FormSubmission & { downloadSubmissionPdfUrl?: string; isInPendingQueue: boolean; isOffline: boolean; isUploadingAttachments: boolean; payment: { amount: number; hostedFormUrl: string; paymentFormUrl: string | undefined; paymentReceiptUrl: string; submissionEvent: FormPaymentEvent } | null; scheduling: { bookingUrl: string; submissionEvent: FormSchedulingEvent } | null; submissionId: string | null; submissionTimestamp: string | null }
NewDraftSubmission: BaseNewFormSubmission & { backgroundUpload?: boolean; lastElementUpdated?: FormElement }
NewFormSubmission: BaseNewFormSubmission & { recaptchas?: { siteKey: string; token: string }[] }
PendingFormSubmission: Omit<FormSubmission, "submission"> & { error?: string; isEditing?: boolean; isSubmitting?: boolean; pendingTimestamp: string }
PendingQueueAction: "SUBMIT_STARTED" | "SUBMIT_FAILED" | "SUBMIT_SUCCEEDED" | "ADDITION" | "DELETION" | "EDIT_STARTED" | "EDIT_CANCELLED"
PendingQueueListener: (results: PendingFormSubmission[], action: PendingQueueAction) => unknown

Type declaration

ProgressListener: (progress: ProgressListenerEvent) => void

Type declaration

ProgressListenerEvent: { progress: number; total: number }

Type declaration

  • progress: number
  • total: number
SubmissionParams: { abortSignal?: AbortSignal; formSubmission: FormSubmission; isPendingQueueEnabled: boolean; onProgress?: ProgressListener; paymentFormUrl: string | undefined; paymentReceiptUrl: string | undefined; pendingTimestamp?: string; schedulingUrlConfiguration?: SchedulingUrlConfiguration; shouldRunExternalIdGeneration: boolean; shouldRunServerValidation: boolean }

Type declaration

  • Optional abortSignal?: AbortSignal
  • formSubmission: FormSubmission
  • isPendingQueueEnabled: boolean
  • Optional onProgress?: ProgressListener
  • paymentFormUrl: string | undefined
  • paymentReceiptUrl: string | undefined
  • Optional pendingTimestamp?: string
  • Optional schedulingUrlConfiguration?: SchedulingUrlConfiguration
  • shouldRunExternalIdGeneration: boolean
  • shouldRunServerValidation: boolean

Functions

  • cancelEditingPendingQueueSubmission(pendingTimestamp: string): Promise<void>
  • Cancel editing a PendingFormSubmission based on the pendingTimestamp property. The function marks the submission as ready for processing by the pending queue

    Example

    const pendingTimestamp = '2020-07-29T01:03:26.573Z'

    await submissionService.cancelEditingPendingQueueSubmission(
    pendingTimestamp,
    )

    Parameters

    • pendingTimestamp: string

    Returns Promise<void>

  • deletePendingQueueSubmission(pendingTimestamp: string): Promise<void>
  • Delete a PendingFormSubmission before it is processed based on the pendingTimestamp property.

    Example

    const pendingTimestamp = '2020-07-29T01:03:26.573Z'
    await submissionService.deletePendingQueueSubmission(pendingTimestamp)

    Parameters

    • pendingTimestamp: string

    Returns Promise<void>

  • editPendingQueueSubmission(pendingTimestamp: string): Promise<{ formId: number; preFillFormDataId: string }>
  • Edit a PendingFormSubmission before it is processed based on the pendingTimestamp property. The function places the submission in an editing state preventing it from being processed by the pending queue and returns a prefill id and form id

    Example

    const pendingTimestamp = '2020-07-29T01:03:26.573Z'
    const { preFillFormDataId, formId } =
    await submissionService.editPendingQueueSubmission(pendingTimestamp)
    window.location.href = `https://mycoolforms.apps.oneblink.io/forms/${formId}?preFillFormDataId=${preFillFormDataId}`

    Parameters

    • pendingTimestamp: string

    Returns Promise<{ formId: number; preFillFormDataId: string }>

  • executeCancelAction(formSubmissionResultOptions: { definition: Form; externalId: null | string; taskCompletion?: { redirectUrl: string; task: Task; taskAction: TaskAction; taskGroup: undefined | TaskGroup; taskGroupInstance: undefined | TaskGroupInstance } }, redirectConfig: { onRedirectToAbsoluteUrl: any; onRedirectToRelativeUrl: any }): Promise<void>
  • Action to cancel completing a form, currently goes back in the browser history or attempts to close the browser tab if there is no history.

    Example

    const options = {
    definition: OneBlinkForm,
    externalId: 'external-id-set-by-developer',
    }
    // Only used for relative URLs
    const pushRelativePath = (path) => {
    window.location.href = path
    }
    // Only used for aboslute URLS
    const replaceAbsolutePath = window.location.replace

    try {
    await submissionService.executeCancelAction(options, {
    onRedirectToRelativeUrl: pushRelativePath,
    onRedirectToAbsoluteUrl: replaceAbsolutePath,
    })
    } catch (error) {
    // Handle error while closing browser tab.
    // Display message to user to close it manually
    }

    Parameters

    • formSubmissionResultOptions: { definition: Form; externalId: null | string; taskCompletion?: { redirectUrl: string; task: Task; taskAction: TaskAction; taskGroup: undefined | TaskGroup; taskGroupInstance: undefined | TaskGroupInstance } }
      • definition: Form
      • externalId: null | string
      • Optional taskCompletion?: { redirectUrl: string; task: Task; taskAction: TaskAction; taskGroup: undefined | TaskGroup; taskGroupInstance: undefined | TaskGroupInstance }
        • redirectUrl: string

          The URL to redirect the user to after completing the task via form submission

        • task: Task

          The task

        • taskAction: TaskAction

          The task action

        • taskGroup: undefined | TaskGroup

          The task group

        • taskGroupInstance: undefined | TaskGroupInstance

          The task group instance

    • redirectConfig: { onRedirectToAbsoluteUrl: any; onRedirectToRelativeUrl: any }
      • onRedirectToAbsoluteUrl:function
        • onRedirectToAbsoluteUrl(url: string): void
      • onRedirectToRelativeUrl:function
        • onRedirectToRelativeUrl(url: string): void

    Returns Promise<void>

  • executePostSubmissionAction(submissionResult: FormSubmissionResult, redirectConfig: { onRedirectToAbsoluteUrl: any; onRedirectToRelativeUrl: any }): Promise<void>
  • Execute the post submission action for a form after a successful form submission.

    Example

    const formSubmissionResult = {
    submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',
    submissionTimestamp: '2020-07-29T01:03:26.573Z'
    formsAppId: 1,
    submission: {
    form: 'data',
    goes: 'here'
    },
    definition: OneBlinkForm,
    payment: {
    hostedFormUrl: 'https://payment.com/transaction'
    },
    formSubmissionDraftId: '2974602c-2c5b-4b46-b086-87ee9b2aa233',
    jobId: 'bb37d1da-9cda-4950-a36a-22f58b25de3a',
    preFillFormDataId: '7763f828-4aaf-49dc-9c1b-e2eeea8fa990',
    externalId: 'external-id-set-by-developer',
    }
    // Only used for relative URLs
    const pushRelativePath = (path) => {
    window.location.href = path
    }
    // Only used for aboslute URLS
    const replaceAbsolutePath = window.location.replace

    try {
    await submissionService.executePostSubmissionAction(formSubmissionResult, {
    onRedirectToRelativeUrl: pushRelativePath,
    onRedirectToAbsoluteUrl: replaceAbsolutePath,
    })
    } catch (error) {
    // Handle error while closing browser tab.
    // Display message to user to close it manually
    }

    Parameters

    • submissionResult: FormSubmissionResult
    • redirectConfig: { onRedirectToAbsoluteUrl: any; onRedirectToRelativeUrl: any }
      • onRedirectToAbsoluteUrl:function
        • onRedirectToAbsoluteUrl(url: string): void
      • onRedirectToRelativeUrl:function
        • onRedirectToRelativeUrl(url: string): void

    Returns Promise<void>

  • getSubmissionData(__namedParameters: { abortSignal?: AbortSignal; formId: number; submissionId: string }): Promise<S3SubmissionData>
  • Retrieve submission data for a known formId and submissionId

    Example

    const formId = 1
    const submissionId = 'fba95b9d-5a9c-463d-ab68-867f431e4120'
    const credentials = await formSubmissionService.getSubmissionData({
    formId,
    submissionId,
    })

    Parameters

    • __namedParameters: { abortSignal?: AbortSignal; formId: number; submissionId: string }
      • Optional abortSignal?: AbortSignal
      • formId: number
      • submissionId: string

    Returns Promise<S3SubmissionData>

  • goBackOrCloseWindow(): Promise<void>
  • Go back in the browser history or attempts to close the browser tab if there is no history.

    Example

    try {
    await submissionService.goBackOrCloseWindow()
    } catch (error) {
    // Handle error while closing browser tab.
    // Display message to user to close it manually
    }

    Returns Promise<void>

  • processPendingQueue(__namedParameters: { shouldRunExternalIdGeneration: boolean; shouldRunServerValidation: boolean }): Promise<void>
  • Force processing the pending queue. This must be called to process the pending queue and is best used when the application comes back online.

    Example

    await submissionService.processPendingQueue()
    

    Parameters

    • __namedParameters: { shouldRunExternalIdGeneration: boolean; shouldRunServerValidation: boolean }
      • shouldRunExternalIdGeneration: boolean
      • shouldRunServerValidation: boolean

    Returns Promise<void>

  • registerPendingQueueAttachmentProgressListener(attachmentId: string, listener: ProgressListener): () => void
  • Register a listener function that will be passed a progress event when an attachment for an item in the pending queue is being processed.

    Example

    const listener = async ({ progress }) => {
    // update the UI to reflect the progress here...
    }
    const deregister =
    await submissionService.registerPendingQueueAttachmentProgressListener(
    attachment.id,
    listener,
    )

    // When no longer needed, remember to deregister the listener
    deregister()

    Parameters

    Returns () => void

      • (): void
      • Register a listener function that will be passed a progress event when an attachment for an item in the pending queue is being processed.

        Example

        const listener = async ({ progress }) => {
        // update the UI to reflect the progress here...
        }
        const deregister =
        await submissionService.registerPendingQueueAttachmentProgressListener(
        attachment.id,
        listener,
        )

        // When no longer needed, remember to deregister the listener
        deregister()

        Returns void

  • Register a listener function that will be passed an array of PendingFormSubmissions when the pending queue is modified.

    Example

    const listener = async (pendingSubmissions) => {
    // use pending submissions here...
    }
    const deregister =
    await submissionService.registerPendingQueueListener(listener)

    // When no longer needed, remember to deregister the listener
    deregister()

    Parameters

    Returns () => void

      • (): void
      • Register a listener function that will be passed an array of PendingFormSubmissions when the pending queue is modified.

        Example

        const listener = async (pendingSubmissions) => {
        // use pending submissions here...
        }
        const deregister =
        await submissionService.registerPendingQueueListener(listener)

        // When no longer needed, remember to deregister the listener
        deregister()

        Returns void

  • registerPendingQueueProgressListener(pendingTimestamp: string, listener: ProgressListener): () => void
  • Register a listener function that will be passed a progress event when an item in the pending queue is being processed.

    Example

    const listener = async ({ progress }) => {
    // update the UI to reflect the progress here...
    }
    const deregister =
    await submissionService.registerPendingQueueProgressListener(
    pendingQueueItem.pendingTimestamp,
    listener,
    )

    // When no longer needed, remember to deregister the listener
    deregister()

    Parameters

    Returns () => void

      • (): void
      • Register a listener function that will be passed a progress event when an item in the pending queue is being processed.

        Example

        const listener = async ({ progress }) => {
        // update the UI to reflect the progress here...
        }
        const deregister =
        await submissionService.registerPendingQueueProgressListener(
        pendingQueueItem.pendingTimestamp,
        listener,
        )

        // When no longer needed, remember to deregister the listener
        deregister()

        Returns void

  • Submit a FormSubmission. Offline submissions will be added to a pending queue and be processed using the processPendingQueue() function. FormSubmissions with payment submission events will return the FormSubmissionResult with a payment property set, this should be used to redirect the user to the payment URL. Will also handle cleaning up auto save data (if the autoSaveKey property is passed), locally stored drafts and prefill data.

    Example

    const formSubmission = {
    formsAppId: 1,
    submission: {
    form: 'data',
    goes: 'here',
    },
    definition: OneBlinkForm,
    captchaTokens: [],
    formSubmissionDraftId: '2974602c-2c5b-4b46-b086-87ee9b2aa233',
    jobId: 'bb37d1da-9cda-4950-a36a-22f58b25de3a',
    preFillFormDataId: '7763f828-4aaf-49dc-9c1b-e2eeea8fa990',
    externalId: 'external-id-set-by-developer',
    }

    // Pass paymentReceiptUrl if submission may require a payment
    const paymentReceiptUrl = `${window.location.origin}/payment-receipt`

    // Pass schedulingBookingUrlConfiguration if submission utilise scheduling
    const schedulingBookingUrlConfiguration = {
    schedulingBookingUrl: 'https://my-website.com/booking',
    schedulingRescheduleUrl: 'https://my-website.com/reschedule',
    schedulingCancelUrl: 'https://my-website.com/cancel',
    }
    const submissionResult = await submissionService.submit({
    formSubmission,
    paymentReceiptUrl,
    schedulingBookingUrlConfiguration,
    })

    if (submissionResult.scheduling) {
    // Redirect user to booking form
    window.location.href = submissionResult.scheduling.bookingUrl
    return
    }

    if (submissionResult.payment) {
    // Redirect user to payment form
    window.location.href = submissionResult.payment.hostedFormUrl
    return
    }

    if (submissionResult.isOffline) {
    if (submissionResult.isInPendingQueue) {
    // Display message to user that the submission
    // has been added to the pending queue
    } else {
    // Display message to user that this submission can
    // not be processed while offline (most likely because it requires a payment)
    }
    return
    }

    // submissionResult.submissionId and submissionResult.submissionTimestamp
    // will be set if the submission was successful

    Parameters

    Returns Promise<FormSubmissionResult>