add plant section management with list and detail views
This commit is contained in:
@@ -14,6 +14,7 @@ import IndexDevice from './pages/master/device/IndexDevice';
|
|||||||
import IndexTag from './pages/master/tag/IndexTag';
|
import IndexTag from './pages/master/tag/IndexTag';
|
||||||
import IndexBrandDevice from './pages/master/brandDevice/IndexBrandDevice';
|
import IndexBrandDevice from './pages/master/brandDevice/IndexBrandDevice';
|
||||||
import IndexErrorCode from './pages/master/errorCode/IndexErrorCode';
|
import IndexErrorCode from './pages/master/errorCode/IndexErrorCode';
|
||||||
|
import IndexPlantSection from './pages/master/plantSection/IndexPlantSection';
|
||||||
|
|
||||||
// History
|
// History
|
||||||
import IndexTrending from './pages/history/trending/IndexTrending';
|
import IndexTrending from './pages/history/trending/IndexTrending';
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ const allItems = [
|
|||||||
icon: <DatabaseOutlined style={{fontSize:'19px'}} />,
|
icon: <DatabaseOutlined style={{fontSize:'19px'}} />,
|
||||||
label: 'Master',
|
label: 'Master',
|
||||||
children: [
|
children: [
|
||||||
|
{
|
||||||
|
key: 'master-plant-section',
|
||||||
|
icon: <ProductOutlined style={{fontSize:'19px'}} />,
|
||||||
|
label: <Link to="/master/plant-section">Plant Section</Link>,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'master-device',
|
key: 'master-device',
|
||||||
icon: <MobileOutlined style={{fontSize:'19px'}} />,
|
icon: <MobileOutlined style={{fontSize:'19px'}} />,
|
||||||
|
|||||||
215
src/pages/master/plantSection/IndexPlantSection.jsx
Normal file
215
src/pages/master/plantSection/IndexPlantSection.jsx
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
|
||||||
|
import React, { memo, useState, useEffect } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { useBreadcrumb } from '../../../layout/LayoutBreadcrumb';
|
||||||
|
import { Form, Typography } from 'antd';
|
||||||
|
import ListPlantSection from './component/ListPlantSection';
|
||||||
|
import DetailPlantSection from './component/DetailPlantSection';
|
||||||
|
|
||||||
|
import { NotifConfirmDialog, NotifAlert } from '../../../components/Global/ToastNotif';
|
||||||
|
|
||||||
|
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 navigate = useNavigate();
|
||||||
|
const { setBreadcrumbItems } = useBreadcrumb();
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
|
||||||
|
const [data, setData] = useState(initialData);
|
||||||
|
const [actionMode, setActionMode] = useState('list');
|
||||||
|
const [editingKey, setEditingKey] = useState('');
|
||||||
|
const [isModalVisible, setIsModalVisible] = useState(false);
|
||||||
|
const [readOnly, setReadOnly] = 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(() => {
|
||||||
|
const token = localStorage.getItem('token');
|
||||||
|
if (token) {
|
||||||
|
setBreadcrumbItems([
|
||||||
|
{ title: <Text strong style={{ fontSize: '14px' }}>• Master</Text> },
|
||||||
|
{ title: <Text strong style={{ fontSize: '14px' }}>Plant Section</Text> }
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
navigate('/signin');
|
||||||
|
}
|
||||||
|
}, [navigate, setBreadcrumbItems]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (actionMode === 'add' || actionMode === 'edit' || actionMode === 'preview') {
|
||||||
|
setIsModalVisible(true);
|
||||||
|
setReadOnly(actionMode === 'preview');
|
||||||
|
} else {
|
||||||
|
setIsModalVisible(false);
|
||||||
|
}
|
||||||
|
}, [actionMode]);
|
||||||
|
|
||||||
|
const handleCancel = () => {
|
||||||
|
setActionMode('list');
|
||||||
|
setEditingKey('');
|
||||||
|
form.resetFields();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOk = () => {
|
||||||
|
if (readOnly) {
|
||||||
|
handleCancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
form.validateFields()
|
||||||
|
.then((values) => {
|
||||||
|
let newData = [...data];
|
||||||
|
if (editingKey) {
|
||||||
|
// Editing existing data
|
||||||
|
const index = newData.findIndex((item) => editingKey === item.key);
|
||||||
|
if (index > -1) {
|
||||||
|
const item = newData[index];
|
||||||
|
newData.splice(index, 1, { ...item, ...values });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Adding new data
|
||||||
|
const newKey = (Math.max(...data.map(item => parseInt(item.key))) + 1).toString();
|
||||||
|
newData = [{ key: newKey, ...values }, ...newData];
|
||||||
|
}
|
||||||
|
setData(newData);
|
||||||
|
NotifAlert({
|
||||||
|
icon: 'success',
|
||||||
|
title: 'Berhasil',
|
||||||
|
message: 'Data Plant Section berhasil disimpan.',
|
||||||
|
});
|
||||||
|
handleCancel();
|
||||||
|
})
|
||||||
|
.catch((info) => {
|
||||||
|
console.log('Validate Failed:', info);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEdit = (record) => {
|
||||||
|
form.setFieldsValue(record);
|
||||||
|
setEditingKey(record.key);
|
||||||
|
setActionMode('edit');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePreview = (record) => {
|
||||||
|
form.setFieldsValue(record);
|
||||||
|
setEditingKey(record.key);
|
||||||
|
setActionMode('preview');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = (record) => {
|
||||||
|
NotifConfirmDialog({
|
||||||
|
icon: 'question',
|
||||||
|
title: 'Konfirmasi',
|
||||||
|
message: `Apakah anda yakin ingin menghapus plant section "${record.nama_plant}"?`,
|
||||||
|
onConfirm: () => {
|
||||||
|
const newData = data.filter((item) => item.key !== record.key);
|
||||||
|
setData(newData);
|
||||||
|
NotifAlert({
|
||||||
|
icon: 'success',
|
||||||
|
title: 'Berhasil',
|
||||||
|
message: `Plant section "${record.nama_plant}" berhasil dihapus.`,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<ListPlantSection
|
||||||
|
setActionMode={setActionMode}
|
||||||
|
handleEdit={handleEdit}
|
||||||
|
handleDelete={handleDelete}
|
||||||
|
handlePreview={handlePreview}
|
||||||
|
getAllPlantSection={getAllPlantSection}
|
||||||
|
/>
|
||||||
|
<DetailPlantSection
|
||||||
|
visible={isModalVisible}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
onOk={handleOk}
|
||||||
|
form={form}
|
||||||
|
editingKey={editingKey}
|
||||||
|
readOnly={readOnly}
|
||||||
|
/>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default IndexPlantSection;
|
||||||
106
src/pages/master/plantSection/component/DetailPlantSection.jsx
Normal file
106
src/pages/master/plantSection/component/DetailPlantSection.jsx
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Modal, Form, Input, ConfigProvider, Button, Typography } from 'antd';
|
||||||
|
|
||||||
|
const { Text } = Typography;
|
||||||
|
|
||||||
|
const DetailPlantSection = ({ visible, onCancel, onOk, form, editingKey, readOnly }) => {
|
||||||
|
const modalTitle = readOnly ? 'Preview Plant Section' : (editingKey ? 'Edit Plant Section' : 'Tambah Plant Section');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
title={modalTitle}
|
||||||
|
visible={visible}
|
||||||
|
onCancel={onCancel}
|
||||||
|
footer={[
|
||||||
|
<React.Fragment key="modal-footer">
|
||||||
|
<ConfigProvider
|
||||||
|
theme={{
|
||||||
|
token: { colorBgContainer: '#E9F6EF' },
|
||||||
|
components: {
|
||||||
|
Button: {
|
||||||
|
defaultBg: 'white',
|
||||||
|
defaultColor: '#23A55A',
|
||||||
|
defaultBorderColor: '#23A55A',
|
||||||
|
defaultHoverColor: '#23A55A',
|
||||||
|
defaultHoverBorderColor: '#23A55A',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button onClick={onCancel}>Batal</Button>
|
||||||
|
</ConfigProvider>
|
||||||
|
<ConfigProvider
|
||||||
|
theme={{
|
||||||
|
token: {
|
||||||
|
colorBgContainer: '#209652',
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
Button: {
|
||||||
|
defaultBg: '#23a55a',
|
||||||
|
defaultColor: '#FFFFFF',
|
||||||
|
defaultBorderColor: '#23a55a',
|
||||||
|
defaultHoverColor: '#FFFFFF',
|
||||||
|
defaultHoverBorderColor: '#23a55a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{!readOnly && (
|
||||||
|
<Button onClick={onOk}>
|
||||||
|
Simpan
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</ConfigProvider>
|
||||||
|
</React.Fragment>,
|
||||||
|
]}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={form} layout="vertical" name="form_in_modal">
|
||||||
|
<div style={{ marginBottom: 12 }}>
|
||||||
|
<Text strong>Kode Plant</Text>
|
||||||
|
<Text style={{ color: 'red' }}> *</Text>
|
||||||
|
<Form.Item
|
||||||
|
name="kode_plant"
|
||||||
|
rules={[{ required: true, message: 'Silakan masukkan kode plant!' }]}
|
||||||
|
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} />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DetailPlantSection;
|
||||||
139
src/pages/master/plantSection/component/ListPlantSection.jsx
Normal file
139
src/pages/master/plantSection/component/ListPlantSection.jsx
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { Button, Col, Row, Space, Input, ConfigProvider, Card } from 'antd';
|
||||||
|
import { PlusOutlined, EditOutlined, DeleteOutlined, SearchOutlined, EyeOutlined } from '@ant-design/icons';
|
||||||
|
import TableList from '../../../../components/Global/TableList';
|
||||||
|
|
||||||
|
const ListPlantSection = ({
|
||||||
|
setActionMode,
|
||||||
|
handleEdit,
|
||||||
|
handleDelete,
|
||||||
|
handlePreview,
|
||||||
|
getAllPlantSection
|
||||||
|
}) => {
|
||||||
|
const [searchValue, setSearchValue] = useState('');
|
||||||
|
const [formDataFilter, setFormDataFilter] = useState({ search: '' });
|
||||||
|
const [trigerFilter, setTrigerFilter] = useState(false);
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
title: 'No',
|
||||||
|
dataIndex: 'key',
|
||||||
|
key: 'key',
|
||||||
|
width: '5%',
|
||||||
|
render: (text, record, index) => index + 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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',
|
||||||
|
render: (_, record) => (
|
||||||
|
<Space size="middle">
|
||||||
|
<Button type="text" icon={<EyeOutlined style={{ color: '#1890ff' }} />} onClick={() => handlePreview(record)} />
|
||||||
|
<Button type="text" icon={<EditOutlined style={{ color: '#faad14' }} />} onClick={() => handleEdit(record)} />
|
||||||
|
<Button type="text" danger icon={<DeleteOutlined />} onClick={() => handleDelete(record)} />
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const handleSearch = () => {
|
||||||
|
setFormDataFilter({ search: searchValue });
|
||||||
|
setTrigerFilter((prev) => !prev);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSearchClear = () => {
|
||||||
|
setSearchValue('');
|
||||||
|
setFormDataFilter({ search: '' });
|
||||||
|
setTrigerFilter((prev) => !prev);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<Row justify="space-between" align="middle" gutter={[8, 8]}>
|
||||||
|
<Col xs={24} sm={24} md={12} lg={12}>
|
||||||
|
<Input.Search
|
||||||
|
placeholder="Cari berdasarkan kode, nama, atau lokasi..."
|
||||||
|
value={searchValue}
|
||||||
|
onChange={(e) => {
|
||||||
|
const value = e.target.value;
|
||||||
|
setSearchValue(value);
|
||||||
|
if (value === '') {
|
||||||
|
handleSearchClear();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onSearch={handleSearch}
|
||||||
|
allowClear={{
|
||||||
|
clearIcon: <span onClick={handleSearchClear}>✕</span>,
|
||||||
|
}}
|
||||||
|
enterButton={
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
icon={<SearchOutlined />}
|
||||||
|
style={{
|
||||||
|
backgroundColor: '#23A55A',
|
||||||
|
borderColor: '#23A55A',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Search
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
size="large"
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
<Col>
|
||||||
|
<ConfigProvider
|
||||||
|
theme={{
|
||||||
|
token: { colorBgContainer: '#E9F6EF' },
|
||||||
|
components: {
|
||||||
|
Button: {
|
||||||
|
defaultBg: 'white',
|
||||||
|
defaultColor: '#23A55A',
|
||||||
|
defaultBorderColor: '#23A55A',
|
||||||
|
defaultHoverColor: '#23A55A',
|
||||||
|
defaultHoverBorderColor: '#23A55A',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
icon={<PlusOutlined />}
|
||||||
|
onClick={() => setActionMode('add')}
|
||||||
|
size="large"
|
||||||
|
>
|
||||||
|
Tambah Data
|
||||||
|
</Button>
|
||||||
|
</ConfigProvider>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<Col xs={24} sm={24} md={24} lg={24} xl={24} style={{ marginTop: '16px' }}>
|
||||||
|
<TableList
|
||||||
|
getData={getAllPlantSection}
|
||||||
|
queryParams={formDataFilter}
|
||||||
|
columns={columns}
|
||||||
|
triger={trigerFilter}
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ListPlantSection;
|
||||||
Reference in New Issue
Block a user