import { mdiIp } from "@mdi/js"; import Icon from "@mdi/react"; import DeleteIcon from "@mui/icons-material/Delete"; import { Avatar, Button, IconButton, ListItem, ListItemAvatar, ListItemText, Paper, Tooltip, Typography, } from "@mui/material"; import { DHCPConfig, DHCPHost } from "../../api/NetworksApi"; import { ServerApi } from "../../api/ServerApi"; import { useConfirm } from "../../hooks/providers/ConfirmDialogProvider"; import { IPInput } from "./IPInput"; import { MACInput } from "./MACInput"; import { TextInput } from "./TextInput"; import Grid from "@mui/material/Grid2"; export function NetDHCPHostReservations(p: { editable: boolean; dhcp: DHCPConfig; version: 4 | 6; onChange?: (d: DHCPConfig) => void; }): React.ReactElement { const addHost = () => { p.dhcp.hosts.push({ ip: p.version === 4 ? "192.168.1.30" : "fd00::b200", name: "host", mac: p.version === 4 ? "00:00:00:00:00:00" : undefined, }); p.onChange?.(p.dhcp); }; return ( <> {p.dhcp.hosts.map((h, num) => ( { p.onChange?.(p.dhcp); }} host={h} onRemove={() => { p.dhcp.hosts.splice(num, 1); p.onChange?.(p.dhcp); }} /> ))} {p.dhcp.hosts.length === 0 && ( You have not set any DHCP host reservations. )} {p.editable && ( Add new host reservation )} > ); } function HostReservationWidget(p: { editable: boolean; host: DHCPHost; version: 4 | 6; onChange: () => void; onRemove: () => void; }): React.ReactElement { const confirm = useConfirm(); const deleteReservation = async () => { if ( !(await confirm("Do you really want to remove this host IP reservation?")) ) return; p.onRemove(); }; return ( ) } > { p.host.name = v!; p.onChange(); }} type="text" size={ServerApi.Config.constraints.dhcp_reservation_host_name} /> } /> {p.version === 4 && ( { p.host.mac = v!; p.onChange?.(); }} /> )} { p.host.ip = v!; p.onChange?.(); }} /> ); }