front-hub/src/pages/History/index.tsx

79 lines
2.6 KiB
TypeScript
Raw Normal View History

2023-09-12 21:45:18 +00:00
import { useEffect, useState } from "react";
2023-08-27 13:04:26 +00:00
import { Box, IconButton, Typography, useMediaQuery, useTheme } from "@mui/material";
2023-07-25 22:31:04 +00:00
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import SectionWrapper from "@root/components/SectionWrapper";
import { Select } from "@root/components/Select";
import { Tabs } from "@root/components/Tabs";
import AccordionWrapper from "./AccordionWrapper";
import { HISTORY } from "./historyMocks";
import { useHistoryTracker } from "@root/utils/hooks/useHistoryTracker";
2023-09-15 21:00:02 +00:00
import { makeRequest, useToken } from "@frontend/kitui";
2023-09-12 21:45:18 +00:00
import axios from "axios";
2023-09-15 21:00:02 +00:00
import { getHistory } from "@root/api/history";
2023-09-12 21:45:18 +00:00
import { useHistoryData } from "@root/utils/hooks/useHistoryData";
2023-07-25 22:31:04 +00:00
const subPages = ["Платежи", "Покупки тарифов", "Окончания тарифов"];
export default function History() {
const [selectedItem, setSelectedItem] = useState<number>(0);
2023-07-25 22:31:04 +00:00
const theme = useTheme();
const upMd = useMediaQuery(theme.breakpoints.up("md"));
const isMobile = useMediaQuery(theme.breakpoints.down(600));
2023-09-01 08:27:14 +00:00
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
2023-09-15 21:00:02 +00:00
const { historyData, error } = useHistoryData();
2023-07-25 22:31:04 +00:00
const handleCustomBackNavigation = useHistoryTracker();
2023-09-15 21:00:02 +00:00
if (!error && historyData) {
console.log(historyData?.records[0].rawDetails.map((rawDetails) => console.log(rawDetails.Key)));
}
2023-08-30 13:17:29 +00:00
2023-07-25 22:31:04 +00:00
return (
<SectionWrapper
maxWidth="lg"
sx={{
mt: upMd ? "25px" : "20px",
mb: upMd ? "70px" : "37px",
px: isTablet ? (isTablet ? "18px" : "40px") : "20px",
2023-07-25 22:31:04 +00:00
}}
>
<Box
sx={{
mt: "20px",
2023-09-01 08:27:14 +00:00
mb: isTablet ? "38px" : "20px",
2023-07-25 22:31:04 +00:00
display: "flex",
2023-08-23 13:24:47 +00:00
alignItems: "center",
2023-07-25 22:31:04 +00:00
gap: "10px",
}}
>
2023-08-23 13:24:47 +00:00
{isMobile && (
2023-08-27 13:04:26 +00:00
<IconButton onClick={handleCustomBackNavigation} sx={{ p: 0, height: "28px", width: "28px", color: "black" }}>
2023-07-25 22:31:04 +00:00
<ArrowBackIcon />
</IconButton>
)}
2023-08-23 13:24:47 +00:00
<Typography
sx={{
fontSize: isMobile ? "24px" : "36px",
fontWeight: "500",
}}
>
История
</Typography>
2023-07-25 22:31:04 +00:00
</Box>
{isMobile ? (
2023-08-27 13:04:26 +00:00
<Select items={subPages} selectedItem={selectedItem} setSelectedItem={setSelectedItem} />
2023-07-25 22:31:04 +00:00
) : (
2023-08-27 13:04:26 +00:00
<Tabs items={subPages} selectedItem={selectedItem} setSelectedItem={setSelectedItem} />
2023-07-25 22:31:04 +00:00
)}
{HISTORY.map((history, index) => (
2023-08-27 13:04:26 +00:00
<Box key={index} hidden={selectedItem !== index} sx={{ mt: upMd ? "27px" : "10px" }}>
2023-07-25 22:31:04 +00:00
<AccordionWrapper content={history} />
</Box>
))}
</SectionWrapper>
);
}