diff --git a/src/App.jsx b/src/App.jsx index 7be1e99..ae251bd 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -23,12 +23,11 @@ import IndexShift from './pages/master/shift/IndexShift'; import IndexJadwalShift from './pages/jadwalShift/IndexJadwalShift'; // History -import IndexTrending from './pages/history/trending/IndexTrending'; -import IndexReport from './pages/history/report/IndexReport'; +import IndexTrending from './pages/report/trending/IndexTrending'; +import IndexReport from './pages/report/report/IndexReport'; // Other Pages import IndexNotification from './pages/notification/IndexNotification'; -import IndexEventAlarm from './pages/eventAlarm/IndexEventAlarm'; import IndexRole from './pages/role/IndexRole'; import IndexUser from './pages/user/IndexUser'; @@ -40,6 +39,8 @@ import SvgCompressorC from './pages/home/SvgCompressorC'; import SvgAirDryerA from './pages/home/SvgAirDryerA'; import SvgAirDryerB from './pages/home/SvgAirDryerB'; import SvgAirDryerC from './pages/home/SvgAirDryerC'; +import IndexHistoryAlarm from './pages/history/alarm/IndexHistoryAlarm'; +import IndexHistoryEvent from './pages/history/event/IndexHistoryEvent'; const App = () => { return ( @@ -84,8 +85,8 @@ const App = () => { }> - } /> - } /> + } /> + } /> }> diff --git a/src/components/Global/TableList.jsx b/src/components/Global/TableList.jsx index 7f495fe..f8c0f2c 100644 --- a/src/components/Global/TableList.jsx +++ b/src/components/Global/TableList.jsx @@ -108,7 +108,7 @@ const TableList = memo(function TableList({ showDeleteDialog={showDeleteDialog} /> ) : ( - + { - const token = localStorage.getItem('token'); - if (token) { - setBreadcrumbItems([ - { - title: ( - - • Event Alarm - - ), - }, - ]); - } else { - navigate('/signin'); - } - }, [navigate, setBreadcrumbItems]); - - useEffect(() => { - if (actionMode === 'preview') { - setIsModalVisible(true); - if (selectedData) { - form.setFieldsValue(selectedData); - } - } else { - setIsModalVisible(false); - form.resetFields(); - } - }, [actionMode, selectedData, form]); - - const handleCancel = () => { - setActionMode('list'); - setSelectedData(null); - form.resetFields(); - }; - - return ( - - - - - ); -}); - -export default IndexEventAlarm; diff --git a/src/pages/eventAlarm/component/DetailEventAlarm.jsx b/src/pages/eventAlarm/component/DetailEventAlarm.jsx deleted file mode 100644 index 0a0b487..0000000 --- a/src/pages/eventAlarm/component/DetailEventAlarm.jsx +++ /dev/null @@ -1,58 +0,0 @@ -import { memo } from 'react'; -import { Modal, Divider, Descriptions } from 'antd'; - -const DetailEventAlarm = memo(function DetailEventAlarm({ visible, onCancel, selectedData }) { - return ( - - {selectedData && ( -
- - - {selectedData.tanggal} - - - {selectedData.plant_sub_section} - - - {selectedData.device} - - - {selectedData.tag} - - - {selectedData.engineer} - - - - - - {/* Additional Info */} -
-
- Catatan: Event alarm ini telah tercatat dalam sistem untuk - monitoring dan analisis lebih lanjut. -
-
-
- )} -
- ); -}); - -export default DetailEventAlarm; diff --git a/src/pages/history/alarm/IndexHistoryAlarm.jsx b/src/pages/history/alarm/IndexHistoryAlarm.jsx new file mode 100644 index 0000000..1fca140 --- /dev/null +++ b/src/pages/history/alarm/IndexHistoryAlarm.jsx @@ -0,0 +1,38 @@ +import React, { memo, useState, useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { useBreadcrumb } from '../../../layout/LayoutBreadcrumb'; +import { Typography } from 'antd'; +import ListHistoryAlarm from './component/ListHistoryAlarm'; + +const { Text } = Typography; + +const IndexHistoryAlarm = memo(function IndexHistoryAlarm() { + const navigate = useNavigate(); + const { setBreadcrumbItems } = useBreadcrumb(); + const [selectedData, setSelectedData] = useState(null); + + useEffect(() => { + const token = localStorage.getItem('token'); + if (token) { + setBreadcrumbItems([ + { + title: ( + + • History Event + + ), + }, + ]); + } else { + navigate('/signin'); + } + }, [navigate, setBreadcrumbItems]); + + return ( + + + + ); +}); + +export default IndexHistoryAlarm; diff --git a/src/pages/history/alarm/component/ListHistoryAlarm.jsx b/src/pages/history/alarm/component/ListHistoryAlarm.jsx new file mode 100644 index 0000000..e11124a --- /dev/null +++ b/src/pages/history/alarm/component/ListHistoryAlarm.jsx @@ -0,0 +1,128 @@ +import React, { memo, useState, useEffect } from 'react'; +import { Button, Row, Col, Card, Input } from 'antd'; +import { SearchOutlined } from '@ant-design/icons'; +import TableList from '../../../../components/Global/TableList'; + +const ListHistoryAlarm = memo(function ListHistoryAlarm(props) { + const columns = [ + { + title: 'No', + key: 'no', + width: '5%', + align: 'center', + render: (_, __, index) => index + 1, + }, + { + title: 'Datetime', + dataIndex: 'datetime', + key: 'datetime', + width: '10%', + }, + { + title: 'Tag Name', + dataIndex: 'tag_name', + key: 'tag_name', + width: '40%', + }, + { + title: 'Value', + dataIndex: 'stat', + key: 'stat', + width: '10%', + }, + { + title: 'Threshold', + dataIndex: 'threshold', + key: 'threshold', + width: '10%', + }, + { + title: 'Condition', + dataIndex: 'condition', + key: 'condition', + width: '20%', + }, + { + title: 'Stat', + dataIndex: 'stat', + key: 'stat', + width: '5%', + }, + ]; + + const [trigerFilter, setTrigerFilter] = useState(false); + + const defaultFilter = { search: '' }; + const [formDataFilter, setFormDataFilter] = useState(defaultFilter); + const [searchValue, setSearchValue] = useState(''); + + const getAllEventAlarm = async (params) => { + return { + data: [], + }; + }; + + const handleSearch = () => { + setFormDataFilter({ search: searchValue }); + setTrigerFilter((prev) => !prev); + }; + + const handleSearchClear = () => { + setSearchValue(''); + setFormDataFilter({ search: '' }); + setTrigerFilter((prev) => !prev); + }; + + return ( + + + + + + + { + const value = e.target.value; + setSearchValue(value); + if (value === '') { + handleSearchClear(); + } + }} + onSearch={handleSearch} + allowClear={{ + clearIcon: , + }} + enterButton={ + + } + size="large" + /> + + + + + + + + + + ); +}); + +export default ListHistoryAlarm; diff --git a/src/pages/history/event/IndexHistoryEvent.jsx b/src/pages/history/event/IndexHistoryEvent.jsx new file mode 100644 index 0000000..8a734d4 --- /dev/null +++ b/src/pages/history/event/IndexHistoryEvent.jsx @@ -0,0 +1,38 @@ +import React, { memo, useState, useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { useBreadcrumb } from '../../../layout/LayoutBreadcrumb'; +import { Typography } from 'antd'; +import ListHistoryEvent from './component/ListHistoryEvent'; + +const { Text } = Typography; + +const IndexHistoryEvent = memo(function IndexHistoryEvent() { + const navigate = useNavigate(); + const { setBreadcrumbItems } = useBreadcrumb(); + const [selectedData, setSelectedData] = useState(null); + + useEffect(() => { + const token = localStorage.getItem('token'); + if (token) { + setBreadcrumbItems([ + { + title: ( + + • History Event + + ), + }, + ]); + } else { + navigate('/signin'); + } + }, [navigate, setBreadcrumbItems]); + + return ( + + + + ); +}); + +export default IndexHistoryEvent; diff --git a/src/pages/eventAlarm/component/ListEventAlarm.jsx b/src/pages/history/event/component/ListHistoryEvent.jsx similarity index 51% rename from src/pages/eventAlarm/component/ListEventAlarm.jsx rename to src/pages/history/event/component/ListHistoryEvent.jsx index 394ca63..45f60a4 100644 --- a/src/pages/eventAlarm/component/ListEventAlarm.jsx +++ b/src/pages/history/event/component/ListHistoryEvent.jsx @@ -1,70 +1,9 @@ import React, { memo, useState, useEffect } from 'react'; import { Button, Row, Col, Card, Input } from 'antd'; import { SearchOutlined } from '@ant-design/icons'; -import { useNavigate } from 'react-router-dom'; -import TableList from '../../../components/Global/TableList'; +import TableList from '../../../../components/Global/TableList'; -// Dummy data untuk riwayat alarm -const initialAlarmsData = [ - { - alarm_id: 1, - tanggal: '2025-01-15 08:30:00', - plant_sub_section: 'Plant A - Section 1', - device: 'Device 001', - tag: 'TEMP-001', - engineer: 'Pras', - }, - { - alarm_id: 2, - tanggal: '2025-01-15 09:15:00', - plant_sub_section: 'Plant B - Section 2', - device: 'Device 002', - tag: 'PRESS-002', - engineer: 'Bagus', - }, - { - alarm_id: 3, - tanggal: '2025-01-15 10:00:00', - plant_sub_section: 'Plant A - Section 3', - device: 'Device 003', - tag: 'FLOW-003', - engineer: 'iqbal', - }, - { - alarm_id: 4, - tanggal: '2025-01-15 11:45:00', - plant_sub_section: 'Plant C - Section 1', - device: 'Device 004', - tag: 'LEVEL-004', - engineer: 'riski', - }, - { - alarm_id: 5, - tanggal: '2025-01-15 13:20:00', - plant_sub_section: 'Plant B - Section 3', - device: 'Device 005', - tag: 'TEMP-005', - engineer: 'anton', - }, - { - alarm_id: 6, - tanggal: '2025-01-15 14:00:00', - plant_sub_section: 'Plant A - Section 2', - device: 'Device 006', - tag: 'PRESS-006', - engineer: 'kurniawan', - }, - { - alarm_id: 7, - tanggal: '2025-01-15 15:30:00', - plant_sub_section: 'Plant C - Section 2', - device: 'Device 007', - tag: 'FLOW-007', - engineer: 'wawan', - }, -]; - -const ListEventAlarm = memo(function ListEventAlarm(props) { +const ListHistoryEvent = memo(function ListHistoryEvent(props) { const columns = [ { title: 'No', @@ -74,33 +13,27 @@ const ListEventAlarm = memo(function ListEventAlarm(props) { render: (_, __, index) => index + 1, }, { - title: 'Tanggal', - dataIndex: 'tanggal', - key: 'tanggal', - width: '15%', + title: 'Datetime', + dataIndex: 'datetime', + key: 'datetime', + width: '10%', }, { - title: 'Plant Sub Section', - dataIndex: 'plant_sub_section', - key: 'plant_sub_section', - width: '25%', + title: 'Tag Name', + dataIndex: 'tag_name', + key: 'tag_name', + width: '40%', }, { - title: 'Device', - dataIndex: 'device', - key: 'device', - width: '15%', + title: 'Stat', + dataIndex: 'stat', + key: 'stat', + width: '5%', }, { - title: 'Tag', - dataIndex: 'tag', - key: 'tag', - width: '15%', - }, - { - title: 'Engineer', - dataIndex: 'engineer', - key: 'engineer', + title: 'Description', + dataIndex: 'description', + key: 'description', width: '15%', }, ]; @@ -111,31 +44,12 @@ const ListEventAlarm = memo(function ListEventAlarm(props) { const [formDataFilter, setFormDataFilter] = useState(defaultFilter); const [searchValue, setSearchValue] = useState(''); - const navigate = useNavigate(); - - // Dummy data function to simulate API call const getAllEventAlarm = async (params) => { return { - data: initialAlarmsData, + data: [], }; }; - useEffect(() => { - const token = localStorage.getItem('token'); - if (token) { - if (props.actionMode == 'list') { - setFormDataFilter(defaultFilter); - doFilter(); - } - } else { - navigate('/signin'); - } - }, [props.actionMode]); - - const doFilter = () => { - setTrigerFilter((prev) => !prev); - }; - const handleSearch = () => { setFormDataFilter({ search: searchValue }); setTrigerFilter((prev) => !prev); @@ -155,15 +69,13 @@ const ListEventAlarm = memo(function ListEventAlarm(props) { { const value = e.target.value; setSearchValue(value); - // Auto search when clearing by backspace/delete if (value === '') { - setFormDataFilter({ search: '' }); - setTrigerFilter((prev) => !prev); + handleSearchClear(); } }} onSearch={handleSearch} @@ -201,4 +113,4 @@ const ListEventAlarm = memo(function ListEventAlarm(props) { ); }); -export default ListEventAlarm; +export default ListHistoryEvent; diff --git a/src/pages/history/report/IndexReport.jsx b/src/pages/history/report/IndexReport.jsx deleted file mode 100644 index 00a4149..0000000 --- a/src/pages/history/report/IndexReport.jsx +++ /dev/null @@ -1,275 +0,0 @@ -import React, { memo, useEffect, useState } from 'react'; -import { useNavigate } from 'react-router-dom'; -import { useBreadcrumb } from '../../../layout/LayoutBreadcrumb'; -import { Typography, Table, Card, Select, DatePicker, Button, Row, Col } from 'antd'; -import { FileTextOutlined } from '@ant-design/icons'; -import { decryptData } from '../../../components/Global/Formatter'; -import dayjs from 'dayjs'; - -const { Text } = Typography; - -// New data structure for tag history -const tagHistoryData = [ - { - tag: 'TEMP_SENSOR_1', - color: '#FF6B4A', - history: [ - { timestamp: '2025-10-09 08:00', value: 75 }, - { timestamp: '2025-10-09 08:05', value: 76 }, - { timestamp: '2025-10-09 08:10', value: 75 }, - ], - }, - { - tag: 'GAS_LEAK_SENSOR_1', - color: '#4ECDC4', - history: [ - { timestamp: '2025-10-09 08:00', value: 10 }, - { timestamp: '2025-10-09 08:05', value: 150 }, - { timestamp: '2025-10-09 08:10', value: 12 }, - ], - }, - { - tag: 'PRESSURE_SENSOR_1', - color: '#FFE66D', - history: [ - { timestamp: '2025-10-09 08:00', value: 1.2 }, - { timestamp: '2025-10-09 08:05', value: 1.3 }, - { timestamp: '2025-10-09 08:10', value: 1.2 }, - ], - }, -]; - -const IndexReport = memo(function IndexReport() { - const navigate = useNavigate(); - const { setBreadcrumbItems } = useBreadcrumb(); - - const [plantSubSection, setPlantSubSection] = useState('Semua Plant'); - const [startDate, setStartDate] = useState(dayjs('2025-09-30')); - const [endDate, setEndDate] = useState(dayjs('2025-10-09')); - const [periode, setPeriode] = useState('30 Menit'); - const [userRole, setUserRole] = useState(null); - const [roleLevel, setRoleLevel] = useState(null); - - useEffect(() => { - const token = localStorage.getItem('token'); - if (token) { - // Get user data and role - let userData = null; - const sessionData = localStorage.getItem('session'); - if (sessionData) { - userData = decryptData(sessionData); - } else { - const userRaw = localStorage.getItem('user'); - if (userRaw) { - try { - userData = { user: JSON.parse(userRaw) }; - } catch (e) { - console.error('Error parsing user data:', e); - } - } - } - - if (userData?.user) { - setUserRole(userData.user.role_name); - setRoleLevel(userData.user.role_level); - } - - setBreadcrumbItems([ - { - title: ( - - • History - - ), - }, - { - title: ( - - Report - - ), - }, - ]); - } else { - navigate('/signin'); - } - }, []); - - const handleReset = () => { - setPlantSubSection('Semua Plant'); - setStartDate(dayjs('2025-09-30')); - setEndDate(dayjs('2025-10-09')); - setPeriode('30 Menit'); - }; - - // Check if user has permission to view data (all except guest) - const canViewData = userRole && userRole !== 'guest'; - - // Convert tag history data to table format - const convertToTableData = () => { - const timestamps = {}; // Use an object to collect data per timestamp - - tagHistoryData.forEach((tagData) => { - tagData.history.forEach((point) => { - if (!timestamps[point.timestamp]) { - timestamps[point.timestamp] = { - key: point.timestamp, - 'Date and Time': point.timestamp, - }; - } - timestamps[point.timestamp][tagData.tag] = point.value; - }); - }); - - // Convert the object to an array - return Object.values(timestamps); - }; - - const tableData = convertToTableData(); - - // Create dynamic columns based on tags - const tags = tagHistoryData.map((tagData) => tagData.tag); - - const columns = [ - { - title: 'Date and Time', - dataIndex: 'Date and Time', - key: 'Date and Time', - fixed: 'left', - width: 180, - render: (text) => {text}, - }, - ...tags.map((tag) => ({ - title: tag, - dataIndex: tag, - key: tag, - align: 'center', - width: 150, - render: (value) => {value !== undefined ? value : '-'}, - })), - ]; - - return ( - -
- {/* Filter Section */} - -
- - ☰ Filter Data - -
- -
-
- - Plant Sub Section - - -
- - - - - - - - - - - - {/* Table Section */} - {/* {!canViewData ? ( - - - Anda tidak memiliki akses untuk melihat data report. -
- Silakan hubungi administrator untuk mendapatkan akses. -
-
- ) : ( */} - -
- - ☰ History Report - -
-
- - {/* )} */} - - - ); -}); - -export default IndexReport; diff --git a/src/pages/history/trending/IndexTrending.jsx b/src/pages/history/trending/IndexTrending.jsx deleted file mode 100644 index 83e1cb0..0000000 --- a/src/pages/history/trending/IndexTrending.jsx +++ /dev/null @@ -1,297 +0,0 @@ -import React, { memo, useEffect, useState } from 'react'; -import { useNavigate } from 'react-router-dom'; -import { useBreadcrumb } from '../../../layout/LayoutBreadcrumb'; -import { Typography, Select, DatePicker, Button, Row, Col, Card } from 'antd'; -import { ResponsiveLine } from '@nivo/line'; -import { FileTextOutlined } from '@ant-design/icons'; -import { decryptData } from '../../../components/Global/Formatter'; -import dayjs from 'dayjs'; -import './trending.css'; - -const { Text } = Typography; - -const IndexTrending = memo(function IndexTrending() { - const navigate = useNavigate(); - const { setBreadcrumbItems } = useBreadcrumb(); - - const [plantSubSection, setPlantSubSection] = useState('Semua Plant'); - const [startDate, setStartDate] = useState(dayjs('2025-09-30')); - const [endDate, setEndDate] = useState(dayjs('2025-10-09')); - const [periode, setPeriode] = useState('10 Menit'); - const [userRole, setUserRole] = useState(null); - const [roleLevel, setRoleLevel] = useState(null); - - useEffect(() => { - const token = localStorage.getItem('token'); - if (token) { - // Get user data and role - let userData = null; - const sessionData = localStorage.getItem('session'); - if (sessionData) { - userData = decryptData(sessionData); - } else { - const userRaw = localStorage.getItem('user'); - if (userRaw) { - try { - userData = { user: JSON.parse(userRaw) }; - } catch (e) { - console.error('Error parsing user data:', e); - } - } - } - - if (userData?.user) { - setUserRole(userData.user.role_name); - setRoleLevel(userData.user.role_level); - } - - setBreadcrumbItems([ - { - title: ( - - • History - - ), - }, - { - title: ( - - Trending - - ), - }, - ]); - } else { - navigate('/signin'); - } - }, []); - - const tagTrendingData = [ - { - id: 'TEMP_SENSOR_1', - color: '#FF6B4A', - data: [ - { y: '08:00', x: 75 }, - { y: '08:05', x: 76 }, - { y: '08:10', x: 75 }, - { y: '08:15', x: 77 }, - { y: '08:20', x: 76 }, - { y: '08:25', x: 78 }, - { y: '08:30', x: 79 }, - ], - }, - { - id: 'GAS_LEAK_SENSOR_1', - color: '#4ECDC4', - data: [ - { y: '08:00', x: 10 }, - { y: '08:05', x: 150 }, - { y: '08:10', x: 40 }, - { y: '08:15', x: 20 }, - { y: '08:20', x: 15 }, - { y: '08:25', x: 18 }, - { y: '08:30', x: 25 }, - ], - }, - { - id: 'PRESSURE_SENSOR_1', - color: '#FFE66D', - data: [ - { y: '08:00', x: 1.2 }, - { y: '08:05', x: 1.3 }, - { y: '08:10', x: 1.2 }, - { y: '08:15', x: 1.4 }, - { y: '08:20', x: 1.5 }, - { y: '08:25', x: 1.3 }, - { y: '08:30', x: 1.2 }, - ], - }, - ]; - - const handleReset = () => { - setPlantSubSection('Semua Plant'); - setStartDate(dayjs('2025-09-30')); - setEndDate(dayjs('2025-10-09')); - setPeriode('10 Menit'); - }; - - // Check if user has permission to view data (all except guest) - const canViewData = userRole && userRole !== 'guest'; - - // Check if user can export/filter (administrator, engineer) - const canExportData = userRole && (userRole === 'administrator' || userRole === 'engineer'); - - return ( - - {/* Filter Section */} - -
- - ☰ Filter Data - -
- -
-
- - Plant Sub Section - - -
- - - - - - - - - - - - {/* Charts Section */} - {/* {!canViewData ? ( - - - Anda tidak memiliki akses untuk melihat data trending. -
- Silakan hubungi administrator untuk mendapatkan akses. -
-
- ) : ( */} - <> - - {/* Line Chart */} - - -
- - ☰ Tag Value Trending - -
-
- -
-
- - - - {/* )} */} - - ); -}); - -export default IndexTrending; diff --git a/src/pages/jadwalShift/component/DetailJadwalShift.jsx b/src/pages/jadwalShift/component/DetailJadwalShift.jsx index 4f77120..83d705f 100644 --- a/src/pages/jadwalShift/component/DetailJadwalShift.jsx +++ b/src/pages/jadwalShift/component/DetailJadwalShift.jsx @@ -1,172 +1,173 @@ import React, { useEffect, useState } from 'react'; import { Modal, - Input, Typography, Button, ConfigProvider, - Row, - Col + Form, + Select, + Spin, + Input } from 'antd'; -import { NotifOk } from '../../../components/Global/ToastNotif'; +import { NotifOk, NotifAlert } from '../../../components/Global/ToastNotif'; +import { updateJadwalShift, createJadwalShift } from '../../../api/jadwal-shift.jsx'; const { Text } = Typography; +const { Option } = Select; const DetailJadwalShift = (props) => { + const [form] = Form.useForm(); const [confirmLoading, setConfirmLoading] = useState(false); + const [employees, setEmployees] = useState([]); + const [loadingEmployees, setLoadingEmployees] = useState(false); - const defaultData = { - id: '', - nama_shift: '', - jam_masuk: '', - jam_pulang: '', - username: '', - nama_employee: '', - whatsapp: '' - }; - - const [FormData, setFormData] = useState(defaultData); + const isReadOnly = props.actionMode === 'preview'; const handleCancel = () => { - props.setSelectedData(null); props.setActionMode('list'); }; + const fetchEmployees = async () => { + setLoadingEmployees(true); + try { + // Data dummy untuk dropdown karyawan + const dummyEmployees = [ + { employee_id: '101', nama_employee: 'Andi Pratama' }, + { employee_id: '102', nama_employee: 'Budi Santoso' }, + { employee_id: '103', nama_employee: 'Citra Lestari' }, + { employee_id: '104', nama_employee: 'Dewi Anggraini' }, + { employee_id: '105', nama_employee: 'Eko Wahyudi' }, + { employee_id: '106', nama_employee: 'Fitriani' }, + ]; + setEmployees(dummyEmployees); + } catch (error) { + NotifAlert({ icon: 'error', title: 'Gagal', message: 'Gagal memuat daftar karyawan.' }); + } finally { + setLoadingEmployees(false); + } + }; + const handleSave = async () => { - setConfirmLoading(true); - // This is a dummy save function for slicing purposes - setTimeout(() => { + try { + const values = await form.validateFields(); + let payload; + let responseMessage; + + setConfirmLoading(true); + if (props.actionMode === 'edit') { + payload = { ...props.selectedData, ...values }; + // await updateJadwalShift(payload.schedule_id, payload); + console.log("Updating schedule with payload:", payload); + responseMessage = 'Jadwal berhasil diperbarui.'; + } else { // 'add' mode + payload = { + employee_id: values.employee_id, + shift_name: props.selectedData.shift_name, + schedule_date: new Date().toISOString().split('T')[0], // Example date + }; + // await createJadwalShift(payload); + console.log("Creating schedule with payload:", payload); + responseMessage = 'User berhasil ditambahkan ke jadwal.'; + } + await new Promise(resolve => setTimeout(resolve, 500)); // Simulasi API call + + NotifOk({ icon: 'success', title: 'Berhasil', message: responseMessage }); + props.setActionMode('list'); // Menutup modal dan memicu refresh di parent + } catch (error) { + const message = error.response?.data?.message || 'Gagal memperbarui jadwal.'; + NotifAlert({ icon: 'error', title: 'Gagal', message }); + } finally { setConfirmLoading(false); - NotifOk({ - icon: 'success', - title: 'Berhasil', - message: 'Data dummy berhasil disimpan.', - }); - props.setActionMode('list'); - }, 1000); + } }; useEffect(() => { - if (props.selectedData) { - setFormData(props.selectedData); - } else { - setFormData(defaultData); + // Hanya jalankan jika modal untuk 'edit' atau 'preview' terbuka + if (props.showModal) { + fetchEmployees(); + if (props.actionMode === 'edit' || props.actionMode === 'preview') { + form.setFieldsValue({ + employee_id: props.selectedData.employee_id, + shift_name: props.selectedData.shift_name, + }); + } else if (props.actionMode === 'add') { + form.setFieldsValue({ + shift_name: props.selectedData.shift_name, + employee_id: null, // Reset employee selection + }); + } } - }, [props.showModal, props.selectedData]); - - // Dummy handler for slicing - const handleInputChange = (e) => { - const { name, value } = e.target; - setFormData({ ...FormData, [name]: value }); - }; + }, [props.actionMode, props.showModal, props.selectedData, form]); return ( - - - - - {!props.readOnly && ( - - )} - + + {!isReadOnly && ( + + )} , ]} > - {FormData && ( -
- -
- Nama Karyawan - - - - Username - - - - Nama Shift - - - - Whatsapp - - - - Jam Masuk - - - - Jam Pulang - - - - - )} + +
+ {props.actionMode === 'add' ? ( + <> + + + + + + + + ) : ( + <> + + + + + + + + )} + +
); }; diff --git a/src/pages/jadwalShift/component/ListJadwalShift.jsx b/src/pages/jadwalShift/component/ListJadwalShift.jsx index 631c3c9..57c11f3 100644 --- a/src/pages/jadwalShift/component/ListJadwalShift.jsx +++ b/src/pages/jadwalShift/component/ListJadwalShift.jsx @@ -1,153 +1,146 @@ import React, { memo, useState, useEffect } from 'react'; -import { Space, Tag, ConfigProvider, Button, Row, Col, Card, Input } from 'antd'; +import { Space, ConfigProvider, Button, Row, Col, Card, Input, Typography, Spin, Divider, Checkbox, Select } from 'antd'; import { PlusOutlined, + SearchOutlined, + EyeOutlined, EditOutlined, DeleteOutlined, - EyeOutlined, - SearchOutlined, } from '@ant-design/icons'; -import { NotifAlert, NotifConfirmDialog } from '../../../components/Global/ToastNotif'; +import { NotifAlert, NotifOk, NotifConfirmDialog } from '../../../components/Global/ToastNotif'; import { useNavigate } from 'react-router-dom'; -import TableList from '../../../components/Global/TableList'; -import { getAllJadwalShift, deleteJadwalShift } from '../../../api/jadwal-shift'; +import { getAllJadwalShift, deleteJadwalShift, updateJadwalShift } from '../../../api/jadwal-shift.jsx'; -const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ - { - title: 'Tanggal Jadwal', - dataIndex: 'schedule_date', - key: 'schedule_date', - render: (date) => date ? new Date(date).toLocaleDateString('id-ID') : '-', - }, - { - title: 'Nama Shift', - dataIndex: 'shift_name', - key: 'shift_name', - render: (text) => text || '-', - }, - { - title: 'Jam Masuk', - dataIndex: 'start_time', - key: 'start_time', - render: (time) => time || '-', - }, - { - title: 'Jam Pulang', - dataIndex: 'end_time', - key: 'end_time', - render: (time) => time || '-', - }, - { - title: 'Status', - dataIndex: 'is_active', - key: 'is_active', - render: (isActive) => ( - - {isActive ? 'Aktif' : 'Tidak Aktif'} - - ), - }, - { - title: 'Aksi', - key: 'aksi', - align: 'center', - render: (_, record) => ( - - - - { - const value = e.target.value; - setSearchValue(value); - if (value === '') { - handleSearchClear(); - } - }} - onSearch={handleSearch} - allowClear={{ - clearIcon: , - }} - enterButton={ - + + Mode Edit Halaman + + + + + + + + ) : ( + <> + + - Search - - } - size="large" - /> - - - - - + + + + { + const value = e.target.value; + setSearchValue(value); + if (value === '') { + handleSearchClear(); + } + }} + onSearch={handleSearch} + allowClear + enterButton={ + - - - + /> + + + )} - - - + + +
+ {(Object.keys(groupedSchedules).length === 0 && !loading) ? ( + Tidak ada data jadwal untuk ditampilkan. + ) : ( + Object.keys(groupedSchedules).map(shiftName => ( // Iterate through each shift (PAGI, SIANG, MALAM) +
{/* Container for each shift section */} + +
+ + SHIFT {shiftName} ({groupedSchedules[shiftName].users.length} Karyawan) + + + {editingShift === shiftName ? ( + + + + + + + + ) : ( + + + + + + + + + )} + + + {/* Horizontal scrollable container for employee cards */} +
+ {groupedSchedules[shiftName].users.length > 0 ? ( + groupedSchedules[shiftName].users.map(user => ( + + {isEditMode && editingShift === null && ( // Checkbox for global delete mode only + handleSelectSchedule(user.schedule_id, e.target.checked)} + onClick={(e) => e.stopPropagation()} // Prevent card click + /> + )} + {editingShift === shiftName || (isEditMode && editingShift === null) ? ( // Global or Shift-specific Edit Mode + // EDIT MODE VIEW +
+ + + + + handleSelectSchedule(user.schedule_id, e.target.checked)} + /> +
+ ) : ( + // NORMAL VIEW +
+
+ {user.nama_employee} + {user.whatsapp} +
+
+ + Terakhir diperbarui
+ {formatRelativeTimestamp(groupedSchedules[shiftName].lastUpdate.timestamp)}
+ oleh {groupedSchedules[shiftName].lastUpdate.user} +
+ +
+
+ )} +
+ )) + ) : ( + Tidak ada karyawan yang dijadwalkan untuk shift ini. + )} +
+ + )) + )} + + ); }); -export default ListJadwalShift; \ No newline at end of file +export default ListJadwalShift; diff --git a/src/pages/master/brandDevice/component/ListBrandDevice.jsx b/src/pages/master/brandDevice/component/ListBrandDevice.jsx index cd9b654..b09f900 100644 --- a/src/pages/master/brandDevice/component/ListBrandDevice.jsx +++ b/src/pages/master/brandDevice/component/ListBrandDevice.jsx @@ -75,13 +75,13 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ width: '20%', }, { - title: 'model', + title: 'Model', dataIndex: 'model', key: 'model', width: '15%', }, { - title: 'status', + title: 'Status', dataIndex: 'status', key: 'status', width: '10%', diff --git a/src/pages/master/device/component/DetailDevice.jsx b/src/pages/master/device/component/DetailDevice.jsx index fc06dde..0e2c56e 100644 --- a/src/pages/master/device/component/DetailDevice.jsx +++ b/src/pages/master/device/component/DetailDevice.jsx @@ -14,6 +14,7 @@ const DetailDevice = (props) => { device_id: '', device_code: '', device_name: '', + brand_device: '', is_active: true, device_location: '', device_description: '', @@ -228,6 +229,7 @@ const DetailDevice = (props) => { }} /> +
Device Name * @@ -239,6 +241,23 @@ const DetailDevice = (props) => { readOnly={props.readOnly} />
+
+ Brand Device + * + +
Device Location [ key: 'device_name', width: '20%', }, + { + title: 'Brand Device', + dataIndex: 'brand_device', + key: 'brand_device', + width: '20%', + }, { title: 'Location', dataIndex: 'device_location', diff --git a/src/pages/master/shift/component/DetailShift.jsx b/src/pages/master/shift/component/DetailShift.jsx index d4df499..ab2d3bc 100644 --- a/src/pages/master/shift/component/DetailShift.jsx +++ b/src/pages/master/shift/component/DetailShift.jsx @@ -1,11 +1,22 @@ import React, { useEffect, useState } from 'react'; -import { Modal, Input, Typography, Switch, Button, ConfigProvider, Divider, TimePicker, Space } from 'antd'; +import { + Modal, + Input, + Typography, + Switch, + Button, + ConfigProvider, + Divider, + TimePicker, + Space, +} from 'antd'; import { NotifOk } from '../../../../components/Global/ToastNotif'; +import { createShift, updateShift } from '../../../../api/master-shift'; +import { validateRun } from '../../../../Utils/validate'; import dayjs from 'dayjs'; +import utc from 'dayjs/plugin/utc'; -// Mock API calls for demonstration -const createShift = async (payload) => ({ statusCode: 201, data: { ...payload, shift_id: Date.now() } }); -const updateShift = async (id, payload) => ({ statusCode: 200, data: { ...payload, shift_id: id } }); +dayjs.extend(utc); const { Text } = Typography; const timeFormat = 'HH:mm'; @@ -16,13 +27,21 @@ const DetailShift = (props) => { const defaultData = { shift_id: '', shift_name: '', - start_time: '08:00', - end_time: '16:00', + start_time: '', + end_time: '', is_active: true, }; const [formData, setFormData] = useState(defaultData); + const handleInputChange = (e) => { + const { name, value } = e.target; + setFormData({ + ...formData, + [name]: value, + }); + }; + const handleCancel = () => { props.setSelectedData(null); props.setActionMode('list'); @@ -31,125 +50,264 @@ const DetailShift = (props) => { const handleSave = async () => { setConfirmLoading(true); - if (!formData.shift_name) { - NotifOk({ icon: 'warning', title: 'Peringatan', message: 'Nama Shift wajib diisi.' }); + // Daftar aturan validasi + const validationRules = [ + { field: 'shift_name', label: 'Shift Name', required: true }, + { field: 'start_time', label: 'Start Time', required: true }, + { field: 'end_time', label: 'End Time', required: true }, + ]; + + if ( + validateRun(formData, validationRules, (errorMessages) => { + NotifOk({ + icon: 'warning', + title: 'Peringatan', + message: errorMessages, + }); + setConfirmLoading(false); + }) + ) + return; + + // Validasi format waktu + if (!formData.start_time || !formData.end_time) { + NotifOk({ + icon: 'warning', + title: 'Peringatan', + message: 'Waktu Mulai dan Waktu Selesai wajib diisi.', + }); setConfirmLoading(false); return; } try { + // Pastikan format waktu HH:mm sesuai validasi BE (regex: /^([01]\d|2[0-3]):([0-5]\d)(:[0-5]\d)?$/) + const formatTimeForAPI = (timeValue) => { + if (!timeValue) return ''; + + // Jika sudah dalam format HH:mm, return langsung + if (typeof timeValue === 'string' && timeValue.match(/^\d{2}:\d{2}$/)) { + return timeValue; + } + + // Parse dengan dayjs dan format ke HH:mm (string murni, bukan Date object) + const time = dayjs(timeValue, 'HH:mm', true); // strict mode + if (time.isValid()) { + return time.format('HH:mm'); // Return string "08:00" bukan Date object + } + + // Fallback: coba parse sebagai ISO date dan ambil jam/menitnya (gunakan UTC) + const isoTime = dayjs.utc(timeValue); + if (isoTime.isValid()) { + return isoTime.format('HH:mm'); + } + + return ''; + }; + const payload = { shift_name: formData.shift_name, - start_time: formData.start_time, - end_time: formData.end_time, + start_time: formatTimeForAPI(formData.start_time), + end_time: formatTimeForAPI(formData.end_time), is_active: formData.is_active, }; + console.log('Payload yang dikirim:', payload); + console.log('Type start_time:', typeof payload.start_time, payload.start_time); + console.log('Type end_time:', typeof payload.end_time, payload.end_time); + const response = props.actionMode === 'edit' ? await updateShift(formData.shift_id, payload) : await createShift(payload); if (response && (response.statusCode === 200 || response.statusCode === 201)) { - NotifOk({ icon: 'success', title: 'Berhasil', message: `Data Shift berhasil disimpan.` }); + const action = props.actionMode === 'edit' ? 'diubah' : 'ditambahkan'; + + NotifOk({ + icon: 'success', + title: 'Berhasil', + message: `Data Shift berhasil ${action}.`, + }); + props.setActionMode('list'); } else { - NotifOk({ icon: 'error', title: 'Gagal', message: response?.message || 'Gagal menyimpan data.' }); + NotifOk({ + icon: 'error', + title: 'Gagal', + message: response?.message || 'Terjadi kesalahan saat menyimpan data.', + }); } } catch (error) { - NotifOk({ icon: 'error', title: 'Error', message: error.message || 'Terjadi kesalahan server.' }); + NotifOk({ + icon: 'error', + title: 'Error', + message: error.message || 'Terjadi kesalahan pada server.', + }); } finally { setConfirmLoading(false); } }; - const handleInputChange = (e) => { - const { name, value } = e.target; - setFormData({ ...formData, [name]: value }); + const handleTimeChange = (time, _, field) => { + // Pastikan format HH:mm yang konsisten sesuai validasi BE + const formattedTime = time && time.isValid() ? time.format('HH:mm') : ''; + setFormData({ + ...formData, + [field]: formattedTime, + }); }; - const handleTimeChange = (time, timeString, field) => { - setFormData({ ...formData, [field]: timeString }); + const handleStatusToggle = (checked) => { + setFormData({ + ...formData, + is_active: checked, + }); }; useEffect(() => { if (props.selectedData) { - setFormData(props.selectedData); + // Konversi waktu dari berbagai format ke HH:mm menggunakan dayjs + const convertTimeToString = (timeValue) => { + if (!timeValue) return ''; + + // Jika sudah dalam format HH:mm, return langsung + if (typeof timeValue === 'string' && timeValue.match(/^\d{2}:\d{2}$/)) { + return timeValue; + } + + // Jika dalam format ISO (1970-01-01T08:00:00.000Z), extract jam:menit dalam UTC + const time = dayjs.utc(timeValue); + if (time.isValid()) { + return time.format('HH:mm'); + } + + return ''; + }; + + setFormData({ + ...props.selectedData, + start_time: convertTimeToString(props.selectedData.start_time), + end_time: convertTimeToString(props.selectedData.end_time), + }); } else { setFormData(defaultData); } - }, [props.showModal, props.selectedData]); - - const modalTitle = `${props.actionMode === 'add' ? 'Tambah' : props.actionMode === 'preview' ? 'Preview' : 'Edit'} Shift`; + }, [props.showModal, props.selectedData, props.actionMode]); return ( - - {!props.readOnly && ( - - )} - , + + + + + + {!props.readOnly && ( + + )} + + , ]} > -
+ {formData && (
- Status -
- setFormData({ ...formData, is_active: checked })} +
+
+ Status +
+
+
+ +
+
+ {formData.is_active ? 'Active' : 'Inactive'} +
+
+
+ + +
+ Shift Name + * + - {formData.is_active ? 'Active' : 'Inactive'} +
+ +
+ Shift Time + * + + + handleTimeChange(time, timeString, 'start_time') + } + style={{ width: '50%' }} + placeholder="Start Time " + disabled={props.readOnly} + /> + + handleTimeChange(time, timeString, 'end_time') + } + style={{ width: '50%' }} + placeholder="End Time " + disabled={props.readOnly} + /> +
- - -
- Nama Shift - * - -
- -
- Waktu Shift - * - - handleTimeChange(time, timeString, 'start_time')} - style={{ width: '50%' }} - placeholder="Waktu Mulai" - disabled={props.readOnly} - /> - handleTimeChange(time, time-string, 'end_time')} - style={{ width: '50%' }} - placeholder="Waktu Selesai" - disabled={props.readOnly} - /> - -
-
+ )} ); }; -export default DetailShift; \ No newline at end of file +export default DetailShift; diff --git a/src/pages/master/shift/component/ListShift.jsx b/src/pages/master/shift/component/ListShift.jsx index 9c8b278..c810568 100644 --- a/src/pages/master/shift/component/ListShift.jsx +++ b/src/pages/master/shift/component/ListShift.jsx @@ -9,19 +9,23 @@ import { } from '@ant-design/icons'; import { NotifAlert, NotifConfirmDialog } from '../../../../components/Global/ToastNotif'; import { useNavigate } from 'react-router-dom'; +import { deleteShift, getAllShift } from '../../../../api/master-shift'; import TableList from '../../../../components/Global/TableList'; -// import { getAllShift, deleteShift } from '../../../../api/master-shift'; // <-- API needs to be created +import dayjs from 'dayjs'; +import utc from 'dayjs/plugin/utc'; -// Mock API calls for demonstration -const getAllShift = async () => ({ - data: [ - { shift_id: 1, shift_name: 'Pagi', start_time: '08:00', end_time: '16:00', is_active: true }, - { shift_id: 2, shift_name: 'Sore', start_time: '16:00', end_time: '00:00', is_active: true }, - { shift_id: 3, shift_name: 'Malam', start_time: '00:00', end_time: '08:00', is_active: false }, - ], - statusCode: 200, -}); -const deleteShift = async (id) => ({ statusCode: 200, message: 'Data berhasil dihapus' }); +dayjs.extend(utc); + +// Helper function untuk convert ISO time ke HH:mm +const formatTime = (timeValue) => { + if (!timeValue) return '-'; + if (typeof timeValue === 'string' && timeValue.match(/^\d{2}:\d{2}$/)) { + return timeValue; + } + // UTC untuk menghindari timezone conversion + const time = dayjs.utc(timeValue); + return time.isValid() ? time.format('HH:mm') : '-'; +}; const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ { @@ -29,7 +33,6 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ dataIndex: 'shift_name', key: 'shift_name', width: '30%', - render: (text, record, index) => `${index + 1}. ${text}`, }, { title: 'Start Time', @@ -37,6 +40,7 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ key: 'start_time', width: '15%', align: 'center', + render: (time) => formatTime(time), }, { title: 'End Time', @@ -44,6 +48,7 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ key: 'end_time', width: '15%', align: 'center', + render: (time) => formatTime(time), }, { title: 'Status', @@ -51,15 +56,9 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ key: 'is_active', width: '15%', align: 'center', - render: (_, { is_active }) => { - const color = is_active ? 'green' : 'red'; - const text = is_active ? 'Active' : 'Inactive'; - return ( - - {text} - - ); - }, + render: (status) => ( + {status ? 'Active' : 'Inactive'} + ), }, { title: 'Aksi', @@ -68,9 +67,25 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ width: '25%', render: (_, record) => ( -
- - - { - const value = e.target.value; - setSearchValue(value); - // Auto search when clearing by backspace/delete - if (value === '') { - handleSearchClear(); - } - }} - onSearch={handleSearch} - allowClear - onClear={handleSearchClear} - enterButton={ - - } - size="large" - /> - - - - + + + + + + { + const value = e.target.value; + setSearchValue(value); + if (value === '') { + handleSearchClear(); + } }} - > - - - - - - - - - - - + onSearch={handleSearch} + allowClear={{ + clearIcon: , + }} + enterButton={ + + } + size="large" + /> + + + + + + + + + + + + + + + + ); }); -export default ListShift; \ No newline at end of file +export default ListShift; diff --git a/src/pages/master/status/component/DetailStatus.jsx b/src/pages/master/status/component/DetailStatus.jsx index 167dbab..11b1afa 100644 --- a/src/pages/master/status/component/DetailStatus.jsx +++ b/src/pages/master/status/component/DetailStatus.jsx @@ -1,5 +1,16 @@ import React, { useEffect, useState } from 'react'; -import { Modal, Input, Divider, Typography, Button, ConfigProvider, InputNumber, Switch, Row, Col } from 'antd'; +import { + Modal, + Input, + Divider, + Typography, + Button, + InputNumber, + Switch, + Row, + Col, + ColorPicker, +} from 'antd'; import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif'; import { validateRun } from '../../../../Utils/validate'; import { createStatus, updateStatus } from '../../../../api/master-status'; @@ -34,6 +45,10 @@ const DetailStatus = (props) => { setFormData({ ...formData, is_active: checked }); }; + const handleColorChange = (color, hex) => { + setFormData({ ...formData, status_color: hex }); + }; + const handleCancel = () => { props.setSelectedData(null); props.setActionMode('list'); @@ -123,7 +138,14 @@ const DetailStatus = (props) => { onCancel={handleCancel} footer={ !props.readOnly && ( -
+
@@ -176,13 +200,35 @@ const DetailStatus = (props) => {
Status Color * - +
+ `color hex: ${color.toHexString()}`} + allowClear={false} + format="hex" + size="large" + style={{ width: '100%' }} + presets={[ + { + label: 'Recommended', + colors: [ + '#EF4444', // Merah + '#3B82F6', // Biru + '#10B981', // Hijau + '#F59E0B', // Kuning + '#8B5CF6', // Ungu + '#EC4899', // Pink + '#F97316', // Orange + '#14B8A6', // Teal + '#6B7280', // Gray + '#000000', // Black + ], + }, + ]} + /> +
Description @@ -199,4 +245,4 @@ const DetailStatus = (props) => { ); }; -export default DetailStatus; \ No newline at end of file +export default DetailStatus; diff --git a/src/pages/master/tag/component/DetailTag.jsx b/src/pages/master/tag/component/DetailTag.jsx index 6ec67fc..96f86f0 100644 --- a/src/pages/master/tag/component/DetailTag.jsx +++ b/src/pages/master/tag/component/DetailTag.jsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react'; -import { Modal, Input, Typography, Switch, Button, ConfigProvider, Divider, Select } from 'antd'; +import { Modal, Input, Typography, Switch, Button, ConfigProvider, Select, Checkbox } from 'antd'; import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif'; import { createTag, updateTag, getAllTag } from '../../../../api/master-tag'; import { getAllDevice } from '../../../../api/master-device'; @@ -34,6 +34,7 @@ const DetailTag = (props) => { lim_high: '', lim_high_crash: '', device_id: null, + description: '', sub_section_id: null, }; @@ -147,10 +148,8 @@ const DetailTag = (props) => { payload.unit = formData.unit.trim(); } - // Add device_id only if it's selected - if (formData.device_id) { - payload.device_id = parseInt(formData.device_id); - } + // Add device_id - backend requires this field even if null + payload.device_id = formData.device_id ? parseInt(formData.device_id) : null; // Add limit fields only if they have values if (formData.lim_low_crash !== '' && formData.lim_low_crash !== null) { @@ -166,10 +165,8 @@ const DetailTag = (props) => { payload.lim_high_crash = parseFloat(formData.lim_high_crash); } - // Add sub_section_id only if it's selected - if (formData.sub_section_id) { - payload.sub_section_id = parseInt(formData.sub_section_id); - } + // Add sub_section_id - backend requires this field even if null + payload.sub_section_id = formData.sub_section_id ? parseInt(formData.sub_section_id) : null; try { const response = @@ -234,24 +231,24 @@ const DetailTag = (props) => { }); }; - const handleAlarmToggle = (checked) => { + const handleAlarmToggle = (e) => { setformData({ ...formData, - is_alarm: checked, + is_alarm: e.target.checked, }); }; - const handleReportToggle = (checked) => { + const handleReportToggle = (e) => { setformData({ ...formData, - is_report: checked, + is_report: e.target.checked, }); }; - const handleHistoryToggle = (checked) => { + const handleHistoryToggle = (e) => { setformData({ ...formData, - is_history: checked, + is_history: e.target.checked, }); }; @@ -336,7 +333,7 @@ const DetailTag = (props) => { } Tag`} open={props.showModal} onCancel={handleCancel} - width={800} + width={1000} footer={[ {
- {/* Alarm, Report, dan History dalam satu baris */} + {/* Tag Code dan Alarm, Report dan History */}
- {/* Alarm Toggle */} + {/* Tag Code - Auto Increment & Read Only */}
-
- Alarm - * -
-
Tag Code + -
- -
-
- {formData.is_alarm === true ? 'Yes' : 'No'} -
+ /> +
+ {/* Alarm Checkbox */} +
+ Alarm +
+
- {/* Report Toggle */} + {/* Report Checkbox */}
-
- Report - * -
-
-
- -
-
- {formData.is_report === true ? 'Yes' : 'No'} -
+ Report +
+
- {/* History Toggle */} + {/* History Checkbox */}
+ History
- History - * -
-
-
- -
-
- {formData.is_history === true ? 'Yes' : 'No'} -
+
- - {/* Tag Code - Auto Increment & Read Only */} -
- Tag Code - -
{/* Tag Number dan Tag Name dalam satu baris */}
{
- {/* Limit Low Crash dan Limit Low dalam satu baris */} + {/* Semua Limit dalam satu baris */}
{/* Limit Low Crash */} @@ -720,17 +656,6 @@ const DetailTag = (props) => { step="any" />
-
-
- {/* Limit High dan Limit High Crash dalam satu baris */} -
-
{/* Limit High */}
Limit High @@ -759,6 +684,18 @@ const DetailTag = (props) => {
+ {/* Description */} +
+ Description + +
)} diff --git a/src/pages/master/tag/component/ListTag.jsx b/src/pages/master/tag/component/ListTag.jsx index 2451e71..c9c41ed 100644 --- a/src/pages/master/tag/component/ListTag.jsx +++ b/src/pages/master/tag/component/ListTag.jsx @@ -44,12 +44,14 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ dataIndex: 'data_type', key: 'data_type', width: '10%', + render: (text) => text || '-', }, { title: 'Unit', dataIndex: 'unit', key: 'unit', width: '8%', + render: (text) => text || '-', }, { title: 'Sub Section', @@ -63,6 +65,7 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ dataIndex: 'device_name', key: 'device_name', width: '12%', + render: (text) => text || '-', }, { title: 'Status', diff --git a/src/pages/master/unit/component/DetailUnit.jsx b/src/pages/master/unit/component/DetailUnit.jsx index 12ca110..cc7c2fb 100644 --- a/src/pages/master/unit/component/DetailUnit.jsx +++ b/src/pages/master/unit/component/DetailUnit.jsx @@ -1,13 +1,16 @@ import React, { useEffect, useState } from 'react'; -import { Modal, Input, Typography, Switch, Button, ConfigProvider, Divider } from 'antd'; +import { Modal, Input, Typography, Switch, Button, ConfigProvider, Divider, Select } from 'antd'; import { NotifOk } from '../../../../components/Global/ToastNotif'; import { createUnit, updateUnit } from '../../../../api/master-unit'; +import { getAllTag } from '../../../../api/master-tag'; // Import API untuk Tag import { validateRun } from '../../../../Utils/validate'; const { Text } = Typography; const DetailUnit = (props) => { const [confirmLoading, setConfirmLoading] = useState(false); + const [tagList, setTagList] = useState([]); + const [loadingTags, setLoadingTags] = useState(false); const defaultData = { unit_id: '', @@ -15,10 +18,28 @@ const DetailUnit = (props) => { unit_name: '', unit_description: '', is_active: true, + tag_id: null, // Tambahkan tag_id }; const [formData, setFormData] = useState(defaultData); + // Fungsi untuk mengambil data Tag + const loadTags = async () => { + setLoadingTags(true); + try { + const params = new URLSearchParams({ limit: 1000, criteria: '' }); + const response = await getAllTag(params); + if (response && response.data) { + const activeTags = response.data.filter((tag) => tag.is_active === true); + setTagList(activeTags); + } + } catch (error) { + console.error('Error loading tags:', error); + } finally { + setLoadingTags(false); + } + }; + const handleCancel = () => { props.setSelectedData(null); props.setActionMode('list'); @@ -27,8 +48,10 @@ const DetailUnit = (props) => { const handleSave = async () => { setConfirmLoading(true); - // Daftar aturan validasi - const validationRules = [{ field: 'unit_name', label: 'Unit Name', required: true }]; + const validationRules = [ + { field: 'unit_name', label: 'Unit Name', required: true }, + { field: 'tag_id', label: 'Tag', required: true }, // Tambah validasi untuk tag_id + ]; if ( validateRun(formData, validationRules, (errorMessages) => { @@ -39,14 +62,16 @@ const DetailUnit = (props) => { }); setConfirmLoading(false); }) - ) + ) { return; + } try { const payload = { - is_active: formData.is_active, unit_name: formData.unit_name, unit_description: formData.unit_description, + is_active: formData.is_active, + tag_id: formData.tag_id, // Tambahkan tag_id ke payload }; const response = @@ -90,6 +115,13 @@ const DetailUnit = (props) => { }); }; + const handleSelectChange = (name, value) => { + setFormData({ + ...formData, + [name]: value, + }); + }; + const handleStatusToggle = (checked) => { setFormData({ ...formData, @@ -98,6 +130,10 @@ const DetailUnit = (props) => { }; useEffect(() => { + if (props.showModal) { + loadTags(); // Panggil fungsi loadTags saat modal muncul + } + if (props.selectedData) { setFormData(props.selectedData); } else { @@ -116,6 +152,7 @@ const DetailUnit = (props) => { } Unit`} open={props.showModal} onCancel={handleCancel} + width={600} footer={[ { - {/* Unit Code - Auto Increment & Read Only */}
Unit Code { />
+
+ Tag + * + +
+
Unit Name * @@ -221,4 +284,4 @@ const DetailUnit = (props) => { ); }; -export default DetailUnit; +export default DetailUnit; \ No newline at end of file diff --git a/src/pages/report/report/IndexReport.jsx b/src/pages/report/report/IndexReport.jsx new file mode 100644 index 0000000..d849260 --- /dev/null +++ b/src/pages/report/report/IndexReport.jsx @@ -0,0 +1,38 @@ +import React, { memo, useState, useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { useBreadcrumb } from '../../../layout/LayoutBreadcrumb'; +import { Typography } from 'antd'; +import ListReport from './component/ListReport'; + +const { Text } = Typography; + +const IndexReport = memo(function IndexReport() { + const navigate = useNavigate(); + const { setBreadcrumbItems } = useBreadcrumb(); + const [selectedData, setSelectedData] = useState(null); + + useEffect(() => { + const token = localStorage.getItem('token'); + if (token) { + setBreadcrumbItems([ + { + title: ( + + • Report + + ), + }, + ]); + } else { + navigate('/signin'); + } + }, [navigate, setBreadcrumbItems]); + + return ( + + + + ); +}); + +export default IndexReport; diff --git a/src/pages/report/report/component/ListReport.jsx b/src/pages/report/report/component/ListReport.jsx new file mode 100644 index 0000000..974af15 --- /dev/null +++ b/src/pages/report/report/component/ListReport.jsx @@ -0,0 +1,163 @@ +import React, { memo, useState, useEffect } from 'react'; +import { Button, Row, Col, Card, Input, DatePicker, Select, Typography } from 'antd'; +import TableList from '../../../../components/Global/TableList'; +import dayjs from 'dayjs'; +import { FileTextOutlined } from '@ant-design/icons'; + +const { Text } = Typography; + +const ListReport = memo(function ListReport(props) { + const columns = [ + { + title: 'No', + key: 'no', + width: '5%', + align: 'center', + render: (_, __, index) => index + 1, + }, + { + title: 'Datetime', + dataIndex: 'datetime', + key: 'datetime', + width: '10%', + }, + { + title: 'Tag Name', + dataIndex: 'tag_name', + key: 'tag_name', + width: '70%', + }, + { + title: 'Value', + dataIndex: 'val', + key: 'val', + width: '10%', + }, + { + title: 'Stat', + dataIndex: 'stat', + key: 'stat', + width: '10%', + }, + ]; + + const [trigerFilter, setTrigerFilter] = useState(false); + + const defaultFilter = { search: '' }; + const [formDataFilter, setFormDataFilter] = useState(defaultFilter); + + const [plantSubSection, setPlantSubSection] = useState('Semua Plant'); + const [startDate, setStartDate] = useState(dayjs('2025-09-30')); + const [endDate, setEndDate] = useState(dayjs('2025-10-09')); + const [periode, setPeriode] = useState('10 Menit'); + + const getAllReport = async (params) => { + return { + data: [], + }; + }; + + const handleReset = () => { + setPlantSubSection('Semua Plant'); + setStartDate(dayjs('2025-09-30')); + setEndDate(dayjs('2025-10-09')); + setPeriode('10 Menit'); + }; + + return ( + + + +
+ + +
+ + Plant Sub Section + + +
+ + + + + + + + + + + + + + + + + + ); +}); + +export default ListReport; diff --git a/src/pages/report/trending/IndexTrending.jsx b/src/pages/report/trending/IndexTrending.jsx new file mode 100644 index 0000000..73540e7 --- /dev/null +++ b/src/pages/report/trending/IndexTrending.jsx @@ -0,0 +1,38 @@ +import React, { memo, useState, useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { useBreadcrumb } from '../../../layout/LayoutBreadcrumb'; +import { Typography } from 'antd'; +import ReportTrending from './ReportTrending'; + +const { Text } = Typography; + +const IndexTrending = memo(function IndexTrending() { + const navigate = useNavigate(); + const { setBreadcrumbItems } = useBreadcrumb(); + const [selectedData, setSelectedData] = useState(null); + + useEffect(() => { + const token = localStorage.getItem('token'); + if (token) { + setBreadcrumbItems([ + { + title: ( + + • Trending + + ), + }, + ]); + } else { + navigate('/signin'); + } + }, [navigate, setBreadcrumbItems]); + + return ( + + + + ); +}); + +export default IndexTrending; diff --git a/src/pages/report/trending/ReportTrending.jsx b/src/pages/report/trending/ReportTrending.jsx new file mode 100644 index 0000000..04a1eb5 --- /dev/null +++ b/src/pages/report/trending/ReportTrending.jsx @@ -0,0 +1,222 @@ +import React, { memo, useState, useEffect } from 'react'; +import { Button, Row, Col, Card, Input, DatePicker, Select, Typography } from 'antd'; +import dayjs from 'dayjs'; +import { FileTextOutlined } from '@ant-design/icons'; +import { ResponsiveLine } from '@nivo/line'; +import './trending.css'; + +const { Text } = Typography; + +const tagTrendingData = [ + { + id: 'TEMP_SENSOR_1', + color: '#FF6B4A', + data: [ + { y: '08:00', x: 75 }, + { y: '08:05', x: 76 }, + { y: '08:10', x: 75 }, + { y: '08:15', x: 77 }, + { y: '08:20', x: 76 }, + { y: '08:25', x: 78 }, + { y: '08:30', x: 79 }, + ], + }, + { + id: 'GAS_LEAK_SENSOR_1', + color: '#4ECDC4', + data: [ + { y: '08:00', x: 10 }, + { y: '08:05', x: 150 }, + { y: '08:10', x: 40 }, + { y: '08:15', x: 20 }, + { y: '08:20', x: 15 }, + { y: '08:25', x: 18 }, + { y: '08:30', x: 25 }, + ], + }, + { + id: 'PRESSURE_SENSOR_1', + color: '#FFE66D', + data: [ + { y: '08:00', x: 1.2 }, + { y: '08:05', x: 1.3 }, + { y: '08:10', x: 1.2 }, + { y: '08:15', x: 1.4 }, + { y: '08:20', x: 1.5 }, + { y: '08:25', x: 1.3 }, + { y: '08:30', x: 1.2 }, + ], + }, +]; + +const ReportTrending = memo(function ReportTrending(props) { + const [trigerFilter, setTrigerFilter] = useState(false); + + const defaultFilter = { search: '' }; + const [formDataFilter, setFormDataFilter] = useState(defaultFilter); + + const [plantSubSection, setPlantSubSection] = useState('Semua Plant'); + const [startDate, setStartDate] = useState(dayjs('2025-09-30')); + const [endDate, setEndDate] = useState(dayjs('2025-10-09')); + const [periode, setPeriode] = useState('10 Menit'); + + const getAllReport = async (params) => { + return { + data: [], + }; + }; + + const handleReset = () => { + setPlantSubSection('Semua Plant'); + setStartDate(dayjs('2025-09-30')); + setEndDate(dayjs('2025-10-09')); + setPeriode('10 Menit'); + }; + + return ( + + + + + + +
+ + Plant Sub Section + + +
+ + + + + + + + + + + + +
+ +
+ + + + + ); +}); + +export default ReportTrending; diff --git a/src/pages/history/trending/trending.css b/src/pages/report/trending/trending.css similarity index 100% rename from src/pages/history/trending/trending.css rename to src/pages/report/trending/trending.css diff --git a/src/pages/role/IndexRole.jsx b/src/pages/role/IndexRole.jsx index 0829656..c446522 100644 --- a/src/pages/role/IndexRole.jsx +++ b/src/pages/role/IndexRole.jsx @@ -1,144 +1,70 @@ import React, { memo, useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; -import { useBreadcrumb } from '../../layout/LayoutBreadcrumb'; -import { Form, Typography } from 'antd'; import ListRole from './component/ListRole'; import DetailRole from './component/DetailRole'; -import { createRole, updateRole } from '../../api/role'; -import { NotifAlert, NotifOk } from '../../components/Global/ToastNotif'; +import { useBreadcrumb } from '../../layout/LayoutBreadcrumb'; +import { Typography } from 'antd'; const { Text } = Typography; const IndexRole = memo(function IndexRole() { const navigate = useNavigate(); const { setBreadcrumbItems } = useBreadcrumb(); - const [form] = Form.useForm(); 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: ( - - • Role - - ), - }, + { title: • Role }, ]); } else { navigate('/signin'); } }, [navigate, setBreadcrumbItems]); - useEffect(() => { - if (actionMode === 'add' || actionMode === 'edit' || actionMode === 'preview') { - setIsModalVisible(true); - setReadOnly(actionMode === 'preview'); - - if (actionMode === 'add') { - form.resetFields(); - } else if (selectedData) { - form.setFieldsValue(selectedData); - } - } else { - setIsModalVisible(false); - form.resetFields(); - } - }, [actionMode, selectedData, form]); - - const handleCancel = () => { - setActionMode('list'); - setSelectedData(null); - form.resetFields(); - }; - - const handleOk = () => { - if (readOnly) { - handleCancel(); - return; - } - - form.validateFields() - .then(async (values) => { - try { - let response; - if (actionMode === 'edit') { - response = await updateRole(selectedData.role_id, values); - console.log('Update Response:', response); - - const isSuccess = response.statusCode === 200 || response.statusCode === 201; - if (isSuccess) { - NotifAlert({ - icon: 'success', - title: 'Berhasil', - message: `Data Role "${values.role_name}" berhasil diubah.`, - }); - handleCancel(); - } else { - NotifOk({ - icon: 'error', - title: 'Gagal', - message: response.message || 'Gagal mengubah data Role', - }); - } - } else if (actionMode === 'add') { - response = await createRole(values); - console.log('Create Response:', response); - - const isSuccess = response.statusCode === 200 || response.statusCode === 201; - if (isSuccess) { - NotifAlert({ - icon: 'success', - title: 'Berhasil', - message: `Data Role "${values.role_name}" berhasil ditambahkan.`, - }); - handleCancel(); - } else { - NotifOk({ - icon: 'error', - title: 'Gagal', - message: response.message || 'Gagal menambahkan data Role', - }); - } - } - } catch (error) { - console.error('Error:', error); - NotifOk({ - icon: 'error', - title: 'Error', - message: 'Terjadi kesalahan saat menyimpan data', - }); - } - }) - .catch((info) => { - console.log('Validate Failed:', info); - }); - }; - return ( ); }); -export default IndexRole; +export default IndexRole; \ No newline at end of file diff --git a/src/pages/role/component/DetailRole.jsx b/src/pages/role/component/DetailRole.jsx index 8d930a8..1c24dbf 100644 --- a/src/pages/role/component/DetailRole.jsx +++ b/src/pages/role/component/DetailRole.jsx @@ -1,72 +1,213 @@ -import React from 'react'; -import { Modal, Form, Input, InputNumber, Switch, Row, Col, Typography, Divider } from 'antd'; +import React, { useEffect, useState } from 'react'; +import { Modal, Input, Divider, Typography, Switch, Button, ConfigProvider, InputNumber, Row, Col } from 'antd'; +import { NotifAlert, NotifOk } from '../../../components/Global/ToastNotif'; +import { validateRun } from '../../../Utils/validate'; +import { createRole, updateRole } from '../../../api/role'; const { Text } = Typography; +const { TextArea } = Input; -const DetailRole = ({ visible, onCancel, onOk, form, editingKey, readOnly }) => { - const modalTitle = editingKey ? (readOnly ? 'Preview Role' : 'Edit Role') : 'Tambah Role'; +const DetailRole = (props) => { + const [confirmLoading, setConfirmLoading] = useState(false); + + const defaultData = { + role_id: '', + role_name: '', + role_level: null, + role_description: '', + is_active: true, + }; + + const [formData, setFormData] = useState(defaultData); + + const handleInputChange = (e) => { + const { name, value } = e.target; + setFormData({ ...formData, [name]: value }); + }; + + const handleInputNumberChange = (value) => { + setFormData({ ...formData, role_level: value }); + }; + + const handleStatusToggle = (checked) => { + setFormData({ ...formData, is_active: checked }); + }; + + const handleCancel = () => { + props.setSelectedData(null); + props.setActionMode('list'); + }; + + const handleSave = async () => { + setConfirmLoading(true); + + const validationRules = [ + { field: 'role_name', label: 'Nama Role', required: true }, + { field: 'role_level', label: 'Level', required: true }, + ]; + + if ( + validateRun(formData, validationRules, (errorMessages) => { + NotifOk({ + icon: 'warning', + title: 'Peringatan', + message: errorMessages, + }); + setConfirmLoading(false); + }) + ) { + return; + } + + try { + const payload = { + role_name: formData.role_name, + role_level: formData.role_level, + role_description: formData.role_description, + is_active: formData.is_active, + }; + + const response = formData.role_id + ? await updateRole(formData.role_id, payload) + : await createRole(payload); + + if (response && (response.statusCode === 200 || response.statusCode === 201)) { + const action = formData.role_id ? 'diubah' : 'ditambahkan'; + NotifOk({ + icon: 'success', + title: 'Berhasil', + message: `Data Role "${payload.role_name}" berhasil ${action}.`, + }); + props.setActionMode('list'); + } else { + NotifAlert({ + icon: 'error', + title: 'Gagal', + message: response?.message || 'Gagal menyimpan data.', + }); + } + } catch (error) { + NotifAlert({ + icon: 'error', + title: 'Error', + message: error.message || 'Terjadi kesalahan pada server.', + }); + } finally { + setConfirmLoading(false); + } + }; + + useEffect(() => { + if (props.selectedData) { + setFormData({ ...defaultData, ...props.selectedData }); + } else { + setFormData(defaultData); + } + }, [props.showModal, props.selectedData]); return ( {modalTitle}} - open={visible} - onCancel={onCancel} - onOk={onOk} - okText="Simpan" - cancelText="Batal" - okButtonProps={{ disabled: readOnly }} - destroyOnClose - + title={ + + {props.actionMode === 'add' + ? 'Tambah Role' + : props.actionMode === 'preview' + ? 'Preview Role' + : 'Edit Role'} + + } + open={props.showModal} + onCancel={handleCancel} + footer={[ + + + + + + {!props.readOnly && ( + + )} + + , + ]} > -
- Status} - valuePropName="checked" - initialValue={true} - > - - - - -
- Nama Role} - rules={[{ required: true, message: 'Nama Role wajib diisi!' }]} - > - - - - - Level} - rules={[{ required: true, message: 'Level wajib diisi!' }]} - > - - - - - - Deskripsi Role} - > - + Status +
+ - - + {formData.is_active ? 'Active' : 'Inactive'} +
+ + +
+
+ Nama Role + * + +
+ + +
+ Level + * + +
+ + +
+ Deskripsi Role +