import React, { useState, useEffect } from 'react'; import { Box, Typography, CircularProgress, useTheme, useMediaQuery, } from '@mui/material'; import { useTranslation } from 'react-i18next'; import { CardContainer } from '@/components/CardContainer'; import { PageWrapper } from '../PageWrapper'; import type { LoginLog } from '../../types/settingsApiType'; import { formatDate } from '@/utils/formatSessionDate'; import { useToast } from '@harmony/kit'; import { useProfile } from '../../hooks/useProfile'; export function RecentLogins() { const { t, i18n } = useTranslation('setting'); const [logs, setLogs] = useState([]); const theme = useTheme(); const isXsup = useMediaQuery(theme.breakpoints.up('xs')); const showToast = useToast(); const { isLoadingProfile, refetchProfile } = useProfile(); // useEffect(() => { // if (profileData?.success && Array.isArray(profileData.loginLogs)) { // setLogs(profileData.loginLogs); // } // }, [profileData]); // useEffect(() => { // if (fetchError) { // showToast({ // message: getErrorMessage(fetchError) || t('active.errorFetch'), // severity: 'error', // }); // } // }, [fetchError, t, showToast]); useEffect(() => { const loadProfile = async () => { const profileData = await refetchProfile(); if (!profileData) return; if (profileData.success) { if (!Array.isArray(profileData.loginLogs)) return; setLogs(profileData.loginLogs); } else { showToast({ message: profileData.message || t('active.errorFetch'), severity: 'error', }); } }; loadProfile(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return ( {isLoadingProfile ? ( ) : ( {logs.map((log, index) => ( {formatDate(log.loginDateTime, i18n.language, t)} {`${log.deviceOs} ${log.deviceName}`} {log.ipAddress} {isXsup && index < logs.length - 1 && ( )} ))} )} ); }