Socotra
UI SDKComponents

DraftTransactionForm

The DraftTransactionForm is a specialized component for updating a policy transaction that is in a draft state. Unlike forms for initialized transactions, its primary role is to generate ParamsChangeInstructionCreateRequest and ModifyChangeInstructionCreateRequest objects. These instructions capture changes to the transaction’s parameters (like effective dates) and its core data, respectively.

Usage

To implement the DraftTransactionForm, you must provide the current transactionSnapshot, the initial paramsChangeInstruction, the relevant productModel, and a handleSubmit function. The form then renders the fields defined in the product model and manages the data to create the change instructions upon submission.

import { DraftTransactionForm } from '@socotra/ec-react-components';
import {
    ProductConfig,
    TransactionSnapshotResponse,
    ParamsChangeInstructionResponse,
} from '@socotra/ec-react-schemas';

// Example Usage
const MyEndorsementComponent = ({
    productModel,
    transactionSnapshot,
    paramsChangeInstruction,
}: {
    productModel: ProductConfig,
    transactionSnapshot: TransactionSnapshotResponse,
    paramsChangeInstruction: ParamsChangeInstructionResponse,
}) => {
    const handleSubmit = (changeRequests) => {
        const [paramsChange, modifyChange] = changeRequests;
        console.log('Params Change Request:', paramsChange);
        console.log('Modify Change Request:', modifyChange);
        // Handle API calls to apply the change instructions
    };

    return (
        <DraftTransactionForm
            productModel={productModel}
            transactionSnapshot={transactionSnapshot}
            paramsChangeInstruction={paramsChangeInstruction}
            handleSubmit={handleSubmit}
            submitButtonText='Apply Changes'
        />
    );
};

Props

PropTypeDescriptionDefault
transactionSnapshotTransactionSnapshotResponseThe snapshot object for the transaction being modified.Required
paramsChangeInstructionParamsChangeInstructionResponseThe initial parameter change instruction created with the transaction.Required
productModelProductConfigThe product configuration from the tenant data model that defines the transaction’s structure.Required
handleSubmit(data: [ParamsChangeInstructionCreateRequest, ModifyChangeInstructionCreateRequest]) => voidCallback triggered on submit. It receives an array containing the two generated change instruction request objects.Required
coverageTermsCoverageTermsConfigRecordThe coverage terms configuration from the tenant data model.undefined
dataTypesDataTypeConfigRecordCustom data types used in the product model.undefined
modifyChangeInstructionModifyChangeInstructionResponseThe most recent modify change instruction from the transaction’s stack, if one exists.undefined
disabledbooleanWhen true, disables the entire form.false
isSubmittingbooleanWhen true, disables form fields and the submit button to indicate a submission is in progress.false
preventFormResetOnDisabledbooleanIf false, the form’s data resets to initial values when disabled becomes true.true
validateOnSubmitbooleanIf true, validation runs on submit, blocking submission if invalid.false
hideSubmitButtonbooleanIf true, the submit button is not rendered.false
submitButtonTextstringCustom text for the submit button.'Update'
idstringA unique ID for the form wrapper element.undefined
titlesobjectAn object to override default labels for form sections like “Coverage Terms”.{}

State Management

The form’s state is managed internally with React’s useState hook.

  • The initial data is populated by the getDefaultDraftTransactionValues utility, which processes the input transactionSnapshot and change instructions.
  • useEffect hooks are in place to re-calculate the form’s data if key props like transactionSnapshot or modifyChangeInstruction change, ensuring the form stays in sync.
  • The underlying JsonForms component updates the state via its onChange handler.

Validation

Validation is performed by Ajv against a dynamically generated JSON Schema.

  • The base schema is generated from the productModel using the dataModelToJSONSchema utility.
  • It is then dynamically extended with definitions for default transaction fields (like effective date) and any coverage terms associated with the product.
  • The validateOnSubmit prop controls whether to perform validation before calling handleSubmit.
  • Error messages are translated using the translateError utility.

Labels and Translations

The text for UI labels and validation messages can be customized.

UI Labels

Labels for sections and fields can be overridden by passing a titles object prop.

KeyDescriptionDefault Value
formTitleThe main title for the entire form.'Transaction'
coverageTermsTitle for the “Coverage Terms” section.'Coverage Terms'
truthyLabelText for a “true” boolean value.'Yes'
falsyLabelText for a “false” boolean value.'No'

On this page