import { FormControl, FormHelperText, Input, Typography } from '@mui/joy'
import { useState } from 'react'
import ModalActions from '../../../components/common/ModalActions'
import { useResponsiveModal } from '../../../hooks/useResponsiveModal'
function EditThingStateModal({ isOpen, onClose, onSave, currentThing }) {
const { ResponsiveModal } = useResponsiveModal()
const [state, setState] = useState(currentThing?.state || '')
const [errors, setErrors] = useState({})
const isValid = () => {
const newErrors = {}
if (state.trim() === '') {
newErrors.state = 'State is required'
}
setErrors(newErrors)
return Object.keys(newErrors).length === 0
}
const handleSave = () => {
if (!isValid()) {
return
}
onSave({
name: currentThing?.name,
type: currentThing?.type,
id: currentThing?.id,
state: state || null,
})
onClose()
}
return (
}
>
Value
setState(e.target.value)}
sx={{ minWidth: 300 }}
/>
{errors.state}
)
}
export default EditThingStateModal