fix is_active error code ft vinix

This commit is contained in:
2025-10-30 15:15:26 +07:00
parent 114ef96de8
commit 4544e33d01
4 changed files with 26 additions and 36 deletions

View File

@@ -4,6 +4,8 @@ import { Form, Input, Row, Col, Typography, Switch } from 'antd';
const { Text } = Typography; const { Text } = Typography;
const BrandForm = ({ form, formData, onValuesChange, isEdit = false }) => { const BrandForm = ({ form, formData, onValuesChange, isEdit = false }) => {
const isActive = Form.useWatch('is_active', form) ?? formData.is_active ?? true;
return ( return (
<Form <Form
layout="vertical" layout="vertical"
@@ -15,12 +17,11 @@ const BrandForm = ({ form, formData, onValuesChange, isEdit = false }) => {
<div style={{ display: 'flex', alignItems: 'center' }}> <div style={{ display: 'flex', alignItems: 'center' }}>
<Form.Item name="is_active" valuePropName="checked" noStyle> <Form.Item name="is_active" valuePropName="checked" noStyle>
<Switch <Switch
checked={formData.is_active} style={{ backgroundColor: isActive ? '#23A55A' : '#bfbfbf' }}
style={{ backgroundColor: formData.is_active ? '#23A55A' : '#bfbfbf' }}
/> />
</Form.Item> </Form.Item>
<Text style={{ marginLeft: 8 }}> <Text style={{ marginLeft: 8 }}>
{formData.is_active ? 'Running' : 'Offline'} {isActive ? 'Running' : 'Offline'}
</Text> </Text>
</div> </div>
</Form.Item> </Form.Item>

View File

@@ -112,6 +112,7 @@ const ErrorCodeForm = ({
const solutionName = values[`solution_name_${fieldId}`]; const solutionName = values[`solution_name_${fieldId}`];
const textSolution = values[`text_solution_${fieldId}`]; const textSolution = values[`text_solution_${fieldId}`];
const solutionStatus = values[`solution_status_${fieldId}`];
const filesForSolution = fileList.filter((file) => file.solutionId === fieldId); const filesForSolution = fileList.filter((file) => file.solutionId === fieldId);
const solutionType = values[`solution_type_${fieldId}`] || solutionTypes[fieldId]; const solutionType = values[`solution_type_${fieldId}`] || solutionTypes[fieldId];
@@ -122,7 +123,7 @@ const ErrorCodeForm = ({
type_solution: 'text', type_solution: 'text',
text_solution: textSolution.trim(), text_solution: textSolution.trim(),
path_solution: '', path_solution: '',
is_active: solutionStatuses[fieldId] !== false, is_active: solutionStatus !== undefined ? solutionStatus : true,
}; };
if (window.currentSolutionData && window.currentSolutionData[fieldId]) { if (window.currentSolutionData && window.currentSolutionData[fieldId]) {
@@ -145,7 +146,7 @@ const ErrorCodeForm = ({
(file.type.startsWith('image/') ? 'image' : 'pdf'), (file.type.startsWith('image/') ? 'image' : 'pdf'),
text_solution: '', text_solution: '',
path_solution: file.uploadPath, path_solution: file.uploadPath,
is_active: solutionStatuses[fieldId] !== false, is_active: solutionStatus !== undefined ? solutionStatus : true,
}; };
if (window.currentSolutionData && window.currentSolutionData[fieldId]) { if (window.currentSolutionData && window.currentSolutionData[fieldId]) {

View File

@@ -20,6 +20,8 @@ const SolutionField = ({
onFileView, onFileView,
errorCodeForm, errorCodeForm,
}) => { }) => {
// Watch the solution status from the form
const watchedStatus = Form.useWatch(`solution_status_${fieldId}`, errorCodeForm);
useEffect(() => { useEffect(() => {
if (currentSolutionData && errorCodeForm) { if (currentSolutionData && errorCodeForm) {
if (currentSolutionData.solution_name) { if (currentSolutionData.solution_name) {
@@ -146,34 +148,22 @@ const SolutionField = ({
</Form.Item> </Form.Item>
<Form.Item label="Status"> <Form.Item label="Status">
<Form.Item
shouldUpdate={(prevValues, currentValues) =>
prevValues[`solution_status_${fieldId}`] !==
currentValues[`solution_status_${fieldId}`]
}
noStyle
>
{({ getFieldValue, setFieldValue }) => {
const currentStatus = getFieldValue(`solution_status_${fieldId}`);
return (
<div style={{ display: 'flex', alignItems: 'center' }}> <div style={{ display: 'flex', alignItems: 'center' }}>
<Form.Item name={`solution_status_${fieldId}`} valuePropName="checked" noStyle>
<Switch <Switch
checked={currentStatus === true}
onChange={(checked) => {
setFieldValue(`solution_status_${fieldId}`, checked);
}}
disabled={isReadOnly} disabled={isReadOnly}
onChange={(checked) => {
onSolutionStatusChange(fieldId, checked);
}}
style={{ style={{
backgroundColor: solutionStatus ? '#23A55A' : '#bfbfbf', backgroundColor: (watchedStatus ?? true) ? '#23A55A' : '#bfbfbf',
}} }}
/> />
</Form.Item>
<Text style={{ marginLeft: 8 }}> <Text style={{ marginLeft: 8 }}>
{currentStatus === true ? 'Active' : 'Non Active'} {(watchedStatus ?? true) ? 'Active' : 'Non Active'}
</Text> </Text>
</div> </div>
);
}}
</Form.Item>
</Form.Item> </Form.Item>
<Form.Item label="Solution Type"> <Form.Item label="Solution Type">

View File

@@ -194,9 +194,7 @@ export const useErrorCodeLogic = (errorCodeForm, fileList) => {
}; };
const handleSolutionStatusChange = (fieldId, status) => { const handleSolutionStatusChange = (fieldId, status) => {
// Update form immediately // Only update local state - form is already updated by Form.Item
errorCodeForm.setFieldValue(`solution_status_${fieldId}`, status);
// Then update local state
setSolutionStatuses(prev => ({ setSolutionStatuses(prev => ({
...prev, ...prev,
[fieldId]: status [fieldId]: status