update user files info
This commit is contained in:
@@ -46,7 +46,7 @@ export default async function Page() {
|
|||||||
<div>
|
<div>
|
||||||
<PageTitle title="audio-protection" />
|
<PageTitle title="audio-protection" />
|
||||||
<div className="split-blocks">
|
<div className="split-blocks">
|
||||||
<ProtectionSummary />
|
<ProtectionSummary fileType={FILE_TYPE}/>
|
||||||
<div className="protection-overview">
|
<div className="protection-overview">
|
||||||
<StackedBarChart data={data} />
|
<StackedBarChart data={data} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export default async function Page() {
|
|||||||
<div>
|
<div>
|
||||||
<PageTitle title="image-protection" />
|
<PageTitle title="image-protection" />
|
||||||
<div className="split-blocks">
|
<div className="split-blocks">
|
||||||
<ProtectionSummary />
|
<ProtectionSummary fileType={FILE_TYPE}/>
|
||||||
<div className="protection-overview">
|
<div className="protection-overview">
|
||||||
<StackedBarChart data={data} />
|
<StackedBarChart data={data} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default async function Page() {
|
|||||||
<div>
|
<div>
|
||||||
<PageTitle title="video-protection" />
|
<PageTitle title="video-protection" />
|
||||||
<div className="split-blocks">
|
<div className="split-blocks">
|
||||||
<ProtectionSummary />
|
<ProtectionSummary fileType={FILE_TYPE}/>
|
||||||
<div className="protection-overview">
|
<div className="protection-overview">
|
||||||
<StackedBarChart data={data} />
|
<StackedBarChart data={data} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,24 +1,15 @@
|
|||||||
import MyContentInfoBlock from '@/app/ui/my-content/my-content-info-block';
|
import MyContentInfoBlock from '@/app/ui/my-content/my-content-info-block';
|
||||||
import { PieChartComponent } from '@/app/components/PieChartComponent';
|
|
||||||
import FilesTable from '@/app/ui/dashboard/files-table';
|
import FilesTable from '@/app/ui/dashboard/files-table';
|
||||||
|
import MyContentPieChart from '@/app/ui/my-content/my-content-pie-chart';
|
||||||
const data = [
|
|
||||||
{ name: 'images', value: 33, color: '#f08c00' },
|
|
||||||
{ name: 'videos', value: 50, color: '#2f9e44' },
|
|
||||||
{ name: 'audios', value: 25, color: '#1971c2' },
|
|
||||||
{ name: 'documents', value: 25, color: '#a561e6' },
|
|
||||||
];
|
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="split-blocks">
|
<div className="split-blocks">
|
||||||
<MyContentInfoBlock />
|
<MyContentInfoBlock />
|
||||||
<div className="protection-overview">
|
<MyContentPieChart />
|
||||||
<PieChartComponent data={data} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<FilesTable fileType={'all'}/>
|
<FilesTable fileType={'all'} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -28,4 +28,37 @@ export async function getUserData() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('error');
|
console.error('error');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getUserFilesInfo() {
|
||||||
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
version: 1,
|
||||||
|
msg_id: 20005,
|
||||||
|
message_body: {
|
||||||
|
action: "user_files_info",
|
||||||
|
token: token
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const parsed = await response.json();
|
||||||
|
if (parsed.message_code === 0) {
|
||||||
|
return parsed.message_body;
|
||||||
|
} else {
|
||||||
|
throw parsed.message_code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`error: ${error}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -69,8 +69,6 @@ export async function authorization(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`${API_BASE_URL}/api/v1/data`);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { email, password } = validatedFields.data;
|
const { email, password } = validatedFields.data;
|
||||||
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@
|
|||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { PieChart, Pie, Cell, ResponsiveContainer } from 'recharts';
|
import { PieChart, Pie, Cell, ResponsiveContainer } from 'recharts';
|
||||||
|
|
||||||
export const PieChartComponent = ({ data }: {
|
export const PieChartComponent = ({ data, show }: {
|
||||||
data: {
|
data: {
|
||||||
name: string,
|
name: string,
|
||||||
value: number,
|
value: number,
|
||||||
color: string
|
color: string
|
||||||
}[]
|
}[],
|
||||||
|
show: number | string
|
||||||
}) => {
|
}) => {
|
||||||
const t = useTranslations('Global');
|
const t = useTranslations('Global');
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ export const PieChartComponent = ({ data }: {
|
|||||||
<ResponsiveContainer width={200} height={200}>
|
<ResponsiveContainer width={200} height={200}>
|
||||||
<PieChart>
|
<PieChart>
|
||||||
<text x={100} y={75} className="pie-char-text">
|
<text x={100} y={75} className="pie-char-text">
|
||||||
0
|
{show}
|
||||||
</text>
|
</text>
|
||||||
<text x={100} y={100} className="pie-char-text">
|
<text x={100} y={100} className="pie-char-text">
|
||||||
{t('out-of')}
|
{t('out-of')}
|
||||||
|
|||||||
@@ -294,6 +294,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
|
|||||||
if (chunkStatus.message_body.missing_chunks === 0) {
|
if (chunkStatus.message_body.missing_chunks === 0) {
|
||||||
setIsFileUploaded(true);
|
setIsFileUploaded(true);
|
||||||
await queryClient.invalidateQueries({ queryKey: ['userFilesData'] });
|
await queryClient.invalidateQueries({ queryKey: ['userFilesData'] });
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['userFilesInfo'] });
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Not all chunks were uploaded');
|
throw new Error('Not all chunks were uploaded');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
export function convertBytes(bytes: number) {
|
||||||
|
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||||
|
|
||||||
|
if (bytes === 0) return '0 B';
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
let value = bytes;
|
||||||
|
|
||||||
|
while (value >= 1024 && i < units.length - 1) {
|
||||||
|
value /= 1024;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${value.toFixed(1)} ${units[i]}`;
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { QueryClient } from '@tanstack/react-query';
|
import { QueryClient } from '@tanstack/react-query';
|
||||||
import { getUserData } from '@/app/actions/action';
|
import { getUserData, getUserFilesInfo } from '@/app/actions/action';
|
||||||
import { getUserFilesData } from '@/app/actions/fileEntity';
|
import { getUserFilesData } from '@/app/actions/fileEntity';
|
||||||
|
|
||||||
export async function prefetchLayoutQueries(queryClient: QueryClient) {
|
export async function prefetchLayoutQueries(queryClient: QueryClient) {
|
||||||
@@ -16,5 +16,9 @@ export async function prefetchLayoutQueries(queryClient: QueryClient) {
|
|||||||
},
|
},
|
||||||
staleTime: 30 * 1000
|
staleTime: 30 * 1000
|
||||||
}),
|
}),
|
||||||
|
queryClient.prefetchQuery({
|
||||||
|
queryKey: ['userFilesInfo'],
|
||||||
|
queryFn: () => getUserFilesInfo()
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -1,29 +1,30 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState, useRef } from 'react';
|
import { useState, useRef, useEffect } from 'react';
|
||||||
import { PieChartComponent } from '@/app/components/PieChartComponent';
|
import { PieChartComponent } from '@/app/components/PieChartComponent';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useClickOutside } from '@/app/hooks/useClickOutside';
|
import { useClickOutside } from '@/app/hooks/useClickOutside';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { getUserFilesData } from '@/app/actions/fileEntity';
|
import { getUserFilesInfo } from '@/app/actions/action';
|
||||||
|
import { convertBytes } from '@/app/lib/convertBytes';
|
||||||
|
|
||||||
const data = [
|
|
||||||
{ name: 'images', value: 33, color: '#f08c00' },
|
|
||||||
{ name: 'videos', value: 50, color: '#2f9e44' },
|
|
||||||
{ name: 'audios', value: 25, color: '#1971c2' },
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
type FilesInfo = {
|
type FilesInfo = {
|
||||||
totalSize: string;
|
totalSize: number;
|
||||||
totalCount: number;
|
totalCount: number;
|
||||||
|
imageQuantity: number;
|
||||||
|
videoQuantity: number;
|
||||||
|
audioQuantity: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default function ProtectionOverview() {
|
export default function ProtectionOverview() {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const [filesCount, setFilesCount] = useState([
|
||||||
|
{ name: 'images', value: 0, color: '#f08c00' },
|
||||||
|
{ name: 'videos', value: 0, color: '#2f9e44' },
|
||||||
|
{ name: 'audios', value: 0, color: '#1971c2' },
|
||||||
|
]);
|
||||||
const t = useTranslations('Global');
|
const t = useTranslations('Global');
|
||||||
const [openDropDownList, setOpenDropDownList] = useState(false);
|
const [openDropDownList, setOpenDropDownList] = useState(false);
|
||||||
const dropDownList = useRef(null);
|
const dropDownList = useRef(null);
|
||||||
@@ -37,26 +38,55 @@ export default function ProtectionOverview() {
|
|||||||
isError,
|
isError,
|
||||||
error,
|
error,
|
||||||
} = useQuery<{
|
} = useQuery<{
|
||||||
formattedTotalSize: string,
|
all_files_size: number,
|
||||||
totalCount: number
|
all_files_quantity: number,
|
||||||
|
images_quantity: number,
|
||||||
|
videos_quantity: number,
|
||||||
|
audios_quantity: number
|
||||||
}, Error, FilesInfo>({
|
}, Error, FilesInfo>({
|
||||||
queryKey: ['userFilesData'],
|
queryKey: ['userFilesInfo'],
|
||||||
queryFn: getUserFilesData,
|
queryFn: getUserFilesInfo,
|
||||||
select: (data): FilesInfo => {
|
select: (data): FilesInfo => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return {
|
return {
|
||||||
totalSize: '0',
|
totalSize: 0,
|
||||||
totalCount: 0
|
totalCount: 0,
|
||||||
|
imageQuantity: 0,
|
||||||
|
videoQuantity: 0,
|
||||||
|
audioQuantity: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalSize: data.formattedTotalSize,
|
totalSize: data.all_files_size,
|
||||||
totalCount: (data.totalCount)
|
totalCount: data.all_files_quantity,
|
||||||
|
imageQuantity: data.images_quantity,
|
||||||
|
videoQuantity: data.videos_quantity,
|
||||||
|
audioQuantity: data.audios_quantity,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setFilesCount([
|
||||||
|
{
|
||||||
|
name: 'images',
|
||||||
|
value: filesInfo?.imageQuantity ? filesInfo?.imageQuantity : 0,
|
||||||
|
color: '#f08c00'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'videos',
|
||||||
|
value: filesInfo?.videoQuantity ? filesInfo?.videoQuantity : 0,
|
||||||
|
color: '#2f9e44'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'audios',
|
||||||
|
value: filesInfo?.audioQuantity ? filesInfo?.audioQuantity : 0,
|
||||||
|
color: '#1971c2'
|
||||||
|
},
|
||||||
|
])
|
||||||
|
}, [filesInfo]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="protection-overview">
|
<div className="protection-overview">
|
||||||
<h3>{t('protecting-your-content')}</h3>
|
<h3>{t('protecting-your-content')}</h3>
|
||||||
@@ -115,11 +145,11 @@ export default function ProtectionOverview() {
|
|||||||
)}
|
)}
|
||||||
{isOpen ? (
|
{isOpen ? (
|
||||||
<div className="protection-stat total-usage">
|
<div className="protection-stat total-usage">
|
||||||
<PieChartComponent data={data} />
|
<PieChartComponent data={filesCount} show={filesInfo?.totalSize ? convertBytes(filesInfo?.totalSize) : 0} />
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="protection-stat total-usage">
|
<div className="protection-stat total-usage">
|
||||||
<div className="protection-stat-value">{filesInfo?.totalSize ? filesInfo?.totalSize : 0} / 0</div>
|
<div className="protection-stat-value">{filesInfo?.totalSize ? convertBytes(filesInfo?.totalSize) : 0} / 0</div>
|
||||||
<div className="protection-stat-label">
|
<div className="protection-stat-label">
|
||||||
{t('disk-space-used')}
|
{t('disk-space-used')}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,8 +1,24 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { IconImageFile, IconVideoFile, IconAudioFile } from '@/app/ui/icons/icons';
|
import { IconImageFile, IconVideoFile, IconAudioFile } from '@/app/ui/icons/icons';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { getUserFilesInfo } from '@/app/actions/action';
|
||||||
|
import {convertBytes} from '@/app/lib/convertBytes';
|
||||||
|
|
||||||
export default function StatsGrid() {
|
export default function StatsGrid() {
|
||||||
const t = useTranslations("Global");
|
const t = useTranslations("Global");
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: filesInfo,
|
||||||
|
isLoading,
|
||||||
|
isError,
|
||||||
|
error,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ['userFilesInfo'],
|
||||||
|
queryFn: getUserFilesInfo,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="block-wrapper stats-wrapper">
|
<div className="block-wrapper stats-wrapper">
|
||||||
<h3>
|
<h3>
|
||||||
@@ -30,10 +46,10 @@ export default function StatsGrid() {
|
|||||||
{t('images')}
|
{t('images')}
|
||||||
</div>
|
</div>
|
||||||
<div className="stats-item second-row">
|
<div className="stats-item second-row">
|
||||||
0
|
{filesInfo.images_quantity ? filesInfo.images_quantity : 0}
|
||||||
</div>
|
</div>
|
||||||
<div className="stats-item second-row">
|
<div className="stats-item second-row">
|
||||||
0
|
{filesInfo.images_size ? convertBytes(filesInfo.images_size) : 0}
|
||||||
</div>
|
</div>
|
||||||
<div className="stats-item second-row">
|
<div className="stats-item second-row">
|
||||||
0
|
0
|
||||||
@@ -47,10 +63,10 @@ export default function StatsGrid() {
|
|||||||
{t('videos')}
|
{t('videos')}
|
||||||
</div>
|
</div>
|
||||||
<div className="stats-item">
|
<div className="stats-item">
|
||||||
0
|
{filesInfo.videos_quantity ? filesInfo.videos_quantity : 0}
|
||||||
</div>
|
</div>
|
||||||
<div className="stats-item">
|
<div className="stats-item">
|
||||||
0
|
{filesInfo.videos_size ? convertBytes(filesInfo.videos_size) : 0}
|
||||||
</div>
|
</div>
|
||||||
<div className="stats-item">
|
<div className="stats-item">
|
||||||
0
|
0
|
||||||
@@ -64,10 +80,10 @@ export default function StatsGrid() {
|
|||||||
{t('audios')}
|
{t('audios')}
|
||||||
</div>
|
</div>
|
||||||
<div className="stats-item last-row">
|
<div className="stats-item last-row">
|
||||||
0
|
{filesInfo.audios_quantity ? filesInfo.audios_quantity : 0}
|
||||||
</div>
|
</div>
|
||||||
<div className="stats-item last-row">
|
<div className="stats-item last-row">
|
||||||
0
|
{filesInfo.audios_size ? convertBytes(filesInfo.audios_size) : 0}
|
||||||
</div>
|
</div>
|
||||||
<div className="stats-item last-row">
|
<div className="stats-item last-row">
|
||||||
0
|
0
|
||||||
|
|||||||
@@ -3,15 +3,43 @@
|
|||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { getUserFilesData } from '@/app/actions/fileEntity';
|
import { getUserFilesData } from '@/app/actions/fileEntity';
|
||||||
|
import { getUserFilesInfo } from '@/app/actions/action';
|
||||||
|
import { convertBytes } from '@/app/lib/convertBytes';
|
||||||
|
|
||||||
type FilesInfo = {
|
type FilesInfo = {
|
||||||
totalSize: string;
|
totalSize: number;
|
||||||
totalCount: number;
|
totalCount: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default function ProtectionSummary() {
|
export default function ProtectionSummary({ fileType }: { fileType: string }) {
|
||||||
const t = useTranslations('Global');
|
const t = useTranslations('Global');
|
||||||
|
console.log(fileType);
|
||||||
|
|
||||||
|
const getFileTypeFields = (fileType: string): { totalSize: string, totalCount: string } => {
|
||||||
|
switch (fileType) {
|
||||||
|
case 'image':
|
||||||
|
return {
|
||||||
|
totalSize: 'images_size',
|
||||||
|
totalCount: 'images_quantity'
|
||||||
|
};
|
||||||
|
case 'video':
|
||||||
|
return {
|
||||||
|
totalSize: 'videos_size',
|
||||||
|
totalCount: 'videos_quantity'
|
||||||
|
};
|
||||||
|
case 'audio':
|
||||||
|
return {
|
||||||
|
totalSize: 'audios_size',
|
||||||
|
totalCount: 'audios_quantity'
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
totalSize: 'all_files_size',
|
||||||
|
totalCount: 'all_files_quantity'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: filesInfo,
|
data: filesInfo,
|
||||||
@@ -19,24 +47,26 @@ export default function ProtectionSummary() {
|
|||||||
isError,
|
isError,
|
||||||
error,
|
error,
|
||||||
} = useQuery<{
|
} = useQuery<{
|
||||||
formattedTotalSize: string,
|
all_files_size: number,
|
||||||
totalCount: number
|
all_files_quantity: number
|
||||||
}, Error, FilesInfo>({
|
}, Error, FilesInfo>({
|
||||||
queryKey: ['userFilesData'],
|
queryKey: ['userFilesInfo'],
|
||||||
queryFn: getUserFilesData,
|
queryFn: getUserFilesInfo,
|
||||||
select: (data): FilesInfo => {
|
select: (data): FilesInfo => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return {
|
return {
|
||||||
totalSize: '0',
|
totalSize: 0,
|
||||||
totalCount: 0
|
totalCount: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fields = getFileTypeFields(fileType);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalSize: data.formattedTotalSize,
|
totalSize: data[fields.totalSize as keyof typeof data],
|
||||||
totalCount: (data.totalCount)
|
totalCount: data[fields.totalCount as keyof typeof data]
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -56,7 +86,7 @@ export default function ProtectionSummary() {
|
|||||||
<div className="protection-stat-label">{t('violations')}</div>
|
<div className="protection-stat-label">{t('violations')}</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="protection-stat total-usage">
|
<div className="protection-stat total-usage">
|
||||||
<div className="protection-stat-value">{filesInfo?.totalSize ? filesInfo?.totalSize : 0} / 0</div>
|
<div className="protection-stat-value">{filesInfo?.totalSize ? convertBytes(filesInfo?.totalSize) : 0} / 0</div>
|
||||||
<div className="protection-stat-label">
|
<div className="protection-stat-label">
|
||||||
{t('disk-space-used')}
|
{t('disk-space-used')}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,72 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
import { IconDocument, IconImageFile, IconVideoFile, IconAudioFile } from '@/app/ui/icons/icons';
|
import { IconDocument, IconImageFile, IconVideoFile, IconAudioFile } from '@/app/ui/icons/icons';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { getUserFilesInfo } from '@/app/actions/action';
|
||||||
|
import { useTranslations } from 'next-intl';
|
||||||
|
import { convertBytes } from '@/app/lib/convertBytes';
|
||||||
|
|
||||||
export default function MyContentInfoBlock() {
|
export default function MyContentInfoBlock() {
|
||||||
|
const t = useTranslations('Global');
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: filesInfo,
|
||||||
|
isLoading,
|
||||||
|
isError,
|
||||||
|
error,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ['userFilesInfo'],
|
||||||
|
queryFn: getUserFilesInfo,
|
||||||
|
});
|
||||||
|
|
||||||
|
const fileTypeSizePercents = () => {
|
||||||
|
if (!filesInfo?.all_files_size) {
|
||||||
|
return {
|
||||||
|
images: 0,
|
||||||
|
videos: 0,
|
||||||
|
audios: 0,
|
||||||
|
documents: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const sizes = {
|
||||||
|
images: filesInfo.images_size || 0,
|
||||||
|
videos: filesInfo.videos_size || 0,
|
||||||
|
audios: filesInfo.audios_size || 0,
|
||||||
|
documents: filesInfo.documents_size || 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const total = filesInfo.all_files_size;
|
||||||
|
|
||||||
|
const rawPercents = {
|
||||||
|
images: (sizes.images / total) * 100,
|
||||||
|
videos: (sizes.videos / total) * 100,
|
||||||
|
audios: (sizes.audios / total) * 100,
|
||||||
|
documents: (sizes.documents / total) * 100,
|
||||||
|
};
|
||||||
|
|
||||||
|
const roundedPercents = {
|
||||||
|
images: Math.floor(rawPercents.images),
|
||||||
|
videos: Math.floor(rawPercents.videos),
|
||||||
|
audios: Math.floor(rawPercents.audios),
|
||||||
|
documents: Math.floor(rawPercents.documents),
|
||||||
|
};
|
||||||
|
|
||||||
|
const remainder = 100 - Object.values(roundedPercents).reduce((a, b) => a + b, 0);
|
||||||
|
|
||||||
|
const fractions = Object.entries(rawPercents).map(([key, value]) => ({
|
||||||
|
key,
|
||||||
|
fraction: value - Math.floor(value)
|
||||||
|
})).sort((a, b) => b.fraction - a.fraction);
|
||||||
|
|
||||||
|
const result = { ...roundedPercents };
|
||||||
|
for (let i = 0; i < remainder; i++) {
|
||||||
|
result[fractions[i].key as keyof typeof result]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="block-wrapper auto grow">
|
<div className="block-wrapper auto grow">
|
||||||
<div className="file-stats-container">
|
<div className="file-stats-container">
|
||||||
@@ -11,13 +77,17 @@ export default function MyContentInfoBlock() {
|
|||||||
<IconImageFile />
|
<IconImageFile />
|
||||||
</div>
|
</div>
|
||||||
<div className="file-stat-info">
|
<div className="file-stat-info">
|
||||||
<h4 className="file-stat-title">Image</h4>
|
<h4 className="file-stat-title">{t('images')}</h4>
|
||||||
<span className="file-stat-usage">0%</span>
|
<span className="file-stat-usage">{fileTypeSizePercents().images}%</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="file-stat-details">
|
<div className="file-stat-details">
|
||||||
<span className="file-stat-count">0 files</span>
|
<span className="file-stat-count">
|
||||||
<span className="file-stat-size">0 GB</span>
|
{filesInfo.images_quantity ? filesInfo.images_quantity : 0} {t('files')}
|
||||||
|
</span>
|
||||||
|
<span className="file-stat-size">
|
||||||
|
{filesInfo.images_size ? convertBytes(filesInfo.images_size) : 0}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -27,13 +97,17 @@ export default function MyContentInfoBlock() {
|
|||||||
<IconVideoFile />
|
<IconVideoFile />
|
||||||
</div>
|
</div>
|
||||||
<div className="file-stat-info">
|
<div className="file-stat-info">
|
||||||
<h4 className="file-stat-title">Videos</h4>
|
<h4 className="file-stat-title">{t('videos')}</h4>
|
||||||
<span className="file-stat-usage">0%</span>
|
<span className="file-stat-usage">{fileTypeSizePercents().videos}%</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="file-stat-details">
|
<div className="file-stat-details">
|
||||||
<span className="file-stat-count">0 files</span>
|
<span className="file-stat-count">
|
||||||
<span className="file-stat-size">0 GB</span>
|
{filesInfo.videos_quantity ? filesInfo.videos_quantity : 0} {t('files')}
|
||||||
|
</span>
|
||||||
|
<span className="file-stat-size">
|
||||||
|
{filesInfo.videos_size ? convertBytes(filesInfo.videos_size) : 0}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -43,13 +117,17 @@ export default function MyContentInfoBlock() {
|
|||||||
<IconAudioFile />
|
<IconAudioFile />
|
||||||
</div>
|
</div>
|
||||||
<div className="file-stat-info">
|
<div className="file-stat-info">
|
||||||
<h4 className="file-stat-title">Audios</h4>
|
<h4 className="file-stat-title">{t('audios')}</h4>
|
||||||
<span className="file-stat-usage">0%</span>
|
<span className="file-stat-usage">{fileTypeSizePercents().audios}%</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="file-stat-details">
|
<div className="file-stat-details">
|
||||||
<span className="file-stat-count">0 files</span>
|
<span className="file-stat-count">
|
||||||
<span className="file-stat-size">0 GB</span>
|
{filesInfo.audios_quantity ? filesInfo.audios_quantity : 0} {t('files')}
|
||||||
|
</span>
|
||||||
|
<span className="file-stat-size">
|
||||||
|
{filesInfo.audios_size ? convertBytes(filesInfo.audios_size) : 0}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -59,13 +137,17 @@ export default function MyContentInfoBlock() {
|
|||||||
<IconDocument />
|
<IconDocument />
|
||||||
</div>
|
</div>
|
||||||
<div className="file-stat-info">
|
<div className="file-stat-info">
|
||||||
<h4 className="file-stat-title">Documents</h4>
|
<h4 className="file-stat-title">{t('documents')}</h4>
|
||||||
<span className="file-stat-usage">0%</span>
|
<span className="file-stat-usage">{fileTypeSizePercents().documents}%</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="file-stat-details">
|
<div className="file-stat-details">
|
||||||
<span className="file-stat-count">0 files</span>
|
<span className="file-stat-count">
|
||||||
<span className="file-stat-size">0 GB</span>
|
{filesInfo.documents_quantity ? filesInfo.documents_quantity : 0} {t('files')}
|
||||||
|
</span>
|
||||||
|
<span className="file-stat-size">
|
||||||
|
{filesInfo.documents_size ? convertBytes(filesInfo.documents_size) : 0}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
'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';
|
||||||
|
|
||||||
|
|
||||||
|
type FilesInfo = {
|
||||||
|
totalSize: number;
|
||||||
|
totalCount: number;
|
||||||
|
imageQuantity: number;
|
||||||
|
videoQuantity: number;
|
||||||
|
audioQuantity: number;
|
||||||
|
documentQuantity: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function MyContentPieChart() {
|
||||||
|
const [filesCount, setFilesCount] = useState([
|
||||||
|
{ name: 'images', value: 0, color: '#f08c00' },
|
||||||
|
{ name: 'videos', value: 0, color: '#2f9e44' },
|
||||||
|
{ name: 'audios', value: 0, color: '#1971c2' },
|
||||||
|
{ 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,
|
||||||
|
}, Error, FilesInfo>({
|
||||||
|
queryKey: ['userFilesInfo'],
|
||||||
|
queryFn: getUserFilesInfo,
|
||||||
|
select: (data): FilesInfo => {
|
||||||
|
if (!data) {
|
||||||
|
return {
|
||||||
|
totalSize: 0,
|
||||||
|
totalCount: 0,
|
||||||
|
imageQuantity: 0,
|
||||||
|
videoQuantity: 0,
|
||||||
|
audioQuantity: 0,
|
||||||
|
documentQuantity: 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,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setFilesCount([
|
||||||
|
{
|
||||||
|
name: 'images',
|
||||||
|
value: filesInfo?.imageQuantity ? filesInfo?.imageQuantity : 0,
|
||||||
|
color: '#f08c00'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'videos',
|
||||||
|
value: filesInfo?.videoQuantity ? filesInfo?.videoQuantity : 0,
|
||||||
|
color: '#2f9e44'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'audios',
|
||||||
|
value: filesInfo?.audioQuantity ? filesInfo?.audioQuantity : 0,
|
||||||
|
color: '#1971c2'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'documents',
|
||||||
|
value: filesInfo?.documentQuantity ? filesInfo?.documentQuantity : 0,
|
||||||
|
color: '#a561e6'
|
||||||
|
},
|
||||||
|
])
|
||||||
|
}, [filesInfo]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="protection-overview">
|
||||||
|
<PieChartComponent data={filesCount} show={filesInfo?.totalSize ? convertBytes(filesInfo?.totalSize) : 0} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ import PaymentTabTransactionHistory from './payment-tab-transaction-history';
|
|||||||
export default function PaymentTabs() {
|
export default function PaymentTabs() {
|
||||||
let [selectedTab, setSelectedTab] = useState('1');
|
let [selectedTab, setSelectedTab] = useState('1');
|
||||||
function switchTabsHandler(tab: string) {
|
function switchTabsHandler(tab: string) {
|
||||||
console.log('click');
|
|
||||||
setSelectedTab(tab);
|
setSelectedTab(tab);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user