From 4544e33d01e1498cdfdce9fe0d99739e8dc14113 Mon Sep 17 00:00:00 2001 From: Rafiafrzl Date: Thu, 30 Oct 2025 15:15:26 +0700 Subject: [PATCH] fix is_active error code ft vinix --- .../brandDevice/component/BrandForm.jsx | 7 +-- .../brandDevice/component/ErrorCodeForm.jsx | 5 +- .../brandDevice/component/SolutionField.jsx | 46 ++++++++----------- .../master/brandDevice/hooks/errorCode.js | 4 +- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/pages/master/brandDevice/component/BrandForm.jsx b/src/pages/master/brandDevice/component/BrandForm.jsx index 42365c4..046045b 100644 --- a/src/pages/master/brandDevice/component/BrandForm.jsx +++ b/src/pages/master/brandDevice/component/BrandForm.jsx @@ -4,6 +4,8 @@ import { Form, Input, Row, Col, Typography, Switch } from 'antd'; const { Text } = Typography; const BrandForm = ({ form, formData, onValuesChange, isEdit = false }) => { + const isActive = Form.useWatch('is_active', form) ?? formData.is_active ?? true; + return (
{
- {formData.is_active ? 'Running' : 'Offline'} + {isActive ? 'Running' : 'Offline'}
diff --git a/src/pages/master/brandDevice/component/ErrorCodeForm.jsx b/src/pages/master/brandDevice/component/ErrorCodeForm.jsx index fbfaff2..1001aa5 100644 --- a/src/pages/master/brandDevice/component/ErrorCodeForm.jsx +++ b/src/pages/master/brandDevice/component/ErrorCodeForm.jsx @@ -112,6 +112,7 @@ const ErrorCodeForm = ({ const solutionName = values[`solution_name_${fieldId}`]; const textSolution = values[`text_solution_${fieldId}`]; + const solutionStatus = values[`solution_status_${fieldId}`]; const filesForSolution = fileList.filter((file) => file.solutionId === fieldId); const solutionType = values[`solution_type_${fieldId}`] || solutionTypes[fieldId]; @@ -122,7 +123,7 @@ const ErrorCodeForm = ({ type_solution: 'text', text_solution: textSolution.trim(), path_solution: '', - is_active: solutionStatuses[fieldId] !== false, + is_active: solutionStatus !== undefined ? solutionStatus : true, }; if (window.currentSolutionData && window.currentSolutionData[fieldId]) { @@ -145,7 +146,7 @@ const ErrorCodeForm = ({ (file.type.startsWith('image/') ? 'image' : 'pdf'), text_solution: '', path_solution: file.uploadPath, - is_active: solutionStatuses[fieldId] !== false, + is_active: solutionStatus !== undefined ? solutionStatus : true, }; if (window.currentSolutionData && window.currentSolutionData[fieldId]) { diff --git a/src/pages/master/brandDevice/component/SolutionField.jsx b/src/pages/master/brandDevice/component/SolutionField.jsx index 7df25d7..dca30ec 100644 --- a/src/pages/master/brandDevice/component/SolutionField.jsx +++ b/src/pages/master/brandDevice/component/SolutionField.jsx @@ -20,6 +20,8 @@ const SolutionField = ({ onFileView, errorCodeForm, }) => { + // Watch the solution status from the form + const watchedStatus = Form.useWatch(`solution_status_${fieldId}`, errorCodeForm); useEffect(() => { if (currentSolutionData && errorCodeForm) { if (currentSolutionData.solution_name) { @@ -146,34 +148,22 @@ const SolutionField = ({ - - prevValues[`solution_status_${fieldId}`] !== - currentValues[`solution_status_${fieldId}`] - } - noStyle - > - {({ getFieldValue, setFieldValue }) => { - const currentStatus = getFieldValue(`solution_status_${fieldId}`); - return ( -
- { - setFieldValue(`solution_status_${fieldId}`, checked); - }} - disabled={isReadOnly} - style={{ - backgroundColor: solutionStatus ? '#23A55A' : '#bfbfbf', - }} - /> - - {currentStatus === true ? 'Active' : 'Non Active'} - -
- ); - }} -
+
+ + { + onSolutionStatusChange(fieldId, checked); + }} + style={{ + backgroundColor: (watchedStatus ?? true) ? '#23A55A' : '#bfbfbf', + }} + /> + + + {(watchedStatus ?? true) ? 'Active' : 'Non Active'} + +
diff --git a/src/pages/master/brandDevice/hooks/errorCode.js b/src/pages/master/brandDevice/hooks/errorCode.js index f1d3e9f..0d748d5 100644 --- a/src/pages/master/brandDevice/hooks/errorCode.js +++ b/src/pages/master/brandDevice/hooks/errorCode.js @@ -194,9 +194,7 @@ export const useErrorCodeLogic = (errorCodeForm, fileList) => { }; const handleSolutionStatusChange = (fieldId, status) => { - // Update form immediately - errorCodeForm.setFieldValue(`solution_status_${fieldId}`, status); - // Then update local state + // Only update local state - form is already updated by Form.Item setSolutionStatuses(prev => ({ ...prev, [fieldId]: status