repair: sollution brand-device

This commit is contained in:
2025-12-12 12:45:00 +07:00
parent 4fab5df300
commit 512282f367
3 changed files with 425 additions and 145 deletions

View File

@@ -15,7 +15,7 @@ export const useSolutionLogic = (solutionForm) => {
name: 'Solution 1',
status: true,
type: 'text',
text: 'Deskripsi untuk Solution 1',
text: 'Solution description',
file: null,
fileUpload: null
}
@@ -63,7 +63,7 @@ export const useSolutionLogic = (solutionForm) => {
solutionForm.setFieldValue(['solution_items', newKey, 'name'], defaultName);
solutionForm.setFieldValue(['solution_items', newKey, 'type'], 'text');
solutionForm.setFieldValue(['solution_items', newKey, 'text'], `Deskripsi untuk ${defaultName}`);
solutionForm.setFieldValue(['solution_items', newKey, 'text'], 'Solution description');
solutionForm.setFieldValue(['solution_items', newKey, 'status'], true);
solutionForm.setFieldValue(['solution_items', newKey, 'file'], null);
solutionForm.setFieldValue(['solution_items', newKey, 'fileUpload'], null);
@@ -112,22 +112,30 @@ export const useSolutionLogic = (solutionForm) => {
...solutionData,
fileUpload: null,
file: null,
text: solutionData.text || `Deskripsi untuk ${solutionData.name || 'Solution'}`
path_solution: null,
fileName: null,
text: solutionData.text || 'Solution description'
};
solutionForm.setFieldValue([...fieldName, 'fileUpload'], null);
solutionForm.setFieldValue([...fieldName, 'file'], null);
solutionForm.setFieldValue([...fieldName, 'path_solution'], null);
solutionForm.setFieldValue([...fieldName, 'fileName'], null);
solutionForm.setFieldValue([...fieldName, 'text'], updatedSolutionData.text);
} else if (value === 'file') {
const updatedSolutionData = {
...solutionData,
text: '',
fileUpload: null,
file: null
file: null,
path_solution: null,
fileName: null
};
solutionForm.setFieldValue([...fieldName, 'text'], '');
solutionForm.setFieldValue([...fieldName, 'fileUpload'], null);
solutionForm.setFieldValue([...fieldName, 'file'], null);
solutionForm.setFieldValue([...fieldName, 'path_solution'], null);
solutionForm.setFieldValue([...fieldName, 'fileName'], null);
}
}, 0);
};
@@ -141,6 +149,10 @@ export const useSolutionLogic = (solutionForm) => {
setSolutionTypes({ 0: 'text' });
setSolutionStatuses({ 0: true });
if (!solutionForm || !solutionForm.resetFields) {
return;
}
solutionForm.resetFields();
setTimeout(() => {
solutionForm.setFieldsValue({
@@ -149,7 +161,7 @@ export const useSolutionLogic = (solutionForm) => {
name: 'Solution 1',
status: true,
type: 'text',
text: '',
text: 'Solution description',
file: null,
fileUpload: null
}
@@ -158,17 +170,18 @@ export const useSolutionLogic = (solutionForm) => {
solutionForm.setFieldValue(['solution_items', 0, 'name'], 'Solution 1');
solutionForm.setFieldValue(['solution_items', 0, 'type'], 'text');
solutionForm.setFieldValue(['solution_items', 0, 'text'], 'Deskripsi untuk Solution 1');
solutionForm.setFieldValue(['solution_items', 0, 'text'], 'Solution description');
solutionForm.setFieldValue(['solution_items', 0, 'status'], true);
solutionForm.setFieldValue(['solution_items', 0, 'file'], null);
solutionForm.setFieldValue(['solution_items', 0, 'fileUpload'], null);
console.log('✅ Reset solution fields with proper structure');
console.log('Form values after reset:', solutionForm.getFieldsValue(true));
}, 100);
};
const checkFirstSolutionValid = () => {
if (!solutionForm || !solutionForm.getFieldsValue) {
return false;
}
const values = solutionForm.getFieldsValue();
const firstField = solutionFields[0];
@@ -177,7 +190,6 @@ export const useSolutionLogic = (solutionForm) => {
}
const solutionKey = firstField.key || firstField;
// Try both notations for compatibility
const commaPath = `solution_items,${solutionKey}`;
const dotPath = `solution_items.${solutionKey}`;
const firstSolution = values[commaPath] || values[dotPath];
@@ -204,7 +216,6 @@ export const useSolutionLogic = (solutionForm) => {
try {
solution = solutionForm.getFieldValue(['solution_items', key]);
} catch (error) {
// Silently handle errors
}
if (!solution && values.solution_items && values.solution_items[key]) {
@@ -233,7 +244,6 @@ export const useSolutionLogic = (solutionForm) => {
}
if (!solution) {
// Try to find the solution in the raw form structure
const rawValues = solutionForm.getFieldsValue();
if (rawValues.solution_items && rawValues.solution_items[key]) {
@@ -242,14 +252,14 @@ export const useSolutionLogic = (solutionForm) => {
}
if (!solution) {
return;
return;
}
const hasName = solution.name && solution.name.trim() !== '';
if (!hasName) {
return;
return;
}
const solutionType = solutionTypes[key] || solution.type || 'text';
@@ -273,35 +283,46 @@ export const useSolutionLogic = (solutionForm) => {
let pathSolution = '';
let fileObject = null;
if (solution.fileUpload && typeof solution.fileUpload === 'object' && Object.keys(solution.fileUpload).length > 0) {
pathSolution = solution.fileUpload.path_solution || solution.fileUpload.uploadPath || '';
fileObject = solution.fileUpload;
} else if (solution.file && typeof solution.file === 'object' && Object.keys(solution.file).length > 0) {
pathSolution = solution.file.path_solution || solution.file.uploadPath || '';
fileObject = solution.file;
} else if (solution.file && typeof solution.file === 'string' && solution.file.trim() !== '') {
pathSolution = solution.file;
}
let typeSolution = solutionTypes[key] || solution.type || 'text';
const typeSolution = solutionTypes[key] || solution.type || 'text';
if (typeSolution === 'file') {
if (fileObject && fileObject.type_solution) {
typeSolution = fileObject.type_solution;
if (solution.fileUpload && typeof solution.fileUpload === 'object' && Object.keys(solution.fileUpload).length > 0) {
pathSolution = solution.fileUpload.path_solution || solution.fileUpload.uploadPath || '';
fileObject = solution.fileUpload;
} else if (solution.file && typeof solution.file === 'object' && Object.keys(solution.file).length > 0) {
pathSolution = solution.file.path_solution || solution.file.uploadPath || '';
fileObject = solution.file;
} else if (solution.file && typeof solution.file === 'string' && solution.file.trim() !== '') {
pathSolution = solution.file;
} else if (solution.path_solution && solution.path_solution.trim() !== '') {
pathSolution = solution.path_solution;
} else {
typeSolution = 'image';
}
}
let finalTypeSolution = typeSolution;
if (typeSolution === 'file') {
if (fileObject && fileObject.type_solution) {
finalTypeSolution = fileObject.type_solution;
} else {
finalTypeSolution = 'image';
}
}
const finalSolution = {
solution_name: solution.name,
type_solution: typeSolution,
text_solution: solution.text || '',
path_solution: pathSolution,
type_solution: finalTypeSolution,
is_active: solution.status !== false && solution.status !== undefined ? solution.status : (solutionStatuses[key] !== false),
};
if (typeSolution === 'text') {
finalSolution.text_solution = solution.text || '';
finalSolution.path_solution = '';
} else {
finalSolution.text_solution = '';
finalSolution.path_solution = pathSolution;
}
result.push(finalSolution);
});
@@ -323,7 +344,7 @@ export const useSolutionLogic = (solutionForm) => {
const newStatuses = {};
solutions.forEach((solution, index) => {
const key = solution.id || index;
const key = solution.brand_code_solution_id || solution.id || index;
let fileObject = null;
if (solution.path_solution && solution.path_solution.trim() !== '') {
@@ -349,7 +370,8 @@ export const useSolutionLogic = (solutionForm) => {
text: solution.text_solution || '',
file: fileObject,
fileUpload: fileObject,
status: solution.is_active !== false
status: solution.is_active !== false,
path_solution: solution.path_solution || ''
};
newTypes[key] = isFileType ? 'file' : 'text';
newStatuses[key] = solution.is_active !== false;
@@ -367,7 +389,8 @@ export const useSolutionLogic = (solutionForm) => {
text: solution.text,
file: solution.file,
fileUpload: solution.fileUpload,
status: solution.status
status: solution.status,
path_solution: solution.path_solution
};
});
@@ -382,7 +405,8 @@ export const useSolutionLogic = (solutionForm) => {
text: solution.text,
file: solution.file,
fileUpload: solution.fileUpload,
status: solution.status
status: solution.status,
path_solution: solution.path_solution
};
});
@@ -396,6 +420,7 @@ export const useSolutionLogic = (solutionForm) => {
form.setFieldValue([`solution_items,${key}`, 'file'], solution.file);
form.setFieldValue([`solution_items,${key}`, 'fileUpload'], solution.fileUpload);
form.setFieldValue([`solution_items,${key}`, 'status'], solution.status);
form.setFieldValue([`solution_items,${key}`, 'path_solution'], solution.path_solution);
form.setFieldValue(['solution_items', key, 'name'], solution.name);
form.setFieldValue(['solution_items', key, 'type'], solution.type);
@@ -403,6 +428,7 @@ export const useSolutionLogic = (solutionForm) => {
form.setFieldValue(['solution_items', key, 'file'], solution.file);
form.setFieldValue(['solution_items', key, 'fileUpload'], solution.fileUpload);
form.setFieldValue(['solution_items', key, 'status'], solution.status);
form.setFieldValue(['solution_items', key, 'path_solution'], solution.path_solution);
});
setSolutionTypes(newTypes);