diff --git a/src/pages/master/plantSection/IndexPlantSection.jsx b/src/pages/master/plantSection/IndexPlantSection.jsx index 8f8520c..c3fdd8d 100644 --- a/src/pages/master/plantSection/IndexPlantSection.jsx +++ b/src/pages/master/plantSection/IndexPlantSection.jsx @@ -1,183 +1,79 @@ - 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, NotifOk } from '../../../components/Global/ToastNotif'; -import { getAllPlantSection, createPlantSection, updatePlantSection, deletePlantSection } from '../../../api/master-plant-section'; +import { useBreadcrumb } from '../../../layout/LayoutBreadcrumb'; +import { Typography } from 'antd'; const { Text } = Typography; const IndexPlantSection = memo(function IndexPlantSection() { const navigate = useNavigate(); const { setBreadcrumbItems } = useBreadcrumb(); - const [form] = Form.useForm(); + const [activeTab, setActiveTab] = useState('plantSection'); const [actionMode, setActionMode] = useState('list'); - const [editingKey, setEditingKey] = useState(''); - const [editingRecord, setEditingRecord] = useState(null); - const [isModalVisible, setIsModalVisible] = useState(false); + const [selectedData, setSelectedData] = useState(null); const [readOnly, setReadOnly] = useState(false); - const [refreshList, setRefreshList] = useState(false); + const [showModal, setShowmodal] = useState(false); + + const setMode = (param) => { + setActionMode(param); + switch (param) { + case 'add': + setReadOnly(false); + setShowmodal(true); + break; + + case 'edit': + setReadOnly(false); + setShowmodal(true); + break; + + case 'preview': + setReadOnly(true); + setShowmodal(true); + break; + + default: + setShowmodal(false); + break; + } + }; useEffect(() => { const token = localStorage.getItem('token'); if (token) { setBreadcrumbItems([ { title: • Master }, - { title: Plant Sub Section } + { title: Plant Section } ]); } 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(''); - setEditingRecord(null); - form.resetFields(); - }; - - const handleOk = async () => { - if (readOnly) { - handleCancel(); - return; - } - - try { - const values = await form.validateFields(); - - if (editingKey && editingRecord) { - // Update existing plant section - const response = await updatePlantSection(editingRecord.sub_section_id, values); - - if (response.statusCode === 200) { - NotifOk({ - icon: 'success', - title: 'Berhasil', - message: response.message || 'Data Sub Section berhasil diupdate.', - }); - setRefreshList(!refreshList); - handleCancel(); - } else { - NotifAlert({ - icon: 'error', - title: 'Gagal', - message: response.message || 'Gagal mengupdate data Sub Section.', - }); - } - } else { - // Create new plant section - const response = await createPlantSection(values); - - if (response.statusCode === 200 || response.statusCode === 201) { - NotifOk({ - icon: 'success', - title: 'Berhasil', - message: response.message || 'Data Sub Section berhasil ditambahkan.', - }); - 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) => { - form.setFieldsValue(record); - setEditingKey(record.sub_section_id || record.key); - setEditingRecord(record); - setActionMode('edit'); - }; - - const handlePreview = (record) => { - form.setFieldsValue(record); - setEditingKey(record.sub_section_id || record.key); - setEditingRecord(record); - setActionMode('preview'); - }; - - const handleDelete = (record) => { - NotifConfirmDialog({ - icon: 'question', - title: 'Konfirmasi', - message: `Apakah anda yakin ingin menghapus sub section "${record.sub_section_name}"?`, - onConfirm: async () => { - try { - const response = await deletePlantSection(record.sub_section_id); - - if (response.statusCode === 200) { - NotifOk({ - 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.', - }); - } - }, - }); - }; + }, []); return ( ); }); -export default IndexPlantSection; +export default IndexPlantSection; \ No newline at end of file diff --git a/src/pages/master/plantSection/component/DetailPlantSection.jsx b/src/pages/master/plantSection/component/DetailPlantSection.jsx index b0ce132..ad73a82 100644 --- a/src/pages/master/plantSection/component/DetailPlantSection.jsx +++ b/src/pages/master/plantSection/component/DetailPlantSection.jsx @@ -1,75 +1,7 @@ -import React from 'react'; -import { Modal, Form, Input, ConfigProvider, Button, Typography } from 'antd'; +import React, { memo } from 'react'; -const { Text } = Typography; +const DetailPlantSection = memo(function DetailPlantSection(props) { + return null; +}); -const DetailPlantSection = ({ visible, onCancel, onOk, form, editingKey, readOnly }) => { - const modalTitle = readOnly - ? 'Preview Sub Section' - : editingKey - ? 'Edit Sub Section' - : 'Tambah Sub Section'; - - return ( - - - - - - {!readOnly && } - - , - ]} - destroyOnClose - > -
-
- Nama Sub Section - * - - - -
-
-
- ); -}; - -export default DetailPlantSection; +export default DetailPlantSection; \ No newline at end of file diff --git a/src/pages/master/plantSection/component/ListPlantSection.jsx b/src/pages/master/plantSection/component/ListPlantSection.jsx index e8c14f8..33d34e1 100644 --- a/src/pages/master/plantSection/component/ListPlantSection.jsx +++ b/src/pages/master/plantSection/component/ListPlantSection.jsx @@ -1,5 +1,5 @@ -import React, { useState, useEffect } from 'react'; -import { Button, Col, Row, Space, Input, ConfigProvider, Card } from 'antd'; +import React, { memo, useState, useEffect } from 'react'; +import { Button, Col, Row, Space, Input, ConfigProvider, Card, Tag, Tabs } from 'antd'; import { PlusOutlined, EditOutlined, @@ -7,156 +7,314 @@ import { SearchOutlined, EyeOutlined, } from '@ant-design/icons'; +import { NotifAlert, NotifConfirmDialog } from '../../../../components/Global/ToastNotif'; +import { useNavigate } from 'react-router-dom'; import TableList from '../../../../components/Global/TableList'; -const ListPlantSection = ({ - setActionMode, - handleEdit, - handleDelete, - handlePreview, - getAllPlantSection, - refreshList, -}) => { - const [searchValue, setSearchValue] = useState(''); - const [formDataFilter, setFormDataFilter] = useState({ criteria: '' }); +// Dummy data for Plant Section +const initialPlantSectionData = [ + { + plant_section_id: 1, + plantName: 'Assembly', + sectionName: 'Line 1', + status: 'Active', + }, + { + plant_section_id: 2, + plantName: 'Assembly', + sectionName: 'Line 2', + status: 'Active', + }, + { + plant_section_id: 3, + plantName: 'Painting', + sectionName: 'Booth A', + status: 'Active', + }, + { + plant_section_id: 4, + plantName: 'Warehouse', + sectionName: 'Receiving', + status: 'Inactive', + }, +]; + +const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ + { + title: 'No', + key: 'no', + width: '5%', + align: 'center', + render: (_, __, index) => index + 1, + }, + { + title: 'Plant Name', + dataIndex: 'plantName', + key: 'plantName', + width: '30%', + }, + { + title: 'Section Name', + dataIndex: 'sectionName', + key: 'sectionName', + width: '30%', + }, + { + title: 'Status', + dataIndex: 'status', + key: 'status', + width: '15%', + align: 'center', + render: (_, { status }) => ( + <> + {status === 'Active' ? ( + + Active + + ) : ( + + Inactive + + )} + + ), + }, + { + title: 'Aksi', + key: 'action', + align: 'center', + width: '20%', + render: (_, record) => ( + + - } - size="large" - /> - - - - - - - - - - - - ); -}; + const showPreviewModal = (param) => { + props.setSelectedData(param); + props.setActionMode('preview'); + }; -export default ListPlantSection; + const showEditModal = (param = null) => { + props.setSelectedData(param); + props.setActionMode('edit'); + }; + + const showAddModal = (param = null) => { + props.setSelectedData(param); + props.setActionMode('add'); + }; + + const showDeleteDialog = (param) => { + NotifConfirmDialog({ + icon: 'question', + title: 'Konfirmasi', + message: 'Apakah anda yakin hapus data "' + param.plantName + ' - ' + param.sectionName + '" ?', + onConfirm: () => handleDelete(param.plant_section_id), + onCancel: () => props.setSelectedData(null), + }); + }; + + const handleDelete = async (plant_section_id) => { + const plantToDelete = plantSectionData.find((plant) => plant.plant_section_id === plant_section_id); + + await new Promise((resolve) => setTimeout(resolve, 300)); + + const updatedPlants = plantSectionData.filter((plant) => plant.plant_section_id !== plant_section_id); + setPlantSectionData(updatedPlants); + + NotifAlert({ + icon: 'success', + title: 'Berhasil', + message: `Data Plant Section "${plantToDelete?.plantName || ''} - ${plantToDelete?.sectionName || ''}" berhasil dihapus.`, + }); + }; + + return ( + + + + + + + { + const value = e.target.value; + setSearchValue(value); + if (value === '') { + setFormDataFilter({ search: '' }); + setTrigerFilter((prev) => !prev); + } + }} + onSearch={handleSearch} + allowClear={{ + clearIcon: , + }} + enterButton={ + + } + size="large" + /> + + + + + + + + + + + + + + + + + ); +}); + +export default ListPlantSection; \ No newline at end of file