import CancelIcon from '@mui/icons-material/Cancel'; import CloseIcon from '@mui/icons-material/Close'; import DoneIcon from '@mui/icons-material/Done'; import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, Grid, TextField, Typography } from '@mui/material'; import { useEffect, useState } from 'react'; import EntityMaskToggle from './EntityMaskToggle'; import { DeviceEntityMask } from './types'; import type { DeviceEntity } from './types'; import { dialogStyle } from 'CustomTheme'; import { useI18nContext } from 'i18n/i18n-react'; import { updateValue } from 'utils'; type SettingsCustomizationDialogProps = { open: boolean; onClose: () => void; onSave: (di: DeviceEntity) => void; selectedItem: DeviceEntity; }; const SettingsCustomizationDialog = ({ open, onClose, onSave, selectedItem }: SettingsCustomizationDialogProps) => { const { LL } = useI18nContext(); const [editItem, setEditItem] = useState(selectedItem); const [error, setError] = useState(false); const updateFormValue = updateValue(setEditItem); const isWriteableNumber = typeof editItem.v === 'number' && editItem.w && !(editItem.m & DeviceEntityMask.DV_READONLY); useEffect(() => { if (open) { setError(false); setEditItem(selectedItem); } }, [open, selectedItem]); const close = () => { onClose(); }; const save = () => { if (isWriteableNumber && editItem.mi && editItem.ma && editItem.mi > editItem?.ma) { setError(true); } else { onSave(editItem); } }; const updateDeviceEntity = (updatedItem: DeviceEntity) => { setEditItem({ ...editItem, m: updatedItem.m }); }; return ( {LL.EDIT() + ' ' + LL.ENTITY()} {LL.ID_OF(LL.ENTITY())}:  {editItem.id} {LL.DEFAULT(1) + ' ' + LL.ENTITY_NAME(1)}:  {editItem.n} {LL.WRITEABLE()}:  {editItem.w ? ( ) : ( )} {isWriteableNumber && ( <> )} {error && ( Error: Check min and max values )} ); }; export default SettingsCustomizationDialog;