update usePatch, implement actions
This commit is contained in:
1 parent
aae1fefb31
commit
f9d0ab5e07
7 files changed
+181
-131
No files matched your search
@@ -15,11 +15,13 @@ export const ActionsMenu = ({ items }: { items: ActionMenuItem[] }) => {
|
||||
const [anchorEl, setAnchorEl] = useState<null | any>(null);
|
||||
const open = Boolean(anchorEl);
|
||||
|
||||
const handleClick = (event: React.MouseEvent<any>) => {
|
||||
setAnchorEl(event.currentTarget);
|
||||
const handleClick = (e: React.MouseEvent<any>) => {
|
||||
e.stopPropagation();
|
||||
setAnchorEl(e.currentTarget);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
const handleClose = (e: React.MouseEvent<any>) => {
|
||||
e.stopPropagation();
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
@@ -36,8 +38,9 @@ export const ActionsMenu = ({ items }: { items: ActionMenuItem[] }) => {
|
||||
{items.map((item) => (
|
||||
<MenuItem
|
||||
key={item.id}
|
||||
onClick={() => {
|
||||
if (item.closeMenu) handleClose();
|
||||
onClick={(e: React.MouseEvent<HTMLLIElement>) => {
|
||||
e.stopPropagation();
|
||||
if (item.closeMenu) handleClose(e);
|
||||
item.action();
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -28,12 +28,16 @@ export type Header<T> = {
|
||||
type DataTableProps<T extends { id?: string | number; _id?: string | number }> = {
|
||||
headers: Header<T>[];
|
||||
data: T[];
|
||||
onRowClick?: (row: T) => void;
|
||||
};
|
||||
|
||||
export function DataTable<T extends { id?: string | number; _id?: string | number }>({
|
||||
headers,
|
||||
data,
|
||||
}: DataTableProps<T>) {
|
||||
export function DataTable<
|
||||
T extends {
|
||||
id?: string | number;
|
||||
_id?: string | number;
|
||||
onRowClick?: (row: T) => void;
|
||||
},
|
||||
>({ headers, data, onRowClick }: DataTableProps<T>) {
|
||||
const theme = useTheme();
|
||||
if (data.length === 0 || headers.length === 0) return <div>No data</div>;
|
||||
return (
|
||||
@@ -77,7 +81,11 @@ export function DataTable<T extends { id?: string | number; _id?: string | numbe
|
||||
const key = row.id || row._id || Math.random();
|
||||
|
||||
return (
|
||||
<TableRow key={key}>
|
||||
<TableRow
|
||||
key={key}
|
||||
sx={{ cursor: onRowClick ? "pointer" : "default" }}
|
||||
onClick={() => (onRowClick ? onRowClick(row) : null)}
|
||||
>
|
||||
{headers.map((header, index) => {
|
||||
return (
|
||||
<TableCell
|
||||
|
||||
@@ -50,7 +50,7 @@ export const HeaderControls = ({
|
||||
<Button
|
||||
loading={isPatching}
|
||||
onClick={async () => {
|
||||
await patch();
|
||||
await patch(`/monitors/${monitor._id}/active`);
|
||||
refetch();
|
||||
}}
|
||||
startIcon={
|
||||
|
||||
Reference in new issue
Block a user