repair: brandDevice add edit page

This commit is contained in:
2025-12-12 16:54:30 +07:00
parent 2ff50342e8
commit ea3adf40cc
5 changed files with 107 additions and 578 deletions

View File

@@ -13,17 +13,17 @@ import {
Tag,
Space,
Input,
ConfigProvider
} from 'antd';
import { EyeOutlined, EditOutlined, DeleteOutlined, PlusOutlined, SearchOutlined } from '@ant-design/icons';
import { NotifAlert, NotifOk, NotifConfirmDialog } from '../../../components/Global/ToastNotif';
import { useBreadcrumb } from '../../../layout/LayoutBreadcrumb';
import { getBrandById, getErrorCodesByBrandId, getErrorCodeById, deleteErrorCode, updateErrorCode as updateErrorCodeAPI, createErrorCode as createErrorCodeAPI } from '../../../api/master-brand';
import { getBrandById, updateBrand, getErrorCodesByBrandId, getErrorCodeById, deleteErrorCode, updateErrorCode as updateErrorCodeAPI, createErrorCode as createErrorCodeAPI } from '../../../api/master-brand';
import { getFileUrl } from '../../../api/file-uploads';
import { SendRequest } from '../../../components/Global/ApiRequest';
import BrandForm from './component/BrandForm';
import ErrorCodeForm from './component/ErrorCodeForm';
import SolutionForm from './component/SolutionForm';
import FormActions from './component/FormActions';
import SparepartSelect from './component/SparepartSelect';
import ListErrorCode from './component/ListErrorCode';
@@ -57,6 +57,7 @@ const EditBrandDevice = () => {
const [solutionTypes, setSolutionTypes] = useState({ 0: 'text' });
const [solutionStatuses, setSolutionStatuses] = useState({ 0: true });
const [currentSolutionData, setCurrentSolutionData] = useState([]);
const [confirmLoading, setConfirmLoading] = useState(false);
const getSolutionData = () => {
if (!solutionForm) return [];
@@ -115,7 +116,7 @@ const EditBrandDevice = () => {
const isFileType = solution.type_solution && solution.type_solution !== 'text';
newSolutionTypes[fieldKey] = isFileType ? 'file' : 'text';
newSolutionStatuses[fieldKey] = solution.is_active !== false;
newSolutionStatuses[fieldKey] = solution.is_active;
let fileObject = null;
if (isFileType && (solution.path_solution || solution.path_document)) {
@@ -135,7 +136,7 @@ const EditBrandDevice = () => {
name: solution.solution_name || '',
type: isFileType ? 'file' : 'text',
text: solution.text_solution || '',
status: solution.is_active !== false,
status: solution.is_active,
file: fileObject,
fileUpload: fileObject,
path_solution: solution.path_solution || solution.path_document || null,
@@ -387,17 +388,64 @@ const EditBrandDevice = () => {
const handleNextStep = async () => {
try {
await brandForm.validateFields();
const currentBrandId = id;
if (currentBrandId) {
navigate(`/master/brand-device/edit/${currentBrandId}?tab=error-codes`);
setConfirmLoading(true);
const brandValues = brandForm.getFieldsValue();
if (!brandValues.brand_name || brandValues.brand_name.trim() === '') {
NotifAlert({
icon: 'warning',
title: 'Perhatian',
message: 'Brand Name wajib diisi!',
});
return;
}
if (!brandValues.brand_manufacture || brandValues.brand_manufacture.trim() === '') {
NotifAlert({
icon: 'warning',
title: 'Perhatian',
message: 'Manufacturer wajib diisi!',
});
return;
}
const brandApiData = {
brand_name: brandValues.brand_name.trim(),
brand_type: brandValues.brand_type || '',
brand_manufacture: brandValues.brand_manufacture.trim(),
brand_model: brandValues.brand_model || '',
is_active: brandValues.is_active !== undefined ? brandValues.is_active : true
};
const response = await updateBrand(id, brandApiData);
if (response && (response.statusCode === 200 || response.statusCode === 201)) {
NotifOk({
icon: 'success',
title: 'Berhasil',
message: 'Brand device berhasil diupdate.',
});
const currentBrandId = id;
if (currentBrandId) {
navigate(`/master/brand-device/edit/${currentBrandId}?tab=error-codes`);
}
} else {
NotifAlert({
icon: 'error',
title: 'Gagal',
message: response?.message || 'Gagal mengupdate brand device',
});
}
} catch (error) {
NotifAlert({
icon: 'warning',
title: 'Perhatian',
message: 'Harap isi semua kolom wajib untuk brand device!',
icon: 'error',
title: 'Gagal',
message: error.message || 'Gagal mengupdate brand device',
});
} finally {
setConfirmLoading(false);
}
};
@@ -433,6 +481,7 @@ const EditBrandDevice = () => {
const handleSaveErrorCode = async () => {
try {
setConfirmLoading(true);
const errorCodeValues = await errorCodeForm.validateFields();
const solutionData = getSolutionData();
@@ -542,6 +591,8 @@ const EditBrandDevice = () => {
title: 'Perhatian',
message: error.message || 'Harap isi semua kolom wajib!',
});
} finally {
setConfirmLoading(false);
}
};
@@ -1165,6 +1216,7 @@ const EditBrandDevice = () => {
type="primary"
size="large"
onClick={handleSaveErrorCode}
loading={confirmLoading}
style={{
backgroundColor: '#23A55A',
borderColor: '#23A55A',
@@ -1197,13 +1249,23 @@ const EditBrandDevice = () => {
};
return (
<Card>
<Steps current={currentStep} style={{ marginBottom: 24 }}>
<Step title="Brand Device Details" />
<Step title="Error Codes & Solutions" />
</Steps>
{renderStepContent()}
<Divider />
<ConfigProvider
theme={{
components: {
Switch: {
colorPrimary: '#23A55A',
colorPrimaryHover: '#23A55A',
},
},
}}
>
<Card>
<Steps current={currentStep} style={{ marginBottom: 24 }}>
<Step title="Brand Device Details" />
<Step title="Error Codes & Solutions" />
</Steps>
{renderStepContent()}
<Divider />
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<div>
{currentStep === 1 && (
@@ -1220,7 +1282,7 @@ const EditBrandDevice = () => {
<Button
type="primary"
onClick={handleNextStep}
loading={loading}
loading={confirmLoading}
style={{
backgroundColor: '#23A55A',
borderColor: '#23A55A',
@@ -1243,7 +1305,8 @@ const EditBrandDevice = () => {
)}
</div>
</div>
</Card>
</Card>
</ConfigProvider>
);
};