connection-item.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import dayjs from "dayjs";
  2. import { useLockFn } from "ahooks";
  3. import { styled, ListItem, IconButton, ListItemText } from "@mui/material";
  4. import { CloseRounded } from "@mui/icons-material";
  5. import { ApiType } from "../../services/types";
  6. import { deleteConnection } from "../../services/api";
  7. const Tag = styled("span")(({ theme }) => ({
  8. display: "inline-block",
  9. fontSize: "12px",
  10. padding: "0 4px",
  11. lineHeight: 1.375,
  12. border: "1px solid #ccc",
  13. borderRadius: 4,
  14. marginRight: "0.1em",
  15. transform: "scale(0.92)",
  16. }));
  17. interface Props {
  18. value: ApiType.ConnectionsItem;
  19. }
  20. const ConnectionItem = (props: Props) => {
  21. const { value } = props;
  22. const onDelete = useLockFn(async () => deleteConnection(value.id));
  23. return (
  24. <ListItem
  25. dense
  26. secondaryAction={
  27. <IconButton edge="end" onClick={onDelete}>
  28. <CloseRounded />
  29. </IconButton>
  30. }
  31. >
  32. <ListItemText
  33. primary={value.metadata.host || value.metadata.destinationIP}
  34. secondary={
  35. <>
  36. <Tag sx={{ textTransform: "uppercase", color: "success" }}>
  37. {value.metadata.network}
  38. </Tag>
  39. <Tag>{value.metadata.type}</Tag>
  40. {value.chains.length > 0 && (
  41. <Tag>{value.chains[value.chains.length - 1]}</Tag>
  42. )}
  43. <Tag>{dayjs(value.start).fromNow()}</Tag>
  44. </>
  45. }
  46. />
  47. </ListItem>
  48. );
  49. };
  50. export default ConnectionItem;