Skip to content

Commit

Permalink
Alerts graph (#2946)
Browse files Browse the repository at this point in the history
* refactor(backoffice-v2): changed home statistics

* feat(backoffice-v3): added filter for isAlert

* refactor(backoffice-v2): updated alert filter copy

* feat(backoffice-v2): added alerts graph to home page

* refactor(backoffice-v2): now using dayjs for last 30 days date

* refactor(backoffice-v2): added from and to to alerts count
  • Loading branch information
Omri-Levy authored and r4zendev committed Jan 14, 2025
1 parent f90f760 commit fe4eeaa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
3 changes: 1 addition & 2 deletions apps/backoffice-v2/src/domains/business-reports/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ type BusinessReportsParams = {
size: number;
};
orderBy?: string;
};
export const fetchBusinessReports = async (params: BusinessReportsParams) => {
}) => {
const queryParams = qs.stringify(params, { encode: false });

const [data, error] = await apiClient({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const PortfolioRiskStatistics: FunctionComponent<
</div>
<div className={'min-h-[10.125rem] rounded-xl bg-[#F6F6F6] p-2'}>
<Card className={'flex h-full flex-col px-3'}>
<CardHeader className={'pb-2'}>Top 10 Content Violations</CardHeader>
<CardHeader className={'pb-2 font-bold'}>Top 10 Content Violations</CardHeader>
<CardContent>
<Table>
<TableHeader className={'[&_tr]:border-b-0'}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ 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';
import dayjs from 'dayjs';
import { useZodSearchParams } from '@/common/hooks/useZodSearchParams/useZodSearchParams';
import { StatisticsSearchSchema } from '@/pages/Statistics/hooks/useStatisticsLogic';
import { useBusinessReportsQuery } from '@/domains/business-reports/hooks/queries/useBusinessReportsQuery/useBusinessReportsQuery';
import { useAuthenticatedUserQuery } from '@/domains/auth/hooks/queries/useAuthenticatedUserQuery/useAuthenticatedUserQuery';
import { getStatisticsSearchSchema } from '@/pages/Statistics/hooks/useStatisticsLogic';

export const usePortfolioRiskStatisticsLogic = ({
violationCounts,
Expand Down Expand Up @@ -59,15 +60,16 @@ export const usePortfolioRiskStatisticsLogic = ({
};

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?.totalItems ?? 0;
const alertedReports = businessReports?.data?.length ?? 0;

return {
riskLevelToFillColor,
Expand All @@ -77,6 +79,7 @@ export const usePortfolioRiskStatisticsLogic = ({
riskIndicatorsSorting,
onSortRiskIndicators,
filteredRiskIndicators,
totalRiskIndicators,
locale,
navigate,
from: last30DaysDateRange.from,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<string | undefined>(from ?? undefined);
const { data, isLoading, error } = useBusinessReportMetricsQuery({
Expand Down

0 comments on commit fe4eeaa

Please sign in to comment.