refactor plant section

This commit is contained in:
2025-10-13 11:02:17 +07:00
parent 577d8c8585
commit d9fb7c9fce
3 changed files with 29 additions and 64 deletions

View File

@@ -2,12 +2,15 @@ import { SendRequest } from '../components/Global/ApiRequest';
const getAllPlantSection = async (queryParams) => {
try {
// Ensure queryParams is URLSearchParams object
const params = queryParams instanceof URLSearchParams ? queryParams : new URLSearchParams(queryParams);
const response = await SendRequest({
method: 'get',
prefix: `plant-sub-section?${queryParams.toString()}`,
prefix: `plant-sub-section?${params.toString()}`,
});
console.log('getAllPlantSection response:', response);
console.log('Query params:', queryParams.toString());
console.log('Query params:', params.toString());
// Backend response structure:
// {
@@ -23,17 +26,23 @@ const getAllPlantSection = async (queryParams) => {
// Check if backend returns paginated data
if (response.paging) {
const totalData = response.data?.[0]?.total_data || response.rows || response.data?.length || 0;
// Extract total_data from first record, or fallback to total_limit or rows
const totalData = response.data?.[0]?.total_data || response.paging.total_limit || response.rows || response.data?.length || 0;
// Use total_limit as total count, handle 0 values for page/limit
const currentPage = response.paging.current_page || 1;
const currentLimit = response.paging.current_limit || 10;
const totalPages = response.paging.total_page || Math.ceil(totalData / currentLimit);
return {
status: response.statusCode || 200,
data: {
data: response.data || [],
paging: {
page: response.paging.current_page || 1,
limit: response.paging.current_limit || 10,
page: currentPage,
limit: currentLimit,
total: totalData,
page_total: response.paging.total_page || Math.ceil(totalData / (response.paging.current_limit || 10))
page_total: totalPages
},
total: totalData
}
@@ -41,9 +50,9 @@ const getAllPlantSection = async (queryParams) => {
}
// Fallback: If backend returns all data without pagination (old behavior)
const params = Object.fromEntries(queryParams);
const currentPage = parseInt(params.page) || 1;
const currentLimit = parseInt(params.limit) || 10;
const parsedParams = Object.fromEntries(params);
const currentPage = parseInt(parsedParams.page) || 1;
const currentLimit = parseInt(parsedParams.limit) || 10;
const allData = response.data || [];
const totalData = allData.length;

View File

@@ -64,39 +64,7 @@ const DetailPlantSection = ({ visible, onCancel, onOk, form, editingKey, readOnl
rules={[{ required: true, message: 'Silakan masukkan nama sub section!' }]}
style={{ marginBottom: 0 }}
>
<Input readOnly={readOnly} placeholder="Masukkan Kode Plant" />
</Form.Item>
</div>
<div style={{ marginBottom: 12 }}>
<Text strong>Nama Plant</Text>
<Text style={{ color: 'red' }}> *</Text>
<Form.Item
name="nama_plant"
rules={[{ required: true, message: 'Silakan masukkan nama plant!' }]}
style={{ marginBottom: 0 }}
>
<Input readOnly={readOnly} placeholder="Masukkan Nama Plant" />
</Form.Item>
</div>
<div style={{ marginBottom: 12 }}>
<Text strong>Lokasi Plant</Text>
<Text style={{ color: 'red' }}> *</Text>
<Form.Item
name="lokasi_plant"
rules={[{ required: true, message: 'Silakan masukkan lokasi plant!' }]}
style={{ marginBottom: 0 }}
>
<Input readOnly={readOnly} placeholder="Masukkan Lokasi Plant" />
</Form.Item>
</div>
<div style={{ marginBottom: 12 }}>
<Text strong>Deskripsi</Text>
<Form.Item name="deskripsi" style={{ marginBottom: 0 }}>
<Input.TextArea
readOnly={readOnly}
placeholder="Masukkan Deskripsi (Opsional)"
rows={4}
/>
<Input readOnly={readOnly} placeholder="Masukkan Nama Sub Section" />
</Form.Item>
</div>
</Form>

View File

@@ -26,38 +26,26 @@ const ListPlantSection = ({
title: 'No',
dataIndex: 'sub_section_id',
key: 'sub_section_id',
width: '10%',
width: '8%',
render: (text, record, index) => index + 1,
},
{
title: 'Kode Sub Section',
dataIndex: 'sub_section_code',
key: 'sub_section_code',
width: '20%',
},
{
title: 'Nama Sub Section',
dataIndex: 'sub_section_name',
key: 'sub_section_name',
width: '35%',
},
{
title: 'Kode Plant',
dataIndex: 'kode_plant',
key: 'kode_plant',
},
{
title: 'Nama Plant',
dataIndex: 'nama_plant',
key: 'nama_plant',
},
{
title: 'Lokasi Plant',
dataIndex: 'lokasi_plant',
key: 'lokasi_plant',
},
{
title: 'Deskripsi',
dataIndex: 'deskripsi',
key: 'deskripsi',
},
{
title: 'Aksi',
key: 'action',
width: '15%',
width: '10%',
render: (_, record) => (
<Space size="middle">
<Button