Skip to content

Commit

Permalink
feat: added initial rendering of UI V2
Browse files Browse the repository at this point in the history
  • Loading branch information
chesterkmr committed Jan 2, 2025
1 parent 14f1dfd commit 8b76559
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

import { ErrorField } from '@/components/organisms/DynamicUI/rule-engines';
import { findDocumentDefinitionById } from '@/components/organisms/UIRenderer/elements/JSONForm/helpers/findDefinitionByName';
import { Document, UIElement, UIPage } from '@/domains/collection-flow';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

import { ARRAY_VALUE_INDEX_PLACEHOLDER } from '@/common/consts/consts';
import { DocumentFieldParams } from '@/components/organisms/UIRenderer/elements/JSONForm/components/DocumentField';
import { UIElement, UIPage } from '@/domains/collection-flow';
Expand All @@ -12,7 +14,7 @@ export const getElementByValueDestination = (

const findByElementDefinitionByDestination = (
targetDestination: string,
elements: UIElement<AnyObject>[],
elements: Array<UIElement<AnyObject>>,
): UIElement<AnyObject> | null => {
for (const element of elements) {
if (element.valueDestination === targetDestination) return element;
Expand All @@ -22,6 +24,7 @@ export const getElementByValueDestination = (
targetDestination,
element.elements,
);

if (foundElement) return foundElement;
}
}
Expand All @@ -36,26 +39,25 @@ export const getElementByValueDestination = (
);

const element = findByElementDefinitionByDestination(originArrayDestinationPath, page.elements);

return element;
}

return findByElementDefinitionByDestination(destination, page.elements);
};

export const getDocumentElementByDocumentError = (
id: string,
page: UIPage,
): UIElement<AnyObject> | null => {
export const getDocumentElementByDocumentError = (id: string, page: any): any => {
const findElement = (
id: string,
elements: UIElement<AnyObject>[],
elements: Array<UIElement<AnyObject>>,
): UIElement<DocumentFieldParams> | null => {
for (const element of elements) {
//@ts-ignore
if (element.options?.documentData?.id === id.replace('document-error-', '')) return element;

if (element.elements) {
const foundInElements = findElement(id, element.elements);

if (foundInElements) return foundInElements;
}
}
Expand Down
6 changes: 3 additions & 3 deletions apps/kyb-app/src/domains/collection-flow/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ITheme } from '@/common/types/settings';
import { Action, Rule, UIElement } from '@/domains/collection-flow/types/ui-schema.types';
import { AnyObject } from '@ballerine/ui';
import { Action, Rule } from '@/domains/collection-flow/types/ui-schema.types';
import { AnyObject, IFormElement } from '@ballerine/ui';
import { RJSFSchema, UiSchema } from '@rjsf/utils';
import { CollectionFlowConfig } from './flow-context.types';

Expand Down Expand Up @@ -128,7 +128,7 @@ export interface UIPage {
name: string;
number: number;
stateName: string;
elements: Array<UIElement<AnyObject>>;
elements: Array<IFormElement<any, any>>;
actions: Action[];
pageValidation?: Rule[];
}
Expand Down
9 changes: 6 additions & 3 deletions apps/kyb-app/src/pages/CollectionFlow/CollectionFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
PageError,
usePageErrors,
} from '@/components/organisms/DynamicUI/Page/hooks/usePageErrors';
import { UIRenderer } from '@/components/organisms/UIRenderer';
import { Cell } from '@/components/organisms/UIRenderer/elements/Cell';
import { Divider } from '@/components/organisms/UIRenderer/elements/Divider';
import { JSONForm } from '@/components/organisms/UIRenderer/elements/JSONForm/JSONForm';
Expand All @@ -37,6 +36,7 @@ import {
setStepCompletionState,
} from '@ballerine/common';
import { AnyObject } from '@ballerine/ui';
import { CollectionFlowUI } from './components/organisms/CollectionFlowUI';
import { FailedScreen } from './components/pages/FailedScreen';
import { useAdditionalWorkflowContext } from './hooks/useAdditionalWorkflowContext';

Expand Down Expand Up @@ -145,7 +145,7 @@ export const CollectionFlow = withSessionProtected(() => {
config={collectionFlowData?.config}
additionalContext={additionalContext}
>
{({ state, stateApi }) => {
{({ state, stateApi, payload }) => {
return (
<DynamicUI.TransitionListener
pages={elements ?? []}
Expand Down Expand Up @@ -299,7 +299,10 @@ export const CollectionFlow = withSessionProtected(() => {
<ProgressBar />
</div>
<div>
<UIRenderer elements={elems} schema={currentPage.elements} />
<CollectionFlowUI
elements={currentPage.elements}
context={payload}
/>
</div>
</div>
</AppShell.FormContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@ interface ICollectionFlowUIProps {
context: object;
}

const validationParams = {
validateOnBlur: true,
abortEarly: false,
};

export const CollectionFlowUI: FunctionComponent<ICollectionFlowUIProps> = ({
elements,
context,
}) => {
return <DynamicFormV2 fieldExtends={formElementsExtends} elements={elements} values={context} />;
return (
<DynamicFormV2
fieldExtends={formElementsExtends}
elements={elements}
values={context}
validationParams={validationParams}
/>
);
};

0 comments on commit 8b76559

Please sign in to comment.