diff --git a/src/pages/master/brandDevice/component/ErrorCodeForm.jsx b/src/pages/master/brandDevice/component/ErrorCodeForm.jsx index 7490fe0..fbfaff2 100644 --- a/src/pages/master/brandDevice/component/ErrorCodeForm.jsx +++ b/src/pages/master/brandDevice/component/ErrorCodeForm.jsx @@ -1,4 +1,14 @@ -import { Form, Divider, Button, Switch, Input, ConfigProvider, Typography, Upload, message } from 'antd'; +import { + Form, + Divider, + Button, + Switch, + Input, + ConfigProvider, + Typography, + Upload, + message, +} from 'antd'; import { PlusOutlined, UploadOutlined, DeleteOutlined } from '@ant-design/icons'; import { NotifAlert } from '../../../../components/Global/ToastNotif'; import SolutionField from './SolutionField'; @@ -28,7 +38,7 @@ const ErrorCodeForm = ({ errorCodes, errorCodeIcon, onErrorCodeIconUpload, - onErrorCodeIconRemove + onErrorCodeIconRemove, }) => { const statusValue = Form.useWatch('status', errorCodeForm); @@ -49,12 +59,15 @@ const ErrorCodeForm = ({ try { const fileExtension = file.name.split('.').pop().toLowerCase(); - const isImageFile = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'].includes(fileExtension); + const isImageFile = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'].includes( + fileExtension + ); const fileType = isImageFile ? 'image' : 'pdf'; const folder = 'images'; const uploadResponse = await uploadFile(file, folder); - const iconPath = uploadResponse.data?.path_icon || uploadResponse.data?.path_solution || ''; + const iconPath = + uploadResponse.data?.path_icon || uploadResponse.data?.path_solution || ''; if (iconPath) { // Extract folder and filename from the path @@ -67,7 +80,7 @@ const ErrorCodeForm = ({ uploadPath: iconPath, url: getFileUrl(folder, filename), // Use the same endpoint as file uploads type_solution: fileType, - solutionId: 'icon' + solutionId: 'icon', }); message.success(`${file.name} uploaded successfully!`); } else { @@ -99,7 +112,7 @@ const ErrorCodeForm = ({ const solutionName = values[`solution_name_${fieldId}`]; const textSolution = values[`text_solution_${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]; if (solutionType === 'text') { @@ -109,11 +122,12 @@ const ErrorCodeForm = ({ type_solution: 'text', text_solution: textSolution.trim(), path_solution: '', - is_active: solutionStatuses[fieldId] !== false + is_active: solutionStatuses[fieldId] !== false, }; if (window.currentSolutionData && window.currentSolutionData[fieldId]) { - solutionData.brand_code_solution_id = window.currentSolutionData[fieldId].brand_code_solution_id; + solutionData.brand_code_solution_id = + window.currentSolutionData[fieldId].brand_code_solution_id; } solutions.push(solutionData); @@ -121,15 +135,22 @@ const ErrorCodeForm = ({ } else if (solutionType === 'file') { filesForSolution.forEach((file) => { const solutionData = { - solution_name: solutionName || file.solution_name || file.name || `Solution ${fieldId}`, - type_solution: file.type_solution || (file.type.startsWith('image/') ? 'image' : 'pdf'), + solution_name: + solutionName || + file.solution_name || + file.name || + `Solution ${fieldId}`, + type_solution: + file.type_solution || + (file.type.startsWith('image/') ? 'image' : 'pdf'), text_solution: '', path_solution: file.uploadPath, - is_active: solutionStatuses[fieldId] !== false + is_active: solutionStatuses[fieldId] !== false, }; if (window.currentSolutionData && window.currentSolutionData[fieldId]) { - solutionData.brand_code_solution_id = window.currentSolutionData[fieldId].brand_code_solution_id; + solutionData.brand_code_solution_id = + window.currentSolutionData[fieldId].brand_code_solution_id; } solutions.push(solutionData); @@ -141,7 +162,8 @@ const ErrorCodeForm = ({ NotifAlert({ icon: 'warning', title: 'Perhatian', - message: 'Setiap error code harus memiliki minimal 1 solution (text atau file)!' + message: + 'Setiap error code harus memiliki minimal 1 solution (text atau file)!', }); return; } @@ -154,13 +176,16 @@ const ErrorCodeForm = ({ path_icon: errorCodeIcon?.uploadPath || '', status: values.status === undefined ? true : values.status, solution: solutions, - key: editingErrorCodeKey || `temp-${Date.now()}` + key: editingErrorCodeKey || `temp-${Date.now()}`, }; onAddErrorCode(newErrorCode); - } catch (error) { - NotifAlert({ icon: 'warning', title: 'Perhatian', message: 'Harap isi semua kolom wajib (error code + minimal 1 solution)!' }); + NotifAlert({ + icon: 'warning', + title: 'Perhatian', + message: 'Harap isi semua kolom wajib (error code + minimal 1 solution)!', + }); } }; @@ -169,14 +194,21 @@ const ErrorCodeForm = ({ errorCodeForm.setFieldsValue({ status: true, solution_status_0: true, - solution_type_0: 'text' + solution_type_0: 'text', }); onResetForm(); }; return ( <> -
+
@@ -203,85 +235,110 @@ const ErrorCodeForm = ({ }, }} > - )}
- + - + - - - - - -
- {errorCodeIcon ? ( - <> - Error Code Icon -
-
- {errorCodeIcon.name} + +
+
+ Icon: + {errorCodeIcon ? ( +
+ Error Code Icon +
+
+ {errorCodeIcon.name.length > 15 + ? errorCodeIcon.name.substring(0, 15) + '...' + : errorCodeIcon.name} +
+ {!isErrorCodeFormReadOnly && ( + + )}
- {!isErrorCodeFormReadOnly && ( - - )}
- - ) : ( - - - - )} + + + )} +
+
+ Color: + + + +
- Upload an icon image (max 2MB, JPG/PNG/GIF) + Choose color and upload icon (max 2MB, JPG/PNG/GIF)
- + @@ -295,7 +352,7 @@ const ErrorCodeForm = ({ solutionType={solutionTypes[fieldId]} solutionStatus={solutionStatuses[fieldId]} isReadOnly={isErrorCodeFormReadOnly} - fileList={fileList.filter(file => file.solutionId === fieldId)} + fileList={fileList.filter((file) => file.solutionId === fieldId)} onRemove={() => onRemoveSolutionField(fieldId)} onSolutionTypeChange={(type) => onSolutionTypeChange(fieldId, type)} onSolutionStatusChange={(status) => onSolutionStatusChange(fieldId, status)} @@ -320,21 +377,17 @@ const ErrorCodeForm = ({ {!isErrorCodeFormReadOnly && editingErrorCodeKey && ( - + )} {isErrorCodeFormReadOnly && editingErrorCodeKey && ( - + )} ); }; -export default ErrorCodeForm; \ No newline at end of file +export default ErrorCodeForm;