diff --git a/src/pages/master/brandDevice/AddBrandDevice.jsx b/src/pages/master/brandDevice/AddBrandDevice.jsx
index 88310a8..d4aced7 100644
--- a/src/pages/master/brandDevice/AddBrandDevice.jsx
+++ b/src/pages/master/brandDevice/AddBrandDevice.jsx
@@ -53,13 +53,6 @@ const AddBrandDevice = () => {
const {
solutionFields,
solutionTypes,
- solutionStatuses,
- solutionsToDelete,
- firstSolutionValid,
- handleAddSolutionField,
- handleRemoveSolutionField,
- handleSolutionTypeChange,
- handleSolutionStatusChange,
resetSolutionFields,
getSolutionData,
setSolutionsForExistingRecord,
@@ -72,7 +65,6 @@ const AddBrandDevice = () => {
const brandValues = await brandForm.validateFields();
const userId = JSON.parse(localStorage.getItem('user') || '{}').user_id || 1;
- // Prepare brand data for API
const brandApiData = {
brand_name: brandValues.brand_name,
brand_type: brandValues.brand_type || '',
@@ -97,7 +89,6 @@ const AddBrandDevice = () => {
});
setCurrentStep(1);
- // Trigger refresh untuk error codes table di fase 2
setTimeout(() => {
setTrigerFilter(prev => !prev);
}, 100);
@@ -239,7 +230,6 @@ const AddBrandDevice = () => {
let allErrorCodes = [];
- // Get error codes from API if brand is created
if (createdBrandId) {
const queryParams = new URLSearchParams({
page: page.toString(),
@@ -258,10 +248,8 @@ const AddBrandDevice = () => {
}
}
- // Add temp error codes
allErrorCodes = [...allErrorCodes, ...tempErrorCodes.filter(ec => ec.status !== 'deleted')];
- // Filter by search text if needed
if (searchText) {
allErrorCodes = allErrorCodes.filter(ec =>
ec.error_code.toLowerCase().includes(searchText.toLowerCase()) ||
@@ -313,7 +301,6 @@ const AddBrandDevice = () => {
render: (text, record) => (
{text}
- {record.status === 'new' && New}
),
},
@@ -360,7 +347,6 @@ const AddBrandDevice = () => {
},
];
- // Query params for table
const queryParams = useMemo(() => {
const params = new URLSearchParams();
params.set('page', '1');
@@ -424,8 +410,6 @@ const AddBrandDevice = () => {
solution: solutionData || [],
spareparts: selectedSparepartIds || []
};
-
- // For create, include error_code field (required)
if (isAddingNewErrorCode) {
payload.error_code = errorCodeValues.error_code;
}
@@ -473,7 +457,6 @@ const AddBrandDevice = () => {
const handleFinish = async () => {
setConfirmLoading(true);
try {
- // Fase 2 completion - brand sudah dibuat di fase 1
NotifOk({
icon: 'success',
title: 'Brand Device Tersimpan',
diff --git a/src/pages/master/brandDevice/AddEditErrorCode.jsx b/src/pages/master/brandDevice/AddEditErrorCode.jsx
index fb65629..04376c0 100644
--- a/src/pages/master/brandDevice/AddEditErrorCode.jsx
+++ b/src/pages/master/brandDevice/AddEditErrorCode.jsx
@@ -62,7 +62,11 @@ const AddEditErrorCode = () => {
const isEditMode = errorCodeId && errorCodeId !== 'add';
setIsEdit(isEditMode);
-
+ // Initialize solution form with proper structure
+ if (!isEditMode) {
+ resetSolutionFields();
+ }
+
setBreadcrumbItems([
{
title: • Master
@@ -158,7 +162,6 @@ const AddEditErrorCode = () => {
});
}
} catch (error) {
- console.error('Failed to load error code:', error);
NotifAlert({
icon: 'error',
title: 'Error',
@@ -173,23 +176,10 @@ const AddEditErrorCode = () => {
try {
await errorCodeForm.validateFields();
- const solutionValues = solutionForm.getFieldsValue();
+ const solutionData = getSolutionData();
- const commaPath = `solution_items,${solutionFields[0]?.key || 0}`;
- const dotPath = `solution_items.${solutionFields[0]?.key || 0}`;
- const firstSolution = solutionValues[commaPath] || solutionValues[dotPath];
-
- let isValid = false;
- if (firstSolution && firstSolution.name && firstSolution.name.trim() !== '') {
- const firstSolutionType = solutionTypes[solutionFields[0]?.key || 0];
- if (firstSolutionType === 'text') {
- isValid = firstSolution.text && firstSolution.text.trim() !== '';
- } else {
- isValid = true;
- }
- }
-
- if (!isValid) {
+ // Validate that at least one solution exists and is valid
+ if (!solutionData || solutionData.length === 0) {
NotifAlert({
icon: 'warning',
title: 'Perhatian',
@@ -198,9 +188,29 @@ const AddEditErrorCode = () => {
return;
}
- const errorCodeValues = errorCodeForm.getFieldsValue();
+ // Validate solutions based on their type
+ const invalidSolutions = solutionData.filter(solution => {
+ if (solution.type_solution === 'text') {
+ return !solution.text_solution || solution.text_solution.trim() === '';
+ } else if (solution.type_solution === 'file') {
+ return !solution.path_solution || solution.path_solution.trim() === '';
+ }
+ return false;
+ });
- const solutionData = getSolutionData();
+ if (invalidSolutions.length > 0) {
+ const invalidNames = invalidSolutions.map(s => s.solution_name).join(', ');
+ NotifAlert({
+ icon: 'warning',
+ title: 'Perhatian',
+ message: `Harap lengkapi solution berikut:\n${invalidSolutions.map(s =>
+ `- ${s.solution_name}: ${s.type_solution === 'text' ? 'Text solution wajib diisi' : 'File wajib diupload'}`
+ ).join('\n')}`,
+ });
+ return;
+ }
+
+ const errorCodeValues = errorCodeForm.getFieldsValue();
setConfirmLoading(true);
@@ -222,17 +232,9 @@ const AddEditErrorCode = () => {
let response;
if (isEdit && errorCodeId) {
- console.log('Updating error code:', errorCodeId);
- console.log('Current brand ID:', currentBrandId);
- console.log('Update payload:', JSON.stringify(payload, null, 2));
- console.log('API URL:', `error-code/brand/${currentBrandId}/${errorCodeId}`);
response = await updateErrorCode(currentBrandId, errorCodeId, payload);
- console.log('Full API response:', response);
} else {
- console.log('Creating new error code');
- console.log('Create payload:', JSON.stringify(payload, null, 2));
response = await createErrorCode(currentBrandId, payload);
- console.log('Full API response:', response);
}
if (response && (response.statusCode === 200 || response.statusCode === 201)) {
@@ -248,7 +250,6 @@ const AddEditErrorCode = () => {
navigate(`/master/brand-device/edit/${currentBrandId}?tab=error-codes`);
}
} else {
- console.log('Error response:', response);
NotifAlert({
icon: 'error',
title: 'Gagal',
@@ -256,12 +257,6 @@ const AddEditErrorCode = () => {
});
}
} catch (error) {
- console.error('Error saving error code:', error);
- console.error('Full error object:', JSON.stringify(error, null, 2));
- if (error.response) {
- console.error('Error response data:', error.response.data);
- console.error('Error response status:', error.response.status);
- }
NotifAlert({
icon: 'error',
title: 'Gagal',
@@ -272,12 +267,6 @@ const AddEditErrorCode = () => {
}
} catch (error) {
- console.error('Error saving error code:', error);
- console.error('Full error object:', JSON.stringify(error, null, 2));
- if (error.response) {
- console.error('Error response data:', error.response.data);
- console.error('Error response status:', error.response.status);
- }
NotifAlert({
icon: 'error',
title: 'Error',
@@ -295,10 +284,7 @@ const AddEditErrorCode = () => {
};
const handleErrorCodeIconUpload = (iconData) => {
- console.log('handleErrorCodeIconUpload received:', iconData);
-
if (!iconData || !iconData.uploadPath) {
- console.error('❌ Invalid icon data received:', iconData);
return null;
}
@@ -309,24 +295,17 @@ const AddEditErrorCode = () => {
};
setErrorCodeIcon(formattedIconData);
- console.log('Icon data stored from upload (no second upload):', formattedIconData);
return formattedIconData;
};
const handleErrorCodeIconRemove = () => {
- console.log('🗑️ Removing error code icon');
setErrorCodeIcon(null);
- console.log('✅ Error code icon removed');
};
const handleSolutionFileUpload = (fileObject) => {
- console.log('Solution file uploaded:', fileObject);
- console.log('File object path_solution:', fileObject?.path_solution);
- console.log('File object uploadPath:', fileObject?.uploadPath);
+ // Handle solution file upload if needed
};
-
-
const resetForm = () => {
errorCodeForm.resetFields();
errorCodeForm.setFieldsValue({
@@ -416,12 +395,7 @@ const AddEditErrorCode = () => {