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
Prop |
Type |
Description |
Default |
|---|---|---|---|
|
|
The snapshot object for the transaction being modified. |
Required |
|
|
The initial parameter change instruction created with the transaction. |
Required |
|
|
The product configuration from the tenant data model that defines the transaction’s structure. |
Required |
|
|
Callback triggered on submit. It receives an array containing the two generated change instruction request objects. |
Required |
|
|
The coverage terms configuration from the tenant data model. |
|
|
|
Custom data types used in the product model. |
|
|
|
The most recent modify change instruction from the transaction’s stack, if one exists. |
|
|
|
When true, disables the entire form. |
|
|
|
When true, disables form fields and the submit button to indicate a submission is in progress. |
|
|
|
If |
|
|
|
If |
|
|
|
If |
|
|
|
Custom text for the submit button. |
|
|
|
A unique ID for the form wrapper element. |
|
|
|
An 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
getDefaultDraftTransactionValuesutility, which processes the inputtransactionSnapshotand change instructions.useEffecthooks are in place to re-calculate the form’s data if key props liketransactionSnapshotormodifyChangeInstructionchange, ensuring the form stays in sync.The underlying
JsonFormscomponent updates the state via itsonChangehandler.
Validation
Validation is performed by Ajv against a dynamically generated JSON Schema.
The base schema is generated from the
productModelusing thedataModelToJSONSchemautility.It is then dynamically extended with definitions for default transaction fields (like effective date) and any coverage terms associated with the product.
The
validateOnSubmitprop controls whether to perform validation before callinghandleSubmit.Error messages are translated using the
translateErrorutility.
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.
Key |
Description |
Default Value |
|---|---|---|
|
The main title for the entire form. |
|
|
Title for the “Coverage Terms” section. |
|
|
Text for a “true” boolean value. |
|
|
Text for a “false” boolean value. |
|