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:
@@ -23,6 +23,7 @@ const DetailDevice = (props) => {
|
|||||||
device_location: '',
|
device_location: '',
|
||||||
device_description: '',
|
device_description: '',
|
||||||
ip_address: '',
|
ip_address: '',
|
||||||
|
listen_channel: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const [formData, setFormData] = useState(defaultData);
|
const [formData, setFormData] = useState(defaultData);
|
||||||
@@ -59,9 +60,10 @@ const DetailDevice = (props) => {
|
|||||||
device_name: formData.device_name,
|
device_name: formData.device_name,
|
||||||
is_active: formData.is_active,
|
is_active: formData.is_active,
|
||||||
device_location: formData.device_location,
|
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,
|
ip_address: formData.ip_address,
|
||||||
brand_id: formData.brand_id,
|
brand_id: formData.brand_id,
|
||||||
|
listen_channel: formData.listen_channel,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = formData.device_id
|
const response = formData.device_id
|
||||||
@@ -326,6 +328,16 @@ const DetailDevice = (props) => {
|
|||||||
readOnly={props.readOnly}
|
readOnly={props.readOnly}
|
||||||
/>
|
/>
|
||||||
</div>
|
</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 }}>
|
<div style={{ marginBottom: 12 }}>
|
||||||
<Text strong>Device Description</Text>
|
<Text strong>Device Description</Text>
|
||||||
<TextArea
|
<TextArea
|
||||||
|
|||||||
@@ -62,6 +62,13 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [
|
|||||||
key: 'ip_address',
|
key: 'ip_address',
|
||||||
width: '10%',
|
width: '10%',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: 'Listen Channel',
|
||||||
|
dataIndex: 'listen_channel',
|
||||||
|
key: 'listen_channel',
|
||||||
|
width: '10%',
|
||||||
|
render: (listen_channel) => listen_channel || '-'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: 'Status',
|
title: 'Status',
|
||||||
dataIndex: 'is_active',
|
dataIndex: 'is_active',
|
||||||
|
|||||||
@@ -21,8 +21,15 @@ const SparepartCardList = ({
|
|||||||
const [loadingQuantities, setLoadingQuantities] = useState({});
|
const [loadingQuantities, setLoadingQuantities] = useState({});
|
||||||
|
|
||||||
const handleQuantityChange = (id, value) => {
|
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 };
|
const newQuantities = { ...updateQuantities };
|
||||||
newQuantities[id] = value;
|
newQuantities[id] = clampedValue;
|
||||||
setUpdateQuantities(newQuantities);
|
setUpdateQuantities(newQuantities);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -319,7 +326,9 @@ const SparepartCardList = ({
|
|||||||
quantity - 1
|
quantity - 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
disabled={isLoading}
|
disabled={
|
||||||
|
isLoading || item.sparepart_qty + quantity <= 0
|
||||||
|
}
|
||||||
style={{ width: 28, height: 28 }}
|
style={{ width: 28, height: 28 }}
|
||||||
/>
|
/>
|
||||||
<Text
|
<Text
|
||||||
|
|||||||
Reference in New Issue
Block a user