mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 10:19:22 +03:00
feat: rendering basic stat info
This commit is contained in:
parent
2c6534648a
commit
d07879a700
@ -38,6 +38,11 @@ import { useCreateCategory } from './category/useCreateCategory';
|
|||||||
import { useDeleteCategory } from './category/useDeleteCategory';
|
import { useDeleteCategory } from './category/useDeleteCategory';
|
||||||
import { useUpdateCategory } from './category/useUpdateCategory';
|
import { useUpdateCategory } from './category/useUpdateCategory';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stat
|
||||||
|
*/
|
||||||
|
import { useFetchStat } from './stat/useFetchStat';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
useLogin,
|
useLogin,
|
||||||
useLogout,
|
useLogout,
|
||||||
@ -59,4 +64,5 @@ export {
|
|||||||
useDeleteCategory,
|
useDeleteCategory,
|
||||||
useUpdateCategory,
|
useUpdateCategory,
|
||||||
useFetchCategories,
|
useFetchCategories,
|
||||||
|
useFetchStat,
|
||||||
};
|
};
|
||||||
|
|||||||
29
src/hooks/queries/stat/useFetchStat.ts
Normal file
29
src/hooks/queries/stat/useFetchStat.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { StatServiceInstance } from '@educt/services/StatService';
|
||||||
|
import { StatInfoType } from '@educt/types';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import useAsync from '@educt/hooks/useAsync';
|
||||||
|
import { useErrorHandler } from 'react-error-boundary';
|
||||||
|
|
||||||
|
const useFetchStat = () => {
|
||||||
|
const handleError = useErrorHandler();
|
||||||
|
|
||||||
|
const fetchStat = async () => {
|
||||||
|
try {
|
||||||
|
const result = await StatServiceInstance.fetchStat();
|
||||||
|
return result.data;
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error);
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const { execute: fetch, ...state } = useAsync<StatInfoType, Parameters<typeof fetchStat>>(fetchStat);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetch();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return { ...state };
|
||||||
|
};
|
||||||
|
|
||||||
|
export { useFetchStat };
|
||||||
@ -21,7 +21,7 @@ import {
|
|||||||
CourseCardList,
|
CourseCardList,
|
||||||
} from './components';
|
} from './components';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { useFetchCourses } from '@educt/hooks/queries';
|
import { useFetchCourses, useFetchStat } from '@educt/hooks/queries';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main page
|
* Main page
|
||||||
@ -31,8 +31,9 @@ const MainPage: React.FC<IPageProps> = () => {
|
|||||||
userStore: { me },
|
userStore: { me },
|
||||||
} = useRootStore();
|
} = useRootStore();
|
||||||
const { data: courses } = useFetchCourses({ limit: 3 });
|
const { data: courses } = useFetchCourses({ limit: 3 });
|
||||||
|
const { data: stat } = useFetchStat();
|
||||||
|
|
||||||
if (me === null || courses === null) return <LoadingPage />;
|
if (me === null || courses === null || stat === null) return <LoadingPage />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageWrapper>
|
<PageWrapper>
|
||||||
@ -40,29 +41,29 @@ const MainPage: React.FC<IPageProps> = () => {
|
|||||||
<PageContent>
|
<PageContent>
|
||||||
<SimpleGrid columns={{ base: 1, md: 2, lg: 4 }} spacing='6'>
|
<SimpleGrid columns={{ base: 1, md: 2, lg: 4 }} spacing='6'>
|
||||||
<Stat>
|
<Stat>
|
||||||
<StatLabel>Unread messages</StatLabel>
|
<StatLabel>Online</StatLabel>
|
||||||
<StatContent>
|
|
||||||
<StatNumber>
|
|
||||||
<Link as={ReactRouterLink} to='/messages'>
|
|
||||||
3
|
|
||||||
</Link>
|
|
||||||
</StatNumber>
|
|
||||||
<StatIcon icon={MdOutlineMessage} />
|
|
||||||
</StatContent>
|
|
||||||
</Stat>
|
|
||||||
|
|
||||||
<Stat>
|
|
||||||
<StatLabel>Registered students</StatLabel>
|
|
||||||
<StatContent>
|
<StatContent>
|
||||||
<StatNumber>24</StatNumber>
|
<StatNumber>24</StatNumber>
|
||||||
<StatIcon icon={MdOutlineGroup} />
|
<StatIcon icon={MdOutlineGroup} />
|
||||||
</StatContent>
|
</StatContent>
|
||||||
</Stat>
|
</Stat>
|
||||||
|
|
||||||
|
<Stat>
|
||||||
|
<StatLabel>Unread messages</StatLabel>
|
||||||
|
<StatContent>
|
||||||
|
<StatNumber>
|
||||||
|
<Link as={ReactRouterLink} to='/messages'>
|
||||||
|
1
|
||||||
|
</Link>
|
||||||
|
</StatNumber>
|
||||||
|
<StatIcon icon={MdOutlineMessage} />
|
||||||
|
</StatContent>
|
||||||
|
</Stat>
|
||||||
|
|
||||||
<Stat>
|
<Stat>
|
||||||
<StatLabel>Courses</StatLabel>
|
<StatLabel>Courses</StatLabel>
|
||||||
<StatContent>
|
<StatContent>
|
||||||
<StatNumber>7</StatNumber>
|
<StatNumber>{stat.courses_count}</StatNumber>
|
||||||
<StatIcon icon={MdOutlineCollectionsBookmark} />
|
<StatIcon icon={MdOutlineCollectionsBookmark} />
|
||||||
</StatContent>
|
</StatContent>
|
||||||
</Stat>
|
</Stat>
|
||||||
@ -70,7 +71,7 @@ const MainPage: React.FC<IPageProps> = () => {
|
|||||||
<Stat>
|
<Stat>
|
||||||
<StatLabel>Lessons</StatLabel>
|
<StatLabel>Lessons</StatLabel>
|
||||||
<StatContent>
|
<StatContent>
|
||||||
<StatNumber>42</StatNumber>
|
<StatNumber>{stat.lessons_count}</StatNumber>
|
||||||
<StatIcon icon={MdOutlineVideoLibrary} />
|
<StatIcon icon={MdOutlineVideoLibrary} />
|
||||||
</StatContent>
|
</StatContent>
|
||||||
</Stat>
|
</Stat>
|
||||||
|
|||||||
24
src/services/StatService.ts
Normal file
24
src/services/StatService.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { AxiosInstance } from 'axios';
|
||||||
|
import { ApiServiceInstance } from '.';
|
||||||
|
import { IApiRespose } from '@educt/interfaces';
|
||||||
|
import { StatInfoType } from '@educt/types';
|
||||||
|
|
||||||
|
class StatService {
|
||||||
|
public api: AxiosInstance;
|
||||||
|
|
||||||
|
constructor(api: AxiosInstance) {
|
||||||
|
this.api = api;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get basic stat info about system
|
||||||
|
*
|
||||||
|
* @returns Stat info
|
||||||
|
*/
|
||||||
|
public async fetchStat(): Promise<IApiRespose<StatInfoType>> {
|
||||||
|
const result = await this.api.get('/v1/stat');
|
||||||
|
return result.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const StatServiceInstance = new StatService(ApiServiceInstance.api);
|
||||||
5
src/types/index.d.ts
vendored
5
src/types/index.d.ts
vendored
@ -40,6 +40,11 @@ export type LessonProgress = {
|
|||||||
} | null;
|
} | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type StatInfoType = {
|
||||||
|
courses_count: string;
|
||||||
|
lessons_count: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type LessonVideoType = {
|
export type LessonVideoType = {
|
||||||
id: number;
|
id: number;
|
||||||
client_name: string;
|
client_name: string;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user