Skip to content

Commit 612ff39

Browse files
authored
fix: fixed edit buttons (#3417)
1 parent 14bcd73 commit 612ff39

File tree

10 files changed

+96
-62
lines changed

10 files changed

+96
-62
lines changed

apps/backoffice-v2/src/lib/blocks/hooks/useEntityInfoBlock/useEntityInfoBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,5 @@ export const useEntityInfoBlock = ({
117117
.buildFlat(),
118118
})
119119
.build();
120-
}, [entity, workflow]);
120+
}, [entity, workflow, onEdit, isEditDisabled]);
121121
};

apps/backoffice-v2/src/lib/blocks/hooks/useKYCBusinessInformationBlock/useKYCBusinessInformationBlock.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useEntityInfoBlock } from '@/lib/blocks/hooks/useEntityInfoBlock/useEnt
44
import { useCaseState } from '@/pages/Entity/components/Case/hooks/useCaseState/useCaseState';
55
import { useCurrentCaseQuery } from '@/pages/Entity/hooks/useCurrentCaseQuery/useCurrentCaseQuery';
66
import { StateTag } from '@ballerine/common';
7+
import { EDIT_TEMPLATES } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useEditCollectionFlow';
78

89
export const useKYCBusinessInformationBlock = () => {
910
const { data: workflow } = useCurrentCaseQuery();
@@ -19,7 +20,7 @@ export const useKYCBusinessInformationBlock = () => {
1920
...entityDataAdditionalInfo
2021
} = workflow?.context?.entity?.data?.additionalInfo ?? {};
2122

22-
const { onEditCollectionFlow } = useEditCollectionFlow();
23+
const { onEditCollectionFlow } = useEditCollectionFlow(EDIT_TEMPLATES.COMPANY_DETAILS);
2324
const { data: session } = useAuthenticatedUserQuery();
2425
const caseState = useCaseState(session?.user ?? null, workflow);
2526

@@ -31,7 +32,7 @@ export const useKYCBusinessInformationBlock = () => {
3132
!workflow?.tags?.includes(StateTag.MANUAL_REVIEW),
3233
!workflow?.workflowDefinition?.config?.editableContext?.entityInfo,
3334
].some(Boolean),
34-
onEdit: onEditCollectionFlow({ steps: ['company_details'] }),
35+
onEdit: onEditCollectionFlow,
3536
});
3637

3738
return blocks;

apps/backoffice-v2/src/lib/blocks/variants/DefaultBlocks/hooks/useCaseBlocksLogic/utils/useTabsToBlocksMap.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import { z } from 'zod';
2121
import { handleZodError } from '@/common/utils/handle-zod-error/handle-zod-error';
2222
import { toast } from 'sonner';
2323
import { t } from 'i18next';
24-
import { useEditCollectionFlow } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useEditCollectionFlow';
24+
import {
25+
EDIT_TEMPLATES,
26+
useEditCollectionFlow,
27+
} from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useEditCollectionFlow';
2528

2629
export type TCaseBlocksCreationProps = {
2730
workflow: TWorkflowById;
@@ -145,7 +148,9 @@ export const useTabsToBlocksMap = ({
145148
const { mutate: mutateInitiateIndividualVerificationAndSendEmail } =
146149
useInitiateIndividualVerificationAndSendEmailMutation();
147150

148-
const { onEditCollectionFlow } = useEditCollectionFlow();
151+
const { onEditCollectionFlow: onEditCompanyOwnership } = useEditCollectionFlow(
152+
EDIT_TEMPLATES.COMPANY_OWNERSHIP,
153+
);
149154
const getInitiateKycEvent = (nextEvents: string[]) => {
150155
if (nextEvents?.includes('start')) {
151156
return 'start';
@@ -291,7 +296,7 @@ export const useTabsToBlocksMap = ({
291296
ids,
292297
workflowId: childWorkflow?.id,
293298
}),
294-
onEdit: onEditCollectionFlow({ steps: ['company_ownership'] }),
299+
onEdit: onEditCompanyOwnership,
295300
reasons:
296301
childWorkflow?.workflowDefinition?.contextSchema?.schema?.properties?.documents?.items?.properties?.decision?.properties?.revisionReason?.anyOf?.find(
297302
({ enum: enum_ }) => !!enum_,
@@ -317,7 +322,6 @@ export const useTabsToBlocksMap = ({
317322
[
318323
getStatusFromCheckStatus,
319324
mutateInitiateIndividualVerificationAndSendEmail,
320-
onEditCollectionFlow,
321325
getStatusFromTags,
322326
getInitiateKycEvent,
323327
getInitiateSanctionsScreeningEvent,
@@ -331,6 +335,7 @@ export const useTabsToBlocksMap = ({
331335
workflow?.workflowDefinition?.config?.isInitiateSanctionsScreeningEnabled,
332336
workflow?.workflowDefinition?.config?.isInitiateKycEnabled,
333337
workflow?.workflowDefinition?.config?.isKycEndUserEditEnabled,
338+
onEditCompanyOwnership,
334339
],
335340
);
336341
const directorToIndividualAdapter = useCallback(
@@ -393,7 +398,7 @@ export const useTabsToBlocksMap = ({
393398
onReuploadNeeded:
394399
({ reason, ids }: { reason: string; ids: string[] }) =>
395400
() => {},
396-
onEdit: onEditCollectionFlow({ steps: ['company_ownership'] }),
401+
onEdit: onEditCompanyOwnership,
397402
reasons: [],
398403
isReuploadNeededDisabled: true,
399404
isApproveDisabled: true,
@@ -411,7 +416,7 @@ export const useTabsToBlocksMap = ({
411416
},
412417
[
413418
mutateInitiateIndividualVerificationAndSendEmail,
414-
onEditCollectionFlow,
419+
onEditCompanyOwnership,
415420
workflow?.workflowDefinition?.config?.language,
416421
workflow?.id,
417422
caseState.actionButtonsEnabled,
@@ -519,7 +524,7 @@ export const useTabsToBlocksMap = ({
519524
onReuploadNeeded:
520525
({ reason, ids }: { reason: string; ids: string[] }) =>
521526
() => {},
522-
onEdit: onEditCollectionFlow({ steps: ['company_ownership'] }),
527+
onEdit: onEditCompanyOwnership,
523528
reasons: [],
524529
isReuploadNeededDisabled: true,
525530
isApproveDisabled: true,
@@ -543,7 +548,7 @@ export const useTabsToBlocksMap = ({
543548
endUsers,
544549
getStatusFromCheckStatus,
545550
mutateInitiateIndividualVerificationAndSendEmail,
546-
onEditCollectionFlow,
551+
onEditCompanyOwnership,
547552
workflow?.workflowDefinition?.config?.language,
548553
],
549554
);

apps/backoffice-v2/src/lib/blocks/variants/DefaultBlocks/hooks/useDefaultBlocksLogic/useDefaultBlocksLogic.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import { useEntityAdditionalInfoBlock } from '@/lib/blocks/hooks/useEntityAdditi
6666
import { useEditCollectionFlow } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useEditCollectionFlow/useEditCollectionFlow';
6767
import { useEndUserByIdQuery } from '@/domains/individuals/queries/useEndUserByIdQuery/useEndUserByIdQuery';
6868
import { useIndividualsRegistryProvidedBlock } from '@/lib/blocks/hooks/useIndividualsRegistryProvidedBlock/useIndividualsRegistryProvidedBlock';
69+
import { EDIT_TEMPLATES } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useEditCollectionFlow';
6970

7071
const registryInfoWhitelist = ['open_corporates'] as const;
7172

@@ -227,7 +228,7 @@ export const useDefaultBlocksLogic = () => {
227228
},
228229
});
229230

230-
const { onEditCollectionFlow } = useEditCollectionFlow();
231+
const { onEditCollectionFlow } = useEditCollectionFlow(EDIT_TEMPLATES.COMPANY_DETAILS);
231232

232233
const entityInfoBlock = useEntityInfoBlock({
233234
entity: workflow?.context?.entity,
@@ -237,7 +238,7 @@ export const useDefaultBlocksLogic = () => {
237238
!workflow?.tags?.includes(StateTag.MANUAL_REVIEW),
238239
!workflow?.workflowDefinition?.config?.editableContext?.entityInfo,
239240
].some(Boolean),
240-
onEdit: onEditCollectionFlow({ steps: ['company_details'] }),
241+
onEdit: onEditCollectionFlow,
241242
});
242243

243244
const entityAdditionalInfoBlock = useEntityAdditionalInfoBlock({

apps/backoffice-v2/src/lib/blocks/variants/KybExampleBlocks/hooks/useKybExampleBlocksLogic/useKybExampleBlocksLogic.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { useReviseDocumentByIdMutation } from '@/domains/documents/hooks/mutatio
3030
import { useRemoveDocumentDecisionByIdMutation } from '@/domains/documents/hooks/mutations/useRemoveDocumentDecisionByIdMutation/useRemoveDocumentDecisionByIdMutation';
3131
import { useApproveDocumentByIdMutation } from '@/domains/documents/hooks/mutations/useApproveDocumentByIdMutation/useApproveDocumentByIdMutation';
3232
import { useEditCollectionFlow } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useEditCollectionFlow/useEditCollectionFlow';
33+
import { EDIT_TEMPLATES } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useEditCollectionFlow';
3334

3435
export const useKybExampleBlocksLogic = () => {
3536
const { entityId: workflowId } = useParams();
@@ -104,7 +105,9 @@ export const useKybExampleBlocksLogic = () => {
104105
);
105106

106107
// Blocks
107-
const { onEditCollectionFlow } = useEditCollectionFlow();
108+
const { onEditCollectionFlow: onEditCompanyDetails } = useEditCollectionFlow(
109+
EDIT_TEMPLATES.COMPANY_DETAILS,
110+
);
108111

109112
const businessInformation = useEntityInfoBlock({
110113
entity: workflow?.context?.entity,
@@ -114,7 +117,7 @@ export const useKybExampleBlocksLogic = () => {
114117
!workflow?.tags?.includes(StateTag.MANUAL_REVIEW),
115118
!workflow?.workflowDefinition?.config?.editableContext?.entityInfo,
116119
].some(Boolean),
117-
onEdit: onEditCollectionFlow({ steps: ['company_details'] }),
120+
onEdit: onEditCompanyDetails,
118121
});
119122

120123
const isWorkflowLevelResolution =

apps/backoffice-v2/src/lib/blocks/variants/ManualReviewBlocks/hooks/useManualReviewBlocksLogic/useManualReviewBlocksLogic.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { StateTag, valueOrNA } from '@ballerine/common';
1313
import { useEntityAdditionalInfoBlock } from '@/lib/blocks/hooks/useEntityAdditionalInfoBlock/useEntityAdditionalInfoBlock';
1414
import { useAddressBlock } from '@/lib/blocks/hooks/useAddressBlock/useAddressBlock';
1515
import { titleCase } from 'string-ts';
16+
import { EDIT_TEMPLATES } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useEditCollectionFlow';
1617

1718
export const useManualReviewBlocksLogic = () => {
1819
const { entityId: workflowId } = useParams();
@@ -60,7 +61,9 @@ export const useManualReviewBlocksLogic = () => {
6061
[mutateRevisionTaskById],
6162
);
6263

63-
const { onEditCollectionFlow } = useEditCollectionFlow();
64+
const { onEditCollectionFlow: onEditCompanyDetails } = useEditCollectionFlow(
65+
EDIT_TEMPLATES.COMPANY_DETAILS,
66+
);
6467

6568
const businessInformation = useEntityInfoBlock({
6669
entity: workflow?.context?.entity,
@@ -70,7 +73,7 @@ export const useManualReviewBlocksLogic = () => {
7073
!workflow?.tags?.includes(StateTag.MANUAL_REVIEW),
7174
!workflow?.workflowDefinition?.config?.editableContext?.entityInfo,
7275
].some(Boolean),
73-
onEdit: onEditCollectionFlow({ steps: ['company_details'] }),
76+
onEdit: onEditCompanyDetails,
7477
});
7578
const isWorkflowLevelResolution =
7679
workflow?.workflowDefinition?.config?.workflowLevelResolution ??

apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/CaseOptions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const CaseOptions = () => {
6363
</DropdownMenuItem>
6464
<DropdownMenuItem className={`w-full px-8 py-1`} asChild>
6565
<Button
66-
onClick={onEditCollectionFlow({ steps: 'all' })}
66+
onClick={onEditCollectionFlow}
6767
variant={'ghost'}
6868
className="justify-start"
6969
disabled={!isCanEditCollectionFlow || isLoading}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { TSteps } from './useEditCollectionFlow';
2+
3+
export const EDIT_TEMPLATES = {
4+
ALL: 'all',
5+
COMPANY_DETAILS: ['company_details'],
6+
COMPANY_OWNERSHIP: ['company_ownership'],
7+
} satisfies Record<string, TSteps>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './useEditCollectionFlow';
2+
export * from './consts';

apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useEditCollectionFlow/useEditCollectionFlow.tsx

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import { useEditCaseStateMutation } from './hooks/useEditCaseStateMutation/useEd
1010
import { useIsCanEditCollectionFlow } from './hooks/useIsCanEditCollectionFlow';
1111
import { useCollectionFlowStateQuery } from '@/domains/collection-flow/hooks/queries/useCollectionFlowStateQuery/useCollectionFlowStateQuery';
1212
import { useUpdateCollectionFlowStateMutation } from '@/domains/collection-flow/hooks/mutations/useUpdateCollectionFlowStateMutation/useUpdateCollectionFlowStateMutation';
13+
import { EDIT_TEMPLATES } from './consts';
1314

14-
export const useEditCollectionFlow = () => {
15+
export type TSteps = Parameters<typeof updateStateForEditing>[0]['steps'];
16+
17+
export const useEditCollectionFlow = (steps: TSteps = EDIT_TEMPLATES.ALL) => {
1518
const { data: workflow, isLoading: isLoadingWorkflow } = useCurrentCaseQuery();
1619
const { mutateAsync: updateWorkflowById, isLoading: isUpdatingWorkflow } =
1720
useUpdateWorkflowByIdMutation({
@@ -36,61 +39,71 @@ export const useEditCollectionFlow = () => {
3639
tags,
3740
config: workflowConfig,
3841
});
39-
const { data: collectionFlowState } = useCollectionFlowStateQuery(workflow?.id || '');
42+
const { data: collectionFlowState, isLoading: isLoadingCollectionFlowState } =
43+
useCollectionFlowStateQuery(workflow?.id || '');
4044
const { mutateAsync: updateCollectionFlowState } = useUpdateCollectionFlowStateMutation();
4145

42-
const onEditCollectionFlow = useCallback(
43-
({ steps }: { steps: Parameters<typeof updateStateForEditing>[0]['steps'] }) =>
44-
async () => {
45-
if (!collectionFlowState || !collectionFlowState.state) {
46-
toast.error('Something went wrong. Please try again later.');
46+
const onEditCollectionFlow = useCallback(async () => {
47+
if (!collectionFlowState || !collectionFlowState.state) {
48+
toast.error('Something went wrong. Please try again later.');
4749

48-
return;
49-
}
50+
return;
51+
}
5052

51-
try {
52-
// Updating case state first to avoid unnecessary collection flow state update in case this step fails
53-
await editCaseState({ workflowId: workflow?.id || '' });
54-
} catch (error) {
55-
toast.error(t('toast:edit_collection_flow_state_transition.error'));
56-
throw new Error('Failed move to edit collection flow. State missing.');
57-
}
53+
try {
54+
// Updating case state first to avoid unnecessary collection flow state update in case this step fails
55+
await editCaseState({ workflowId: workflow?.id || '' });
56+
} catch (error) {
57+
toast.error(t('toast:edit_collection_flow_state_transition.error'));
58+
throw new Error('Failed move to edit collection flow. State missing.');
59+
}
5860

59-
const updatedCollectionFlowState = updateStateForEditing({
60-
collectionFlowState: collectionFlowState.state,
61-
steps,
62-
});
61+
const updatedCollectionFlowState = updateStateForEditing({
62+
collectionFlowState: collectionFlowState.state,
63+
steps,
64+
});
6365

64-
await updateCollectionFlowState({
65-
workflowId: workflow?.id || '',
66-
state: updatedCollectionFlowState,
67-
action: 'step_request',
68-
});
66+
await updateCollectionFlowState({
67+
workflowId: workflow?.id || '',
68+
state: updatedCollectionFlowState,
69+
action: 'step_request',
70+
});
6971

70-
try {
71-
const collectionFlowBaseUrl = (workflow as TWorkflowById)?.context?.metadata
72-
?.collectionFlowUrl;
72+
try {
73+
const collectionFlowBaseUrl = (workflow as TWorkflowById)?.context?.metadata
74+
?.collectionFlowUrl;
7375

74-
if (!collectionFlowBaseUrl) {
75-
throw new Error('Collection flow URL is missing.');
76-
}
76+
if (!collectionFlowBaseUrl) {
77+
throw new Error('Collection flow URL is missing.');
78+
}
7779

78-
const url = buildCollectionFlowUrl(collectionFlowBaseUrl, {
79-
workflowId: workflow?.id,
80-
});
80+
const url = buildCollectionFlowUrl(collectionFlowBaseUrl, {
81+
workflowId: workflow?.id,
82+
});
8183

82-
window.open(url, '_blank');
83-
} catch (error) {
84-
toast.error(t('toast:edit_collection_flow.error_opening_collection_flow'));
85-
throw new Error('Failed to open collection flow in new tab.');
86-
}
87-
},
88-
[updateWorkflowById, editCaseState, workflow, collectionFlowState, updateCollectionFlowState],
89-
);
84+
window.open(url, '_blank');
85+
} catch (error) {
86+
toast.error(t('toast:edit_collection_flow.error_opening_collection_flow'));
87+
throw new Error('Failed to open collection flow in new tab.');
88+
}
89+
}, [
90+
updateWorkflowById,
91+
editCaseState,
92+
workflow,
93+
collectionFlowState,
94+
updateCollectionFlowState,
95+
steps,
96+
]);
9097

9198
const isLoading = useMemo(
92-
() => [isEditCaseStateLoading, isUpdatingWorkflow, isLoadingWorkflow].some(Boolean),
93-
[isEditCaseStateLoading, isUpdatingWorkflow, isLoadingWorkflow],
99+
() =>
100+
[
101+
isEditCaseStateLoading,
102+
isUpdatingWorkflow,
103+
isLoadingWorkflow,
104+
isLoadingCollectionFlowState,
105+
].some(Boolean),
106+
[isEditCaseStateLoading, isUpdatingWorkflow, isLoadingWorkflow, isLoadingCollectionFlowState],
94107
);
95108

96109
return {

0 commit comments

Comments
 (0)