Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MatanYadaev committed Feb 12, 2025
1 parent a013f04 commit 7cbaa35
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 26 deletions.
11 changes: 7 additions & 4 deletions apps/backoffice-v2/src/domains/business-reports/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ import {
MERCHANT_REPORT_STATUSES_MAP,
MERCHANT_REPORT_TYPES,
MERCHANT_REPORT_VERSIONS,
MerchantReportStatus,
MerchantReportType,
MerchantReportVersion,
ReportSchema,
} from '@ballerine/common';

const statusOverrides = {
[MERCHANT_REPORT_STATUSES_MAP.failed]: MERCHANT_REPORT_STATUSES_MAP['in-progress'],
[MERCHANT_REPORT_STATUSES_MAP['quality-control']]: MERCHANT_REPORT_STATUSES_MAP['in-progress'],
} as const satisfies Partial<Record<MerchantReportStatus, MerchantReportStatus>>;

export const BusinessReportSchema = ReportSchema.transform(data => ({
...data,
status:
data.status === MERCHANT_REPORT_STATUSES_MAP.failed
? MERCHANT_REPORT_STATUSES_MAP['quality-control']
: data.status,
status: data.status in statusOverrides ? statusOverrides[data.status] : 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,
Expand Down
10 changes: 5 additions & 5 deletions packages/common/src/consts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,36 +183,36 @@ 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>;
) as { [K in MerchantReportStatus]: K };

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>;
) as { [K in MerchantReportType]: K };

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>;
) as { [K in MerchantReportVersion]: K };

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>;
) as { [K in MerchantReportRiskLevel]: K };

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>;
) as { [K in RiskIndicatorRiskLevel]: K };
2 changes: 1 addition & 1 deletion packages/common/src/schemas/report-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

export const FacebookPageSchema = z.object({
id: z.string(),
url: z.string().nullish(),
url: z.string(),
name: z.string().nullish(),
email: z.string().nullish(),
likes: z.number().nullish(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const AdsAndSocialMedia = (pages: {
<h3 className="mb-2 text-base font-bold">Social Media</h3>

<div className="flex w-full flex-col gap-4">
{AdsProviders.map(toLowerCase).map(provider => {
{AdsProviders.map(provider => {
const page = pages[provider];

if (!page) {
Expand Down Expand Up @@ -216,13 +216,15 @@ export const AdsAndSocialMedia = (pages: {
})}
href={url}
>
<Image
key={screenshotUrl}
src={screenshotUrl}
alt={`${capitalize(provider)} image`}
role="link"
className="h-auto max-h-96 w-auto"
/>
{screenshotUrl && (
<Image
key={screenshotUrl}
src={screenshotUrl}
alt={`${capitalize(provider)} image`}
role="link"
className="h-auto max-h-96 w-auto"
/>
)}
</a>
</div>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { ComponentProps, FunctionComponent } from 'react';
import {
getSeverityFromRiskScore,
MERCHANT_REPORT_RISK_LEVELS_MAP,
MerchantReportRiskLevel,
RiskIndicatorRiskLevel,
Severity,
SeverityType,
Expand All @@ -21,7 +22,7 @@ export const BusinessReportSummary: FunctionComponent<{
search: string;
riskIndicators: z.infer<typeof RiskIndicatorSchema>[] | null;
}>;
riskLevel: string;
riskLevel: MerchantReportRiskLevel;
homepageScreenshotUrl: string | null;
Link: ComponentProps<typeof RiskIndicatorsSummary>['Link'];
}> = ({ sections, summary, ongoingMonitoringSummary, riskLevel, homepageScreenshotUrl, Link }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { FunctionComponent } from 'react';
import { Card, CardContent, CardHeader } from '@/components';
import { EcosystemTable } from '@/components/templates/report/components/Ecosystem/components/EcosystemTable/EcosystemTable';
import { ContentTooltip } from '@/components/molecules/ContentTooltip/ContentTooltip';
import { EcosystemRecordSchema } from '@/schemas/report-schema';
import { EcosystemRecordSchema } from '@ballerine/common';
import { z } from 'zod';

export const Ecosystem: FunctionComponent<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, { FunctionComponent } from 'react';
import { columns } from '@/components/templates/report/components/Ecosystem/components/EcosystemTable/columns';
import { DataTable } from '@/components/organisms/DataTable/DataTable';
import { ColumnDef } from '@tanstack/react-table';
import { EcosystemRecordSchema } from '@/schemas/report-schema';
import { z } from 'zod';
import { EcosystemRecordSchema } from '@ballerine/common';

export const EcosystemTable: FunctionComponent<{
data: z.infer<typeof EcosystemRecordSchema>[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ export const WebsiteCredibility: FunctionComponent<{
}) => {
// TODO: Ideally should happen on backend
const trafficSources = useMemo(() => {
if (!trafficData.trafficSources?.length) {
if (!Object.keys(trafficData.trafficSources ?? {}).length) {
return [];
}

const values = Object.entries(trafficData.trafficSources)
const values = Object.entries(trafficData.trafficSources ?? {})
.map(([label, value]) => ({
label,
value: Number((value * 100).toFixed(2)),
Expand Down Expand Up @@ -211,7 +211,7 @@ export const WebsiteCredibility: FunctionComponent<{
>
{!!websiteReputationRiskIndicators?.length &&
websiteReputationRiskIndicators.map(({ reason, sourceUrl }) => (
<li className="list-decimal">
<li key={reason} className="list-decimal">
{reason}
{!!sourceUrl && (
<span className="ms-4">
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/templates/report/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ObjectValues } from '@ballerine/common';

export const AdsProvider = {
FACEBOOK: 'FACEBOOK',
INSTAGRAM: 'INSTAGRAM',
FACEBOOK: 'facebook',
INSTAGRAM: 'instagram',
} as const;

export const AdsProviders = [
Expand Down

0 comments on commit 7cbaa35

Please sign in to comment.