konect brand device on device

This commit is contained in:
2025-11-19 15:57:38 +07:00
parent b5fbf2f745
commit 6a21b65808
2 changed files with 65 additions and 17 deletions

View File

@@ -1,7 +1,8 @@
import React, { useEffect, useState } from 'react';
import { Modal, Input, Divider, Typography, Switch, Button, ConfigProvider } from 'antd';
import { Modal, Input, Divider, Typography, Switch, Button, ConfigProvider, Select } from 'antd';
import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif';
import { createDevice, updateDevice } from '../../../../api/master-device';
import { getAllBrands } from '../../../../api/master-brand';
import { validateRun } from '../../../../Utils/validate';
const { Text } = Typography;
@@ -9,12 +10,15 @@ const { TextArea } = Input;
const DetailDevice = (props) => {
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) => {
<div style={{ marginBottom: 12 }}>
<Text strong>Brand Device</Text>
<Text style={{ color: 'red' }}> *</Text>
<Input
name="brand_device"
value={formData.brand_device}
onChange={handleInputChange}
placeholder="Enter Brand Device"
readOnly={props.readOnly}
disabled
style={{
backgroundColor: '#f5f5f5',
cursor: 'not-allowed',
color: formData.brand_device ? '#000000' : '#bfbfbf',
}}
/>
<Select
name="brand_id"
value={formData.brand_id}
onChange={(value) => 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) => (
<Select.Option key={brand.brand_id} value={brand.brand_id}>
{`${brand.brand_code} - ${brand.brand_name} `}
</Select.Option>
))}
</Select>
</div>
<div style={{ marginBottom: 12 }}>
<Text strong>Device Location</Text>

View File

@@ -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',