diff --git a/src/pages/history/trending/IndexTrending.jsx b/src/pages/history/trending/IndexTrending.jsx index 0a1ade5..ec81f95 100644 --- a/src/pages/history/trending/IndexTrending.jsx +++ b/src/pages/history/trending/IndexTrending.jsx @@ -5,6 +5,7 @@ import { Typography, Select, DatePicker, Button, Row, Col, Card, Statistic } fro import { ResponsiveLine } from '@nivo/line'; import { ResponsivePie } from '@nivo/pie'; import { FileTextOutlined, ToolOutlined, CheckCircleOutlined, ClockCircleOutlined } from '@ant-design/icons'; +import { decryptData } from '../../../components/Global/Formatter'; import dayjs from 'dayjs'; import './trending.css'; @@ -18,10 +19,33 @@ const IndexTrending = memo(function IndexTrending() { const [startDate, setStartDate] = useState(dayjs('2025-09-30')); const [endDate, setEndDate] = useState(dayjs('2025-10-09')); const [periode, setPeriode] = useState('Bulanan'); + 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 }, @@ -106,6 +130,12 @@ const IndexTrending = memo(function IndexTrending() { setPeriode('Bulanan'); }; + // 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 (
@@ -170,12 +200,21 @@ const IndexTrending = memo(function IndexTrending() { - - @@ -183,56 +222,66 @@ const IndexTrending = memo(function IndexTrending() { {/* Statistics Cards */} - - - -
- -
- Total Error} - value={245} - valueStyle={{ fontSize: '24px', fontWeight: 'bold', color: '#333' }} - /> -
- - - -
- -
- Sedang Maintenance} - value={12} - valueStyle={{ fontSize: '24px', fontWeight: 'bold', color: '#333' }} - /> -
- - - -
- -
- Selesai Diperbaiki} - value={233} - valueStyle={{ fontSize: '24px', fontWeight: 'bold', color: '#333' }} - /> -
- - - -
- -
- Rata-rata Waktu Perbaikan} - value="2.5 jam" - valueStyle={{ fontSize: '24px', fontWeight: 'bold', color: '#333' }} - /> -
- -
+ {!canViewData ? ( + + + Anda tidak memiliki akses untuk melihat data trending. +
+ Silakan hubungi administrator untuk mendapatkan akses. +
+
+ ) : ( + <> + + + +
+ +
+ Total Error} + value={245} + valueStyle={{ fontSize: '24px', fontWeight: 'bold', color: '#333' }} + /> +
+ + + +
+ +
+ Sedang Maintenance} + value={12} + valueStyle={{ fontSize: '24px', fontWeight: 'bold', color: '#333' }} + /> +
+ + + +
+ +
+ Selesai Diperbaiki} + value={233} + valueStyle={{ fontSize: '24px', fontWeight: 'bold', color: '#333' }} + /> +
+ + + +
+ +
+ Rata-rata Waktu Perbaikan} + value="2.5 jam" + valueStyle={{ fontSize: '24px', fontWeight: 'bold', color: '#333' }} + /> +
+ +
{/* Charts Section */} @@ -380,6 +429,8 @@ const IndexTrending = memo(function IndexTrending() { + + )}
);