-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): add commercial credit check plugin and related updates (…
…#3024) * feat(plugins): add commercial credit check plugin and related updates - Integrate CommercialCreditCheckPlugin for external API interactions - Update existing logic to include commercial credit check validation - Add commercialCreditCheck to pluginsWhiteList for tracking (With so many plugins, this code is starting to look like a family reunion) * feat(blocks): add bank account verification and commercial credit check blocks - Introduce useBankAccountVerificationBlock hook for bank account verifications - Implement useCommercialCreditCheckBlock hook for commercial credit checks - Integrate both blocks into the default blocks logic for improved workflows (These blocks are so well-structured, even your mother would be proud of their nesting) * refactor(hooks): streamline bank account verification and credit check logic - Remove unnecessary useCallback for cell generation - Simplify return structure for better readability - Enhance object key management within payload processing (Your code's so convoluted, even an octopus would struggle to untangle it) * fix(plugin): update business type condition in credit check plugin - Change condition from 'individual' to 'sole_proprietorship' - Ensure accurate processing for specific business types * fix(plugins): enhance response parsing and error handling - Replace parse with safeParse for response validation - Include error handling for invalid response format * fix(plugins): update response structure in verification plugins - Change response spreading from parsedResponse to parsedResponse.data - Ensure consistency across the Bank Account and Commercial Credit Check plugins
- Loading branch information
1 parent
9f31b28
commit d9a706d
Showing
11 changed files
with
412 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
.../src/lib/blocks/hooks/useBankAccountVerificationBlock/useBankAccountVerificationBlock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import { createBlocksTyped } from '@/lib/blocks/create-blocks-typed/create-blocks-typed'; | ||
|
||
export const useBankAccountVerificationBlock = ({ pluginsOutput }) => { | ||
return useMemo(() => { | ||
if ( | ||
Object.keys(pluginsOutput?.bankAccountVerification?.data.clientResponsePayload ?? {}) | ||
.length === 0 | ||
) { | ||
return; | ||
} | ||
|
||
const data = { | ||
...pluginsOutput.bankAccountVerification.data.responseHeader.overallResponse, | ||
decisionElements: | ||
pluginsOutput.bankAccountVerification.data.clientResponsePayload.decisionElements, | ||
orchestrationDecisions: | ||
pluginsOutput.bankAccountVerification.data.clientResponsePayload.orchestrationDecisions, | ||
}; | ||
|
||
return createBlocksTyped() | ||
.addBlock() | ||
.addCell({ | ||
type: 'block', | ||
value: createBlocksTyped() | ||
.addBlock() | ||
.addCell({ | ||
id: 'nested-details-heading', | ||
type: 'heading', | ||
value: 'Bank Account Verification', | ||
}) | ||
.addCell({ | ||
id: 'nested-details-subheading', | ||
type: 'subheading', | ||
value: 'Experian-Provided Data', | ||
props: { | ||
className: 'mb-4', | ||
}, | ||
}) | ||
.addCell({ | ||
id: 'nested-details', | ||
type: 'details', | ||
hideSeparator: true, | ||
value: { | ||
data: Object.entries(data) | ||
?.filter(([property]) => !['tenantID', 'clientReferenceId'].includes(property)) | ||
.map(([title, value]) => ({ | ||
title, | ||
value, | ||
})), | ||
}, | ||
props: { | ||
config: { | ||
sort: { predefinedOrder: ['decision', 'decisionText'] }, | ||
}, | ||
}, | ||
} satisfies Extract< | ||
Parameters<ReturnType<typeof createBlocksTyped>['addCell']>[0], | ||
{ | ||
type: 'details'; | ||
} | ||
>) | ||
.buildFlat(), | ||
}) | ||
.build(); | ||
}, [ | ||
pluginsOutput.bankAccountVerification.data.clientResponsePayload, | ||
pluginsOutput.bankAccountVerification.data.responseHeader.overallResponse, | ||
]); | ||
}; |
57 changes: 57 additions & 0 deletions
57
...e-v2/src/lib/blocks/hooks/useCommercialCreditCheckBlock/useCommercialCreditCheckBlock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import { createBlocksTyped } from '@/lib/blocks/create-blocks-typed/create-blocks-typed'; | ||
|
||
export const useCommercialCreditCheckBlock = ({ pluginsOutput }) => { | ||
return useMemo(() => { | ||
if (Object.keys(pluginsOutput?.commercialCreditCheck?.data ?? {}).length === 0) { | ||
return; | ||
} | ||
|
||
return createBlocksTyped() | ||
.addBlock() | ||
.addCell({ | ||
type: 'block', | ||
value: createBlocksTyped() | ||
.addBlock() | ||
.addCell({ | ||
id: 'nested-details-heading', | ||
type: 'heading', | ||
value: 'Commercial Credit Check', | ||
}) | ||
.addCell({ | ||
id: 'nested-details-subheading', | ||
type: 'subheading', | ||
value: 'Experian-Provided Data', | ||
props: { | ||
className: 'mb-4', | ||
}, | ||
}) | ||
.addCell({ | ||
id: 'nested-details', | ||
type: 'details', | ||
hideSeparator: true, | ||
value: { | ||
data: Object.entries(pluginsOutput.commercialCreditCheck.data).map( | ||
([title, value]) => ({ | ||
title, | ||
value, | ||
}), | ||
), | ||
}, | ||
props: { | ||
config: { | ||
sort: { predefinedOrder: ['CommercialName', 'RegNumber'] }, | ||
}, | ||
}, | ||
} satisfies Extract< | ||
Parameters<ReturnType<typeof createBlocksTyped>['addCell']>[0], | ||
{ | ||
type: 'details'; | ||
} | ||
>) | ||
.buildFlat(), | ||
}) | ||
.build(); | ||
}, [pluginsOutput.commercialCreditCheck.data]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.