import React from 'react'; import { useTranslation } from 'react-i18next'; import { useDispatch } from 'react-redux'; import { LOCALSTORAGE_KEY_ACCOUNTS, LOCALSTORAGE_KEY_TOKEN } from '../const'; import { useGetSessionQuery } from '../services/session'; import { useSelector } from '../store'; import { setAccounts } from '../store/slices/screen'; import { LoginForm } from './LoginForm'; import { Skeleton } from './Skeleton'; export const AccountsPage: React.VFC = () => { const {data} = useGetSessionQuery(undefined); const {t} = useTranslation(); const dispatch = useDispatch(); const {accounts, accountTokens} = useSelector(state => state.screen); const switchAccount = (token: string) => { const newAccounts = accountTokens.filter(a => a !== token); newAccounts.push(localStorage.getItem(LOCALSTORAGE_KEY_TOKEN) ?? ''); localStorage.setItem(LOCALSTORAGE_KEY_ACCOUNTS, JSON.stringify(newAccounts)); localStorage.setItem(LOCALSTORAGE_KEY_TOKEN, token); location.reload(); }; return !data ? (
) : (
{t('_accounts.switchAccount')}
{ accounts.length === accountTokens.length ? ( accounts.map(account => ( )) ) : (
...
) }
); };