import {ReactElement, useState} from "react" import {AxiosError} from "axios" import {MdList} from "react-icons/md" import {FaMask} from "react-icons/fa" import {useTranslation} from "react-i18next" import sortArray from "sort-array" import {useQuery} from "@tanstack/react-query" import {InputAdornment, List, MenuItem, TextField, Typography} from "@mui/material" import {DecryptedReportContent, PaginationResult, Report} from "~/server-types" import {getReports} from "~/apis" import {DecryptReport, QueryResult, SimplePage} from "~/components" import {createEnumMapFromTranslation} from "~/utils" import {groupBy} from "lodash" import {WithEncryptionRequired} from "~/hocs" import EmptyStateScreen from "~/route-widgets/ReportsRoute/EmptyStateScreen" import ReportInformationItem from "~/route-widgets/ReportsRoute/ReportInformationItem" enum SortingView { List = "List", GroupByAlias = "GroupByAlias", } const SORTING_VIEW_ICON_MAP: Record = { [SortingView.List]: , [SortingView.GroupByAlias]: , } function ReportsRoute(): ReactElement { const {t} = useTranslation("reports") const sortingViewNameMap = createEnumMapFromTranslation( "pageActions.sort.values", SortingView, )(key => t(key)) const query = useQuery, AxiosError>(["get_reports"], getReports) const [sortingView, setSortingView] = useState(SortingView.List) return ( 0 && ( setSortingView(event.target.value as SortingView)} label={t("pageActions.sort.label")} id="sorting" InputProps={{ startAdornment: ( {SORTING_VIEW_ICON_MAP[sortingView]} ), }} select > {Object.keys(sortingViewNameMap).map(name => ( {t(sortingViewNameMap[name as SortingView])} ))} ) } > > query={query}> {result => ( {reports => ( <> {(() => { if (result.items.length === 0) { return } switch (sortingView) { case SortingView.List: return sortArray( reports as DecryptedReportContent[], { by: "messageDetails.meta.createdAt", order: "desc", }, ).map(report => ( )) case SortingView.GroupByAlias: return Object.entries( groupBy( reports as DecryptedReportContent[], report => report.messageDetails.meta.to, ), ).map( ([alias, reports]: [ string, DecryptedReportContent[], ]) => (
{alias} {reports.map(report => ( ))}
), ) } })()} )}
)}
) } export default WithEncryptionRequired(ReportsRoute)