Skip to content

Commit

Permalink
Added statistic(alpha version)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslavUsenko committed Jan 19, 2024
1 parent d31e7d4 commit c2f11f6
Show file tree
Hide file tree
Showing 38 changed files with 875 additions and 140 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tres",
"private": true,
"version": "1.4.0",
"version": "1.5.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
6 changes: 6 additions & 0 deletions public/assets/processing_time.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/assets/tickets_count.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/assets/users_count.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"deleted": "Deleted"
},
"notifications": "Notifications",
"statistic": "Statistic",
"generalTickets": "General Tickets",
"settings": "Settings"
},
Expand Down Expand Up @@ -251,7 +252,19 @@
"close": "Close"
},
"statistic": {
"heading": "Statistic"
"heading": "Statistic",
"activitySummary": {
"heading": "Activity summary"
},
"calendarStatistic": {
"heading": "Calendar"
},
"mentionedFaculties": {
"heading": "Mentioned faculties"
},
"systemStatus": {
"heading": "Current system status"
}
},
"privacyPolicy": {
"postscript": {
Expand Down
15 changes: 14 additions & 1 deletion public/locales/ua/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"deleted": "Видалені"
},
"notifications": "Сповіщення",
"statistic": "Статистика",
"generalTickets": "Поточні звернення",
"settings": "Налаштування"
},
Expand Down Expand Up @@ -251,7 +252,19 @@
"close": "Вирішений"
},
"statistic": {
"heading": "Статистика"
"heading": "Статистика",
"activitySummary": {
"heading": "Підсумок діяльності"
},
"calendarStatistic": {
"heading": "Календар"
},
"mentionedFaculties": {
"heading": "Згадані факультети"
},
"systemStatus": {
"heading": "Поточний стан системи"
}
},
"privacyPolicy": {
"postscript": {
Expand Down
6 changes: 6 additions & 0 deletions src/assets/processing_time.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/tickets_count.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/users_count.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions src/components/StatisticCard/StatisticCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { CSSProperties, FC } from "react";
import { useTranslation } from "react-i18next";

import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import useTheme from "@mui/material/styles/useTheme";

import IPalette from "theme/IPalette.interface";

interface StatisticCardProps {
title: string;
width: number;
children: JSX.Element;
styles?: CSSProperties;
}

const StatisticCard: FC<StatisticCardProps> = ({
title,
width,
children,
styles,
}) => {
const { t } = useTranslation();
const { palette }: IPalette = useTheme();

return (
<Box
sx={{
...styles,
display: "flex",
flexDirection: "column",
gap: "20px",
p: "15px 20px",
width: `${width}px`,
height: `fit-content`,
borderRadius: 1,
bgcolor: palette.grey.card,
border: `1px solid ${palette.grey.active}`,
}}
>
<Typography sx={{ fontSize: 20 }}>
{t(`statistic.${title}.heading`)}
</Typography>
{children}
</Box>
);
};

export { StatisticCard };
1 change: 1 addition & 0 deletions src/components/StatisticCard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { StatisticCard } from "./StatisticCard";
2 changes: 1 addition & 1 deletion src/constants/scopes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const scopes = {
REPORTS: "Reports",
QA: "Q/A",
SUGGESTIONS: "Suggestions",
SUGGESTION: "Suggestion",
};

export { scopes };
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import GridViewIcon from "@mui/icons-material/GridView";
import GridViewSharpIcon from "@mui/icons-material/GridViewSharp";
import ExpandLess from "@mui/icons-material/ExpandLess";
import ExpandMore from "@mui/icons-material/ExpandMore";
import InsertChartIcon from "@mui/icons-material/InsertChart";
import InsertChartOutlinedIcon from "@mui/icons-material/InsertChartOutlined";

import { NavbarListItem } from "./components/NavbarListItem";

Expand Down Expand Up @@ -103,15 +105,26 @@ const GeneralActions: FC<GeneralActionsProps> = ({
handleListItemClick={handleListItemClick}
/>
{isAdmin && (
<NavbarListItem
title={"queue"}
endpoint={endpoints.QUEUE}
disabled={!isAuth}
selectedKey={selectedKey}
handleListItemClick={handleListItemClick}
activeIcon={<GridViewSharpIcon />}
disableIcon={<GridViewIcon />}
/>
<>
<NavbarListItem
title={"queue"}
endpoint={endpoints.QUEUE}
disabled={!isAuth}
selectedKey={selectedKey}
handleListItemClick={handleListItemClick}
activeIcon={<GridViewSharpIcon />}
disableIcon={<GridViewIcon />}
/>
<NavbarListItem
title={"statistic"}
endpoint={endpoints.STATISTIC}
disabled={!isAuth}
selectedKey={selectedKey}
handleListItemClick={handleListItemClick}
activeIcon={<InsertChartIcon />}
disableIcon={<InsertChartOutlinedIcon />}
/>
</>
)}
<NavbarListItem
title={"notifications"}
Expand Down
81 changes: 38 additions & 43 deletions src/pages/Statistic/Statistic.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { FC, useEffect, useState } from "react";
import { FC, useEffect } from "react";
import { useTranslation } from "react-i18next";

import Box from "@mui/material/Box";
import Grid from "@mui/material/Grid";
import Typography from "@mui/material/Typography";

import { GlobalStatistic } from "./components/GlobalStatistic";
import { StatusesStatistic } from "./components/StatusesStatistic";
import { ActivitySummary } from "./components/ActivitySummary";
import { CalendarStatistic } from "./components/CalendarStatistic";
import { FacultiesStatistic } from "./components/FacultiesStatistic";

import { useGetStatisticsMutation } from "api/statistics.api";
import { useGetStatusesQuery } from "api/meta.api";

export interface IGlobalStatus {
status_id: number;
status_name: string;
count: number;
}
import {
useGetFacultyStatisticQuery,
useGetGeneralStatisticMutation,
useGetSummaryActivityQuery,
} from "api/statistic.api";

export interface IPeriodStatus {
date: string;
Expand All @@ -23,51 +23,46 @@ export interface IPeriodStatus {
tickets_count: number;
}

export interface IStatus {
status_id: number;
name: string;
}

type ApiResponse = {
data?: {
global: IGlobalStatus[];
period: IPeriodStatus[];
};
error?: any;
};

const Statistic: FC = () => {
const { t } = useTranslation();

const [getStatistics] = useGetStatisticsMutation();
const { data: statuses, isSuccess } = useGetStatusesQuery({});

const [global, setGlobal] = useState([]);
const { data: summaryActivity } = useGetSummaryActivityQuery({});
const { data: facultiesStatistic } = useGetFacultyStatisticQuery({});
const [getStatistics, { data: generalStatistic }] =
useGetGeneralStatisticMutation();

useEffect(() => {
getStatistics(JSON.stringify({})).then((res: ApiResponse) => {
if (res?.data) {
const statistics = JSON.parse(res.data as any);

setGlobal(statistics.global.statuses);
}
});
getStatistics(JSON.stringify({}));
}, []);

return (
<Grid container sx={{ width: "100%" }}>
<Grid container>
<Box>
<Typography variant="h1" sx={{ textAlign: "center" }}>
{t("statistic.heading")}
</Typography>
<Typography variant="h1">{t("statistic.heading")}</Typography>
</Box>
<Box sx={{ width: "100%" }}>
{global.length > 0 && isSuccess && (
<GlobalStatistic
globalStatistic={global}
statuses={statuses.statuses_list}
<Box
sx={{
display: "grid",
gap: "20px",
gridTemplateAreas: `"statuses calendar faculties faculties"
"statuses activities activities none"`,
pt: "100px !important",
}}
>
{generalStatistic && (
<StatusesStatistic statusesStatistic={generalStatistic.statuses} />
)}
{generalStatistic && (
<CalendarStatistic calendarStatistic={generalStatistic.scopes} />
)}
{facultiesStatistic && (
<FacultiesStatistic
facultiesStatistic={facultiesStatistic.faculties_data}
/>
)}
{summaryActivity && (
<ActivitySummary summaryActivity={summaryActivity} />
)}
</Box>
</Grid>
);
Expand Down
Loading

0 comments on commit c2f11f6

Please sign in to comment.