Skip to content

Commit

Permalink
fix: fixed sync of last step progress & fixed context overrides (#2788)
Browse files Browse the repository at this point in the history
  • Loading branch information
chesterkmr authored Oct 17, 2024
1 parent 538b0ca commit c3a7841
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useUIElementHandlers } from '@/components/organisms/UIRenderer/hooks/us
import { useUIElementState } from '@/components/organisms/UIRenderer/hooks/useUIElementState';
import { UIElementComponent } from '@/components/organisms/UIRenderer/types';
import { UIPage } from '@/domains/collection-flow';
import { useFlowContextQuery } from '@/hooks/useFlowContextQuery';
import { useFlowTracking } from '@/hooks/useFlowTracking';
import { Button } from '@ballerine/ui';
import set from 'lodash/set';
Expand All @@ -25,8 +24,7 @@ export const SubmitButton: UIElementComponent<{ text: string }> = ({ definition
const { currentPage, pages } = usePageResolverContext();
const { errors } = usePageContext();
const isValid = useMemo(() => !Object.values(errors).length, [errors]);
const { isPluginLoading } = useStateManagerContext();
const { data: context } = useFlowContextQuery();
const { isPluginLoading, stateApi, payload } = useStateManagerContext();

const setPageElementsTouched = useCallback(
(page: UIPage, state: UIState) => {
Expand Down Expand Up @@ -69,23 +67,26 @@ export const SubmitButton: UIElementComponent<{ text: string }> = ({ definition
currentPage,
state,
);
onClickHandler();

const isFinishPage = currentPage?.name === pages.at(-1)?.name;

if (isFinishPage && isValid && context) {
set(context, `flowConfig.stepsProgress.${currentPage?.stateName}.isCompleted`, true);
if (isFinishPage && isValid) {
set(payload, `flowConfig.stepsProgress.${currentPage?.stateName}.isCompleted`, true);

stateApi.setContext(payload);
}

onClickHandler();

if (isFinishPage && isValid) {
trackFinish();
}
}, [
context,
payload,
currentPage,
pages,
state,
isValid,
stateApi,
setPageElementsTouched,
onClickHandler,
trackFinish,
Expand Down
23 changes: 0 additions & 23 deletions apps/kyb-app/src/pages/CollectionFlow/CollectionFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { StepperUI } from '@/components/organisms/UIRenderer/elements/StepperUI'
import { SubmitButton } from '@/components/organisms/UIRenderer/elements/SubmitButton';
import { Title } from '@/components/organisms/UIRenderer/elements/Title';
import { useCustomer } from '@/components/providers/CustomerProvider';
import { fetchFlowContext } from '@/domains/collection-flow';
import { CollectionFlowContext } from '@/domains/collection-flow/types/flow-context.types';
import { prepareInitialUIState } from '@/helpers/prepareInitialUIState';
import { useFlowContextQuery } from '@/hooks/useFlowContextQuery';
Expand All @@ -30,7 +29,6 @@ import { Failed } from '@/pages/CollectionFlow/components/pages/Failed';
import { Rejected } from '@/pages/CollectionFlow/components/pages/Rejected';
import { Success } from '@/pages/CollectionFlow/components/pages/Success';
import { AnyObject } from '@ballerine/ui';
import get from 'lodash/get';
import set from 'lodash/set';

const elems = {
Expand Down Expand Up @@ -139,27 +137,6 @@ export const CollectionFlow = withSessionProtected(() => {

await stateApi.invokePlugin('sync_workflow_runtime');
}}
onFinish={async (tools, lastState) => {
tools.setElementCompleted(lastState, true);
const isAlreadyCompleted = get(
stateApi.getContext(),
`flowConfig.stepsProgress.${lastState}.isCompleted`,
);

if (!isAlreadyCompleted) {
const latestContext = await fetchFlowContext();

set(
latestContext.context,
`flowConfig.stepsProgress.${lastState}.isCompleted`,
true,
);

stateApi.setContext(latestContext.context);

await stateApi.invokePlugin('sync_workflow_runtime');
}
}}
>
{() => {
// Temp state, has to be resolved to success or failure by plugins
Expand Down

0 comments on commit c3a7841

Please sign in to comment.