'use client'; import React, { useEffect, useState } from 'react'; import { useRouter } from 'next/navigation'; import { getActivityHistory } from '@/app/API/profile/updateProfile'; import './activity.scss'; interface ActivityData { id: number; activity_type: string; details: any; createdAt: string; ip_address?: string; user_agent?: string; } interface PaginationInfo { totalCount: number; totalPages: number; currentPage: number; } const ActivityPage = () => { const router = useRouter(); const [activities, setActivities] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [pagination, setPagination] = useState({ totalCount: 0, totalPages: 0, currentPage: 1 }); useEffect(() => { fetchActivities(1); }, []); const fetchActivities = async (page: number) => { setLoading(true); try { const response = await getActivityHistory(page, 10); if (response.status === 'success') { setActivities(response.data.activities); setPagination({ totalCount: response.data.totalCount, totalPages: response.data.totalPages, currentPage: response.data.currentPage }); } else { throw new Error(response.message || 'Failed to load activity history'); } } catch (err: any) { setError(err.message || 'Error loading activity history'); } finally { setLoading(false); } }; const formatDate = (dateString: string) => { const date = new Date(dateString); return date.toLocaleString(); }; const renderPagination = () => { if (pagination.totalPages <= 1) return null; return ( ); }; const getActivityIcon = (activityType: string) => { switch (activityType) { case 'LOGIN': return 'bi-box-arrow-in-right'; case 'LOGOUT': return 'bi-box-arrow-right'; case 'PASSWORD_CHANGE': return 'bi-key'; case 'SECURITY_CHANGE': return 'bi-shield-check'; case 'EMAIL_CHANGE': return 'bi-envelope'; case 'PROFILE_UPDATE': return 'bi-person'; default: return 'bi-clock-history'; } }; return (

Activity History

View your recent account activities

{error && (
{error}
)}
{loading ? (
Loading...
) : activities.length > 0 ? ( <>
{activities.map(activity => (
{activity.activity_type.replace(/_/g, ' ')}
{formatDate(activity.createdAt)}

{activity.details?.message || 'Activity recorded'}

{activity.ip_address && (
IP: {activity.ip_address} {activity.user_agent && ( {activity.user_agent.substring(0, 50)} {activity.user_agent.length > 50 ? '...' : ''} )}
)}
))}
{renderPagination()} ) : (

No activity recorded yet

)}
); }; export default ActivityPage;