diff --git a/src/pages/master/plantSection/component/DetailPlantSection.jsx b/src/pages/master/plantSection/component/DetailPlantSection.jsx
index 75be3ef..5515df4 100644
--- a/src/pages/master/plantSection/component/DetailPlantSection.jsx
+++ b/src/pages/master/plantSection/component/DetailPlantSection.jsx
@@ -10,20 +10,41 @@ const DetailPlantSection = (props) => {
const [confirmLoading, setConfirmLoading] = useState(false);
const defaultData = {
- sub_section_id: '',
- sub_section_code: '',
- sub_section_name: '',
+ plant_sub_section_id: '',
+ plant_sub_section_code: '',
+ plant_sub_section_name: '',
+ table_name_value: '', // Fix field name
+ plant_sub_section_description: '',
is_active: true,
};
const [formData, setFormData] = useState(defaultData);
const handleInputChange = (e) => {
- const { name, value } = e.target;
- setFormData({
- ...formData,
- [name]: value,
- });
+ // Handle different input types
+ let name, value;
+
+ if (e && e.target) {
+ // Standard input
+ name = e.target.name;
+ value = e.target.value;
+ } else if (e && e.type === 'change') {
+ // Switch or other components
+ name = e.name || e.target?.name;
+ value = e.value !== undefined ? e.value : e.checked;
+ } else {
+ // Fallback
+ return;
+ }
+
+ console.log(`📝 Input change: ${name} = ${value}`);
+
+ if (name) {
+ setFormData(prev => ({
+ ...prev,
+ [name]: value,
+ }));
+ }
};
const handleCancel = () => {
@@ -36,7 +57,7 @@ const DetailPlantSection = (props) => {
// Daftar aturan validasi
const validationRules = [
- { field: 'sub_section_name', label: 'Plant Sub Section Name', required: true },
+ { field: 'plant_sub_section_name', label: 'Plant Sub Section Name', required: true },
];
if (
@@ -52,14 +73,20 @@ const DetailPlantSection = (props) => {
return;
try {
+ console.log("💾 Current formData before save:", formData);
+
const payload = {
+ plant_sub_section_name: formData.plant_sub_section_name,
+ plant_sub_section_description: formData.plant_sub_section_description,
+ table_name_value: formData.table_name_value, // Fix field name
is_active: formData.is_active,
- sub_section_name: formData.sub_section_name,
};
+ console.log("📤 Payload to be sent:", payload);
+
const response =
props.actionMode === 'edit'
- ? await updatePlantSection(formData.sub_section_id, payload)
+ ? await updatePlantSection(formData.plant_sub_section_id, payload)
: await createPlantSection(payload);
if (response && (response.statusCode === 200 || response.statusCode === 201)) {
@@ -98,9 +125,17 @@ const DetailPlantSection = (props) => {
};
useEffect(() => {
+ console.log("🔄 Modal state changed:", {
+ showModal: props.showModal,
+ actionMode: props.actionMode,
+ selectedData: props.selectedData
+ });
+
if (props.selectedData) {
+ console.log("📋 Setting form data from selectedData:", props.selectedData);
setFormData(props.selectedData);
} else {
+ console.log("📋 Resetting to default data");
setFormData(defaultData);
}
}, [props.showModal, props.selectedData, props.actionMode]);
@@ -195,13 +230,33 @@ const DetailPlantSection = (props) => {