From bddd249e072062d742ee97e49eebfe23ea6c52dd Mon Sep 17 00:00:00 2001 From: Vinix Date: Thu, 23 Oct 2025 15:22:44 +0700 Subject: [PATCH] join tag on unit --- .../master/unit/component/DetailUnit.jsx | 79 +++++++++++++++++-- 1 file changed, 71 insertions(+), 8 deletions(-) diff --git a/src/pages/master/unit/component/DetailUnit.jsx b/src/pages/master/unit/component/DetailUnit.jsx index 12ca110..cc7c2fb 100644 --- a/src/pages/master/unit/component/DetailUnit.jsx +++ b/src/pages/master/unit/component/DetailUnit.jsx @@ -1,13 +1,16 @@ import React, { useEffect, useState } from 'react'; -import { Modal, Input, Typography, Switch, Button, ConfigProvider, Divider } from 'antd'; +import { Modal, Input, Typography, Switch, Button, ConfigProvider, Divider, Select } from 'antd'; import { NotifOk } from '../../../../components/Global/ToastNotif'; import { createUnit, updateUnit } from '../../../../api/master-unit'; +import { getAllTag } from '../../../../api/master-tag'; // Import API untuk Tag import { validateRun } from '../../../../Utils/validate'; const { Text } = Typography; const DetailUnit = (props) => { const [confirmLoading, setConfirmLoading] = useState(false); + const [tagList, setTagList] = useState([]); + const [loadingTags, setLoadingTags] = useState(false); const defaultData = { unit_id: '', @@ -15,10 +18,28 @@ const DetailUnit = (props) => { unit_name: '', unit_description: '', is_active: true, + tag_id: null, // Tambahkan tag_id }; const [formData, setFormData] = useState(defaultData); + // Fungsi untuk mengambil data Tag + const loadTags = async () => { + setLoadingTags(true); + try { + const params = new URLSearchParams({ limit: 1000, criteria: '' }); + const response = await getAllTag(params); + if (response && response.data) { + const activeTags = response.data.filter((tag) => tag.is_active === true); + setTagList(activeTags); + } + } catch (error) { + console.error('Error loading tags:', error); + } finally { + setLoadingTags(false); + } + }; + const handleCancel = () => { props.setSelectedData(null); props.setActionMode('list'); @@ -27,8 +48,10 @@ const DetailUnit = (props) => { const handleSave = async () => { setConfirmLoading(true); - // Daftar aturan validasi - const validationRules = [{ field: 'unit_name', label: 'Unit Name', required: true }]; + const validationRules = [ + { field: 'unit_name', label: 'Unit Name', required: true }, + { field: 'tag_id', label: 'Tag', required: true }, // Tambah validasi untuk tag_id + ]; if ( validateRun(formData, validationRules, (errorMessages) => { @@ -39,14 +62,16 @@ const DetailUnit = (props) => { }); setConfirmLoading(false); }) - ) + ) { return; + } try { const payload = { - is_active: formData.is_active, unit_name: formData.unit_name, unit_description: formData.unit_description, + is_active: formData.is_active, + tag_id: formData.tag_id, // Tambahkan tag_id ke payload }; const response = @@ -90,6 +115,13 @@ const DetailUnit = (props) => { }); }; + const handleSelectChange = (name, value) => { + setFormData({ + ...formData, + [name]: value, + }); + }; + const handleStatusToggle = (checked) => { setFormData({ ...formData, @@ -98,6 +130,10 @@ const DetailUnit = (props) => { }; useEffect(() => { + if (props.showModal) { + loadTags(); // Panggil fungsi loadTags saat modal muncul + } + if (props.selectedData) { setFormData(props.selectedData); } else { @@ -116,6 +152,7 @@ const DetailUnit = (props) => { } Unit`} open={props.showModal} onCancel={handleCancel} + width={600} footer={[ { - {/* Unit Code - Auto Increment & Read Only */}
Unit Code { />
+
+ Tag + * + +
+
Unit Name * @@ -221,4 +284,4 @@ const DetailUnit = (props) => { ); }; -export default DetailUnit; +export default DetailUnit; \ No newline at end of file