From 2f621fc6c27d8ecd1e8f4ecddea7bb5cc533556f Mon Sep 17 00:00:00 2001 From: Iqbal Rizqi Kurniawan Date: Thu, 16 Oct 2025 23:39:41 +0700 Subject: [PATCH] update status active inactive --- .../component/DetailPlantSection.jsx | 217 +++++++++++++++++- .../component/ListPlantSection.jsx | 29 +-- 2 files changed, 219 insertions(+), 27 deletions(-) diff --git a/src/pages/master/plantSection/component/DetailPlantSection.jsx b/src/pages/master/plantSection/component/DetailPlantSection.jsx index ad73a82..af0c871 100644 --- a/src/pages/master/plantSection/component/DetailPlantSection.jsx +++ b/src/pages/master/plantSection/component/DetailPlantSection.jsx @@ -1,7 +1,216 @@ -import React, { memo } from 'react'; +import { useEffect, useState } from 'react'; +import { Modal, Input, Divider, Typography, Switch, Button, ConfigProvider, Select } from 'antd'; +import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif'; -const DetailPlantSection = memo(function DetailPlantSection(props) { - return null; -}); +const { Text } = Typography; + +const DetailPlantSection = (props) => { + const [confirmLoading, setConfirmLoading] = useState(false); + + const defaultData = { + plant_section_id: '', + plantName: '', + status: true, + }; + + const [FormData, setFormData] = useState(defaultData); + + const handleCancel = () => { + props.setSelectedData(null); + props.setActionMode('list'); + }; + + const handleSave = async () => { + setConfirmLoading(true); + + if (!FormData.plantName) { + NotifOk({ + icon: 'warning', + title: 'Peringatan', + message: 'Kolom Plant Name Tidak Boleh Kosong', + }); + setConfirmLoading(false); + return; + } + + const payload = { + plantName: FormData.plantName, + status: FormData.status, + }; + + try { + await new Promise((resolve) => setTimeout(resolve, 500)); + + const response = { + statusCode: FormData.plant_section_id ? 200 : 201, + data: { + plantName: FormData.plantName, + }, + }; + + if (response && (response.statusCode === 200 || response.statusCode === 201)) { + NotifOk({ + icon: 'success', + title: 'Berhasil', + message: `Data Plant Section "${ + response.data?.plantName || FormData.plantName + }" berhasil ${FormData.plant_section_id ? 'diubah' : 'ditambahkan'}.`, + }); + + props.setActionMode('list'); + } else { + NotifAlert({ + icon: 'error', + title: 'Gagal', + message: response?.message || 'Terjadi kesalahan saat menyimpan data.', + }); + } + } catch (error) { + console.error('Save Plant Section Error:', error); + NotifAlert({ + icon: 'error', + title: 'Error', + message: error.message || 'Terjadi kesalahan pada server. Coba lagi nanti.', + }); + } + + setConfirmLoading(false); + }; + + const handleInputChange = (e) => { + const { name, value } = e.target; + setFormData({ + ...FormData, + [name]: value, + }); + }; + + const handleStatusChange = (value) => { + setFormData({ + ...FormData, + status: value, + }); + }; + + useEffect(() => { + const token = localStorage.getItem('token'); + if (token) { + if (props.selectedData != null) { + setFormData(props.selectedData); + } else { + setFormData(defaultData); + } + } else { + // navigate('/signin'); // Uncomment if useNavigate is imported + } + }, [props.showModal]); + + return ( + + + + + + {!props.readOnly && ( + + )} + + , + ]} + > + {FormData && ( +
+ +
+ Status + * +
+
+ +
+
+ {FormData.status === true ? 'Active' : 'Inactive'} +
+
+
+
+ Plant Name + * + +
+
+ )} +
+ ); +}; 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 33d34e1..fe62fa4 100644 --- a/src/pages/master/plantSection/component/ListPlantSection.jsx +++ b/src/pages/master/plantSection/component/ListPlantSection.jsx @@ -16,25 +16,16 @@ const initialPlantSectionData = [ { plant_section_id: 1, plantName: 'Assembly', - sectionName: 'Line 1', status: 'Active', }, { plant_section_id: 2, - plantName: 'Assembly', - sectionName: 'Line 2', + plantName: 'Painting', status: 'Active', }, { plant_section_id: 3, - plantName: 'Painting', - sectionName: 'Booth A', - status: 'Active', - }, - { - plant_section_id: 4, plantName: 'Warehouse', - sectionName: 'Receiving', status: 'Inactive', }, ]; @@ -51,13 +42,7 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ title: 'Plant Name', dataIndex: 'plantName', key: 'plantName', - width: '30%', - }, - { - title: 'Section Name', - dataIndex: 'sectionName', - key: 'sectionName', - width: '30%', + width: '65%', }, { title: 'Status', @@ -137,8 +122,7 @@ const ListPlantSection = memo(function ListPlantSection(props) { const searchLower = searchParam.toLowerCase(); filteredPlantSections = plantSectionData.filter( (plant) => - plant.plantName.toLowerCase().includes(searchLower) || - plant.sectionName.toLowerCase().includes(searchLower) + plant.plantName.toLowerCase().includes(searchLower) ); } @@ -210,7 +194,7 @@ const ListPlantSection = memo(function ListPlantSection(props) { NotifConfirmDialog({ icon: 'question', title: 'Konfirmasi', - message: 'Apakah anda yakin hapus data "' + param.plantName + ' - ' + param.sectionName + '" ?', + message: 'Apakah anda yakin hapus data "' + param.plantName + '" ?', onConfirm: () => handleDelete(param.plant_section_id), onCancel: () => props.setSelectedData(null), }); @@ -227,7 +211,7 @@ const ListPlantSection = memo(function ListPlantSection(props) { NotifAlert({ icon: 'success', title: 'Berhasil', - message: `Data Plant Section "${plantToDelete?.plantName || ''} - ${plantToDelete?.sectionName || ''}" berhasil dihapus.`, + message: `Data Plant Section "${plantToDelete?.plantName || ''}" berhasil dihapus.`, }); }; @@ -301,7 +285,6 @@ const ListPlantSection = memo(function ListPlantSection(props) { mobile cardColor={'#42AAFF'} header={'plantName'} - subHeader={'sectionName'} showPreviewModal={showPreviewModal} showEditModal={showEditModal} showDeleteDialog={showDeleteDialog} @@ -317,4 +300,4 @@ const ListPlantSection = memo(function ListPlantSection(props) { ); }); -export default ListPlantSection; \ No newline at end of file +export default ListPlantSection;