import React, { FC, Fragment, useCallback, useEffect } from 'react'; import { ISocialProvider } from '~/redux/auth/types'; import styles from './styles.module.scss'; import { Placeholder } from '~/components/placeholders/Placeholder'; import { Icon } from '~/components/input/Icon'; import { Button } from '~/components/input/Button'; import { Group } from '~/components/containers/Group'; import * as AUTH_ACTIONS from '~/redux/auth/actions'; import { selectAuthProfile } from '~/redux/auth/selectors'; import { IState } from '~/redux/store'; import { connect } from 'react-redux'; import { API } from '~/constants/api'; import { ProfileAccountsError } from '~/components/profile/ProfileAccountsError'; const mapStateToProps = (state: IState) => selectAuthProfile(state).socials; const mapDispatchToProps = { authGetSocials: AUTH_ACTIONS.authGetSocials, authDropSocial: AUTH_ACTIONS.authDropSocial, authAttachSocial: AUTH_ACTIONS.authAttachSocial, authSetSocials: AUTH_ACTIONS.authSetSocials, }; type IProps = ReturnType & typeof mapDispatchToProps & {}; const SOCIAL_ICONS: Record = { vkontakte: 'vk', google: 'google', }; const ProfileAccountsUnconnected: FC = ({ authGetSocials, authDropSocial, authAttachSocial, authSetSocials, accounts, is_loading, error, }) => { const onMessage = useCallback( (event: MessageEvent) => { if (!event?.data?.type) return; switch (event?.data?.type) { case 'oauth_processed': return authAttachSocial(event?.data?.payload?.token); case 'oauth_error': return authSetSocials({ error: event?.data?.payload?.error || '' }); default: return; } }, [authAttachSocial, authSetSocials] ); const openOauthWindow = useCallback( (provider: ISocialProvider) => () => { window.open(API.USER.OAUTH_WINDOW(provider), '', 'width=600,height=400'); }, [] ); const resetErrors = useCallback(() => authSetSocials({ error: '' }), [authSetSocials]); useEffect(() => { authGetSocials(); }, [authGetSocials]); useEffect(() => { window.addEventListener('message', onMessage); return () => window.removeEventListener('message', onMessage); }, [onMessage]); return ( {error && }

Ты можешь входить в Убежище, используя аккаунты на других сайтах вместо ввода логина и пароля.

Мы честно украдём и будем хранить твои имя, фото и адрес на этом сайте, но никому о них не расскажем.

{is_loading && (
{[...new Array(accounts.length || 1)].map((_, i) => ( ))}
)} {!is_loading && accounts.length > 0 && (
{!is_loading && accounts.map(it => (
{it.name || it.id}
authDropSocial(it.provider, it.id)} />
))}
)}
); }; const ProfileAccounts = connect(mapStateToProps, mapDispatchToProps)(ProfileAccountsUnconnected); export { ProfileAccounts };