feat: add listen channel field to DetailDevice component and update ListDevice to display it; enhance quantity handling in SparepartCardList to prevent negative adjustments

This commit is contained in:
2025-12-04 15:59:57 +07:00
parent 147171373c
commit acaf1b3946
3 changed files with 31 additions and 3 deletions

View File

@@ -23,6 +23,7 @@ const DetailDevice = (props) => {
device_location: '',
device_description: '',
ip_address: '',
listen_channel: '',
};
const [formData, setFormData] = useState(defaultData);
@@ -59,9 +60,10 @@ const DetailDevice = (props) => {
device_name: formData.device_name,
is_active: formData.is_active,
device_location: formData.device_location,
device_description: formData.device_description,
device_description: (formData.device_description && formData.device_description.trim() !== '') ? formData.device_description : ' ',
ip_address: formData.ip_address,
brand_id: formData.brand_id,
listen_channel: formData.listen_channel,
};
const response = formData.device_id
@@ -326,6 +328,16 @@ const DetailDevice = (props) => {
readOnly={props.readOnly}
/>
</div>
<div style={{ marginBottom: 12 }}>
<Text strong>Listen Channel</Text>
<Input
name="listen_channel"
value={formData.listen_channel}
onChange={handleInputChange}
placeholder="Enter Listen Channel"
readOnly={props.readOnly}
/>
</div>
<div style={{ marginBottom: 12 }}>
<Text strong>Device Description</Text>
<TextArea

View File

@@ -62,6 +62,13 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [
key: 'ip_address',
width: '10%',
},
{
title: 'Listen Channel',
dataIndex: 'listen_channel',
key: 'listen_channel',
width: '10%',
render: (listen_channel) => listen_channel || '-'
},
{
title: 'Status',
dataIndex: 'is_active',

View File

@@ -21,8 +21,15 @@ const SparepartCardList = ({
const [loadingQuantities, setLoadingQuantities] = useState({});
const handleQuantityChange = (id, value) => {
// Prevent the adjustment from going below the negative value of the original quantity
// This ensures the final quantity (original + adjustment) never goes below 0
const originalQty = data.find((item) => item.sparepart_id === id)?.sparepart_qty || 0;
const maxNegativeAdjustment = -originalQty;
const clampedValue = Math.max(value, maxNegativeAdjustment);
const newQuantities = { ...updateQuantities };
newQuantities[id] = value;
newQuantities[id] = clampedValue;
setUpdateQuantities(newQuantities);
};
@@ -319,7 +326,9 @@ const SparepartCardList = ({
quantity - 1
)
}
disabled={isLoading}
disabled={
isLoading || item.sparepart_qty + quantity <= 0
}
style={{ width: 28, height: 28 }}
/>
<Text