mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
fix: disallow deletion of all login history entries (#4159)
https://linear.app/unleash/issue/2-1191/disallow-deletion-of-all-login-entries-in-history-ui Disallows deletion of all login history entries on the UI. ![image](https://github.com/Unleash/unleash/assets/14320932/f2378d61-0738-4614-b9c5-e81444e8dde1)
This commit is contained in:
parent
e22662e140
commit
0dec24722d
@ -1,28 +0,0 @@
|
||||
import { Dialogue } from 'component/common/Dialogue/Dialogue';
|
||||
|
||||
interface ILoginHistoryDeleteAllDialogProps {
|
||||
open: boolean;
|
||||
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
onConfirm: () => void;
|
||||
}
|
||||
|
||||
export const LoginHistoryDeleteAllDialog = ({
|
||||
open,
|
||||
setOpen,
|
||||
onConfirm,
|
||||
}: ILoginHistoryDeleteAllDialogProps) => (
|
||||
<Dialogue
|
||||
title="Clear login history?"
|
||||
open={open}
|
||||
primaryButtonText="Clear login history"
|
||||
secondaryButtonText="Cancel"
|
||||
onClick={onConfirm}
|
||||
onClose={() => {
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
You are about to clear the login history.
|
||||
<br />
|
||||
This will delete all the login events.
|
||||
</Dialogue>
|
||||
);
|
@ -1,8 +1,6 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { TablePlaceholder, VirtualizedTable } from 'component/common/Table';
|
||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||
import useToast from 'hooks/useToast';
|
||||
import { formatUnknownError } from 'utils/formatUnknownError';
|
||||
import { PageContent } from 'component/common/PageContent/PageContent';
|
||||
import { PageHeader } from 'component/common/PageHeader/PageHeader';
|
||||
import { IconButton, Tooltip, useMediaQuery } from '@mui/material';
|
||||
@ -23,8 +21,7 @@ import { useLoginHistoryApi } from 'hooks/api/actions/useLoginHistoryApi/useLogi
|
||||
import { formatDateYMDHMS } from 'utils/formatDate';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { createLocalStorage } from 'utils/createLocalStorage';
|
||||
import { Delete, Download } from '@mui/icons-material';
|
||||
import { LoginHistoryDeleteAllDialog } from './LoginHistoryDeleteAllDialog/LoginHistoryDeleteAllDialog';
|
||||
import { Download } from '@mui/icons-material';
|
||||
|
||||
export type PageQueryType = Partial<
|
||||
Record<'sort' | 'order' | 'search', string>
|
||||
@ -45,10 +42,8 @@ const AUTH_TYPE_LABEL: { [key: string]: string } = {
|
||||
};
|
||||
|
||||
export const LoginHistoryTable = () => {
|
||||
const { setToastData, setToastApiError } = useToast();
|
||||
|
||||
const { events, loading, refetch } = useLoginHistory();
|
||||
const { removeAllEvents, downloadCSV } = useLoginHistoryApi();
|
||||
const { events, loading } = useLoginHistory();
|
||||
const { downloadCSV } = useLoginHistoryApi();
|
||||
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const [initialState] = useState(() => ({
|
||||
@ -65,21 +60,6 @@ export const LoginHistoryTable = () => {
|
||||
}));
|
||||
|
||||
const [searchValue, setSearchValue] = useState(initialState.globalFilter);
|
||||
const [deleteAllOpen, setDeleteAllOpen] = useState(false);
|
||||
|
||||
const onDeleteAllConfirm = async () => {
|
||||
try {
|
||||
await removeAllEvents();
|
||||
setToastData({
|
||||
title: `History has been cleared`,
|
||||
type: 'success',
|
||||
});
|
||||
refetch();
|
||||
setDeleteAllOpen(false);
|
||||
} catch (error: unknown) {
|
||||
setToastApiError(formatUnknownError(error));
|
||||
}
|
||||
};
|
||||
|
||||
const isExtraSmallScreen = useMediaQuery(theme.breakpoints.down('sm'));
|
||||
const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
|
||||
@ -235,18 +215,6 @@ export const LoginHistoryTable = () => {
|
||||
<Download />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<Tooltip
|
||||
title="Clear login history"
|
||||
arrow
|
||||
>
|
||||
<IconButton
|
||||
onClick={() =>
|
||||
setDeleteAllOpen(true)
|
||||
}
|
||||
>
|
||||
<Delete />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
@ -294,11 +262,6 @@ export const LoginHistoryTable = () => {
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<LoginHistoryDeleteAllDialog
|
||||
open={deleteAllOpen}
|
||||
setOpen={setDeleteAllOpen}
|
||||
onConfirm={onDeleteAllConfirm}
|
||||
/>
|
||||
</PageContent>
|
||||
);
|
||||
};
|
||||
|
@ -22,20 +22,8 @@ export const useLoginHistoryApi = () => {
|
||||
window.location.assign(url);
|
||||
};
|
||||
|
||||
const removeAllEvents = async () => {
|
||||
const requestId = 'removeAllEvents';
|
||||
const req = createRequest(
|
||||
'api/admin/logins',
|
||||
{ method: 'DELETE' },
|
||||
requestId
|
||||
);
|
||||
|
||||
await makeRequest(req.caller, req.id);
|
||||
};
|
||||
|
||||
return {
|
||||
downloadCSV,
|
||||
removeAllEvents,
|
||||
errors,
|
||||
loading,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user