Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace draftService

Helper functions for handling drafts.

import { draftService } from '@oneblink/apps'

Index

Type aliases

LocalFormSubmissionDraft: Omit<FormSubmissionDraft, "id" | "versions"> & { draftSubmission: DraftSubmission | undefined; versions: FormSubmissionDraftVersion[] | undefined }

Functions

  • deleteDraft(formSubmissionDraftId: string, formsAppId: number, abortSignal?: AbortSignal): Promise<void>
  • Remove a draft from the local store and sync with remote drafts.

    Example

    const draftId = 'd3aeb944-d0b3-11ea-87d0-0242ac130003'
    await draftService.deleteDraft(draftId)

    Parameters

    • formSubmissionDraftId: string
    • formsAppId: number
    • Optional abortSignal: AbortSignal

    Returns Promise<void>

  • getDraftAndData(formsAppId: number, formSubmissionDraftId: undefined | null | string, abortSignal: undefined | AbortSignal): Promise<DraftSubmission | undefined>
  • Get a single Draft and the associated submission data.

    Example

    const draftId = 'd3aeb944-d0b3-11ea-87d0-0242ac130003'
    const { draft, draftData, lastElementUpdated } =
    await draftService.getDraftAndData(draftId)
    // use "draftData" to prefill a from

    Parameters

    • formsAppId: number
    • formSubmissionDraftId: undefined | null | string
    • abortSignal: undefined | AbortSignal

    Returns Promise<DraftSubmission | undefined>

  • Register a listener function that will be passed an array of Drafts when a draft is added, updated or deleted.

    Example

    const listener = async (drafts) => {
    // use drafts here...
    }
    const deregister = await draftService.registerDraftsListener(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 Drafts when a draft is added, updated or deleted.

        Example

        const listener = async (drafts) => {
        // use drafts here...
        }
        const deregister = await draftService.registerDraftsListener(listener)

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

        Returns void

  • syncDrafts(param0: { abortSignal?: AbortSignal; formsAppId: number; throwError?: boolean }): Promise<void>
  • Force a sync of remote drafts with locally stored drafts. This function will swallow all errors thrown unless true is passed for the throwError property.

    Example

    await draftService.syncDrafts({
    throwError: true,
    formsAppId: 1,
    })

    Parameters

    • param0: { abortSignal?: AbortSignal; formsAppId: number; throwError?: boolean }
      • Optional abortSignal?: AbortSignal

        Signal to abort the requests

      • formsAppId: number

        The id of the OneBlink Forms App to sync drafts with

      • Optional throwError?: boolean

        true to throw errors while syncing

    Returns Promise<void>

  • upsertDraft(options: { abortSignal?: AbortSignal; autoSaveKey?: string; draftSubmissionInput: DraftSubmissionInput; formSubmissionDraftId: undefined | string; onProgress?: ProgressListener; pendingTimestamp?: string }): Promise<void>
  • Create or update a Draft in the local store and sync it with remote drafts. Will also handle cleaning up auto save data (if the autoSaveKey property is passed).

    Example

    const abortController = new AbortController()
    const formSubmissionDraftId = 'd3aeb944-d0b3-11ea-87d0-0242ac130003' // pass `undefined` to create a new draft
    const autoSaveKey = 'SET ME TO DELETE AUTOSAVE DATA AFTER SAVING DRAFT'
    const draftSubmissionInput = {
    title: 1,
    formsAppId: 1,
    submission: {
    form: 'data',
    goes: 'here',
    },
    definition: {
    form: 'definition',
    goes: 'here',
    },
    }
    await draftService.upsertDraft({
    formSubmissionDraftId,
    autoSaveKey,
    draftSubmissionInput,
    abortSignal: abortController.signal,
    onProgress: (progress) => {
    // ...
    },
    })

    Parameters

    • options: { abortSignal?: AbortSignal; autoSaveKey?: string; draftSubmissionInput: DraftSubmissionInput; formSubmissionDraftId: undefined | string; onProgress?: ProgressListener; pendingTimestamp?: string }
      • Optional abortSignal?: AbortSignal
      • Optional autoSaveKey?: string
      • draftSubmissionInput: DraftSubmissionInput
      • formSubmissionDraftId: undefined | string
      • Optional onProgress?: ProgressListener
      • Optional pendingTimestamp?: string

    Returns Promise<void>