From e18d052f2146dae18514cbae8d760c72bde8ad9a Mon Sep 17 00:00:00 2001 From: Omri Levy Date: Mon, 6 Jan 2025 16:42:09 +0200 Subject: [PATCH 1/6] refactor(backoffice-v2): changed home statistics --- .../PortfolioRiskStatistics.tsx | 48 ++----------------- .../usePortfolioRiskStatisticsLogic.tsx | 2 +- .../workflows-service/prisma/data-migrations | 2 +- 3 files changed, 6 insertions(+), 46 deletions(-) diff --git a/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/PortfolioRiskStatistics.tsx b/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/PortfolioRiskStatistics.tsx index 8248120f68..46777c5c74 100644 --- a/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/PortfolioRiskStatistics.tsx +++ b/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/PortfolioRiskStatistics.tsx @@ -1,11 +1,9 @@ -import React, { FunctionComponent } from 'react'; +import { FunctionComponent } from 'react'; import { Card } from '@/common/components/atoms/Card/Card'; import { CardHeader } from '@/common/components/atoms/Card/Card.Header'; import { CardContent } from '@/common/components/atoms/Card/Card.Content'; import { Cell, Pie, PieChart } from 'recharts'; import { ctw } from '@/common/utils/ctw/ctw'; -import { Button } from '@/common/components/atoms/Button/Button'; -import { TrendingDown, TrendingUp } from 'lucide-react'; import { Table, TableBody, @@ -31,8 +29,6 @@ export const PortfolioRiskStatistics: FunctionComponent
- Risk Indicators + Top 10 Content Violations -
- - {Intl.NumberFormat().format(totalRiskIndicators)} - - Total indicators -
-
- - -
Indicator - Amount + Amount @@ -183,7 +143,7 @@ export const PortfolioRiskStatistics: FunctionComponent - + {Intl.NumberFormat().format(count)} diff --git a/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx b/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx index 317377c19d..a90ac6de7b 100644 --- a/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx +++ b/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx @@ -25,7 +25,7 @@ export const usePortfolioRiskStatisticsLogic = ({ () => violationCounts .sort((a, b) => (riskIndicatorsSorting === 'asc' ? a.count - b.count : b.count - a.count)) - .slice(0, 5), + .slice(0, 10), [violationCounts, riskIndicatorsSorting], ); const widths = useMemo( diff --git a/services/workflows-service/prisma/data-migrations b/services/workflows-service/prisma/data-migrations index dd1ca2a9f1..4dd5c936e0 160000 --- a/services/workflows-service/prisma/data-migrations +++ b/services/workflows-service/prisma/data-migrations @@ -1 +1 @@ -Subproject commit dd1ca2a9f151f31d2a3f4620b5e8a58f1f216fec +Subproject commit 4dd5c936e0c01f190aa4dbed081d443684a26c14 From fb76c3697d235440372df0135e668b9dddaa3158 Mon Sep 17 00:00:00 2001 From: Omri Levy Date: Wed, 8 Jan 2025 12:13:31 +0200 Subject: [PATCH 2/6] feat(backoffice-v3): added filter for isAlert --- .../useBusinessReportsQuery.tsx | 3 ++ .../domains/business-reports/query-keys.ts | 1 + .../MerchantMonitoring.page.tsx | 42 ++++++++++++++++++- .../useMerchantMonitoringLogic.tsx | 26 +++++++++++- .../src/pages/MerchantMonitoring/schemas.ts | 28 +++++++++++-- 5 files changed, 92 insertions(+), 8 deletions(-) diff --git a/apps/backoffice-v2/src/domains/business-reports/hooks/queries/useBusinessReportsQuery/useBusinessReportsQuery.tsx b/apps/backoffice-v2/src/domains/business-reports/hooks/queries/useBusinessReportsQuery/useBusinessReportsQuery.tsx index 78480b4078..d82c352987 100644 --- a/apps/backoffice-v2/src/domains/business-reports/hooks/queries/useBusinessReportsQuery/useBusinessReportsQuery.tsx +++ b/apps/backoffice-v2/src/domains/business-reports/hooks/queries/useBusinessReportsQuery/useBusinessReportsQuery.tsx @@ -17,6 +17,7 @@ export const useBusinessReportsQuery = ({ findings, from, to, + isAlert, }: { reportType?: MerchantReportType; search: string; @@ -29,6 +30,7 @@ export const useBusinessReportsQuery = ({ findings: string[]; from?: string; to?: string; + isAlert?: boolean; }) => { const isAuthenticated = useIsAuthenticated(); @@ -45,6 +47,7 @@ export const useBusinessReportsQuery = ({ findings, from, to, + isAlert, }), enabled: isAuthenticated && !!sortBy && !!sortDir && !!page && !!pageSize, staleTime: 100_000, diff --git a/apps/backoffice-v2/src/domains/business-reports/query-keys.ts b/apps/backoffice-v2/src/domains/business-reports/query-keys.ts index b9aba396b4..b58ce7a74e 100644 --- a/apps/backoffice-v2/src/domains/business-reports/query-keys.ts +++ b/apps/backoffice-v2/src/domains/business-reports/query-keys.ts @@ -27,6 +27,7 @@ export const businessReportsQueryKey = createQueryKeys('business-reports', { findings: string[]; from?: string; to?: string; + isAlert?: boolean; }) => ({ queryKey: [{ page, pageSize, sortBy, sortDir, ...params }], queryFn: () => { diff --git a/apps/backoffice-v2/src/pages/MerchantMonitoring/MerchantMonitoring.page.tsx b/apps/backoffice-v2/src/pages/MerchantMonitoring/MerchantMonitoring.page.tsx index e369e02883..b258497fdd 100644 --- a/apps/backoffice-v2/src/pages/MerchantMonitoring/MerchantMonitoring.page.tsx +++ b/apps/backoffice-v2/src/pages/MerchantMonitoring/MerchantMonitoring.page.tsx @@ -1,4 +1,4 @@ -import React, { FunctionComponent } from 'react'; +import { FunctionComponent } from 'react'; import { isNonEmptyArray } from '@ballerine/common'; import { UrlPagination } from '@/common/components/molecules/UrlPagination/UrlPagination'; import { useMerchantMonitoringLogic } from '@/pages/MerchantMonitoring/hooks/useMerchantMonitoringLogic/useMerchantMonitoringLogic'; @@ -49,6 +49,7 @@ export const MerchantMonitoring: FunctionComponent = () => { onReportTypeChange, onClearAllFilters, REPORT_TYPE_TO_DISPLAY_TEXT, + IS_ALERT_TO_DISPLAY_TEXT, FINDINGS_FILTER, RISK_LEVEL_FILTER, STATUS_LEVEL_FILTER, @@ -57,8 +58,10 @@ export const MerchantMonitoring: FunctionComponent = () => { riskLevels, statuses, findings, + isAlert, multiselectProps, isClearAllButtonVisible, + onIsAlertChange, } = useMerchantMonitoringLogic(); return ( @@ -131,7 +134,7 @@ export const MerchantMonitoring: FunctionComponent = () => { + + + {Object.entries(IS_ALERT_TO_DISPLAY_TEXT).map(([value, label]) => ( + + onIsAlertChange(value as keyof typeof IS_ALERT_TO_DISPLAY_TEXT) + } + > + {label} + + ))} + + {isClearAllButtonVisible && (
@@ -152,6 +154,32 @@ export const PortfolioRiskStatistics: FunctionComponent< +
+ + Unresolved Monitoring Alerts + +
+
+ + + {Intl.NumberFormat().format(alertedReports)} + +
+ + View + +
+
+
+
); diff --git a/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx b/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx index 2393168308..23d287954d 100644 --- a/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx +++ b/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx @@ -7,6 +7,9 @@ import { } from '@/pages/Statistics/components/PortfolioRiskStatistics/constants'; import { z } from 'zod'; import { MetricsResponseSchema } from '@/domains/business-reports/hooks/queries/useBusinessReportMetricsQuery/useBusinessReportMetricsQuery'; +import { useLocale } from '@/common/hooks/useLocale/useLocale'; +import { useNavigate } from 'react-router-dom'; +import { useBusinessReportsQuery } from '@/domains/business-reports/hooks/queries/useBusinessReportsQuery/useBusinessReportsQuery'; export const usePortfolioRiskStatisticsLogic = ({ riskLevelCounts, @@ -40,6 +43,31 @@ export const usePortfolioRiskStatisticsLogic = ({ ), [filteredRiskIndicators], ); + const locale = useLocale(); + const navigate = useNavigate(); + const getLast30DaysDateRange = () => { + const currentDate = new Date(); + const thirtyDaysAgo = new Date(currentDate.getTime() - 30 * 24 * 60 * 60 * 1000); // Subtract 30 days in milliseconds + + const currentYear = currentDate.getFullYear(); + const currentMonth = (currentDate.getMonth() + 1).toString().padStart(2, '0'); + const currentDay = currentDate.getDate().toString().padStart(2, '0'); + + const startYear = thirtyDaysAgo.getFullYear(); + const startMonth = (thirtyDaysAgo.getMonth() + 1).toString().padStart(2, '0'); + const startDay = thirtyDaysAgo.getDate().toString().padStart(2, '0'); + + return { + from: `${startYear}-${startMonth}-${startDay}`, + to: `${currentYear}-${currentMonth}-${currentDay}`, + }; + }; + + const { from, to } = getLast30DaysDateRange(); + const { data: businessReports } = useBusinessReportsQuery({ + isAlert: true, + }); + const alertedReports = businessReports?.data?.length ?? 0; return { riskLevelToFillColor, @@ -50,5 +78,10 @@ export const usePortfolioRiskStatisticsLogic = ({ onSortRiskIndicators, filteredRiskIndicators, totalRiskIndicators, + locale, + navigate, + from, + to, + alertedReports, }; }; From 2d07f3c9534a5d5fcd4a2ac95ab23d09c1ec95e3 Mon Sep 17 00:00:00 2001 From: Omri Levy Date: Wed, 8 Jan 2025 16:03:58 +0200 Subject: [PATCH 5/6] refactor(backoffice-v2): now using dayjs for last 30 days date --- .../usePortfolioRiskStatisticsLogic.tsx | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx b/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx index 23d287954d..fac659e3e2 100644 --- a/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx +++ b/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx @@ -10,6 +10,7 @@ import { MetricsResponseSchema } from '@/domains/business-reports/hooks/queries/ import { useLocale } from '@/common/hooks/useLocale/useLocale'; import { useNavigate } from 'react-router-dom'; import { useBusinessReportsQuery } from '@/domains/business-reports/hooks/queries/useBusinessReportsQuery/useBusinessReportsQuery'; +import dayjs from 'dayjs'; export const usePortfolioRiskStatisticsLogic = ({ riskLevelCounts, @@ -46,20 +47,12 @@ export const usePortfolioRiskStatisticsLogic = ({ const locale = useLocale(); const navigate = useNavigate(); const getLast30DaysDateRange = () => { - const currentDate = new Date(); - const thirtyDaysAgo = new Date(currentDate.getTime() - 30 * 24 * 60 * 60 * 1000); // Subtract 30 days in milliseconds - - const currentYear = currentDate.getFullYear(); - const currentMonth = (currentDate.getMonth() + 1).toString().padStart(2, '0'); - const currentDay = currentDate.getDate().toString().padStart(2, '0'); - - const startYear = thirtyDaysAgo.getFullYear(); - const startMonth = (thirtyDaysAgo.getMonth() + 1).toString().padStart(2, '0'); - const startDay = thirtyDaysAgo.getDate().toString().padStart(2, '0'); + const today = dayjs(); + const thirtyDaysAgo = today.subtract(30, 'day'); return { - from: `${startYear}-${startMonth}-${startDay}`, - to: `${currentYear}-${currentMonth}-${currentDay}`, + from: thirtyDaysAgo.format('YYYY-MM-DD'), + to: today.format('YYYY-MM-DD'), }; }; From bda56bc568613b0fe0971c947588ffabaad73114 Mon Sep 17 00:00:00 2001 From: Omri Levy Date: Wed, 8 Jan 2025 16:31:09 +0200 Subject: [PATCH 6/6] refactor(backoffice-v2): added from and to to alerts count --- .../usePortfolioRiskStatisticsLogic.tsx | 15 ++++++++++++--- .../pages/Statistics/hooks/useStatisticsLogic.tsx | 11 ++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx b/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx index fac659e3e2..82521cebfa 100644 --- a/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx +++ b/apps/backoffice-v2/src/pages/Statistics/components/PortfolioRiskStatistics/hooks/usePortfolioRiskStatisticsLogic/usePortfolioRiskStatisticsLogic.tsx @@ -11,6 +11,9 @@ import { useLocale } from '@/common/hooks/useLocale/useLocale'; import { useNavigate } from 'react-router-dom'; import { useBusinessReportsQuery } from '@/domains/business-reports/hooks/queries/useBusinessReportsQuery/useBusinessReportsQuery'; import dayjs from 'dayjs'; +import { useZodSearchParams } from '@/common/hooks/useZodSearchParams/useZodSearchParams'; +import { useAuthenticatedUserQuery } from '@/domains/auth/hooks/queries/useAuthenticatedUserQuery/useAuthenticatedUserQuery'; +import { getStatisticsSearchSchema } from '@/pages/Statistics/hooks/useStatisticsLogic'; export const usePortfolioRiskStatisticsLogic = ({ riskLevelCounts, @@ -56,9 +59,15 @@ export const usePortfolioRiskStatisticsLogic = ({ }; }; - const { from, to } = getLast30DaysDateRange(); + const last30DaysDateRange = getLast30DaysDateRange(); + const { data: userData } = useAuthenticatedUserQuery(); + const registrationDate = new Date(userData?.user?.registrationDate ?? '1970-01-01'); + const StatisticsSearchSchema = getStatisticsSearchSchema(registrationDate); + const [{ from }] = useZodSearchParams(StatisticsSearchSchema); const { data: businessReports } = useBusinessReportsQuery({ isAlert: true, + from, + to: dayjs(from).add(1, 'month').format('YYYY-MM-DD'), }); const alertedReports = businessReports?.data?.length ?? 0; @@ -73,8 +82,8 @@ export const usePortfolioRiskStatisticsLogic = ({ totalRiskIndicators, locale, navigate, - from, - to, + from: last30DaysDateRange.from, + to: last30DaysDateRange.to, alertedReports, }; }; diff --git a/apps/backoffice-v2/src/pages/Statistics/hooks/useStatisticsLogic.tsx b/apps/backoffice-v2/src/pages/Statistics/hooks/useStatisticsLogic.tsx index ffcaaf44ad..dca35fd8ed 100644 --- a/apps/backoffice-v2/src/pages/Statistics/hooks/useStatisticsLogic.tsx +++ b/apps/backoffice-v2/src/pages/Statistics/hooks/useStatisticsLogic.tsx @@ -5,11 +5,8 @@ import dayjs from 'dayjs'; import { useState } from 'react'; import { z } from 'zod'; -export const useStatisticsLogic = () => { - const { data: userData } = useAuthenticatedUserQuery(); - const registrationDate = new Date(userData?.user?.registrationDate ?? '1970-01-01'); - - const StatisticsSearchSchema = z.object({ +export const getStatisticsSearchSchema = (registrationDate: Date) => + z.object({ from: z .string() .optional() @@ -25,6 +22,10 @@ export const useStatisticsLogic = () => { }), }); +export const useStatisticsLogic = () => { + const { data: userData } = useAuthenticatedUserQuery(); + const registrationDate = new Date(userData?.user?.registrationDate ?? '1970-01-01'); + const StatisticsSearchSchema = getStatisticsSearchSchema(registrationDate); const [{ from }, setSearchParams] = useZodSearchParams(StatisticsSearchSchema); const [date, setDate] = useState(from ?? undefined); const { data, isLoading, error } = useBusinessReportMetricsQuery({