Skip to content

configsSubstore

Manages the lifecycle of user configurations in the current session. A configuration (TConfig) pairs a form with a name, a quantity, and a derived completion status. All form state and selected values are stored separately (in formSubstore and valuesSubstore) and automatically kept in sync when a config is added, removed, or copied.

Table of contents

Properties

Methods


Properties

currentConfigId

currentConfigId: number | undefined

ID of the currently active configuration, or undefined when none is selected.

Use this to scope reads from formSubstore.fromConfigs and valuesSubstore.valuesConfigs to the active config.

Related


configsCounter

configsCounter: number

Auto-incrementing counter used to assign unique IDs to new configurations.

Each call to addConfig increments this counter and uses the resulting value as the new config’s id. You do not need to manage this directly.

Related

  • addConfig — consumes and increments this counter

configs

configs: TConfig[]

Ordered list of all configurations in the current session.

type TConfig = {
id: number;
name: string;
formId: number;
formName: string;
status: "in-progress" | "completed" | "incomplete";
configQuantity: number;
missingRequiredElements: TMissingRequiredElement[];
};
type TMissingRequiredElement = {
id: number;
groupId: number | undefined;
label: string;
};

status is derived automatically from the values in valuesSubstore:

  • "completed" — all required elements have a selection
  • "incomplete" — at least one required element is missing a selection
  • "in-progress" — the config has not been interacted with yet

Related


Methods

setCurrentConfigId

setCurrentConfigId: (configId: number) => void

Sets the currently active configuration by ID.

Parameters

NameTypeDescription
configIdnumberID of an existing config in configs

Related


addConfig

addConfig: (
config: Omit<TConfig, "id" | "status" | "missingRequiredElements">,
preConfig?: TPreConfigConfig,
) => number

Adds a new configuration entry and returns its generated ID.

Internally the SDK:

  1. Increments configsCounter to produce the new id
  2. Initialises a FormStoreItem in formSubstore.fromConfigs for this config
  3. Initialises a ValuesStoreItem in valuesSubstore.valuesConfigs for this config
  4. If preConfig is provided, pre-fills values and quantities accordingly

Parameters

NameTypeDescription
configOmit<TConfig, "id" | "status" | "missingRequiredElements">Config metadata (name, formId, formName, configQuantity)
preConfigTPreConfigConfig (optional)Pre-filled values/quantities to apply on creation

Returns number — the newly assigned config ID.

Related


removeConfig

removeConfig: (configId: number) => void

Removes a configuration and all associated form and value data.

The SDK also removes the corresponding entries from formSubstore.fromConfigs and valuesSubstore.valuesConfigs. If the removed config was the active one, currentConfigId is cleared.

Parameters

NameTypeDescription
configIdnumberID of the config to remove

Related


updateConfig

updateConfig: (
configId: number,
config: Partial<Omit<TConfig, "id" | "formName" | "status">>,
) => void

Partially updates a configuration’s metadata fields.

Only name, formId, and configQuantity can be changed. id, formName, and status are immutable through this method.

Parameters

NameTypeDescription
configIdnumberID of the config to update
configPartial<Omit<TConfig, "id" | "formName" | "status">>Fields to update

Related

  • configs — the list is updated in place

updateConfigPosition

updateConfigPosition: (configId: number, newPosition: number) => void

Reorders a configuration to a new index in the list.

newPosition is zero-based. The config is removed from its current position and inserted at newPosition.

Parameters

NameTypeDescription
configIdnumberID of the config to move
newPositionnumberTarget zero-based index

Related

  • configs — the ordering of this array is changed

copyConfig

copyConfig: (configId: number) => void

Duplicates an existing configuration, including its form and value data.

The SDK:

  1. Creates a new config entry with incremented ID (via addConfig internally)
  2. Deep-copies the form state from formSubstore.fromConfigs[configId]
  3. Deep-copies values and quantities from valuesSubstore.valuesConfigs[configId]

Parameters

NameTypeDescription
configIdnumberID of the config to duplicate

Related


setupFromPreConfig

setupFromPreConfig: (
preConfig: TPreConfig,
args: {
defaultConfigName: string;
skipCleanConfigs?: boolean;
},
) => void

Initialises the store from a pre-configuration object, replacing existing configs.

A TPreConfig encodes one or more configurations with their pre-filled values, quantities, and optional contact-field overrides. After this call the store’s configs list is replaced with the configs described in preConfig.

Set skipCleanConfigs: true to append to the existing list instead of replacing it.

Parameters

NameTypeDescription
preConfigTPreConfigPre-configuration payload
args.defaultConfigNamestringFallback name for configs that don’t specify one
args.skipCleanConfigsboolean (optional)When true, existing configs are kept and new ones are appended

Related