import { useEffect, useState } from 'react' import { Container } from 'react-bootstrap' import { useParams } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { Link } from 'react-router-dom' import { getUserProfile, listUserThanksGiven, listUserThanksReceived } from '../api/client' export default function Profile() { const { id } = useParams() const { t } = useTranslation() const [profile, setProfile] = useState(null) const [error, setError] = useState('') const [loading, setLoading] = useState(true) const [thanksGiven, setThanksGiven] = useState([]) const [thanksReceived, setThanksReceived] = useState([]) const [loadingThanks, setLoadingThanks] = useState(true) useEffect(() => { let active = true setLoading(true) setError('') Promise.all([getUserProfile(id), listUserThanksGiven(id), listUserThanksReceived(id)]) .then(([profileData, givenData, receivedData]) => { if (!active) return setProfile(profileData) setThanksGiven(Array.isArray(givenData) ? givenData : []) setThanksReceived(Array.isArray(receivedData) ? receivedData : []) }) .catch((err) => { if (!active) return setError(err.message) setThanksGiven([]) setThanksReceived([]) }) .finally(() => { if (!active) return setLoading(false) setLoadingThanks(false) }) return () => { active = false } }, [id]) const formatDateTime = (value) => { if (!value) return '—' const date = new Date(value) if (Number.isNaN(date.getTime())) return '—' const day = String(date.getDate()).padStart(2, '0') const month = String(date.getMonth() + 1).padStart(2, '0') const year = String(date.getFullYear()) const hours = String(date.getHours()).padStart(2, '0') const minutes = String(date.getMinutes()).padStart(2, '0') const seconds = String(date.getSeconds()).padStart(2, '0') return `${day}.${month}.${year} ${hours}:${minutes}:${seconds}` } return (
{t('profile.title')}
{loading &&

{t('profile.loading')}

} {error &&

{error}

} {profile && (
{profile.avatar_url ? ( ) : (