fix is_active error code ft vinix
This commit is contained in:
@@ -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 (
|
||||
<Form
|
||||
layout="vertical"
|
||||
@@ -15,12 +17,11 @@ const BrandForm = ({ form, formData, onValuesChange, isEdit = false }) => {
|
||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<Form.Item name="is_active" valuePropName="checked" noStyle>
|
||||
<Switch
|
||||
checked={formData.is_active}
|
||||
style={{ backgroundColor: formData.is_active ? '#23A55A' : '#bfbfbf' }}
|
||||
style={{ backgroundColor: isActive ? '#23A55A' : '#bfbfbf' }}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Text style={{ marginLeft: 8 }}>
|
||||
{formData.is_active ? 'Running' : 'Offline'}
|
||||
{isActive ? 'Running' : 'Offline'}
|
||||
</Text>
|
||||
</div>
|
||||
</Form.Item>
|
||||
|
||||
@@ -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]) {
|
||||
|
||||
@@ -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 = ({
|
||||
</Form.Item>
|
||||
|
||||
<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' }}>
|
||||
<Form.Item name={`solution_status_${fieldId}`} valuePropName="checked" noStyle>
|
||||
<Switch
|
||||
checked={currentStatus === true}
|
||||
onChange={(checked) => {
|
||||
setFieldValue(`solution_status_${fieldId}`, checked);
|
||||
}}
|
||||
disabled={isReadOnly}
|
||||
onChange={(checked) => {
|
||||
onSolutionStatusChange(fieldId, checked);
|
||||
}}
|
||||
style={{
|
||||
backgroundColor: solutionStatus ? '#23A55A' : '#bfbfbf',
|
||||
backgroundColor: (watchedStatus ?? true) ? '#23A55A' : '#bfbfbf',
|
||||
}}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Text style={{ marginLeft: 8 }}>
|
||||
{currentStatus === true ? 'Active' : 'Non Active'}
|
||||
{(watchedStatus ?? true) ? 'Active' : 'Non Active'}
|
||||
</Text>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Form.Item>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="Solution Type">
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user