lavoce #2
@@ -247,7 +247,6 @@ const TableList = memo(function TableList({
|
||||
loading={gridLoading}
|
||||
scroll={{
|
||||
y: 520,
|
||||
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -256,7 +255,7 @@ const TableList = memo(function TableList({
|
||||
<Row justify="space-between" align="middle">
|
||||
<Col>
|
||||
<div>
|
||||
Menampilkan {pagingResponse.totalData} Data dari{' '}
|
||||
Menampilkan {pagingResponse.totalPage} Data dari{' '}
|
||||
{pagingResponse.perPage} Halaman
|
||||
</div>
|
||||
</Col>
|
||||
|
||||
@@ -10,14 +10,14 @@ const LayoutLogo = () => {
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
backgroundColor: '#001529',
|
||||
padding: '1rem',
|
||||
borderRadius: '1rem',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
background: 'radial-gradient(circle at center, rgba(255,255,255,0.95), rgba(220,220,220,0.5))',
|
||||
background:
|
||||
'radial-gradient(circle at center, rgba(255,255,255,0.95), rgba(220,220,220,0.5))',
|
||||
borderRadius: '50%',
|
||||
width: 160,
|
||||
height: 160,
|
||||
@@ -26,7 +26,7 @@ const LayoutLogo = () => {
|
||||
alignItems: 'center',
|
||||
boxShadow: '0 6px 20px rgba(0, 0, 0, 0.2)',
|
||||
position: 'relative',
|
||||
overflow: 'hidden'
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
{/* Ring sebelum logo utama */}
|
||||
@@ -37,7 +37,7 @@ const LayoutLogo = () => {
|
||||
width: 160,
|
||||
height: 160,
|
||||
position: 'absolute',
|
||||
zIndex: 1
|
||||
zIndex: 1,
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -66,4 +66,4 @@ const LayoutLogo = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default LayoutLogo;
|
||||
export default LayoutLogo;
|
||||
|
||||
@@ -57,7 +57,7 @@ const SignIn = () => {
|
||||
localStorage.setItem('token', accessToken);
|
||||
localStorage.setItem('user', JSON.stringify(user));
|
||||
|
||||
NotifOk({
|
||||
NotifAlert({
|
||||
icon: 'success',
|
||||
title: 'Login Berhasil',
|
||||
message: res?.message || 'Selamat datang!',
|
||||
|
||||
@@ -45,7 +45,7 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [
|
||||
title: 'Device Code',
|
||||
dataIndex: 'device_code',
|
||||
key: 'device_code',
|
||||
width: '5%',
|
||||
width: '10%',
|
||||
},
|
||||
{
|
||||
title: 'Device Name',
|
||||
@@ -94,17 +94,20 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [
|
||||
<Space>
|
||||
<Button
|
||||
type="text"
|
||||
style={{ borderColor: '#1890ff' }}
|
||||
icon={<EyeOutlined style={{ color: '#1890ff' }} />}
|
||||
onClick={() => showPreviewModal(record)}
|
||||
/>
|
||||
<Button
|
||||
type="text"
|
||||
style={{ borderColor: '#faad14' }}
|
||||
icon={<EditOutlined style={{ color: '#faad14' }} />}
|
||||
onClick={() => showEditModal(record)}
|
||||
/>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
style={{ borderColor: 'red' }}
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => showDeleteDialog(record)}
|
||||
/>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import React, { memo, useEffect } from 'react';
|
||||
import React, { memo, useState, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import ListTag from './component/ListTag';
|
||||
import DetailTag from './component/DetailTag';
|
||||
import { useBreadcrumb } from '../../../layout/LayoutBreadcrumb';
|
||||
import { Typography } from 'antd';
|
||||
|
||||
@@ -9,6 +11,35 @@ const IndexTag = memo(function IndexTag() {
|
||||
const navigate = useNavigate();
|
||||
const { setBreadcrumbItems } = useBreadcrumb();
|
||||
|
||||
const [actionMode, setActionMode] = useState('list');
|
||||
const [selectedData, setSelectedData] = useState(null);
|
||||
const [readOnly, setReadOnly] = 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) {
|
||||
@@ -22,9 +53,23 @@ const IndexTag = memo(function IndexTag() {
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Tag Page</h1>
|
||||
</div>
|
||||
<React.Fragment>
|
||||
<ListTag
|
||||
actionMode={actionMode}
|
||||
setActionMode={setMode}
|
||||
selectedData={selectedData}
|
||||
setSelectedData={setSelectedData}
|
||||
readOnly={readOnly}
|
||||
/>
|
||||
<DetailTag
|
||||
setActionMode={setMode}
|
||||
selectedData={selectedData}
|
||||
setSelectedData={setSelectedData}
|
||||
readOnly={readOnly}
|
||||
showModal={showModal}
|
||||
actionMode={actionMode}
|
||||
/>
|
||||
</React.Fragment>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
286
src/pages/master/tag/component/DetailTag.jsx
Normal file
286
src/pages/master/tag/component/DetailTag.jsx
Normal file
@@ -0,0 +1,286 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Modal, Input, Divider, Typography, Button, ConfigProvider, Select } from 'antd';
|
||||
import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif';
|
||||
|
||||
const { Text } = Typography;
|
||||
const { TextArea } = Input;
|
||||
|
||||
const DetailTag = (props) => {
|
||||
const [confirmLoading, setConfirmLoading] = useState(false);
|
||||
|
||||
const defaultData = {
|
||||
tag_id: '',
|
||||
tag_code: '',
|
||||
tag_name: '',
|
||||
tag_value: 'Off',
|
||||
tag_type: 'alarm',
|
||||
tag_description: '',
|
||||
};
|
||||
|
||||
const [FormData, setFormData] = useState(defaultData);
|
||||
|
||||
const handleCancel = () => {
|
||||
props.setSelectedData(null);
|
||||
props.setActionMode('list');
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
setConfirmLoading(true);
|
||||
|
||||
// Validasi required fields
|
||||
if (!FormData.tag_code) {
|
||||
NotifOk({
|
||||
icon: 'warning',
|
||||
title: 'Peringatan',
|
||||
message: 'Kolom Tag Code Tidak Boleh Kosong',
|
||||
});
|
||||
setConfirmLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FormData.tag_name) {
|
||||
NotifOk({
|
||||
icon: 'warning',
|
||||
title: 'Peringatan',
|
||||
message: 'Kolom Tag Name Tidak Boleh Kosong',
|
||||
});
|
||||
setConfirmLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FormData.tag_value) {
|
||||
NotifOk({
|
||||
icon: 'warning',
|
||||
title: 'Peringatan',
|
||||
message: 'Kolom Tag Value Tidak Boleh Kosong',
|
||||
});
|
||||
setConfirmLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FormData.tag_type) {
|
||||
NotifOk({
|
||||
icon: 'warning',
|
||||
title: 'Peringatan',
|
||||
message: 'Kolom Tag Type Tidak Boleh Kosong',
|
||||
});
|
||||
setConfirmLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
tag_code: FormData.tag_code,
|
||||
tag_name: FormData.tag_name,
|
||||
tag_value: FormData.tag_value,
|
||||
tag_type: FormData.tag_type,
|
||||
tag_description: FormData.tag_description,
|
||||
};
|
||||
|
||||
try {
|
||||
// Simulate API call
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
const response = {
|
||||
statusCode: FormData.tag_id ? 200 : 201,
|
||||
data: {
|
||||
tag_name: FormData.tag_name,
|
||||
},
|
||||
};
|
||||
|
||||
console.log('Save Tag Response:', response);
|
||||
|
||||
// Check if response is successful
|
||||
if (response && (response.statusCode === 200 || response.statusCode === 201)) {
|
||||
NotifOk({
|
||||
icon: 'success',
|
||||
title: 'Berhasil',
|
||||
message: `Data Tag "${response.data?.tag_name || FormData.tag_name}" berhasil ${
|
||||
FormData.tag_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 Tag 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 handleSelectChange = (name, value) => {
|
||||
setFormData({
|
||||
...FormData,
|
||||
[name]: 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 (
|
||||
<Modal
|
||||
title={`${
|
||||
props.actionMode === 'add'
|
||||
? 'Tambah'
|
||||
: props.actionMode === 'preview'
|
||||
? 'Preview'
|
||||
: 'Edit'
|
||||
} Tag`}
|
||||
open={props.showModal}
|
||||
onCancel={handleCancel}
|
||||
footer={[
|
||||
<>
|
||||
<ConfigProvider
|
||||
theme={{
|
||||
token: { colorBgContainer: '#E9F6EF' },
|
||||
components: {
|
||||
Button: {
|
||||
defaultBg: 'white',
|
||||
defaultColor: '#23A55A',
|
||||
defaultBorderColor: '#23A55A',
|
||||
defaultHoverColor: '#23A55A',
|
||||
defaultHoverBorderColor: '#23A55A',
|
||||
defaultHoverColor: '#23A55A',
|
||||
},
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Button onClick={handleCancel}>Batal</Button>
|
||||
</ConfigProvider>
|
||||
<ConfigProvider
|
||||
theme={{
|
||||
token: {
|
||||
colorBgContainer: '#209652',
|
||||
},
|
||||
components: {
|
||||
Button: {
|
||||
defaultBg: '#23a55a',
|
||||
defaultColor: '#FFFFFF',
|
||||
defaultBorderColor: '#23a55a',
|
||||
defaultHoverColor: '#FFFFFF',
|
||||
defaultHoverBorderColor: '#23a55a',
|
||||
},
|
||||
},
|
||||
}}
|
||||
>
|
||||
{!props.readOnly && (
|
||||
<Button loading={confirmLoading} onClick={handleSave}>
|
||||
Simpan
|
||||
</Button>
|
||||
)}
|
||||
</ConfigProvider>
|
||||
</>,
|
||||
]}
|
||||
>
|
||||
{FormData && (
|
||||
<div>
|
||||
<div hidden>
|
||||
<Text strong>Tag ID</Text>
|
||||
<Input
|
||||
name="tag_id"
|
||||
value={FormData.tag_id}
|
||||
onChange={handleInputChange}
|
||||
disabled
|
||||
/>
|
||||
</div>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>Tag Code</Text>
|
||||
<Text style={{ color: 'red' }}> *</Text>
|
||||
<Input
|
||||
name="tag_code"
|
||||
value={FormData.tag_code}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Enter Tag Code"
|
||||
readOnly={props.readOnly}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>Tag Name</Text>
|
||||
<Text style={{ color: 'red' }}> *</Text>
|
||||
<Input
|
||||
name="tag_name"
|
||||
value={FormData.tag_name}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Enter Tag Name"
|
||||
readOnly={props.readOnly}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>Tag Value</Text>
|
||||
<Text style={{ color: 'red' }}> *</Text>
|
||||
<Select
|
||||
value={FormData.tag_value}
|
||||
onChange={(value) => handleSelectChange('tag_value', value)}
|
||||
disabled={props.readOnly}
|
||||
style={{ width: '100%' }}
|
||||
placeholder="Select Value"
|
||||
options={[
|
||||
{ value: 'On', label: 'On' },
|
||||
{ value: 'Off', label: 'Off' },
|
||||
{ value: 'Critical', label: 'Critical' },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>Tag Type</Text>
|
||||
<Text style={{ color: 'red' }}> *</Text>
|
||||
<Select
|
||||
value={FormData.tag_type}
|
||||
onChange={(value) => handleSelectChange('tag_type', value)}
|
||||
disabled={props.readOnly}
|
||||
style={{ width: '100%' }}
|
||||
placeholder="Select Type"
|
||||
options={[
|
||||
{ value: 'alarm', label: 'Alarm' },
|
||||
{ value: 'measurement', label: 'Measurement' },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>Tag Description</Text>
|
||||
<TextArea
|
||||
name="tag_description"
|
||||
value={FormData.tag_description}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Enter Tag Description (Optional)"
|
||||
readOnly={props.readOnly}
|
||||
rows={4}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default DetailTag;
|
||||
486
src/pages/master/tag/component/ListTag.jsx
Normal file
486
src/pages/master/tag/component/ListTag.jsx
Normal file
@@ -0,0 +1,486 @@
|
||||
import React, { memo, useState, useEffect } from 'react';
|
||||
import { Space, Tag, ConfigProvider, Button, Row, Col, Card, Input } from 'antd';
|
||||
import {
|
||||
PlusOutlined,
|
||||
EditOutlined,
|
||||
DeleteOutlined,
|
||||
EyeOutlined,
|
||||
SearchOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { NotifAlert, NotifConfirmDialog } from '../../../../components/Global/ToastNotif';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import TableList from '../../../../components/Global/TableList';
|
||||
|
||||
// Dummy data
|
||||
const initialTagsData = [
|
||||
{
|
||||
tag_id: 1,
|
||||
tag_code: 'J06-OPEN',
|
||||
tag_name: 'tag 1',
|
||||
tag_value: 'On',
|
||||
tag_type: 'alarm',
|
||||
tag_description: 'test1',
|
||||
},
|
||||
{
|
||||
tag_id: 2,
|
||||
tag_code: 'J06-CLS',
|
||||
tag_name: 'tag 2',
|
||||
tag_value: 'Off',
|
||||
tag_type: 'alarm',
|
||||
tag_description: 'tes2',
|
||||
},
|
||||
{
|
||||
tag_id: 3,
|
||||
tag_code: 'J06-VRS',
|
||||
tag_name: 'tag 3',
|
||||
tag_value: 'Critical',
|
||||
tag_type: 'measurement',
|
||||
tag_description: 'test3',
|
||||
},
|
||||
{
|
||||
tag_id: 4,
|
||||
tag_code: 'J07-IR',
|
||||
tag_name: 'tag 4 R',
|
||||
tag_value: 'On',
|
||||
tag_type: 'measurement',
|
||||
tag_description: 'test 4',
|
||||
},
|
||||
{
|
||||
tag_id: 5,
|
||||
tag_code: 'K01-CLS',
|
||||
tag_name: 'tag 5',
|
||||
tag_value: 'Off',
|
||||
tag_type: 'alarm',
|
||||
tag_description: 'tes5',
|
||||
},
|
||||
{
|
||||
tag_id: 6,
|
||||
tag_code: 'J07-IS',
|
||||
tag_name: 'tag6',
|
||||
tag_value: 'On',
|
||||
tag_type: 'measurement',
|
||||
tag_description: 'tes6',
|
||||
},
|
||||
{
|
||||
tag_id: 7,
|
||||
tag_code: 'J07-IT',
|
||||
tag_name: 'tag7',
|
||||
tag_value: 'Critical',
|
||||
tag_type: 'measurement',
|
||||
tag_description: 'tes7',
|
||||
},
|
||||
{
|
||||
tag_id: 8,
|
||||
tag_code: 'J06-VST',
|
||||
tag_name: 'tag8',
|
||||
tag_value: 'On',
|
||||
tag_type: 'measurement',
|
||||
tag_description: 'tes8',
|
||||
},
|
||||
{
|
||||
tag_id: 9,
|
||||
tag_code: 'J06-VTR',
|
||||
tag_name: 'tag9',
|
||||
tag_value: 'On',
|
||||
tag_type: 'measurement',
|
||||
tag_description: 'tes9',
|
||||
},
|
||||
{
|
||||
tag_id: 10,
|
||||
tag_code: 'K02-OPEN',
|
||||
tag_name: 'tag10',
|
||||
tag_value: 'On',
|
||||
tag_type: 'alarm',
|
||||
tag_description: 'tes10',
|
||||
},
|
||||
{
|
||||
tag_id: 11,
|
||||
tag_code: 'K02-CLS',
|
||||
tag_name: 'Kontaktor K02 Close',
|
||||
tag_value: 'Off',
|
||||
tag_type: 'alarm',
|
||||
tag_description: 'Kontaktor K02 dalam kondisi tertutup',
|
||||
},
|
||||
{
|
||||
tag_id: 12,
|
||||
tag_code: 'J08-FREQ',
|
||||
tag_name: 'Frequency',
|
||||
tag_value: 'On',
|
||||
tag_type: 'measurement',
|
||||
tag_description: 'Frekuensi sistem normal (50Hz)',
|
||||
},
|
||||
{
|
||||
tag_id: 13,
|
||||
tag_code: 'J08-PF',
|
||||
tag_name: 'Power Factor',
|
||||
tag_value: 'Critical',
|
||||
tag_type: 'measurement',
|
||||
tag_description: 'Power factor rendah, perlu perbaikan',
|
||||
},
|
||||
{
|
||||
tag_id: 14,
|
||||
tag_code: 'TR01-TEMP',
|
||||
tag_name: 'Transformer Temperature',
|
||||
tag_value: 'Critical',
|
||||
tag_type: 'alarm',
|
||||
tag_description: 'Suhu trafo melebihi batas aman',
|
||||
},
|
||||
{
|
||||
tag_id: 15,
|
||||
tag_code: 'TR01-OIL',
|
||||
tag_name: 'Transformer Oil Level',
|
||||
tag_value: 'On',
|
||||
tag_type: 'alarm',
|
||||
tag_description: 'Level oli trafo normal',
|
||||
},
|
||||
{
|
||||
tag_id: 16,
|
||||
tag_code: 'GEN01-RUN',
|
||||
tag_name: 'Generator Running',
|
||||
tag_value: 'Off',
|
||||
tag_type: 'alarm',
|
||||
tag_description: 'Generator dalam kondisi mati',
|
||||
},
|
||||
{
|
||||
tag_id: 17,
|
||||
tag_code: 'GEN01-FUEL',
|
||||
tag_name: 'Generator Fuel Level',
|
||||
tag_value: 'On',
|
||||
tag_type: 'measurement',
|
||||
tag_description: 'Level bahan bakar generator mencukupi',
|
||||
},
|
||||
{
|
||||
tag_id: 18,
|
||||
tag_code: 'UPS01-BAT',
|
||||
tag_name: 'UPS Battery Status',
|
||||
tag_value: 'On',
|
||||
tag_type: 'alarm',
|
||||
tag_description: 'Status battery UPS normal',
|
||||
},
|
||||
{
|
||||
tag_id: 19,
|
||||
tag_code: 'UPS01-LOAD',
|
||||
tag_name: 'UPS Load',
|
||||
tag_value: 'Critical',
|
||||
tag_type: 'measurement',
|
||||
tag_description: 'Beban UPS mendekati kapasitas maksimal',
|
||||
},
|
||||
{
|
||||
tag_id: 20,
|
||||
tag_code: 'PANEL-DOOR',
|
||||
tag_name: 'Panel Door Status',
|
||||
tag_value: 'Off',
|
||||
tag_type: 'alarm',
|
||||
tag_description: 'Pintu panel tertutup',
|
||||
},
|
||||
];
|
||||
|
||||
const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [
|
||||
{
|
||||
title: 'ID',
|
||||
dataIndex: 'tag_id',
|
||||
key: 'tag_id',
|
||||
width: '5%',
|
||||
hidden: 'true',
|
||||
},
|
||||
{
|
||||
title: 'Tag Code',
|
||||
dataIndex: 'tag_code',
|
||||
key: 'tag_code',
|
||||
width: '10%',
|
||||
},
|
||||
{
|
||||
title: 'Tag Name',
|
||||
dataIndex: 'tag_name',
|
||||
key: 'tag_name',
|
||||
width: '20%',
|
||||
},
|
||||
{
|
||||
title: 'Value',
|
||||
dataIndex: 'tag_value',
|
||||
key: 'tag_value',
|
||||
width: '10%',
|
||||
align: 'center',
|
||||
render: (_, { tag_value }) => {
|
||||
let color = 'default';
|
||||
if (tag_value.toLowerCase() === 'on') color = 'green';
|
||||
else if (tag_value.toLowerCase() === 'off') color = 'gray';
|
||||
else if (tag_value.toLowerCase() === 'critical') color = 'red';
|
||||
return (
|
||||
<Tag color={color} key={'value'}>
|
||||
{tag_value}
|
||||
</Tag>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Type',
|
||||
dataIndex: 'tag_type',
|
||||
key: 'tag_type',
|
||||
width: '10%',
|
||||
},
|
||||
{
|
||||
title: 'Description',
|
||||
dataIndex: 'tag_description',
|
||||
key: 'tag_description',
|
||||
width: '25%',
|
||||
},
|
||||
{
|
||||
title: 'Aksi',
|
||||
key: 'aksi',
|
||||
align: 'center',
|
||||
width: '15%',
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Button
|
||||
icon={<EyeOutlined />}
|
||||
onClick={() => showPreviewModal(record)}
|
||||
style={{
|
||||
color: '#1890ff',
|
||||
borderColor: '#1890ff',
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => showEditModal(record)}
|
||||
style={{
|
||||
color: '#faad14',
|
||||
borderColor: '#faad14',
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => showDeleteDialog(record)}
|
||||
style={{
|
||||
borderColor: '#ff4d4f',
|
||||
}}
|
||||
/>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const ListTag = memo(function ListTag(props) {
|
||||
const [showFilter, setShowFilter] = useState(false);
|
||||
const [trigerFilter, setTrigerFilter] = useState(false);
|
||||
const [tagsData, setTagsData] = useState(initialTagsData);
|
||||
|
||||
const defaultFilter = { search: '' };
|
||||
const [formDataFilter, setFormDataFilter] = useState(defaultFilter);
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
// Dummy data function to simulate API call - now uses state
|
||||
const getAllTag = async (params) => {
|
||||
// Simulate API delay
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
|
||||
// Extract URLSearchParams - TableList sends URLSearchParams object
|
||||
const searchParam = params.get('search') || '';
|
||||
const page = parseInt(params.get('page')) || 1;
|
||||
const limit = parseInt(params.get('limit')) || 10;
|
||||
|
||||
console.log('getAllTag called with:', { searchParam, page, limit });
|
||||
|
||||
// Filter by search
|
||||
let filteredTags = tagsData;
|
||||
if (searchParam) {
|
||||
const searchLower = searchParam.toLowerCase();
|
||||
filteredTags = tagsData.filter(
|
||||
(tag) =>
|
||||
tag.tag_code.toLowerCase().includes(searchLower) ||
|
||||
tag.tag_name.toLowerCase().includes(searchLower) ||
|
||||
tag.tag_type.toLowerCase().includes(searchLower) ||
|
||||
tag.tag_description.toLowerCase().includes(searchLower)
|
||||
);
|
||||
}
|
||||
|
||||
// Pagination logic
|
||||
const totalData = filteredTags.length;
|
||||
const totalPages = Math.ceil(totalData / limit);
|
||||
const startIndex = (page - 1) * limit;
|
||||
const endIndex = startIndex + limit;
|
||||
const paginatedData = filteredTags.slice(startIndex, endIndex);
|
||||
|
||||
// Return structure that matches TableList expectation
|
||||
// Based on TableList code:
|
||||
// - resData.data.data = array of items
|
||||
// - resData.data.total = total count
|
||||
// - resData.data.paging.page = current page
|
||||
// - resData.data.paging.limit = items per page
|
||||
// - resData.data.paging.total = total items
|
||||
// - resData.data.paging.page_total = total pages
|
||||
return {
|
||||
status: 200,
|
||||
statusCode: 200,
|
||||
data: {
|
||||
data: paginatedData,
|
||||
total: totalData,
|
||||
paging: {
|
||||
page: page,
|
||||
limit: limit,
|
||||
total: totalData,
|
||||
page_total: totalPages,
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
if (props.actionMode == 'list') {
|
||||
setFormDataFilter(defaultFilter);
|
||||
doFilter();
|
||||
}
|
||||
} else {
|
||||
navigate('/signin');
|
||||
}
|
||||
}, [props.actionMode, tagsData]);
|
||||
|
||||
const toggleFilter = () => {
|
||||
setFormDataFilter(defaultFilter);
|
||||
setShowFilter((prev) => !prev);
|
||||
};
|
||||
|
||||
const doFilter = () => {
|
||||
setTrigerFilter((prev) => !prev);
|
||||
};
|
||||
|
||||
const handleSearch = () => {
|
||||
setFormDataFilter({ search: searchValue });
|
||||
setTrigerFilter((prev) => !prev);
|
||||
};
|
||||
|
||||
const handleSearchClear = () => {
|
||||
setSearchValue('');
|
||||
setFormDataFilter({ search: '' });
|
||||
setTrigerFilter((prev) => !prev);
|
||||
};
|
||||
|
||||
const showPreviewModal = (param) => {
|
||||
props.setSelectedData(param);
|
||||
props.setActionMode('preview');
|
||||
};
|
||||
|
||||
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.tag_name + '" ?',
|
||||
onConfirm: () => handleDelete(param.tag_id),
|
||||
onCancel: () => props.setSelectedData(null),
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = async (tag_id) => {
|
||||
// Find tag name before deleting
|
||||
const tagToDelete = tagsData.find((tag) => tag.tag_id === tag_id);
|
||||
|
||||
// Simulate delete API call
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
|
||||
// Remove from state
|
||||
const updatedTags = tagsData.filter((tag) => tag.tag_id !== tag_id);
|
||||
setTagsData(updatedTags);
|
||||
|
||||
NotifAlert({
|
||||
icon: 'success',
|
||||
title: 'Berhasil',
|
||||
message: `Data Tag "${tagToDelete?.tag_name || ''}" berhasil dihapus.`,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Card>
|
||||
<Row>
|
||||
<Col xs={24}>
|
||||
<Row justify="space-between" align="middle" gutter={[8, 8]}>
|
||||
<Col xs={24} sm={24} md={12} lg={12}>
|
||||
<Input.Search
|
||||
placeholder="Search tag by code, name, or type..."
|
||||
value={searchValue}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setSearchValue(value);
|
||||
// Auto search when clearing by backspace/delete
|
||||
if (value === '') {
|
||||
setFormDataFilter({ search: '' });
|
||||
setTrigerFilter((prev) => !prev);
|
||||
}
|
||||
}}
|
||||
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>
|
||||
<Space wrap size="small">
|
||||
<ConfigProvider
|
||||
theme={{
|
||||
token: { colorBgContainer: '#E9F6EF' },
|
||||
components: {
|
||||
Button: {
|
||||
defaultBg: 'white',
|
||||
defaultColor: '#23A55A',
|
||||
defaultBorderColor: '#23A55A',
|
||||
defaultHoverColor: '#23A55A',
|
||||
defaultHoverBorderColor: '#23A55A',
|
||||
},
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => showAddModal()}
|
||||
size="large"
|
||||
>
|
||||
Tambah Data
|
||||
</Button>
|
||||
</ConfigProvider>
|
||||
</Space>
|
||||
</Col>
|
||||
</Row>
|
||||
</Col>
|
||||
<Col xs={24} sm={24} md={24} lg={24} xl={24} style={{ marginTop: '16px' }}>
|
||||
<TableList
|
||||
getData={getAllTag}
|
||||
queryParams={formDataFilter}
|
||||
columns={columns(showPreviewModal, showEditModal, showDeleteDialog)}
|
||||
triger={trigerFilter}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
</React.Fragment>
|
||||
);
|
||||
});
|
||||
|
||||
export default ListTag;
|
||||
Reference in New Issue
Block a user