Skip to content

Commit ece1c7a

Browse files
committed
feat: reworked status computation
1 parent 4031696 commit ece1c7a

File tree

2 files changed

+51
-16
lines changed

2 files changed

+51
-16
lines changed

apps/backoffice-v2/src/lib/blocks/variants/DefaultBlocks/hooks/useCaseBlocksLogic/utils/compute-individual-kyc-check-status.ts

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@ const getStatusFromTags = (tags: string[]) => {
2929
}
3030
};
3131

32-
export const computeIndividualKycCheckStatus = ({
33-
endUser,
34-
tags,
35-
}: {
36-
endUser?: TEndUser;
37-
tags: TWorkflowById['tags'];
38-
}): TIndividualKycCheckStatus | undefined => {
32+
const getStatusFromEndUser = (endUser: TEndUser) => {
3933
if (endUser?.individualVerificationsChecks?.status === 'in-progress') {
4034
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.PENDING;
4135
}
@@ -44,7 +38,7 @@ export const computeIndividualKycCheckStatus = ({
4438
!endUser?.approvalState ||
4539
[EndUserApprovalState.NEW, EndUserApprovalState.PROCESSING].includes(endUser?.approvalState)
4640
) {
47-
return getStatusFromTags(tags || []);
41+
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.PENDING;
4842
}
4943

5044
if (endUser?.approvalState === EndUserApprovalState.APPROVED) {
@@ -55,3 +49,40 @@ export const computeIndividualKycCheckStatus = ({
5549
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.REJECTED;
5650
}
5751
};
52+
53+
export const computeIndividualKycCheckStatus = ({
54+
endUser,
55+
tags,
56+
}: {
57+
endUser: TEndUser;
58+
tags: TWorkflowById['tags'];
59+
}): TIndividualKycCheckStatus | undefined => {
60+
if (endUser?.individualVerificationsChecks?.status === 'in-progress') {
61+
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.PENDING;
62+
}
63+
64+
const statusFromTags = getStatusFromTags(tags || []);
65+
const endUserStatus = getStatusFromEndUser(endUser);
66+
67+
const isPending = [endUserStatus, statusFromTags].includes(
68+
INDIVIDUAL_KYC_CHECK_STATUS_ENUM.PENDING,
69+
);
70+
const isApproved = [endUser.approvalState, statusFromTags].includes(
71+
EndUserApprovalState.APPROVED,
72+
);
73+
const isRejected = [endUser.approvalState, statusFromTags].includes(
74+
EndUserApprovalState.REJECTED,
75+
);
76+
77+
if (isPending) {
78+
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.PENDING;
79+
}
80+
81+
if (isApproved) {
82+
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.APPROVED;
83+
}
84+
85+
if (isRejected) {
86+
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.REJECTED;
87+
}
88+
};

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
} from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useEditCollectionFlow';
2727
import { computeIndividualKycCheckStatus } from './compute-individual-kyc-check-status';
2828
import { useMutateIndividualApprovalDecision } from '@/domains/individuals/mutations/useMutateIndividualApprovalDecision/useMutateIndividualApprovalDecision';
29-
import { EndUserApprovalState } from '@/domains/individuals/fetchers';
29+
import { EndUserApprovalState, TEndUser } from '@/domains/individuals/fetchers';
3030

3131
export type TCaseBlocksCreationProps = {
3232
workflow: TWorkflowById;
@@ -174,9 +174,10 @@ export const useTabsToBlocksMap = ({
174174
const initiateSanctionsScreeningEvent = getInitiateSanctionsScreeningEvent(
175175
childWorkflow?.nextEvents ?? [],
176176
);
177-
const endUser = endUsers?.find(
178-
endUser => endUser.id === childWorkflow?.context?.entity?.data?.ballerineEntityId,
179-
);
177+
const endUser =
178+
endUsers?.find(
179+
endUser => endUser.id === childWorkflow?.context?.entity?.data?.ballerineEntityId,
180+
) || ({} as TEndUser);
180181
const {
181182
amlHits,
182183
id: _id,
@@ -185,7 +186,7 @@ export const useTabsToBlocksMap = ({
185186
gender,
186187
individualVerificationsChecks,
187188
...endUserRest
188-
} = endUser ?? {};
189+
} = endUser;
189190
const {
190191
gender: genderAdditionalInfo,
191192
dateOfBirth: dateOfBirthAdditionalInfo,
@@ -419,8 +420,10 @@ export const useTabsToBlocksMap = ({
419420
),
420421
)
421422
?.map(director => {
422-
const endUser = endUsers?.find(endUser => endUser.id === director.ballerineEntityId);
423-
const { amlHits, individualVerificationsChecks, ...directorEndUser } = endUser ?? {};
423+
const endUser =
424+
endUsers?.find(endUser => endUser.id === director.ballerineEntityId) ||
425+
({} as TEndUser);
426+
const { amlHits, individualVerificationsChecks, ...directorEndUser } = endUser;
424427
const status = computeIndividualKycCheckStatus({
425428
endUser,
426429
tags: [],
@@ -447,7 +450,8 @@ export const useTabsToBlocksMap = ({
447450
}: NonNullable<
448451
TWorkflowById['context']['entity']['data']['additionalInfo']['peopleOfInterest']
449452
>[number]) => {
450-
const endUser = endUsers?.find(endUser => endUser.id === ballerineEntityId);
453+
const endUser =
454+
endUsers?.find(endUser => endUser.id === ballerineEntityId) || ({} as TEndUser);
451455
const {
452456
id: _id,
453457
amlHits,

0 commit comments

Comments
 (0)