Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use report_outcomes for report display #3035

Merged
merged 12 commits into from
Feb 13, 2025
Merged
30 changes: 0 additions & 30 deletions apps/backoffice-v2/src/domains/business-reports/constants.ts

This file was deleted.

58 changes: 13 additions & 45 deletions apps/backoffice-v2/src/domains/business-reports/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,19 @@ import {
MERCHANT_REPORT_VERSIONS,
MerchantReportType,
MerchantReportVersion,
} from '@/domains/business-reports/constants';

export const BusinessReportSchema = z
.object({
id: z.string(),
reportType: z.enum([MERCHANT_REPORT_TYPES[0]!, ...MERCHANT_REPORT_TYPES.slice(1)]),
createdAt: z.string().datetime(),
updatedAt: z.string().datetime(),
displayDate: z.string().datetime(),
riskScore: z.number().nullable(),
status: z.enum([MERCHANT_REPORT_STATUSES[0]!, ...MERCHANT_REPORT_STATUSES.slice(1)]),
parentCompanyName: z.string().nullable(),
merchantId: z.string(),
workflowVersion: z.enum([MERCHANT_REPORT_VERSIONS[0]!, ...MERCHANT_REPORT_VERSIONS.slice(1)]),
isAlert: z.boolean().nullish(),
companyName: z.string().nullish(),
monitoringStatus: z.boolean(),
website: z.object({
id: z.string(),
url: z.string().url(),
createdAt: z
.string()
.datetime()
.transform(value => new Date(value)),
updatedAt: z
.string()
.datetime()
.transform(value => new Date(value)),
}),
data: z.record(z.string(), z.unknown()).nullish(),
})
.transform(data => ({
...data,
status:
data.status === MERCHANT_REPORT_STATUSES_MAP.failed
? MERCHANT_REPORT_STATUSES_MAP['quality-control']
: data.status,
companyName:
data?.companyName ??
(data?.data?.websiteCompanyAnalysis as UnknownRecord | undefined)?.companyName ??
data?.parentCompanyName,
website: data?.website.url,
data: data.status === 'completed' ? data?.data : null,
riskScore: data.status === 'completed' ? data?.riskScore : null,
}));
ReportSchema,
} from '@ballerine/common';

export const BusinessReportSchema = ReportSchema.transform(data => ({
...data,
status:
data.status === MERCHANT_REPORT_STATUSES_MAP.failed
? MERCHANT_REPORT_STATUSES_MAP['quality-control']
: data.status,
website: data.website.url,
riskLevel: data.status === MERCHANT_REPORT_STATUSES_MAP.completed ? data.riskLevel : null,
data: data.status === MERCHANT_REPORT_STATUSES_MAP.completed ? data?.data : null,
}));

export const BusinessReportsSchema = z.object({
data: z.array(BusinessReportSchema),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { TabsContent } from '@/common/components/organisms/Tabs/Tabs.Content';
import { useWebsiteMonitoringBusinessReportTab } from '@/lib/blocks/variants/WebsiteMonitoringBlocks/hooks/useWebsiteMonitoringReportBlock/hooks/useWebsiteMonitoringBusinessReportTab/useWebsiteMonitoringBusinessReportTab';
import { BusinessReportSummary } from '@ballerine/ui';
import { RiskIndicatorLink } from '@/domains/business-reports/components/RiskIndicatorLink/RiskIndicatorLink';
import { MERCHANT_REPORT_TYPES_MAP } from '@ballerine/common';

export const WebsiteMonitoringBusinessReportTab = ({
businessReport,
Expand All @@ -18,27 +19,21 @@ export const WebsiteMonitoringBusinessReportTab = ({
const {
activeMonitoringTab,
riskIndicators,
riskLevels,
riskScore,
tabs,
summary,
ongoingMonitoringSummary,
getUpdatedSearchParamsWithActiveMonitoringTab,
search,
homepageScreenshotUrl,
} = useWebsiteMonitoringBusinessReportTab({
businessReport,
});

return (
<div className={'grid gap-y-4'}>
<BusinessReportSummary
summary={summary}
ongoingMonitoringSummary={ongoingMonitoringSummary}
riskLevels={riskLevels}
summary={businessReport.data!.summary!}
ongoingMonitoringSummary={businessReport.data!.ongoingMonitoringSummary!}
riskIndicators={riskIndicators}
riskScore={riskScore}
homepageScreenshotUrl={homepageScreenshotUrl}
riskScore={businessReport.data!.riskScore!}
homepageScreenshotUrl={businessReport.data!.homepageScreenshotUrl}
Link={RiskIndicatorLink}
/>
<Tabs defaultValue={activeMonitoringTab} className="w-full" key={activeMonitoringTab}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,20 @@ import { TBusinessReport } from '@/domains/business-reports/fetchers';
import { useCallback } from 'react';
import { useSearchParamsByEntity } from '@/common/hooks/useSearchParamsByEntity/useSearchParamsByEntity';
import { useLocation } from 'react-router-dom';
import { createReportAdapter, useReportTabs } from '@ballerine/ui';
import { useReportTabs } from '@ballerine/ui';
import { RiskIndicatorLink } from '@/domains/business-reports/components/RiskIndicatorLink/RiskIndicatorLink';
import { UnknownRecord } from 'type-fest';
import { MERCHANT_REPORT_TYPES_MAP } from '@ballerine/common';

export const useWebsiteMonitoringBusinessReportTab = ({
businessReport,
}: {
businessReport: TBusinessReport;
}) => {
const { tabs: tabsWithSummary, riskIndicators: originalRiskIndicators } = useReportTabs({
reportVersion: businessReport?.workflowVersion,
report: businessReport?.data ?? {},
companyName:
(businessReport?.data?.websiteCompanyAnalysis as UnknownRecord | undefined)?.companyName ??
'',
const { tabs: tabsWithSummary, sectionsSummary: originalSectionsSummary } = useReportTabs({
report: businessReport ?? {},
Link: RiskIndicatorLink,
});
const adapter = createReportAdapter({
reportVersion: businessReport?.workflowVersion,
});
const { riskLevels, riskScore, summary, ongoingMonitoringSummary, homepageScreenshotUrl } =
adapter(businessReport?.data ?? {});
const tabs = tabsWithSummary?.filter(tab => tab.value !== 'summary');
const [{ activeMonitoringTab }] = useSearchParamsByEntity();
const { search } = useLocation();
Expand All @@ -37,24 +29,19 @@ export const useWebsiteMonitoringBusinessReportTab = ({
},
[],
);
const riskIndicators = originalRiskIndicators?.map(riskIndicator => ({
...riskIndicator,
const riskIndicators = originalSectionsSummary?.map(section => ({
...section,
search: getUpdatedSearchParamsWithActiveMonitoringTab({
tab: riskIndicator.search.split('=')[1] ?? '',
tab: section.search.split('=')[1] ?? '',
search,
}),
}));

return {
activeMonitoringTab,
riskIndicators,
riskLevels,
riskScore,
tabs,
summary,
ongoingMonitoringSummary,
getUpdatedSearchParamsWithActiveMonitoringTab,
search,
homepageScreenshotUrl,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { IndicatorCircle } from '@/common/components/atoms/IndicatorCircle/Indic
import { useEllipsesWithTitle } from '@/common/hooks/useEllipsesWithTitle/useEllipsesWithTitle';
import { ctw } from '@/common/utils/ctw/ctw';
import {
getSeverityFromRiskScore,
MERCHANT_REPORT_STATUSES_MAP,
MERCHANT_REPORT_TYPES_MAP,
} from '@/domains/business-reports/constants';
import { getSeverityFromRiskScore } from '@ballerine/common';
} from '@ballerine/common';
import {
Badge,
CheckCircle,
Expand Down Expand Up @@ -65,25 +65,18 @@ export const columns = [
},
header: 'Website',
}),
columnHelper.accessor('riskScore', {
columnHelper.accessor('riskLevel', {
cell: info => {
const riskScore = info.getValue();
const severity = getSeverityFromRiskScore(riskScore);
const riskLevel = info.getValue();

return (
<div className="flex items-center gap-2">
{!riskScore && riskScore !== 0 && <TextWithNAFallback className={'py-0.5'} />}
{(riskScore || riskScore === 0) && (
<Badge
className={ctw(
severityToClassName[
(severity?.toUpperCase() as keyof typeof severityToClassName) ?? 'DEFAULT'
],
'w-20 py-0.5 font-bold',
)}
>
{titleCase(severity ?? '')}
{riskLevel ? (
<Badge className={ctw(severityToClassName[riskLevel], 'w-20 py-0.5 font-bold')}>
{titleCase(riskLevel)}
</Badge>
) : (
<TextWithNAFallback className={'py-0.5'} />
)}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useCallback } from 'react';
import { Link, useLocation } from 'react-router-dom';

import { useLocale } from '@/common/hooks/useLocale/useLocale';
import { MERCHANT_REPORT_STATUSES_MAP } from '@/domains/business-reports/constants';
import { MERCHANT_REPORT_STATUSES_MAP } from '@ballerine/common';
import { TBusinessReports } from '@/domains/business-reports/fetchers';

export const useMerchantMonitoringTableLogic = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ import { TabsContent } from '@/common/components/organisms/Tabs/Tabs.Content';
import { TabsList } from '@/common/components/organisms/Tabs/Tabs.List';
import { TabsTrigger } from '@/common/components/organisms/Tabs/Tabs.Trigger';
import { ctw } from '@/common/utils/ctw/ctw';
import { MERCHANT_REPORT_STATUSES_MAP } from '@/domains/business-reports/constants';
import { Notes } from '@/domains/notes/Notes';
import { useMerchantMonitoringBusinessReportLogic } from '@/pages/MerchantMonitoringBusinessReport/hooks/useMerchantMonitoringBusinessReportLogic/useMerchantMonitoringBusinessReportLogic';
import { MERCHANT_REPORT_STATUSES_MAP } from '@ballerine/common';

const DialogDropdownItem = forwardRef<
React.ElementRef<typeof DropdownMenuItem>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import { useToggle } from '@/common/hooks/useToggle/useToggle';
import { useZodSearchParams } from '@/common/hooks/useZodSearchParams/useZodSearchParams';
import { safeUrl } from '@/common/utils/safe-url/safe-url';
import { RiskIndicatorLink } from '@/domains/business-reports/components/RiskIndicatorLink/RiskIndicatorLink';
import { MERCHANT_REPORT_STATUSES_MAP } from '@/domains/business-reports/constants';
import { useBusinessReportByIdQuery } from '@/domains/business-reports/hooks/queries/useBusinessReportByIdQuery/useBusinessReportByIdQuery';
import { useCreateNoteMutation } from '@/domains/notes/hooks/mutations/useCreateNoteMutation/useCreateNoteMutation';
import { useNotesByNoteable } from '@/domains/notes/hooks/queries/useNotesByNoteable/useNotesByNoteable';
import { useToggleMonitoringMutation } from '@/pages/MerchantMonitoringBusinessReport/hooks/useToggleMonitoringMutation/useToggleMonitoringMutation';
import { isObject } from '@ballerine/common';
import {
isObject,
MERCHANT_REPORT_STATUSES_MAP,
MERCHANT_REPORT_TYPES_MAP,
} from '@ballerine/common';
import { zodResolver } from '@hookform/resolvers/zod';
import { useLocale } from '@/common/hooks/useLocale/useLocale';

Expand Down Expand Up @@ -88,11 +91,11 @@ export const useMerchantMonitoringBusinessReportLogic = () => {
});

const onSubmit: SubmitHandler<z.infer<typeof ZodDeboardingSchema>> = async (data, e) => {
if (!businessReport?.merchantId) {
throw new Error('Merchant ID is missing');
if (!businessReport?.business.id) {
throw new Error('Business ID is missing');
}

return turnOffMonitoringMutation.mutate(businessReport.merchantId);
return turnOffMonitoringMutation.mutate(businessReport.business.id);
};

const { mutateAsync: mutateCreateNote } = useCreateNoteMutation({ disableToast: true });
Expand All @@ -101,7 +104,7 @@ export const useMerchantMonitoringBusinessReportLogic = () => {
onSuccess: () => {
void mutateCreateNote({
content: 'Monitoring turned on',
entityId: businessReport?.merchantId ?? '',
entityId: businessReport?.business.id ?? '',
entityType: 'Business',
noteableId: businessReport?.id ?? '',
noteableType: 'Report',
Expand Down Expand Up @@ -131,7 +134,7 @@ export const useMerchantMonitoringBusinessReportLogic = () => {
.join(' ');
void mutateCreateNote({
content,
entityId: businessReport?.merchantId ?? '',
entityId: businessReport?.business.id ?? '',
entityType: 'Business',
noteableId: businessReport?.id ?? '',
noteableType: 'Report',
Expand All @@ -152,9 +155,7 @@ export const useMerchantMonitoringBusinessReportLogic = () => {
});

const { tabs } = useReportTabs({
reportVersion: businessReport?.workflowVersion,
report: businessReport?.data ?? {},
companyName: businessReport?.companyName,
report: businessReport ?? {},
Link: RiskIndicatorLink,
});

Expand Down
46 changes: 46 additions & 0 deletions packages/common/src/consts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,49 @@ export const MatchReasonCode = {

export const URL_PATTERN =
/^(https?:\/\/)?((([\da-z]([\da-z-]*[\da-z])*)\.)+[a-z]{2,}|((25[0-5]|2[0-4]\d|1\d{2}|\d{1,2})\.){3}(25[0-5]|2[0-4]\d|1\d{2}|\d{1,2})|localhost)(:\d{1,5})?(\/[\w!$%&'()*+,.:;=@~-]*)*(\?([\w!$%&'()*+,.:;=@~-]+=[\w!$%&'()*+,.:;=@~-]*(&[\w!$%&'()*+,.:;=@~-]+=[\w!$%&'()*+,.:;=@~-]*)*)?)?(#[\w!$%&'()*+,.:;=@~-]*)?$/i;

export const MERCHANT_REPORT_STATUSES = [
'draft',
'in-progress',
'completed',
'quality-control',
'failed',
] as const;

export type MerchantReportStatus = (typeof MERCHANT_REPORT_STATUSES)[number];

export const MERCHANT_REPORT_STATUSES_MAP = Object.fromEntries(
MERCHANT_REPORT_STATUSES.map(status => [status, status]),
) as Record<MerchantReportStatus, MerchantReportStatus>;

export const MERCHANT_REPORT_TYPES = ['MERCHANT_REPORT_T1', 'ONGOING_MERCHANT_REPORT_T1'] as const;

export type MerchantReportType = (typeof MERCHANT_REPORT_TYPES)[number];

export const MERCHANT_REPORT_TYPES_MAP = Object.fromEntries(
MERCHANT_REPORT_TYPES.map(type => [type, type]),
) as Record<MerchantReportType, MerchantReportType>;

export const MERCHANT_REPORT_VERSIONS = ['1', '2', '3'] as const;

export type MerchantReportVersion = (typeof MERCHANT_REPORT_VERSIONS)[number];

export const MERCHANT_REPORT_VERSIONS_MAP = Object.fromEntries(
MERCHANT_REPORT_VERSIONS.map(version => [version, version]),
) as Record<MerchantReportVersion, MerchantReportVersion>;

export const MERCHANT_REPORT_RISK_LEVELS = ['low', 'medium', 'high', 'critical'] as const;

export type MerchantReportRiskLevel = (typeof MERCHANT_REPORT_RISK_LEVELS)[number];

export const MERCHANT_REPORT_RISK_LEVELS_MAP = Object.fromEntries(
MERCHANT_REPORT_RISK_LEVELS.map(level => [level, level]),
) as Record<MerchantReportRiskLevel, MerchantReportRiskLevel>;

export const RISK_INDICATOR_RISK_LEVELS = ['positive', 'moderate', 'critical'] as const;

export type RiskIndicatorRiskLevel = (typeof RISK_INDICATOR_RISK_LEVELS)[number];

export const RISK_INDICATOR_RISK_LEVELS_MAP = Object.fromEntries(
RISK_INDICATOR_RISK_LEVELS.map(level => [level, level]),
) as Record<RiskIndicatorRiskLevel, RiskIndicatorRiskLevel>;
1 change: 1 addition & 0 deletions packages/common/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export { type TAvailableDocuments, type TDocument } from './documents/workflow/d
export * from './workflow/end-user.schema';
export { WorkflowDefinitionConfigThemeSchema } from './workflow/workflow-config-theme';
export { BusinessDataSchema, IndividualDataSchema } from './documents/schemas/entity-schema';
export * from './report-schema';
Loading