diff --git a/src/components/Global/CardList.jsx b/src/components/Global/CardList.jsx index ee9cc9e..39b7693 100644 --- a/src/components/Global/CardList.jsx +++ b/src/components/Global/CardList.jsx @@ -54,43 +54,42 @@ const CardList = ({ } style={getCardStyle()} actions={[ - - } - onClick={() => showPreviewModal(item)} - /> - } - onClick={() => showEditModal(item)} - /> - } - onClick={() => showDeleteDialog(item)} - /> - , + showPreviewModal(item)} + />, + showEditModal(item)} + />, + showDeleteDialog(item)} + />, ]} > {column.map((itemCard, index) => ( - {!itemCard.hidden && itemCard.title !== 'No' && itemCard.title !== 'Aksi' && ( - - {itemCard.title}:{' '} - {itemCard.render - ? itemCard.render(item[itemCard.dataIndex], item, index) - : item[itemCard.dataIndex] || item[itemCard.key] || '-' - } - - )} + {!itemCard.hidden && + itemCard.title !== 'No' && + itemCard.title !== 'Aksi' && ( + + {itemCard.title}:{' '} + {itemCard.render + ? itemCard.render( + item[itemCard.dataIndex], + item, + index + ) + : item[itemCard.dataIndex] || + item[itemCard.key] || + '-'} + + )} ))} diff --git a/src/pages/master/status/IndexStatus.jsx b/src/pages/master/status/IndexStatus.jsx index 61cc608..4542207 100644 --- a/src/pages/master/status/IndexStatus.jsx +++ b/src/pages/master/status/IndexStatus.jsx @@ -13,45 +13,73 @@ const IndexStatus = memo(function IndexStatus() { const [actionMode, setActionMode] = useState('list'); const [selectedData, setSelectedData] = useState(null); - const [isModalVisible, setIsModalVisible] = useState(false); const [readOnly, setReadOnly] = useState(false); + const [showModal, setShowModal] = useState(false); + + const setMode = (param) => { + setShowModal(true); + switch (param) { + case 'add': + setReadOnly(false); + break; + + case 'edit': + setReadOnly(false); + break; + + case 'preview': + setReadOnly(true); + break; + + default: + setShowModal(false); + break; + } + setActionMode(param); + }; useEffect(() => { const token = localStorage.getItem('token'); if (token) { setBreadcrumbItems([ - { title: • Master }, - { title: Status } + { + title: ( + + • Master + + ), + }, + { + title: ( + + Status + + ), + }, ]); } else { navigate('/signin'); } - }, [navigate, setBreadcrumbItems]); - - useEffect(() => { - if (actionMode === 'add' || actionMode === 'edit' || actionMode === 'preview') { - setIsModalVisible(true); - setReadOnly(actionMode === 'preview'); - } else { - setIsModalVisible(false); - } - }, [actionMode]); + }, []); return ( - {actionMode === 'list' && + {actionMode === 'list' && ( - } + )} ); diff --git a/src/pages/master/status/component/ListStatus.jsx b/src/pages/master/status/component/ListStatus.jsx index ce5dd42..25c773e 100644 --- a/src/pages/master/status/component/ListStatus.jsx +++ b/src/pages/master/status/component/ListStatus.jsx @@ -1,68 +1,89 @@ import React, { memo, useState, useEffect } from 'react'; -import { Space, ConfigProvider, Button, Row, Col, Card, Input, Segmented, Table, Pagination } from 'antd'; +import { Space, ConfigProvider, Button, Row, Col, Card, Input } from 'antd'; import { PlusOutlined, EditOutlined, DeleteOutlined, EyeOutlined, SearchOutlined, - AppstoreOutlined, - TableOutlined, } from '@ant-design/icons'; import { NotifAlert, NotifConfirmDialog } from '../../../../components/Global/ToastNotif'; import { useNavigate } from 'react-router-dom'; import { deleteStatus, getAllStatuss } from '../../../../api/master-status'; +import TableList from '../../../../components/Global/TableList'; + +const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ + { title: 'Number', dataIndex: 'status_number', key: 'status_number', width: '15%' }, + { title: 'Name', dataIndex: 'status_name', key: 'status_name', width: '25%' }, + { + title: 'Description', + dataIndex: 'status_description', + key: 'status_description', + width: '40%', + }, + { + title: 'Aksi', + key: 'aksi', + align: 'center', + width: '20%', + render: (_, record) => ( + + } + onClick={() => showPreviewModal(record)} + /> + } + onClick={() => showEditModal(record)} + /> + } + onClick={() => showDeleteDialog(record)} + /> + + ), + }, +]; const ListStatus = memo(function ListStatus(props) { - const [data, setData] = useState([]); - const [loading, setLoading] = useState(true); - const [viewMode, setViewMode] = useState('card'); const [trigerFilter, setTrigerFilter] = useState(false); + const defaultFilter = { criteria: '' }; + const [formDataFilter, setFormDataFilter] = useState(defaultFilter); const [searchValue, setSearchValue] = useState(''); - const [pagination, setPagination] = useState({ current: 1, pageSize: 10, total: 0 }); const navigate = useNavigate(); - const fetchData = async (page = 1, pageSize = 10) => { - setLoading(true); - try { - const params = new URLSearchParams(); - params.append('page', page); - params.append('limit', pageSize); - if (searchValue) { - params.append('search', searchValue); - } - const response = await getAllStatuss(params); - setData(response.data || []); - setPagination(prev => ({ ...prev, total: response.paging?.total || 0, current: page, pageSize: pageSize })); - } catch (error) { - console.error("Failed to fetch status data:", error); - setData([]); - } finally { - setLoading(false); - } - }; - useEffect(() => { const token = localStorage.getItem('token'); - if (!token) { + if (token) { + if (props.actionMode === 'list') { + setFormDataFilter(defaultFilter); + doFilter(); + } + } else { navigate('/signin'); - return; } - fetchData(pagination.current, pagination.pageSize); - }, [props.actionMode, trigerFilter, navigate]); + }, [props.actionMode]); const doFilter = () => { - setTrigerFilter(prev => !prev); + setTrigerFilter((prev) => !prev); }; - const handleSearch = (value) => { - setSearchValue(value); - setPagination(prev => ({ ...prev, current: 1 })); // Reset to first page on search - doFilter(); + const handleSearch = () => { + setFormDataFilter({ criteria: searchValue }); + setTrigerFilter((prev) => !prev); }; - const handlePaginationChange = (page, pageSize) => { - fetchData(page, pageSize); + const handleSearchClear = () => { + setSearchValue(''); + setFormDataFilter({ criteria: '' }); + setTrigerFilter((prev) => !prev); }; const showPreviewModal = (record) => { @@ -93,40 +114,24 @@ const ListStatus = memo(function ListStatus(props) { try { const response = await deleteStatus(status_id); if (response.statusCode === 200) { - NotifAlert({ icon: 'success', title: 'Berhasil', message: 'Data Status berhasil dihapus.' }); + NotifAlert({ + icon: 'success', + title: 'Berhasil', + message: 'Data Status berhasil dihapus.', + }); doFilter(); } else { - NotifAlert({ icon: 'error', title: 'Gagal', message: response?.message || 'Gagal Menghapus Data' }); + NotifAlert({ + icon: 'error', + title: 'Gagal', + message: response?.message || 'Gagal Menghapus Data', + }); } } catch (error) { NotifAlert({ icon: 'error', title: 'Error', message: error.message }); } }; - const columns = [ - { title: 'Number', dataIndex: 'status_number', key: 'status_number', width: '15%' }, - { title: 'Name', dataIndex: 'status_name', key: 'status_name', width: '25%' }, - { title: 'Description', dataIndex: 'status_description', key: 'status_description', width: '40%' }, - { - title: 'Aksi', key: 'aksi', align: 'center', width: '20%', - render: (_, record) => ( - - } onClick={() => showPreviewModal(record)} /> - } onClick={() => showEditModal(record)} /> - } onClick={() => showDeleteDialog(record)} /> - - ), - }, - ]; - - const getCardStyle = (color) => { - return { border: `2px solid ${color || '#d9d9d9'}`, height: '100%' }; - }; - - const getTitleStyle = (color) => { - return { backgroundColor: color || 'transparent', color: '#fff', padding: '2px 8px', borderRadius: '4px', display: 'inline-block' }; - }; - return ( @@ -134,7 +139,16 @@ const ListStatus = memo(function ListStatus(props) { { + const value = e.target.value; + setSearchValue(value); + if (value === '') { + handleSearchClear(); + } + }} + allowClear={{ + clearIcon: ✕, + }} enterButton={ - - - - }, { value: 'table', icon: }]} - value={viewMode} - onChange={setViewMode} + + - - - {viewMode === 'card' ? ( - - {data.map(item => ( - - {item.status_name}} - style={getCardStyle(item.status_color)} - actions={[ - showPreviewModal(item)} />, - showEditModal(item)} />, - showDeleteDialog(item)} />, - ]} - > - Number: {item.status_number} - Description: {item.status_description} - - - ))} - - ) : ( - <> - ({ ...item, key: item.status_id }))} - pagination={false} - loading={loading} - /> - - > - )} - ); }); -export default ListStatus; \ No newline at end of file +export default ListStatus;
- {itemCard.title}:{' '} - {itemCard.render - ? itemCard.render(item[itemCard.dataIndex], item, index) - : item[itemCard.dataIndex] || item[itemCard.key] || '-' - } -
+ {itemCard.title}:{' '} + {itemCard.render + ? itemCard.render( + item[itemCard.dataIndex], + item, + index + ) + : item[itemCard.dataIndex] || + item[itemCard.key] || + '-'} +
Number: {item.status_number}
Description: {item.status_description}