Skip to content

Commit

Permalink
feat(business-report): upgrade user-facing part of the social media d…
Browse files Browse the repository at this point in the history
…ata UI
  • Loading branch information
r4zendev committed Dec 27, 2024
1 parent 01c1a6c commit 72d5306
Show file tree
Hide file tree
Showing 18 changed files with 365 additions and 202 deletions.
3 changes: 2 additions & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dev": "vite",
"clean": "rimraf ./tsconfig.tsbuildinfo && rimraf ./dist",
"build": "tsc && vite build",
"build:watch": "vite build --watch",
"lint": "eslint . --fix",
"format": "prettier --write .",
"preview": "vite preview",
Expand Down Expand Up @@ -53,7 +54,7 @@
"dayjs": "^1.11.6",
"i18n-iso-countries": "^7.6.0",
"lodash": "^4.17.21",
"lucide-react": "^0.144.0",
"lucide-react": "^0.245.0",
"react": "^18.0.37",
"react-dom": "^18.0.5",
"react-error-boundary": "^4.0.13",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/components/atoms/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const buttonVariants = cva(
secondary: 'bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80',
ghost: 'hover:bg-accent hover:text-accent-foreground',
link: 'text-primary underline-offset-4 hover:underline',
browserLink:
'text-blue-600 hover:text-blue-800 visited:text-purple-600 underline-offset-4 hover:underline',
},
size: {
default: 'h-9 px-4 py-2',
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/atoms/Image/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { useImageProps } from 'react-image';
export interface ImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, 'src'> {
src: useImageProps['srcList'];
useImageProps?: Omit<useImageProps, 'srcList'>;
width: CSSProperties['width'];
height: CSSProperties['height'];
width?: CSSProperties['width'];
height?: CSSProperties['height'];
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './ads-provider-adapter';
export * from './create-report-adapter';
export * from './report-adapter';
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AdsProviders, severityToDisplaySeverity } from '@/components/templates/report/constants';
import { adsProviderAdapter } from '@/components';
import { severityToDisplaySeverity } from '@/components/templates/report/constants';
import { TAdsProvider } from '@/components/templates/report/types';
import { SeverityType } from '@ballerine/common';
import { booleanToYesOrNo, SeverityType } from '@ballerine/common';

const getLabel = ({ label, provider }: { label: string; provider: string }) => {
if (label === 'page') {
Expand All @@ -23,6 +22,47 @@ export const toRiskLabels = (riskIndicators: Array<{ name: string; riskLevel: st
}));
};

export const toSocialMediaPresence = (data: Record<string, any>) => {
const { facebookData, instagramData } = data ?? {};

return {
facebook: {
page: facebookData?.pageUrl,
id: facebookData?.id,
creationDate: facebookData?.creationDate,
categories: facebookData?.pageCategories,
address: facebookData?.address,
phoneNumber: facebookData?.phoneNumber,
email: facebookData?.email,
likes: facebookData?.numberOfLikes,
},
instagram: {
page: instagramData?.pageUrl,
userName: instagramData?.username,
categories: instagramData?.pageCategories,
biography: instagramData?.biography,
followers: instagramData?.numberOfFollowers,
isBusinessAccount: booleanToYesOrNo(instagramData?.isBusinessAccount),
isVerified: booleanToYesOrNo(instagramData?.isVerified),
},
} as const satisfies Record<Lowercase<TAdsProvider>, Record<string, unknown>>;
};

export const toAdsImages = (data: Record<string, any>) => {
const { facebookData, instagramData } = data ?? {};

return {
facebook: {
src: facebookData?.screenshotUrl,
link: facebookData?.pageUrl,
},
instagram: {
src: instagramData?.screenshotUrl,
link: instagramData?.pageUrl,
},
};
};

const normalizeRiskLevel = (riskTypeLevels: Record<string, SeverityType>) => {
return Object.entries(riskTypeLevels).reduce((acc, [riskType, riskLevel]) => {
acc[riskType] =
Expand All @@ -41,30 +81,7 @@ export const reportAdapter = {
adsAndSocialMediaAnalysis: toRiskLabels(
report?.summary?.riskIndicatorsByDomain?.adsAndSocialViolations,
),
adsAndSocialMediaPresence: [
...Object.entries({ facebook: report?.socialMedia?.facebookData ?? {} }),
...Object.entries({ instagram: report?.socialMedia?.instagramData ?? {} }),
]
.map(([provider, data]) => {
if (!AdsProviders.includes(provider.toUpperCase() as TAdsProvider)) {
return;
}

const adapter = adsProviderAdapter[provider as keyof typeof adsProviderAdapter];
const adaptedData = adapter(data);

return {
label: provider,
items: Object.entries(adaptedData).map(([label, value]) => ({
label: getLabel({
label,
provider,
}),
value,
})),
};
})
?.filter((value): value is NonNullable<typeof value> => Boolean(value)),
adsAndSocialMediaPresence: toSocialMediaPresence(report?.socialMedia),
websiteLineOfBusinessAnalysis:
report?.summary?.riskIndicatorsByDomain?.lineOfBusinessViolations?.map(
({
Expand Down Expand Up @@ -125,16 +142,7 @@ export const reportAdapter = {
websiteCredibilityAnalysis: toRiskLabels(
report?.summary?.riskIndicatorsByDomain?.tldViolations,
),
adsImages: [
...Object.entries({ facebook: report?.socialMedia?.facebookData ?? {} }),
...Object.entries({ instagram: report?.socialMedia?.instagramData ?? {} }),
]
.map(([provider, data]) => ({
provider,
src: data?.screenshotUrl,
link: data?.pageUrl,
}))
.filter(({ src }: { src: string }) => !!src),
adsImages: toAdsImages(report?.socialMedia),
relatedAdsImages: report?.socialMedia?.pickedAds
?.map((data: { screenshotUrl: string; link: string }) => ({
src: data?.screenshotUrl,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 72d5306

Please sign in to comment.