Something went wrong. Try again.
Self-hosted file management and sharing system, supports multiple storage providers. forked from tdvorak.tngl.sh/cloudreve
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114import { DialogContent, Table, TableBody, TableCell, TableHead, TableRow, Typography,} from "@mui/material";import { useEffect, useState } from "react";import { useTranslation } from "react-i18next";import { getFileActivity } from "../../../../api/api.ts";import { ActivityEvent } from "../../../../api/dashboard.ts";import { closeActivityDialog } from "../../../../redux/globalStateSlice.ts";import { useAppDispatch, useAppSelector } from "../../../../redux/hooks.ts";import AutoHeight from "../../../Common/AutoHeight.tsx";import { StyledTableContainerPaper } from "../../../Common/StyledComponents.tsx";import DraggableDialog from "../../../Dialogs/DraggableDialog.tsx";import { getEventName } from "../../../Admin/Settings/Event/Events.tsx";import TablePagination from "../../../Admin/Common/TablePagination.tsx";
const ActivityDialog = () => { const { t } = useTranslation(); const dispatch = useAppDispatch();
const open = useAppSelector((state) => state.globalState.activityDialogOpen); const target = useAppSelector((state) => state.globalState.activityDialogFile); const shareId = useAppSelector((state) => state.globalState.activityDialogShareId);
const [events, setEvents] = useState<ActivityEvent[] | undefined>(undefined); const [total, setTotal] = useState(0); const [page, setPage] = useState(1); const pageSize = 20;
const uri = target?.path;
useEffect(() => { if (!open || (!uri && !shareId)) { return; } setEvents(undefined); dispatch(getFileActivity(uri, page, pageSize, shareId)).then((res) => { setEvents(res.events); setTotal(res.total); }); }, [open, uri, page, shareId]);
useEffect(() => { if (open) { setPage(1); } }, [open]);
return ( <DraggableDialog title={t("application:fileManager.activity")} loading={events === undefined} dialogProps={{ open: open ?? false, onClose: () => dispatch(closeActivityDialog()), fullWidth: true, maxWidth: "md", }} > <DialogContent> <AutoHeight> <Typography variant="body2" color="text.secondary" sx={{ mb: 2 }}> {t("application:fileManager.activityDes", { name: target?.name })} </Typography> <StyledTableContainerPaper> <Table size="small"> <TableHead> <TableRow> <TableCell>{t("dashboard:event.event")}</TableCell> <TableCell>{t("dashboard:event.initiator")}</TableCell> <TableCell>{t("dashboard:event.ip")}</TableCell> <TableCell>{t("dashboard:event.datetime")}</TableCell> </TableRow> </TableHead> <TableBody> {events?.map((event) => ( <TableRow key={event.id} hover> <TableCell>{t(`dashboard:settings.event.${getEventName(event.type)}`, getEventName(event.type))}</TableCell> <TableCell>{event.actor_name || event.actor_id || "-"}</TableCell> <TableCell>{event.ip || "-"}</TableCell> <TableCell>{new Date(event.created_at * 1000).toLocaleString()}</TableCell> </TableRow> ))} {events?.length === 0 && ( <TableRow> <TableCell colSpan={4} align="center"> {t("dashboard:event.noEvents")} </TableCell> </TableRow> )} </TableBody> </Table> </StyledTableContainerPaper> {total > pageSize && ( <TablePagination page={page} totalItems={total} rowsPerPage={pageSize} onChange={(_e, value) => setPage(value)} /> )} </AutoHeight> </DialogContent> </DraggableDialog> );};
export default ActivityDialog;