diff --git a/src/pages/master/tag/component/DetailTag.jsx b/src/pages/master/tag/component/DetailTag.jsx index 3c862a9..11ee17a 100644 --- a/src/pages/master/tag/component/DetailTag.jsx +++ b/src/pages/master/tag/component/DetailTag.jsx @@ -3,6 +3,7 @@ import { Modal, Input, Typography, Button, ConfigProvider, Switch, Select } from import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif'; import { createTag, updateTag, getAllTag } from '../../../../api/master-tag'; import { getAllDevice } from '../../../../api/master-device'; +import { getAllPlantSection } from '../../../../api/master-plant-section'; const { Text } = Typography; @@ -10,6 +11,8 @@ const DetailTag = (props) => { const [confirmLoading, setConfirmLoading] = useState(false); const [deviceList, setDeviceList] = useState([]); const [loadingDevices, setLoadingDevices] = useState(false); + const [plantSubSectionList, setPlantSubSectionList] = useState([]); + const [loadingPlantSubSections, setLoadingPlantSubSections] = useState(false); const defaultData = { tag_id: '', @@ -224,7 +227,6 @@ const DetailTag = (props) => { const params = new URLSearchParams({ limit: 1000 }); const response = await getAllDevice(params); if (response && response.data && response.data.data) { - console.log('Loaded devices:', response.data.data); // Debug setDeviceList(response.data.data); } } catch (error) { @@ -234,12 +236,33 @@ const DetailTag = (props) => { } }; + const loadPlantSubSections = async () => { + setLoadingPlantSubSections(true); + try { + const params = new URLSearchParams({ limit: 1000 }); + const response = await getAllPlantSection(params); + + if (response && response.data && response.data.data) { + // Filter hanya plant sub section yang active + const activePlantSubSections = response.data.data.filter( + (section) => section.is_active === true + ); + setPlantSubSectionList(activePlantSubSections); + } + } catch (error) { + console.error('Error loading plant sub sections:', error); + } finally { + setLoadingPlantSubSections(false); + } + }; + useEffect(() => { const token = localStorage.getItem('token'); if (token) { if (props.showModal) { - // Load devices when modal opens + // Load devices and plant sub sections when modal opens loadDevices(); + loadPlantSubSections(); } if (props.selectedData != null) { @@ -422,7 +445,7 @@ const DetailTag = (props) => { * { style={{ backgroundColor: '#f5f5f5' }} /> + + Plant Sub Section Name + handleSelectChange('sub_section_id', value)} + disabled={props.readOnly} + loading={loadingPlantSubSections} + showSearch + allowClear + optionFilterProp="children" + filterOption={(input, option) => { + const text = option.children; + if (!text) return false; + return text.toLowerCase().includes(input.toLowerCase()); + }} + > + {plantSubSectionList.map((section) => ( + + {section.sub_section_name || ''} + + ))} + + {/* Device ID hidden - value dari dropdown */}