@@ -2,11 +2,12 @@ import PropTypes from 'prop-types';
22import React from 'react' ;
33import styled from 'styled-components' ;
44import { withTranslation } from 'react-i18next' ;
5+ import { useDispatch } from 'react-redux' ;
56
67import { remSize } from '../../../theme' ;
7-
88import { GithubIcon , GoogleIcon } from '../../../common/icons' ;
99import Button from '../../../common/Button' ;
10+ import { unlinkService } from '../actions' ;
1011
1112const authUrls = {
1213 github : '/auth/github' ,
@@ -16,11 +17,11 @@ const authUrls = {
1617const linkLabels = {
1718 github : {
1819 connect : 'Connect GitHub Account' ,
19- connected : 'Re-link GitHub Account'
20+ unlink : 'Unlink GitHub Account'
2021 } ,
2122 google : {
2223 connect : 'Connect Google Account' ,
23- connected : 'Re-link Google Account'
24+ unlink : 'Unlink Google Account'
2425 }
2526} ;
2627
@@ -46,18 +47,33 @@ function SocialAuthButton({
4647 github : t ( 'SocialAuthButton.Github' ) ,
4748 google : t ( 'SocialAuthButton.Google' )
4849 } ;
49- let label ;
50+ const dispatch = useDispatch ( ) ;
5051 if ( linkStyle ) {
51- label = isConnected ? linkLabels [ service ] . connected : linkLabels [ service ] . connect ;
52- } else {
53- label = labels [ service ] ;
52+ if ( isConnected ) {
53+ return (
54+ < StyledButton
55+ iconBefore = { < ServiceIcon aria-label = { t ( 'SocialAuthButton.LogoARIA' , { serviceauth : service } ) } /> }
56+ onClick = { ( ) => { dispatch ( unlinkService ( service ) ) ; } }
57+ >
58+ { linkLabels [ service ] . unlink }
59+ </ StyledButton >
60+ ) ;
61+ }
62+ return (
63+ < StyledButton
64+ iconBefore = { < ServiceIcon aria-label = { t ( 'SocialAuthButton.LogoARIA' , { serviceauth : service } ) } /> }
65+ href = { authUrls [ service ] }
66+ >
67+ { linkLabels [ service ] . connect }
68+ </ StyledButton >
69+ ) ;
5470 }
5571 return (
5672 < StyledButton
5773 iconBefore = { < ServiceIcon aria-label = { t ( 'SocialAuthButton.LogoARIA' , { serviceauth : service } ) } /> }
5874 href = { authUrls [ service ] }
5975 >
60- { label }
76+ { labels [ service ] }
6177 </ StyledButton >
6278 ) ;
6379}
0 commit comments