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 { 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>
|
||||||
|
|||||||
@@ -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]) {
|
||||||
|
|||||||
@@ -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
|
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||||
shouldUpdate={(prevValues, currentValues) =>
|
<Form.Item name={`solution_status_${fieldId}`} valuePropName="checked" noStyle>
|
||||||
prevValues[`solution_status_${fieldId}`] !==
|
<Switch
|
||||||
currentValues[`solution_status_${fieldId}`]
|
disabled={isReadOnly}
|
||||||
}
|
onChange={(checked) => {
|
||||||
noStyle
|
onSolutionStatusChange(fieldId, checked);
|
||||||
>
|
}}
|
||||||
{({ getFieldValue, setFieldValue }) => {
|
style={{
|
||||||
const currentStatus = getFieldValue(`solution_status_${fieldId}`);
|
backgroundColor: (watchedStatus ?? true) ? '#23A55A' : '#bfbfbf',
|
||||||
return (
|
}}
|
||||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
/>
|
||||||
<Switch
|
</Form.Item>
|
||||||
checked={currentStatus === true}
|
<Text style={{ marginLeft: 8 }}>
|
||||||
onChange={(checked) => {
|
{(watchedStatus ?? true) ? 'Active' : 'Non Active'}
|
||||||
setFieldValue(`solution_status_${fieldId}`, checked);
|
</Text>
|
||||||
}}
|
</div>
|
||||||
disabled={isReadOnly}
|
|
||||||
style={{
|
|
||||||
backgroundColor: solutionStatus ? '#23A55A' : '#bfbfbf',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Text style={{ marginLeft: 8 }}>
|
|
||||||
{currentStatus === true ? 'Active' : 'Non Active'}
|
|
||||||
</Text>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
</Form.Item>
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item label="Solution Type">
|
<Form.Item label="Solution Type">
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user