1
1
import Button from "@material-ui/core/Button"
2
- import { makeStyles } from "@material-ui/core/styles"
2
+ import FormHelperText from "@material-ui/core/FormHelperText"
3
+ import { makeStyles , Theme } from "@material-ui/core/styles"
3
4
import { SvgIconProps } from "@material-ui/core/SvgIcon"
4
5
import Tooltip from "@material-ui/core/Tooltip"
5
6
import GitHub from "@material-ui/icons/GitHub"
@@ -14,14 +15,18 @@ export interface GitAuthProps {
14
15
type : TypesGen . GitProvider
15
16
authenticated : boolean
16
17
authenticateURL : string
18
+ error ?: string
17
19
}
18
20
19
21
export const GitAuth : FC < GitAuthProps > = ( {
20
22
type,
21
23
authenticated,
22
24
authenticateURL,
25
+ error,
23
26
} ) => {
24
- const styles = useStyles ( )
27
+ const styles = useStyles ( {
28
+ error : typeof error !== "undefined" ,
29
+ } )
25
30
26
31
let prettyName : string
27
32
let Icon : ( props : SvgIconProps ) => JSX . Element
@@ -57,41 +62,42 @@ export const GitAuth: FC<GitAuthProps> = ({
57
62
authenticated ? "You're already authenticated! No action needed." : ``
58
63
}
59
64
>
60
- < a
61
- href = { redirectURL }
62
- className = { styles . link }
63
- onClick = { ( event ) => {
64
- event . preventDefault ( )
65
- // If the user is already authenticated, we don't want to redirect them
66
- if ( authenticated || authenticateURL === "" ) {
67
- return
68
- }
69
- window . open ( redirectURL , "_blank" , "width=900,height=600" )
70
- } }
71
- >
72
- < Button className = { styles . button } disabled = { authenticated } fullWidth >
73
- < div className = { styles . root } >
74
- < Icon className = { styles . icon } / >
75
- < div className = { styles . text } >
65
+ < div >
66
+ < a
67
+ href = { redirectURL }
68
+ className = { styles . link }
69
+ onClick = { ( event ) => {
70
+ event . preventDefault ( )
71
+ // If the user is already authenticated, we don't want to redirect them
72
+ if ( authenticated || authenticateURL === "" ) {
73
+ return
74
+ }
75
+ window . open ( redirectURL , "_blank" , "width=900,height=600" )
76
+ } }
77
+ >
78
+ < Button className = { styles . button } disabled = { authenticated } fullWidth >
79
+ < div className = { styles . root } >
80
+ < Icon className = { styles . icon } / >
76
81
< Typography variant = "body2" >
77
82
{ authenticated
78
83
? `You're authenticated with ${ prettyName } !`
79
84
: `Click to login with ${ prettyName } !` }
80
85
</ Typography >
81
- { ! authenticated && (
82
- < Typography variant = "caption" color = "textSecondary" >
83
- { "You'll be redirected back here once authenticated." }
84
- </ Typography >
85
- ) }
86
86
</ div >
87
- </ div >
88
- </ Button >
89
- </ a >
87
+ </ Button >
88
+ </ a >
89
+ { error && < FormHelperText error > { error } </ FormHelperText > }
90
+ </ div >
90
91
</ Tooltip >
91
92
)
92
93
}
93
94
94
- const useStyles = makeStyles ( ( ) => ( {
95
+ const useStyles = makeStyles <
96
+ Theme ,
97
+ {
98
+ error : boolean
99
+ }
100
+ > ( ( theme ) => ( {
95
101
link : {
96
102
textDecoration : "none" ,
97
103
} ,
@@ -104,11 +110,8 @@ const useStyles = makeStyles(() => ({
104
110
} ,
105
111
button : {
106
112
height : "unset" ,
107
- } ,
108
- text : {
109
- display : "flex" ,
110
- flexDirection : "column" ,
111
- gap : 4 ,
113
+ border : ( { error } ) =>
114
+ error ? `1px solid ${ theme . palette . error . main } ` : "unset" ,
112
115
} ,
113
116
icon : {
114
117
width : 32 ,
0 commit comments