diff --git a/src/pages/contact/component/ListContact.jsx b/src/pages/contact/component/ListContact.jsx index f6ff048..936361d 100644 --- a/src/pages/contact/component/ListContact.jsx +++ b/src/pages/contact/component/ListContact.jsx @@ -122,7 +122,7 @@ const ContactCard = memo(function ContactCard({ contact, showEditModal, showDele {contact.contact_phone || contact.phone} @@ -142,10 +142,12 @@ const ContactCard = memo(function ContactCard({ contact, showEditModal, showDele > { const [confirmLoading, setConfirmLoading] = useState(false); + const [brands, setBrands] = useState([]); + const [loadingBrands, setLoadingBrands] = useState(false); const defaultData = { device_id: '', device_code: '', device_name: '', - brand_device: '', + brand_id: '', + brand_code: '', is_active: true, device_location: '', device_description: '', @@ -35,6 +39,7 @@ const DetailDevice = (props) => { const validationRules = [ { field: 'device_name', label: 'Device Name', required: true }, { field: 'ip_address', label: 'Ip Address', required: true, ip: true }, + { field: 'brand_id', label: 'Brand Device', required: true }, ]; if ( @@ -56,6 +61,7 @@ const DetailDevice = (props) => { device_location: formData.device_location, device_description: formData.device_description, ip_address: formData.ip_address, + brand_id: formData.brand_id, }; const response = formData.device_id @@ -102,6 +108,13 @@ const DetailDevice = (props) => { }); }; + const handleSelectChange = (name, value) => { + setFormData({ + ...formData, + [name]: value, + }); + }; + const handleStatusToggle = (event) => { const isChecked = event; setFormData({ @@ -110,6 +123,32 @@ const DetailDevice = (props) => { }); }; + // Fungsi untuk mengambil daftar brand + const fetchBrands = async () => { + setLoadingBrands(true); + try { + const response = await getAllBrands(new URLSearchParams()); + if (response && response.data) { + setBrands(response.data || []); + } + } catch (error) { + console.error('Error fetching brands:', error); + NotifAlert({ + icon: 'error', + title: 'Error', + message: error.message || 'Gagal mengambil data brand', + }); + } finally { + setLoadingBrands(false); + } + }; + + useEffect(() => { + if (props.showModal && (props.actionMode === 'add' || props.actionMode === 'edit')) { + fetchBrands(); + } + }, [props.showModal, props.actionMode]); + useEffect(() => { if (props.selectedData) { setFormData(props.selectedData); @@ -244,19 +283,26 @@ const DetailDevice = (props) => { Brand Device * - + handleSelectChange('brand_id', value)} + placeholder="Select Brand Device" + disabled={props.readOnly} + loading={loadingBrands} + style={{ width: '100%' }} + allowClear + showSearch + filterOption={(input, option) => + option.children.toLowerCase().includes(input.toLowerCase()) + } + > + {brands.map((brand) => ( + + {`${brand.brand_code} - ${brand.brand_name} `} + + ))} + Device Location diff --git a/src/pages/master/device/component/ListDevice.jsx b/src/pages/master/device/component/ListDevice.jsx index d3cf0b9..ae7fcb4 100644 --- a/src/pages/master/device/component/ListDevice.jsx +++ b/src/pages/master/device/component/ListDevice.jsx @@ -13,6 +13,7 @@ import { NotifAlert, NotifOk, NotifConfirmDialog } from '../../../../components/ import { useNavigate } from 'react-router-dom'; import { deleteDevice, getAllDevice } from '../../../../api/master-device'; import TableList from '../../../../components/Global/TableList'; +import { getAllBrands } from '../../../../api/master-brand'; const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ { @@ -44,9 +45,10 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ }, { title: 'Brand Device', - dataIndex: 'brand_device', - key: 'brand_device', + dataIndex: 'brand_name', + key: 'brand_name', width: '20%', + render: (brand_name) => brand_name || '-' }, { title: 'Location',