lavoce #2
@@ -6,108 +6,29 @@ import { Form, Typography } from 'antd';
|
|||||||
import ListPlantSection from './component/ListPlantSection';
|
import ListPlantSection from './component/ListPlantSection';
|
||||||
import DetailPlantSection from './component/DetailPlantSection';
|
import DetailPlantSection from './component/DetailPlantSection';
|
||||||
|
|
||||||
import { NotifConfirmDialog, NotifAlert } from '../../../components/Global/ToastNotif';
|
import { NotifConfirmDialog, NotifAlert, NotifOk } from '../../../components/Global/ToastNotif';
|
||||||
|
import { getAllPlantSection, createPlantSection, updatePlantSection, deletePlantSection } from '../../../api/master-plant-section';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
// Mock Data
|
|
||||||
const initialData = [
|
|
||||||
{
|
|
||||||
key: '1',
|
|
||||||
kode_plant: 'PL-001',
|
|
||||||
nama_plant: 'Seksi Produksi A',
|
|
||||||
lokasi_plant: 'Gedung 1, Lantai 2',
|
|
||||||
deskripsi: 'Seksi yang bertanggung jawab untuk lini produksi A.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: '2',
|
|
||||||
kode_plant: 'PL-002',
|
|
||||||
nama_plant: 'Seksi Pengepakan',
|
|
||||||
lokasi_plant: 'Gedung 1, Lantai 1',
|
|
||||||
deskripsi: 'Area pengepakan dan persiapan pengiriman.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: '3',
|
|
||||||
kode_plant: 'PL-003',
|
|
||||||
nama_plant: 'Gudang Bahan Baku',
|
|
||||||
lokasi_plant: 'Gudang A',
|
|
||||||
deskripsi: 'Penyimpanan bahan baku utama.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: '4',
|
|
||||||
kode_plant: 'PL-004',
|
|
||||||
nama_plant: 'Seksi Kualitas',
|
|
||||||
lokasi_plant: 'Laboratorium QC',
|
|
||||||
deskripsi: 'Pemeriksaan dan kontrol kualitas produk.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: '5',
|
|
||||||
kode_plant: 'PL-005',
|
|
||||||
nama_plant: 'Seksi Perawatan',
|
|
||||||
lokasi_plant: 'Workshop',
|
|
||||||
deskripsi: 'Perawatan dan perbaikan mesin produksi.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: '6',
|
|
||||||
kode_plant: 'PL-006',
|
|
||||||
nama_plant: 'Gudang Jadi',
|
|
||||||
lokasi_plant: 'Gudang B',
|
|
||||||
deskripsi: 'Penyimpanan produk yang siap dikirim.',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const IndexPlantSection = memo(function IndexPlantSection() {
|
const IndexPlantSection = memo(function IndexPlantSection() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { setBreadcrumbItems } = useBreadcrumb();
|
const { setBreadcrumbItems } = useBreadcrumb();
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
|
|
||||||
const [data, setData] = useState(initialData);
|
|
||||||
const [actionMode, setActionMode] = useState('list');
|
const [actionMode, setActionMode] = useState('list');
|
||||||
const [editingKey, setEditingKey] = useState('');
|
const [editingKey, setEditingKey] = useState('');
|
||||||
|
const [editingRecord, setEditingRecord] = useState(null);
|
||||||
const [isModalVisible, setIsModalVisible] = useState(false);
|
const [isModalVisible, setIsModalVisible] = useState(false);
|
||||||
const [readOnly, setReadOnly] = useState(false);
|
const [readOnly, setReadOnly] = useState(false);
|
||||||
|
const [refreshList, setRefreshList] = useState(false);
|
||||||
// Mock API function
|
|
||||||
const getAllPlantSection = async (params) => {
|
|
||||||
const { page = 1, limit = 10, search = '' } = Object.fromEntries(params.entries());
|
|
||||||
|
|
||||||
let filteredData = data;
|
|
||||||
if (search) {
|
|
||||||
filteredData = data.filter(item =>
|
|
||||||
item.nama_plant.toLowerCase().includes(search.toLowerCase()) ||
|
|
||||||
item.kode_plant.toLowerCase().includes(search.toLowerCase()) ||
|
|
||||||
item.lokasi_plant.toLowerCase().includes(search.toLowerCase())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const start = (page - 1) * limit;
|
|
||||||
const end = start + limit;
|
|
||||||
const paginatedData = filteredData.slice(start, end);
|
|
||||||
|
|
||||||
return new Promise(resolve => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve({
|
|
||||||
status: 200,
|
|
||||||
data: {
|
|
||||||
data: paginatedData,
|
|
||||||
total: filteredData.length,
|
|
||||||
paging: {
|
|
||||||
page: parseInt(page),
|
|
||||||
limit: parseInt(limit),
|
|
||||||
total: filteredData.length,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}, 500);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
if (token) {
|
if (token) {
|
||||||
setBreadcrumbItems([
|
setBreadcrumbItems([
|
||||||
{ title: <Text strong style={{ fontSize: '14px' }}>• Master</Text> },
|
{ title: <Text strong style={{ fontSize: '14px' }}>• Master</Text> },
|
||||||
{ title: <Text strong style={{ fontSize: '14px' }}>Plant Section</Text> }
|
{ title: <Text strong style={{ fontSize: '14px' }}>Plant Sub Section</Text> }
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
navigate('/signin');
|
navigate('/signin');
|
||||||
@@ -126,51 +47,79 @@ const IndexPlantSection = memo(function IndexPlantSection() {
|
|||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setActionMode('list');
|
setActionMode('list');
|
||||||
setEditingKey('');
|
setEditingKey('');
|
||||||
|
setEditingRecord(null);
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOk = () => {
|
const handleOk = async () => {
|
||||||
if (readOnly) {
|
if (readOnly) {
|
||||||
handleCancel();
|
handleCancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
form.validateFields()
|
|
||||||
.then((values) => {
|
try {
|
||||||
let newData = [...data];
|
const values = await form.validateFields();
|
||||||
if (editingKey) {
|
|
||||||
// Editing existing data
|
if (editingKey && editingRecord) {
|
||||||
const index = newData.findIndex((item) => editingKey === item.key);
|
// Update existing plant section
|
||||||
if (index > -1) {
|
const response = await updatePlantSection(editingRecord.sub_section_id, values);
|
||||||
const item = newData[index];
|
|
||||||
newData.splice(index, 1, { ...item, ...values });
|
if (response.statusCode === 200) {
|
||||||
}
|
NotifOk({
|
||||||
|
icon: 'success',
|
||||||
|
title: 'Berhasil',
|
||||||
|
message: response.message || 'Data Sub Section berhasil diupdate.',
|
||||||
|
});
|
||||||
|
setRefreshList(!refreshList);
|
||||||
|
handleCancel();
|
||||||
} else {
|
} else {
|
||||||
// Adding new data
|
NotifAlert({
|
||||||
const newKey = (Math.max(...data.map(item => parseInt(item.key))) + 1).toString();
|
icon: 'error',
|
||||||
newData = [{ key: newKey, ...values }, ...newData];
|
title: 'Gagal',
|
||||||
|
message: response.message || 'Gagal mengupdate data Sub Section.',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
setData(newData);
|
} else {
|
||||||
NotifAlert({
|
// Create new plant section
|
||||||
icon: 'success',
|
const response = await createPlantSection(values);
|
||||||
title: 'Berhasil',
|
|
||||||
message: 'Data Plant Section berhasil disimpan.',
|
if (response.statusCode === 200 || response.statusCode === 201) {
|
||||||
});
|
NotifOk({
|
||||||
handleCancel();
|
icon: 'success',
|
||||||
})
|
title: 'Berhasil',
|
||||||
.catch((info) => {
|
message: response.message || 'Data Sub Section berhasil ditambahkan.',
|
||||||
console.log('Validate Failed:', info);
|
});
|
||||||
|
setRefreshList(!refreshList);
|
||||||
|
handleCancel();
|
||||||
|
} else {
|
||||||
|
NotifAlert({
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Gagal',
|
||||||
|
message: response.message || 'Gagal menambahkan data Sub Section.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Validate Failed:', error);
|
||||||
|
NotifAlert({
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Validasi Gagal',
|
||||||
|
message: 'Mohon lengkapi semua field yang wajib diisi.',
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEdit = (record) => {
|
const handleEdit = (record) => {
|
||||||
form.setFieldsValue(record);
|
form.setFieldsValue(record);
|
||||||
setEditingKey(record.key);
|
setEditingKey(record.sub_section_id || record.key);
|
||||||
|
setEditingRecord(record);
|
||||||
setActionMode('edit');
|
setActionMode('edit');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePreview = (record) => {
|
const handlePreview = (record) => {
|
||||||
form.setFieldsValue(record);
|
form.setFieldsValue(record);
|
||||||
setEditingKey(record.key);
|
setEditingKey(record.sub_section_id || record.key);
|
||||||
|
setEditingRecord(record);
|
||||||
setActionMode('preview');
|
setActionMode('preview');
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -178,15 +127,33 @@ const IndexPlantSection = memo(function IndexPlantSection() {
|
|||||||
NotifConfirmDialog({
|
NotifConfirmDialog({
|
||||||
icon: 'question',
|
icon: 'question',
|
||||||
title: 'Konfirmasi',
|
title: 'Konfirmasi',
|
||||||
message: `Apakah anda yakin ingin menghapus plant section "${record.nama_plant}"?`,
|
message: `Apakah anda yakin ingin menghapus sub section "${record.sub_section_name}"?`,
|
||||||
onConfirm: () => {
|
onConfirm: async () => {
|
||||||
const newData = data.filter((item) => item.key !== record.key);
|
try {
|
||||||
setData(newData);
|
const response = await deletePlantSection(record.sub_section_id);
|
||||||
NotifAlert({
|
|
||||||
icon: 'success',
|
if (response.statusCode === 200) {
|
||||||
title: 'Berhasil',
|
NotifOk({
|
||||||
message: `Plant section "${record.nama_plant}" berhasil dihapus.`,
|
icon: 'success',
|
||||||
});
|
title: 'Berhasil',
|
||||||
|
message: response.message || `Sub section "${record.sub_section_name}" berhasil dihapus.`,
|
||||||
|
});
|
||||||
|
setRefreshList(!refreshList);
|
||||||
|
} else {
|
||||||
|
NotifAlert({
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Gagal',
|
||||||
|
message: response.message || 'Gagal menghapus data Sub Section.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Delete error:', error);
|
||||||
|
NotifAlert({
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Gagal',
|
||||||
|
message: 'Terjadi kesalahan saat menghapus data.',
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -199,6 +166,7 @@ const IndexPlantSection = memo(function IndexPlantSection() {
|
|||||||
handleDelete={handleDelete}
|
handleDelete={handleDelete}
|
||||||
handlePreview={handlePreview}
|
handlePreview={handlePreview}
|
||||||
getAllPlantSection={getAllPlantSection}
|
getAllPlantSection={getAllPlantSection}
|
||||||
|
refreshList={refreshList}
|
||||||
/>
|
/>
|
||||||
<DetailPlantSection
|
<DetailPlantSection
|
||||||
visible={isModalVisible}
|
visible={isModalVisible}
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ import { Modal, Form, Input, ConfigProvider, Button, Typography } from 'antd';
|
|||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
const DetailPlantSection = ({ visible, onCancel, onOk, form, editingKey, readOnly }) => {
|
const DetailPlantSection = ({ visible, onCancel, onOk, form, editingKey, readOnly }) => {
|
||||||
const modalTitle = readOnly ? 'Preview Plant Section' : (editingKey ? 'Edit Plant Section' : 'Tambah Plant Section');
|
const modalTitle = readOnly
|
||||||
|
? 'Preview Sub Section'
|
||||||
|
: editingKey
|
||||||
|
? 'Edit Sub Section'
|
||||||
|
: 'Tambah Sub Section';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
@@ -45,11 +49,7 @@ const DetailPlantSection = ({ visible, onCancel, onOk, form, editingKey, readOnl
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{!readOnly && (
|
{!readOnly && <Button onClick={onOk}>Simpan</Button>}
|
||||||
<Button onClick={onOk}>
|
|
||||||
Simpan
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</ConfigProvider>
|
</ConfigProvider>
|
||||||
</React.Fragment>,
|
</React.Fragment>,
|
||||||
]}
|
]}
|
||||||
@@ -57,11 +57,11 @@ const DetailPlantSection = ({ visible, onCancel, onOk, form, editingKey, readOnl
|
|||||||
>
|
>
|
||||||
<Form form={form} layout="vertical" name="form_in_modal">
|
<Form form={form} layout="vertical" name="form_in_modal">
|
||||||
<div style={{ marginBottom: 12 }}>
|
<div style={{ marginBottom: 12 }}>
|
||||||
<Text strong>Kode Plant</Text>
|
<Text strong>Nama Sub Section</Text>
|
||||||
<Text style={{ color: 'red' }}> *</Text>
|
<Text style={{ color: 'red' }}> *</Text>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="kode_plant"
|
name="sub_section_name"
|
||||||
rules={[{ required: true, message: 'Silakan masukkan kode plant!' }]}
|
rules={[{ required: true, message: 'Silakan masukkan nama sub section!' }]}
|
||||||
style={{ marginBottom: 0 }}
|
style={{ marginBottom: 0 }}
|
||||||
>
|
>
|
||||||
<Input readOnly={readOnly} placeholder="Masukkan Kode Plant" />
|
<Input readOnly={readOnly} placeholder="Masukkan Kode Plant" />
|
||||||
@@ -91,11 +91,12 @@ const DetailPlantSection = ({ visible, onCancel, onOk, form, editingKey, readOnl
|
|||||||
</div>
|
</div>
|
||||||
<div style={{ marginBottom: 12 }}>
|
<div style={{ marginBottom: 12 }}>
|
||||||
<Text strong>Deskripsi</Text>
|
<Text strong>Deskripsi</Text>
|
||||||
<Form.Item
|
<Form.Item name="deskripsi" style={{ marginBottom: 0 }}>
|
||||||
name="deskripsi"
|
<Input.TextArea
|
||||||
style={{ marginBottom: 0 }}
|
readOnly={readOnly}
|
||||||
>
|
placeholder="Masukkan Deskripsi (Opsional)"
|
||||||
<Input.TextArea readOnly={readOnly} placeholder="Masukkan Deskripsi (Opsional)" rows={4} />
|
rows={4}
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
@@ -103,4 +104,4 @@ const DetailPlantSection = ({ visible, onCancel, onOk, form, editingKey, readOnl
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DetailPlantSection;
|
export default DetailPlantSection;
|
||||||
|
|||||||
@@ -1,27 +1,39 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Button, Col, Row, Space, Input, ConfigProvider, Card } from 'antd';
|
import { Button, Col, Row, Space, Input, ConfigProvider, Card } from 'antd';
|
||||||
import { PlusOutlined, EditOutlined, DeleteOutlined, SearchOutlined, EyeOutlined } from '@ant-design/icons';
|
import {
|
||||||
|
PlusOutlined,
|
||||||
|
EditOutlined,
|
||||||
|
DeleteOutlined,
|
||||||
|
SearchOutlined,
|
||||||
|
EyeOutlined,
|
||||||
|
} from '@ant-design/icons';
|
||||||
import TableList from '../../../../components/Global/TableList';
|
import TableList from '../../../../components/Global/TableList';
|
||||||
|
|
||||||
const ListPlantSection = ({
|
const ListPlantSection = ({
|
||||||
setActionMode,
|
setActionMode,
|
||||||
handleEdit,
|
handleEdit,
|
||||||
handleDelete,
|
handleDelete,
|
||||||
handlePreview,
|
handlePreview,
|
||||||
getAllPlantSection
|
getAllPlantSection,
|
||||||
|
refreshList,
|
||||||
}) => {
|
}) => {
|
||||||
const [searchValue, setSearchValue] = useState('');
|
const [searchValue, setSearchValue] = useState('');
|
||||||
const [formDataFilter, setFormDataFilter] = useState({ search: '' });
|
const [formDataFilter, setFormDataFilter] = useState({ criteria: '' });
|
||||||
const [trigerFilter, setTrigerFilter] = useState(false);
|
const [trigerFilter, setTrigerFilter] = useState(false);
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
title: 'No',
|
title: 'No',
|
||||||
dataIndex: 'key',
|
dataIndex: 'sub_section_id',
|
||||||
key: 'key',
|
key: 'sub_section_id',
|
||||||
width: '5%',
|
width: '10%',
|
||||||
render: (text, record, index) => index + 1,
|
render: (text, record, index) => index + 1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: 'Nama Sub Section',
|
||||||
|
dataIndex: 'sub_section_name',
|
||||||
|
key: 'sub_section_name',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: 'Kode Plant',
|
title: 'Kode Plant',
|
||||||
dataIndex: 'kode_plant',
|
dataIndex: 'kode_plant',
|
||||||
@@ -45,24 +57,41 @@ const ListPlantSection = ({
|
|||||||
{
|
{
|
||||||
title: 'Aksi',
|
title: 'Aksi',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
|
width: '15%',
|
||||||
render: (_, record) => (
|
render: (_, record) => (
|
||||||
<Space size="middle">
|
<Space size="middle">
|
||||||
<Button type="text" style={{ borderColor: '#1890ff' }} icon={<EyeOutlined style={{ color: '#1890ff' }} />} onClick={() => handlePreview(record)} />
|
<Button
|
||||||
<Button type="text" style={{ borderColor: '#faad14' }} icon={<EditOutlined style={{ color: '#faad14' }} />} onClick={() => handleEdit(record)} />
|
type="text"
|
||||||
<Button type="text" danger style={{ borderColor: 'red' }} icon={<DeleteOutlined />} onClick={() => handleDelete(record)} />
|
style={{ borderColor: '#1890ff' }}
|
||||||
|
icon={<EyeOutlined style={{ color: '#1890ff' }} />}
|
||||||
|
onClick={() => handlePreview(record)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
style={{ borderColor: '#faad14' }}
|
||||||
|
icon={<EditOutlined style={{ color: '#faad14' }} />}
|
||||||
|
onClick={() => handleEdit(record)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
danger
|
||||||
|
style={{ borderColor: 'red' }}
|
||||||
|
icon={<DeleteOutlined />}
|
||||||
|
onClick={() => handleDelete(record)}
|
||||||
|
/>
|
||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
setFormDataFilter({ search: searchValue });
|
setFormDataFilter({ criteria: searchValue });
|
||||||
setTrigerFilter((prev) => !prev);
|
setTrigerFilter((prev) => !prev);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSearchClear = () => {
|
const handleSearchClear = () => {
|
||||||
setSearchValue('');
|
setSearchValue('');
|
||||||
setFormDataFilter({ search: '' });
|
setFormDataFilter({ criteria: '' });
|
||||||
setTrigerFilter((prev) => !prev);
|
setTrigerFilter((prev) => !prev);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -71,7 +100,7 @@ const ListPlantSection = ({
|
|||||||
<Row justify="space-between" align="middle" gutter={[8, 8]}>
|
<Row justify="space-between" align="middle" gutter={[8, 8]}>
|
||||||
<Col xs={24} sm={24} md={12} lg={12}>
|
<Col xs={24} sm={24} md={12} lg={12}>
|
||||||
<Input.Search
|
<Input.Search
|
||||||
placeholder="Cari berdasarkan kode, nama, atau lokasi..."
|
placeholder="Cari berdasarkan nama sub section..."
|
||||||
value={searchValue}
|
value={searchValue}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const value = e.target.value;
|
const value = e.target.value;
|
||||||
@@ -130,10 +159,11 @@ const ListPlantSection = ({
|
|||||||
queryParams={formDataFilter}
|
queryParams={formDataFilter}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
triger={trigerFilter}
|
triger={trigerFilter}
|
||||||
|
refreshList={refreshList}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ListPlantSection;
|
export default ListPlantSection;
|
||||||
|
|||||||
Reference in New Issue
Block a user