mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-18 01:18:23 +02:00
fix: disallow deletion of single login history entries (#4149)
https://linear.app/unleash/issue/2-1185/disallow-deletion-of-single-login-entries-in-history-ui Disallows deletion of single login history entries on the UI. 
This commit is contained in:
parent
6d591fcd17
commit
dd32e8ae0d
@ -1,29 +0,0 @@
|
|||||||
import { Dialogue } from 'component/common/Dialogue/Dialogue';
|
|
||||||
import { ILoginEvent } from 'interfaces/loginEvent';
|
|
||||||
|
|
||||||
interface ILoginHistoryDeleteDialogProps {
|
|
||||||
event?: ILoginEvent;
|
|
||||||
open: boolean;
|
|
||||||
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
||||||
onConfirm: (event: ILoginEvent) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const LoginHistoryDeleteDialog = ({
|
|
||||||
event,
|
|
||||||
open,
|
|
||||||
setOpen,
|
|
||||||
onConfirm,
|
|
||||||
}: ILoginHistoryDeleteDialogProps) => (
|
|
||||||
<Dialogue
|
|
||||||
title="Delete event?"
|
|
||||||
open={open}
|
|
||||||
primaryButtonText="Delete event"
|
|
||||||
secondaryButtonText="Cancel"
|
|
||||||
onClick={() => onConfirm(event!)}
|
|
||||||
onClose={() => {
|
|
||||||
setOpen(false);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
You are about to delete event: <strong>#{event?.id}</strong>
|
|
||||||
</Dialogue>
|
|
||||||
);
|
|
@ -19,8 +19,6 @@ import { TimeAgoCell } from 'component/common/Table/cells/TimeAgoCell/TimeAgoCel
|
|||||||
import { useLoginHistory } from 'hooks/api/getters/useLoginHistory/useLoginHistory';
|
import { useLoginHistory } from 'hooks/api/getters/useLoginHistory/useLoginHistory';
|
||||||
import { LoginHistorySuccessfulCell } from './LoginHistorySuccessfulCell/LoginHistorySuccessfulCell';
|
import { LoginHistorySuccessfulCell } from './LoginHistorySuccessfulCell/LoginHistorySuccessfulCell';
|
||||||
import { ILoginEvent } from 'interfaces/loginEvent';
|
import { ILoginEvent } from 'interfaces/loginEvent';
|
||||||
import { LoginHistoryActionsCell } from './LoginHistoryActionsCell/LoginHistoryActionsCell';
|
|
||||||
import { LoginHistoryDeleteDialog } from './LoginHistoryDeleteDialog/LoginHistoryDeleteDialog';
|
|
||||||
import { useLoginHistoryApi } from 'hooks/api/actions/useLoginHistoryApi/useLoginHistoryApi';
|
import { useLoginHistoryApi } from 'hooks/api/actions/useLoginHistoryApi/useLoginHistoryApi';
|
||||||
import { formatDateYMDHMS } from 'utils/formatDate';
|
import { formatDateYMDHMS } from 'utils/formatDate';
|
||||||
import { useSearchParams } from 'react-router-dom';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
@ -50,7 +48,7 @@ export const LoginHistoryTable = () => {
|
|||||||
const { setToastData, setToastApiError } = useToast();
|
const { setToastData, setToastApiError } = useToast();
|
||||||
|
|
||||||
const { events, loading, refetch } = useLoginHistory();
|
const { events, loading, refetch } = useLoginHistory();
|
||||||
const { removeEvent, removeAllEvents, downloadCSV } = useLoginHistoryApi();
|
const { removeAllEvents, downloadCSV } = useLoginHistoryApi();
|
||||||
|
|
||||||
const [searchParams, setSearchParams] = useSearchParams();
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
const [initialState] = useState(() => ({
|
const [initialState] = useState(() => ({
|
||||||
@ -67,24 +65,8 @@ export const LoginHistoryTable = () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const [searchValue, setSearchValue] = useState(initialState.globalFilter);
|
const [searchValue, setSearchValue] = useState(initialState.globalFilter);
|
||||||
const [selectedEvent, setSelectedEvent] = useState<ILoginEvent>();
|
|
||||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
|
||||||
const [deleteAllOpen, setDeleteAllOpen] = useState(false);
|
const [deleteAllOpen, setDeleteAllOpen] = useState(false);
|
||||||
|
|
||||||
const onDeleteConfirm = async (event: ILoginEvent) => {
|
|
||||||
try {
|
|
||||||
await removeEvent(event.id);
|
|
||||||
setToastData({
|
|
||||||
title: `Event has been deleted`,
|
|
||||||
type: 'success',
|
|
||||||
});
|
|
||||||
refetch();
|
|
||||||
setDeleteOpen(false);
|
|
||||||
} catch (error: unknown) {
|
|
||||||
setToastApiError(formatUnknownError(error));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDeleteAllConfirm = async () => {
|
const onDeleteAllConfirm = async () => {
|
||||||
try {
|
try {
|
||||||
await removeAllEvents();
|
await removeAllEvents();
|
||||||
@ -144,21 +126,6 @@ export const LoginHistoryTable = () => {
|
|||||||
filterName: 'success',
|
filterName: 'success',
|
||||||
filterParsing: (value: boolean) => value.toString(),
|
filterParsing: (value: boolean) => value.toString(),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Header: 'Actions',
|
|
||||||
id: 'Actions',
|
|
||||||
align: 'center',
|
|
||||||
Cell: ({ row: { original: event } }: any) => (
|
|
||||||
<LoginHistoryActionsCell
|
|
||||||
onDelete={() => {
|
|
||||||
setSelectedEvent(event);
|
|
||||||
setDeleteOpen(true);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
width: 150,
|
|
||||||
disableSortBy: true,
|
|
||||||
},
|
|
||||||
// Always hidden -- for search
|
// Always hidden -- for search
|
||||||
{
|
{
|
||||||
accessor: 'failure_reason',
|
accessor: 'failure_reason',
|
||||||
@ -327,12 +294,6 @@ export const LoginHistoryTable = () => {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<LoginHistoryDeleteDialog
|
|
||||||
event={selectedEvent}
|
|
||||||
open={deleteOpen}
|
|
||||||
setOpen={setDeleteOpen}
|
|
||||||
onConfirm={onDeleteConfirm}
|
|
||||||
/>
|
|
||||||
<LoginHistoryDeleteAllDialog
|
<LoginHistoryDeleteAllDialog
|
||||||
open={deleteAllOpen}
|
open={deleteAllOpen}
|
||||||
setOpen={setDeleteAllOpen}
|
setOpen={setDeleteAllOpen}
|
||||||
|
@ -22,17 +22,6 @@ export const useLoginHistoryApi = () => {
|
|||||||
window.location.assign(url);
|
window.location.assign(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeEvent = async (eventId: number) => {
|
|
||||||
const requestId = 'removeEvent';
|
|
||||||
const req = createRequest(
|
|
||||||
`api/admin/logins/${eventId}`,
|
|
||||||
{ method: 'DELETE' },
|
|
||||||
requestId
|
|
||||||
);
|
|
||||||
|
|
||||||
await makeRequest(req.caller, req.id);
|
|
||||||
};
|
|
||||||
|
|
||||||
const removeAllEvents = async () => {
|
const removeAllEvents = async () => {
|
||||||
const requestId = 'removeAllEvents';
|
const requestId = 'removeAllEvents';
|
||||||
const req = createRequest(
|
const req = createRequest(
|
||||||
@ -46,7 +35,6 @@ export const useLoginHistoryApi = () => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
downloadCSV,
|
downloadCSV,
|
||||||
removeEvent,
|
|
||||||
removeAllEvents,
|
removeAllEvents,
|
||||||
errors,
|
errors,
|
||||||
loading,
|
loading,
|
||||||
|
Loading…
Reference in New Issue
Block a user