feat: update data structure for tag history and adjust related components for consistency
This commit is contained in:
@@ -26,7 +26,7 @@ const DetailDevice = (props) => {
|
||||
device_id: '',
|
||||
device_code: '',
|
||||
device_name: '',
|
||||
device_status: true,
|
||||
is_active: true,
|
||||
device_location: 'Building A',
|
||||
device_description: '',
|
||||
ip_address: '',
|
||||
@@ -139,7 +139,7 @@ const DetailDevice = (props) => {
|
||||
// Backend validation schema doesn't include device_code
|
||||
const payload = {
|
||||
device_name: FormData.device_name,
|
||||
device_status: FormData.device_status,
|
||||
is_active: FormData.is_active,
|
||||
device_location: FormData.device_location,
|
||||
ip_address: FormData.ip_address,
|
||||
};
|
||||
@@ -211,11 +211,10 @@ const DetailDevice = (props) => {
|
||||
const isChecked = event;
|
||||
setFormData({
|
||||
...FormData,
|
||||
device_status: isChecked ? true : false,
|
||||
is_active: isChecked ? true : false,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
@@ -312,16 +311,14 @@ const DetailDevice = (props) => {
|
||||
disabled={props.readOnly}
|
||||
style={{
|
||||
backgroundColor:
|
||||
FormData.device_status === true ? '#23A55A' : '#bfbfbf',
|
||||
FormData.is_active === true ? '#23A55A' : '#bfbfbf',
|
||||
}}
|
||||
checked={FormData.device_status === true}
|
||||
checked={FormData.is_active === true}
|
||||
onChange={handleStatusToggle}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Text>
|
||||
{FormData.device_status === true ? 'Running' : 'Offline'}
|
||||
</Text>
|
||||
<Text>{FormData.is_active === true ? 'Running' : 'Offline'}</Text>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -16,7 +16,7 @@ const DetailTag = (props) => {
|
||||
|
||||
const defaultData = {
|
||||
tag_id: '',
|
||||
tag_code: '',
|
||||
|
||||
tag_name: '',
|
||||
tag_number: '',
|
||||
data_type: '',
|
||||
@@ -24,8 +24,7 @@ const DetailTag = (props) => {
|
||||
is_active: true,
|
||||
is_alarm: false,
|
||||
device_id: null,
|
||||
device_code: '',
|
||||
device_name: '',
|
||||
|
||||
sub_section_id: null,
|
||||
};
|
||||
|
||||
@@ -118,6 +117,18 @@ const DetailTag = (props) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validasi data type harus Diskrit atau Analog
|
||||
const validDataTypes = ['Diskrit', 'Analog'];
|
||||
if (!validDataTypes.includes(FormData.data_type)) {
|
||||
NotifOk({
|
||||
icon: 'warning',
|
||||
title: 'Peringatan',
|
||||
message: `Data Type harus "Diskrit" atau "Analog". Nilai "${FormData.data_type}" tidak valid. Silakan pilih dari dropdown.`,
|
||||
});
|
||||
setConfirmLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FormData.unit || FormData.unit.trim() === '') {
|
||||
NotifOk({
|
||||
icon: 'warning',
|
||||
@@ -141,17 +152,22 @@ const DetailTag = (props) => {
|
||||
|
||||
// Prepare payload berdasarkan backend validation schema
|
||||
const payload = {
|
||||
tag_name: FormData.tag_name,
|
||||
tag_name: FormData.tag_name.trim(),
|
||||
tag_number: parseInt(FormData.tag_number),
|
||||
data_type: FormData.data_type,
|
||||
unit: FormData.unit,
|
||||
unit: FormData.unit.trim(),
|
||||
is_active: FormData.is_active,
|
||||
is_alarm: FormData.is_alarm,
|
||||
device_id: parseInt(FormData.device_id),
|
||||
device_code: FormData.device_code,
|
||||
device_name: FormData.device_name,
|
||||
};
|
||||
|
||||
// Add sub_section_id only if it's selected
|
||||
if (FormData.sub_section_id) {
|
||||
payload.sub_section_id = parseInt(FormData.sub_section_id);
|
||||
}
|
||||
|
||||
// Debug logging
|
||||
|
||||
try {
|
||||
let response;
|
||||
|
||||
@@ -185,6 +201,7 @@ const DetailTag = (props) => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Save Tag Error:', error);
|
||||
console.error('Error details:', error);
|
||||
NotifAlert({
|
||||
icon: 'error',
|
||||
title: 'Error',
|
||||
@@ -215,8 +232,6 @@ const DetailTag = (props) => {
|
||||
setFormData({
|
||||
...FormData,
|
||||
device_id: deviceId,
|
||||
device_code: selectedDevice?.device_code || '',
|
||||
device_name: selectedDevice?.device_name || '',
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -51,6 +51,13 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [
|
||||
key: 'unit',
|
||||
width: '8%',
|
||||
},
|
||||
{
|
||||
title: 'Sub Section',
|
||||
dataIndex: 'sub_section_name',
|
||||
key: 'sub_section_name',
|
||||
width: '12%',
|
||||
render: (text) => text || '-',
|
||||
},
|
||||
{
|
||||
title: 'Device',
|
||||
dataIndex: 'device_name',
|
||||
|
||||
Reference in New Issue
Block a user