2023-12-13 14:32:57 +03:00
|
|
|
|
'use client';
|
|
|
|
|
|
2023-12-25 16:53:27 +03:00
|
|
|
|
import { AnimatePresence } from 'framer-motion';
|
2023-08-26 17:26:49 +03:00
|
|
|
|
import { useMemo, useState } from 'react';
|
2023-12-17 20:19:28 +03:00
|
|
|
|
import { FiBell, FiBellOff } from 'react-icons/fi';
|
2023-08-26 17:26:49 +03:00
|
|
|
|
|
2023-12-13 14:32:57 +03:00
|
|
|
|
import InfoError from '@/components/InfoError';
|
2024-01-04 19:38:12 +03:00
|
|
|
|
import { Loader } from '@/components/ui/Loader';
|
|
|
|
|
import MiniButton from '@/components/ui/MiniButton';
|
|
|
|
|
import Overlay from '@/components/ui/Overlay';
|
2023-12-13 14:32:57 +03:00
|
|
|
|
import { useAuth } from '@/context/AuthContext';
|
|
|
|
|
import { useLibrary } from '@/context/LibraryContext';
|
|
|
|
|
import { useUserProfile } from '@/context/UserProfileContext';
|
|
|
|
|
|
2023-08-26 17:26:49 +03:00
|
|
|
|
import EditorPassword from './EditorPassword';
|
|
|
|
|
import EditorProfile from './EditorProfile';
|
|
|
|
|
import ViewSubscriptions from './ViewSubscriptions';
|
2023-07-31 23:47:18 +03:00
|
|
|
|
|
|
|
|
|
function UserTabs() {
|
|
|
|
|
const { user, error, loading } = useUserProfile();
|
2023-08-26 17:26:49 +03:00
|
|
|
|
const { user: auth } = useAuth();
|
|
|
|
|
const { items } = useLibrary();
|
|
|
|
|
|
2023-08-27 00:19:19 +03:00
|
|
|
|
const [showSubs, setShowSubs] = useState(false);
|
2023-08-26 17:26:49 +03:00
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
|
const subscriptions = useMemo(() => {
|
2023-08-26 17:26:49 +03:00
|
|
|
|
return items.filter(item => auth?.subscriptions.includes(item.id));
|
|
|
|
|
}, [auth, items]);
|
2023-07-31 23:47:18 +03:00
|
|
|
|
|
|
|
|
|
return (
|
2023-12-28 14:04:44 +03:00
|
|
|
|
<>
|
2024-01-04 19:30:10 +03:00
|
|
|
|
{loading ? <Loader /> : null}
|
2023-12-28 14:04:44 +03:00
|
|
|
|
{error ? <InfoError error={error} /> : null}
|
|
|
|
|
{user ? (
|
|
|
|
|
<div className='flex gap-6 py-2'>
|
|
|
|
|
<div>
|
|
|
|
|
<Overlay position='top-0 right-0'>
|
|
|
|
|
<MiniButton
|
|
|
|
|
title='Показать/Скрыть отслеживаемые схемы'
|
|
|
|
|
icon={
|
|
|
|
|
showSubs ? (
|
|
|
|
|
<FiBell size='1.25rem' className='clr-text-primary' />
|
|
|
|
|
) : (
|
|
|
|
|
<FiBellOff size='1.25rem' className='clr-text-primary' />
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
onClick={() => setShowSubs(prev => !prev)}
|
|
|
|
|
/>
|
|
|
|
|
</Overlay>
|
|
|
|
|
<h1 className='mb-4'>Учетные данные пользователя</h1>
|
|
|
|
|
<div className='flex py-2'>
|
|
|
|
|
<EditorProfile />
|
|
|
|
|
<EditorPassword />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<AnimatePresence>
|
|
|
|
|
{subscriptions.length > 0 && showSubs ? <ViewSubscriptions items={subscriptions} /> : null}
|
|
|
|
|
</AnimatePresence>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-07-31 23:47:18 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
|
export default UserTabs;
|