1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

listening for backend events

This commit is contained in:
Fedor Katurov 2020-07-27 17:35:59 +07:00
parent 2466f01b0b
commit 3ae22fb63d
3 changed files with 24 additions and 8 deletions

View file

@ -15,6 +15,8 @@ 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 mapStateToProps> & typeof mapDispatchToProps & {};
@ -27,21 +29,29 @@ const SOCIAL_ICONS: Record<ISocialProvider, string> = {
const ProfileAccountsUnconnected: FC<IProps> = ({
authGetSocials,
authDropSocial,
authAttachSocial,
authSetSocials,
accounts,
is_loading,
}) => {
const onMessage = useCallback(event => {
// TODO: handle errors
if (event?.data?.type !== 'oauth_attach' || !event?.data?.payload?.token) return;
const onMessage = useCallback(
(event: MessageEvent) => {
if (!event?.data?.type) return;
const token = event?.data?.payload?.token;
console.log('GOT TOKEN!!!', token);
}, []);
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) => () => {
console.log(API.USER.OAUTH_WINDOW(provider));
window.open(API.USER.OAUTH_WINDOW(provider), '', 'width=600,height=400');
},
[]