diff --git a/package.json b/package.json index 634d507..b5a2879 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "no-copy-frontend", - "version": "0.39.0", + "version": "0.40.0", "private": true, "scripts": { "dev": "next dev -p 2999", diff --git a/src/app/actions/action.ts b/src/app/actions/action.ts index d6b2c1e..0241efc 100644 --- a/src/app/actions/action.ts +++ b/src/app/actions/action.ts @@ -62,7 +62,7 @@ export async function getUserFilesInfo() { } } } catch (error) { - console.error(`error: ${error}`); + return null } } diff --git a/src/app/hooks/react-query/useUserFilesInfo.ts b/src/app/hooks/react-query/useUserFilesInfo.ts new file mode 100644 index 0000000..9919a48 --- /dev/null +++ b/src/app/hooks/react-query/useUserFilesInfo.ts @@ -0,0 +1,96 @@ +import { useQuery } from '@tanstack/react-query'; +import { getUserFilesInfo } from '@/app/actions/action'; + +export interface FilesInfo { + total: { + size: number; + quantity: number; + check: number; + violation: number; + protected: number; + }; + images: { + quantity: number; + size: number; + check: number; + violation: number; + protected: number; + }; + videos: { + quantity: number; + size: number; + check: number; + violation: number; + protected: number; + }; + audios: { + quantity: number; + size: number; + check: number; + violation: number; + protected: number; + }; + documents: { + quantity: number; + size: number; + check: number; + violation: number; + protected: number; + }; +} + +export const useUserFilesInfo = () => { + return useQuery({ + queryKey: ['userFilesInfo'], + queryFn: getUserFilesInfo, + select: (data): FilesInfo => { + if (!data) { + return { + total: { size: 0, quantity: 0, check: 0, violation: 0, protected: 0 }, + images: { quantity: 0, size: 0, check: 0, violation: 0, protected: 0 }, + videos: { quantity: 0, size: 0, check: 0, violation: 0, protected: 0 }, + audios: { quantity: 0, size: 0, check: 0, violation: 0, protected: 0 }, + documents: { quantity: 0, size: 0, check: 0, violation: 0, protected: 0 }, + }; + } + + return { + total: { + size: data.all_files_size, + quantity: data.all_files_quantity, + check: data.all_files_check, + violation: data.all_files_violation, + protected: data.protected_files_count, + }, + images: { + quantity: data.images_quantity, + size: data.images_size, + check: data.images_check, + violation: data.images_violations, + protected: data.protected_image_files_count, + }, + videos: { + quantity: data.videos_quantity, + size: data.videos_size, + check: data.videos_check, + violation: data.videos_violations, + protected: data.protected_video_files_count, + }, + audios: { + quantity: data.audios_quantity, + size: data.audios_size, + check: data.audios_check, + violation: data.audios_violations, + protected: data.protected_audio_files_count, + }, + documents: { + quantity: data.document_quantity, + size: data.document_size, + check: data.document_check, + violation: data.document_violations, + protected: data.protected_document_files_count, + }, + }; + }, + }); +}; \ No newline at end of file diff --git a/src/app/lib/getProcents.ts b/src/app/lib/getProcents.ts index df8145b..eb43f48 100644 --- a/src/app/lib/getProcents.ts +++ b/src/app/lib/getProcents.ts @@ -1,5 +1,5 @@ export function getProcents( - currentNumber: number, + currentNumber: number | undefined, totalNumber: number, decimals: number = 0 ): number { @@ -7,7 +7,7 @@ export function getProcents( return 0; } - if (totalNumber === 0) { + if (totalNumber === 0 || typeof currentNumber === 'undefined') { return 0; } diff --git a/src/app/ui/dashboard/new/dashboard-files-info.tsx b/src/app/ui/dashboard/new/dashboard-files-info.tsx index 3bb79ab..7a7e2ef 100644 --- a/src/app/ui/dashboard/new/dashboard-files-info.tsx +++ b/src/app/ui/dashboard/new/dashboard-files-info.tsx @@ -1,22 +1,12 @@ 'use client' import { useTranslations } from 'next-intl'; -import { useQuery } from '@tanstack/react-query'; -import { getUserFilesInfo } from '@/app/actions/action'; import {convertBytes} from '@/app/lib/convertBytes'; +import {useUserFilesInfo} from '@/app/hooks/react-query/useUserFilesInfo'; export default function DashboardFilesInfo() { const t = useTranslations("Global"); - - const { - data: filesInfo, - isLoading, - isError, - error, - } = useQuery({ - queryKey: ['userFilesInfo'], - queryFn: getUserFilesInfo, - }); + const { data: filesInfo, isLoading, isError, error } = useUserFilesInfo(); return (
@@ -24,20 +14,20 @@ export default function DashboardFilesInfo() {
{t('images')}
-
{filesInfo?.images_quantity ? filesInfo?.images_quantity : 0}
+
{filesInfo?.images.quantity ? filesInfo?.images.quantity : 0}
{t('your-image')}
{t('size')} - {filesInfo?.images_size ? convertBytes(filesInfo?.images_size) : 0} + {filesInfo?.images.size ? convertBytes(filesInfo?.images.size) : 0}
{t('PROTECTED')} - {filesInfo?.protected_image_files_count ? filesInfo?.protected_image_files_count : 0} + {filesInfo?.images.protected ? filesInfo?.images.protected : 0}
{t('violations')} - {filesInfo?.images_violations ? filesInfo?.images_violations : 0} + {filesInfo?.images.violation ? filesInfo?.images.violation : 0}
@@ -46,20 +36,20 @@ export default function DashboardFilesInfo() {
{t('videos')}
-
{filesInfo?.videos_quantity ? filesInfo?.videos_quantity : 0}
+
{filesInfo?.videos.quantity ? filesInfo?.videos.quantity : 0}
{t('your-videos')}
{t('size')} - {filesInfo?.videos_size ? convertBytes(filesInfo?.videos_size) : 0} + {filesInfo?.videos.size ? convertBytes(filesInfo?.videos.size) : 0}
{t('PROTECTED')} - {filesInfo?.protected_video_files_count ? filesInfo?.protected_video_files_count : 0} + {filesInfo?.videos.protected ? filesInfo?.videos.protected : 0}
{t('violations')} - {filesInfo?.videos_violations ? filesInfo?.videos_violations : 0} + {filesInfo?.videos.violation ? filesInfo?.videos.violation : 0}
@@ -68,20 +58,20 @@ export default function DashboardFilesInfo() {
{t('audios')}
-
{filesInfo?.audios_quantity ? filesInfo?.audios_quantity : 0}
+
{filesInfo?.audios.quantity ? filesInfo?.audios.quantity : 0}
{t('your-audios')}
{t('size')} - {filesInfo?.audios_size ? convertBytes(filesInfo?.audios_size) : 0} + {filesInfo?.audios.size ? convertBytes(filesInfo?.audios.size) : 0}
{t('PROTECTED')} - {filesInfo?.protected_audio_files_count ? filesInfo?.protected_audio_files_count : 0} + {filesInfo?.audios.protected ? filesInfo?.audios.protected : 0}
{t('violations')} - {filesInfo?.audios_violations ? filesInfo?.audios_violations : 0} + {filesInfo?.audios.violation ? filesInfo?.audios.violation : 0}
@@ -90,20 +80,20 @@ export default function DashboardFilesInfo() {
{t('documents')}
-
{filesInfo?.documents_quantity ? filesInfo?.documents_quantity : 0}
+
{filesInfo?.documents.quantity ? filesInfo?.documents.quantity : 0}
{t('your-documents')}
{t('size')} - {filesInfo?.documents_check ? convertBytes(filesInfo?.documents_check) : 0} + {filesInfo?.documents.check? convertBytes(filesInfo?.documents.check) : 0}
{t('PROTECTED')} - {filesInfo?.documents_check ? filesInfo?.documents_check : 0} + {filesInfo?.documents.protected ? filesInfo?.documents.protected : 0}
{t('violations')} - {filesInfo?.documents_violations ? filesInfo?.documents_violations : 0} + {filesInfo?.documents.violation ? filesInfo?.documents.violation : 0}
diff --git a/src/app/ui/dashboard/new/dashboard-user-stats.tsx b/src/app/ui/dashboard/new/dashboard-user-stats.tsx index cfdae78..e6640aa 100644 --- a/src/app/ui/dashboard/new/dashboard-user-stats.tsx +++ b/src/app/ui/dashboard/new/dashboard-user-stats.tsx @@ -1,29 +1,19 @@ 'use client' import { useTranslations } from 'next-intl'; -import { useQuery } from '@tanstack/react-query'; -import { getUserFilesInfo } from '@/app/actions/action'; import {convertBytes} from '@/app/lib/convertBytes'; +import {useUserFilesInfo} from '@/app/hooks/react-query/useUserFilesInfo'; export default function DashboardUserStats() { const t = useTranslations("Global"); - - const { - data: filesInfo, - isLoading, - isError, - error, - } = useQuery({ - queryKey: ['userFilesInfo'], - queryFn: getUserFilesInfo, - }); + const { data: filesInfo, isLoading, isError, error } = useUserFilesInfo(); return (
ЗАЩИЩЁННЫЕ ФАЙЛЫ
-
{filesInfo?.protected_files_count ? filesInfo?.protected_files_count : 0}
+
{filesInfo?.total.protected ? filesInfo?.total.protected : 0}
Файлов под защитой
🛡️
@@ -37,7 +27,7 @@ export default function DashboardUserStats() {
НАРУШЕНИЯ
-
{filesInfo?.all_files_violations ? filesInfo?.all_files_violations : 0}
+
{filesInfo?.total.violation ? filesInfo?.total.violation : 0}
Требуют внимания
⚠️
@@ -45,7 +35,7 @@ export default function DashboardUserStats() {
ХРАНИЛИЩЕ
- {filesInfo?.all_files_size ? convertBytes(filesInfo?.all_files_size) : 0} + {filesInfo?.total.size ? convertBytes(filesInfo?.total.size) : 0}
Использовано места
💾
diff --git a/src/app/ui/dashboard/new/dashborad-limits-section.tsx b/src/app/ui/dashboard/new/dashborad-limits-section.tsx index 6434d0b..f20de55 100644 --- a/src/app/ui/dashboard/new/dashborad-limits-section.tsx +++ b/src/app/ui/dashboard/new/dashborad-limits-section.tsx @@ -1,20 +1,11 @@ 'use client' -import { useQuery } from '@tanstack/react-query'; -import { getUserFilesInfo } from '@/app/actions/action'; import { convertBytes } from '@/app/lib/convertBytes'; import { getProcents } from '@/app/lib/getProcents'; +import { useUserFilesInfo } from '@/app/hooks/react-query/useUserFilesInfo'; export default function DahboardLimitsSection() { - const { - data: filesInfo, - isLoading, - isError, - error, - } = useQuery({ - queryKey: ['userFilesInfo'], - queryFn: getUserFilesInfo, - }); + const { data: filesInfo, isLoading, isError, error } = useUserFilesInfo(); return (
@@ -26,13 +17,13 @@ export default function DahboardLimitsSection() { 🔍 Проверки
-
{filesInfo?.all_files_check ? filesInfo?.all_files_check : 0} / 10,000
+
{filesInfo?.total.check ? filesInfo?.total.check : 0} / 10,000
- {getProcents(filesInfo?.all_files_check, 10000)}% + {getProcents(filesInfo?.total.check, 10000)}%
@@ -42,13 +33,13 @@ export default function DahboardLimitsSection() { 💾 Хранилище -
{filesInfo?.all_files_size ? convertBytes(filesInfo?.all_files_size) : 0} / 1,024 МБ
+
{filesInfo?.total.size ? convertBytes(filesInfo?.total.size) : 0} / 1,024 МБ
-
+
- {getProcents(filesInfo?.all_files_size, 1000000000)}% + {getProcents(filesInfo?.total.size, 1000000000)}%
@@ -57,13 +48,13 @@ export default function DahboardLimitsSection() { 📁 Файлы
-
{filesInfo?.all_files_quantity ? filesInfo?.all_files_quantity : 0} / 500
+
{filesInfo?.total.quantity ? filesInfo?.total.quantity : 0} / 500
-
+
- {getProcents(filesInfo?.all_files_quantity, 500)}% + {getProcents(filesInfo?.total.quantity, 500)}%
diff --git a/src/app/ui/dashboard/protection-overview.tsx b/src/app/ui/dashboard/protection-overview.tsx index 52a0c1a..9477623 100644 --- a/src/app/ui/dashboard/protection-overview.tsx +++ b/src/app/ui/dashboard/protection-overview.tsx @@ -5,23 +5,9 @@ import { PieChartComponent } from '@/app/components/PieChartComponent'; import { useTranslations, useLocale } from 'next-intl'; import Link from 'next/link'; import { useClickOutside } from '@/app/hooks/useClickOutside'; -import { useQuery } from '@tanstack/react-query'; -import { getUserFilesInfo } from '@/app/actions/action'; import { convertBytes } from '@/app/lib/convertBytes'; import { pluralize } from '@/app/lib/pluralize'; - -type FilesInfo = { - totalSize: number; - totalCount: number; - imageQuantity: number; - videoQuantity: number; - audioQuantity: number; - imageSize: number; - videoSize: number; - audioSize: number; - documentSize: number; -}; - +import { useUserFilesInfo } from '@/app/hooks/react-query/useUserFilesInfo'; export default function ProtectionOverview() { const [isOpen, setIsOpen] = useState(false); @@ -42,68 +28,23 @@ export default function ProtectionOverview() { openDropDownList ); - const { - data: filesInfo, - isLoading, - isError, - error, - } = useQuery<{ - all_files_size: number, - all_files_quantity: number, - images_quantity: number, - videos_quantity: number, - audios_quantity: number, - images_size: number, - videos_size: number, - audios_size: number, - documents_size: number, - }, Error, FilesInfo>({ - queryKey: ['userFilesInfo'], - queryFn: getUserFilesInfo, - select: (data): FilesInfo => { - if (!data) { - return { - totalSize: 0, - totalCount: 0, - imageQuantity: 0, - videoQuantity: 0, - audioQuantity: 0, - imageSize: 0, - videoSize: 0, - audioSize: 0, - documentSize: 0, - } - } - - return { - totalSize: data.all_files_size, - totalCount: data.all_files_quantity, - imageQuantity: data.images_quantity, - videoQuantity: data.videos_quantity, - audioQuantity: data.audios_quantity, - imageSize: data.images_size, - videoSize: data.videos_size, - audioSize: data.audios_size, - documentSize: data.documents_size, - } - }, - }); + const { data: filesInfo, isLoading, isError, error } = useUserFilesInfo(); useEffect(() => { setFilesCount([ { name: 'images-few', - value: filesInfo?.imageSize ? filesInfo?.imageSize : 0, + value: filesInfo?.images.size ? filesInfo?.images.size : 0, color: '#f08c00' }, { name: 'videos', - value: filesInfo?.videoSize ? filesInfo?.videoSize : 0, + value: filesInfo?.videos.size ? filesInfo?.videos.size : 0, color: '#2f9e44' }, { name: 'audios', - value: filesInfo?.audioSize ? filesInfo?.audioSize : 0, + value: filesInfo?.audios.size ? filesInfo?.audios.size : 0, color: '#1971c2' }, ]) @@ -134,14 +75,14 @@ export default function ProtectionOverview() {
- {filesInfo?.totalCount ? ( + {filesInfo?.total.quantity ? ( <>
- {filesInfo?.totalCount ? filesInfo?.totalCount : 0} + {filesInfo?.total.quantity ? filesInfo?.total.quantity : 0} - {pluralizeFiles(filesInfo?.totalCount || 0)} + {pluralizeFiles(filesInfo?.total.quantity || 0)}
@@ -196,18 +137,18 @@ export default function ProtectionOverview() { )} {isOpen ? (
- +
) : (
-
{filesInfo?.totalSize ? convertBytes(filesInfo?.totalSize) : 0} / 0
+
{filesInfo?.total.size ? convertBytes(filesInfo?.total.size) : 0} / 0
{t('disk-space-used')}
)}
- {!!filesInfo?.totalCount && ( + {!!filesInfo?.total.quantity && (
@@ -130,10 +121,10 @@ export default function MyContentInfoBlock() {
- {filesInfo?.audios_quantity || 0} {pluralizeFiles(filesInfo?.audios_quantity || 0)} + {filesInfo?.audios.quantity || 0} {pluralizeFiles(filesInfo?.audios.quantity || 0)} - {filesInfo?.audios_size ? convertBytes(filesInfo?.audios_size) : 0} + {filesInfo?.audios.size ? convertBytes(filesInfo?.audios.size) : 0}
@@ -150,10 +141,10 @@ export default function MyContentInfoBlock() {
- {filesInfo?.documents_quantity || 0} {pluralizeFiles(filesInfo?.documents_quantity || 0)} + {filesInfo?.documents.quantity || 0} {pluralizeFiles(filesInfo?.documents.quantity || 0)} - {filesInfo?.documents_size ? convertBytes(filesInfo?.documents_size) : 0} + {filesInfo?.documents.size ? convertBytes(filesInfo?.documents.size) : 0}
diff --git a/src/app/ui/my-content/my-content-pie-chart.tsx b/src/app/ui/my-content/my-content-pie-chart.tsx index d6ae2d7..caf060e 100644 --- a/src/app/ui/my-content/my-content-pie-chart.tsx +++ b/src/app/ui/my-content/my-content-pie-chart.tsx @@ -1,10 +1,9 @@ 'use client' import { PieChartComponent } from '@/app/components/PieChartComponent'; -import { useQuery } from '@tanstack/react-query'; -import { getUserFilesInfo } from '@/app/actions/action'; import { useState, useEffect } from 'react'; import { convertBytes } from '@/app/lib/convertBytes'; +import { useUserFilesInfo } from '@/app/hooks/react-query/useUserFilesInfo'; type FilesInfo = { @@ -28,76 +27,27 @@ export default function MyContentPieChart() { { name: 'documents', value: 0, color: '#a561e6' }, ]); - const { - data: filesInfo, - isLoading, - isError, - error, - } = useQuery<{ - all_files_size: number, - all_files_quantity: number, - images_quantity: number, - videos_quantity: number, - audios_quantity: number, - documents_quantity: number, - images_size: number, - videos_size: number, - audios_size: number, - documents_size: number, - }, Error, FilesInfo>({ - queryKey: ['userFilesInfo'], - queryFn: getUserFilesInfo, - select: (data): FilesInfo => { - if (!data) { - return { - totalSize: 0, - totalCount: 0, - imageQuantity: 0, - videoQuantity: 0, - audioQuantity: 0, - documentQuantity: 0, - imageSize: 0, - videoSize: 0, - audioSize: 0, - documentSize: 0, - } - } - - return { - totalSize: data.all_files_size, - totalCount: data.all_files_quantity, - imageQuantity: data.images_quantity, - videoQuantity: data.videos_quantity, - audioQuantity: data.audios_quantity, - documentQuantity: data.documents_quantity, - imageSize: data.images_size, - videoSize: data.videos_size, - audioSize: data.audios_size, - documentSize: data.documents_size, - } - }, - }); - + const { data: filesInfo, isLoading, isError, error } = useUserFilesInfo(); useEffect(() => { setFilesCount([ { name: 'images-few', - value: filesInfo?.imageSize ? filesInfo?.imageSize : 0, + value: filesInfo?.images.size ? filesInfo?.images.size : 0, color: '#f08c00' }, { name: 'videos', - value: filesInfo?.videoSize ? filesInfo?.videoSize : 0, + value: filesInfo?.videos.size ? filesInfo?.videos.size : 0, color: '#2f9e44' }, { name: 'audios', - value: filesInfo?.audioSize ? filesInfo?.audioSize : 0, + value: filesInfo?.audios.size ? filesInfo?.audios.size : 0, color: '#1971c2' }, { name: 'documents', - value: filesInfo?.documentSize ? filesInfo?.documentSize : 0, + value: filesInfo?.documents.size ? filesInfo?.documents.size : 0, color: '#a561e6' }, ]) @@ -105,7 +55,7 @@ export default function MyContentPieChart() { return (
- +
) } \ No newline at end of file diff --git a/src/app/ui/my-content/new/my-content-page-title.tsx b/src/app/ui/my-content/new/my-content-page-title.tsx index a619ce8..7f45584 100644 --- a/src/app/ui/my-content/new/my-content-page-title.tsx +++ b/src/app/ui/my-content/new/my-content-page-title.tsx @@ -2,21 +2,13 @@ 'use client' import { useTranslations } from 'next-intl'; -import { useQuery } from '@tanstack/react-query'; -import { getUserFilesInfo } from '@/app/actions/action'; import { convertBytes } from '@/app/lib/convertBytes'; +import { useUserFilesInfo } from '@/app/hooks/react-query/useUserFilesInfo'; export default function MyContentPageTitleColorFrame({ title, description }: { title: string, description: string }) { const t = useTranslations('Global'); - const { - data: filesInfo, - isLoading, - isError, - error, - } = useQuery({ - queryKey: ['userFilesInfo'], - queryFn: getUserFilesInfo, - }); + + const { data: filesInfo, isLoading, isError, error } = useUserFilesInfo(); return (
@@ -31,7 +23,7 @@ export default function MyContentPageTitleColorFrame({ title, description }: { t
-
{filesInfo?.all_files_quantity}
+
{filesInfo?.total.quantity}
Файлов
@@ -41,7 +33,7 @@ export default function MyContentPageTitleColorFrame({ title, description }: { t
-
{filesInfo?.all_files_size ? convertBytes(filesInfo?.all_files_size) : 0}
+
{convertBytes(filesInfo?.total.size ?? 0)}
Хранилище
diff --git a/src/app/ui/my-content/new/my-content-stats-overview.tsx b/src/app/ui/my-content/new/my-content-stats-overview.tsx index 9047861..deffedf 100644 --- a/src/app/ui/my-content/new/my-content-stats-overview.tsx +++ b/src/app/ui/my-content/new/my-content-stats-overview.tsx @@ -1,22 +1,13 @@ 'use client' import { useTranslations } from 'next-intl'; -import { useQuery } from '@tanstack/react-query'; -import { getUserFilesInfo } from '@/app/actions/action'; import { convertBytes } from '@/app/lib/convertBytes'; import { IconDocument, IconShield, IconSearch, IconDiscet } from '@/app/ui/icons/icons'; +import {useUserFilesInfo} from '@/app/hooks/react-query/useUserFilesInfo'; export default function MyContentStatsOverview() { const t = useTranslations('Global'); - const { - data: filesInfo, - isLoading, - isError, - error, - } = useQuery({ - queryKey: ['userFilesInfo'], - queryFn: getUserFilesInfo, - }); + const { data: filesInfo, isLoading, isError, error } = useUserFilesInfo(); return (
@@ -27,7 +18,7 @@ export default function MyContentStatsOverview() {
{/*
+0%
*/} -
{filesInfo?.all_files_quantity}
+
{filesInfo?.total.quantity}
Всего файлов
@@ -38,7 +29,7 @@ export default function MyContentStatsOverview() { {/*
+0%
*/} -
{filesInfo?.protected_files_count}
+
{filesInfo?.total.protected}
Защищено файлов
@@ -60,7 +51,7 @@ export default function MyContentStatsOverview() { {/*
+0%
*/} -
{filesInfo?.all_files_size ? convertBytes(filesInfo?.all_files_size) : 0}
+
{convertBytes(filesInfo?.total.size ?? 0)}
Хранилище
diff --git a/src/app/ui/reports/reports-info.tsx b/src/app/ui/reports/reports-info.tsx index 375a0a1..9b96ef6 100644 --- a/src/app/ui/reports/reports-info.tsx +++ b/src/app/ui/reports/reports-info.tsx @@ -1,23 +1,13 @@ 'use client' import { useTranslations } from 'next-intl'; -import { useQuery } from '@tanstack/react-query'; -import { getUserFilesInfo } from '@/app/actions/action'; -import {convertBytes} from '@/app/lib/convertBytes'; -import { useEffect } from 'react'; +import {useUserFilesInfo} from '@/app/hooks/react-query/useUserFilesInfo'; export default function ReportsInfo() { const t = useTranslations("Global"); - const { - data: filesInfo, - isLoading, - isError, - error, - } = useQuery({ - queryKey: ['userFilesInfo'], - queryFn: getUserFilesInfo, - }); + + const { data: filesInfo, isLoading, isError, error } = useUserFilesInfo(); return (
@@ -25,21 +15,21 @@ export default function ReportsInfo() {
{t('all-content')}
-
{filesInfo?.all_files_quantity ? filesInfo?.all_files_quantity : 0}
+
{filesInfo?.total.quantity ? filesInfo?.total.quantity : 0}
{t('violations-few')}
-
{filesInfo?.all_files_violation ? filesInfo?.all_files_violation : 0}
+
{filesInfo?.total.violation ? filesInfo?.total.violation : 0}
{t('monitoring')}
-
{filesInfo?.all_files_check ? filesInfo?.all_files_check : 0}
+
{filesInfo?.total.check ? filesInfo?.total.check : 0}
diff --git a/src/app/ui/violations/violations-statistic.tsx b/src/app/ui/violations/violations-statistic.tsx index b3e2541..e37dc79 100644 --- a/src/app/ui/violations/violations-statistic.tsx +++ b/src/app/ui/violations/violations-statistic.tsx @@ -1,51 +1,25 @@ 'use client' import { useTranslations } from 'next-intl'; -import { useQuery } from '@tanstack/react-query'; -import { getUserFilesInfo } from '@/app/actions/action'; - -type FilesInfo = { - totalSize: number; - totalCount: number; -}; +import { useUserFilesInfo } from '@/app/hooks/react-query/useUserFilesInfo'; export default function ViolationsStatistic() { const t = useTranslations('Global'); - const { - data: filesInfo, - isLoading, - isError, - error, - } = useQuery<{ - all_files_size: number, - all_files_quantity: number - }, Error, FilesInfo>({ - queryKey: ['userFilesInfo'], - queryFn: getUserFilesInfo, - select: (data): FilesInfo => { - if (!data) { - return { - totalSize: 0, - totalCount: 0 - } - } - - return { - totalSize: data.all_files_size, - totalCount: data.all_files_quantity - } - } - }); + const { data: filesInfo, isLoading, isError, error } = useUserFilesInfo(); return (
-
0
+
+ {filesInfo?.total.violation} +
{t(`total-violations`)}
-
0
+
+ {filesInfo?.total.violation} +
{t(`new`)}