11import React , { useState } from 'react'
2- import Modal from 'react-modal'
32import AppButton from '../../components/AppButton'
3+ import withModal from '../../components/withModal'
44
5- interface Props {
5+ interface LoginFormProps {
66 onLogin : ( oidcIssuer : string ) => void
77}
88
9- const LoginPrompt : React . FC < Props > = ( { onLogin, ...props } : Props ) => {
10- const [ promptOpen , setPromptOpen ] = useState ( false )
9+ const LoginButton = ( { ...props } ) => < AppButton { ...props } > Login</ AppButton >
10+
11+ const LoginForm = ( { onLogin } : LoginFormProps ) => {
1112 const [ idp , setIdp ] = useState (
1213 localStorage . getItem ( 'idp' ) ?? 'https://solidcommunity.net' ,
1314 )
@@ -23,80 +24,33 @@ const LoginPrompt: React.FC<Props> = ({ onLogin, ...props }: Props) => {
2324 const newValue = e . currentTarget . value
2425 setIdp ( newValue )
2526 }
26-
27- if ( ! promptOpen ) {
28- return (
29- < >
30- < AppButton
31- { ...props }
32- onClick = { e => {
33- e . preventDefault ( )
34- setPromptOpen ( true )
35- } }
36- >
37- Login
38- </ AppButton >
39- </ >
40- )
41- }
42-
4327 return (
44- < >
45- < Modal
46- isOpen = { promptOpen }
47- onRequestClose = { ( ) => setPromptOpen ( false ) }
48- contentLabel = "Connect your Solid Pod"
49- overlayClassName = { {
50- base : 'modal modal-background is-active' ,
51- afterOpen : '' ,
52- beforeClose : '' ,
53- } }
54- className = { {
55- base : 'modal-content' ,
56- afterOpen : '' ,
57- beforeClose : '' ,
58- } }
59- closeTimeoutMS = { 50 }
60- >
61- < button className = "modal-close" onClick = { ( ) => setPromptOpen ( false ) } >
62- close
63- </ button >
64-
65- < div className = "card" >
66- < header className = "card-header" >
67- < p className = "card-header-title" >
68- Select your Solid identity provider
69- </ p >
70- </ header >
71- < div className = "card-content" >
72- < form onSubmit = { onSubmit } >
73- < div className = "field" >
74- < div className = "control" >
75- < input
76- id = "idp"
77- className = "input"
78- type = "url"
79- value = { idp }
80- onChange = { onChangeInput }
81- placeholder = "Where is your Solid Pod?"
82- />
83- </ div >
84- </ div >
85- < div className = "field" >
86- < div className = "control" >
87- < input
88- type = "submit"
89- value = "Connect"
90- className = "button is-link"
91- />
92- </ div >
93- </ div >
94- </ form >
95- </ div >
28+ < form onSubmit = { onSubmit } >
29+ < div className = "field" >
30+ < div className = "control" >
31+ < input
32+ id = "idp"
33+ className = "input"
34+ type = "url"
35+ value = { idp }
36+ onChange = { onChangeInput }
37+ placeholder = "Where is your Solid Pod?"
38+ />
39+ </ div >
40+ </ div >
41+ < div className = "field" >
42+ < div className = "control" >
43+ < input type = "submit" value = "Connect" className = "button is-link" />
9644 </ div >
97- </ Modal >
98- </ >
45+ </ div >
46+ </ form >
9947 )
10048}
10149
50+ const LoginPrompt = withModal (
51+ LoginButton ,
52+ LoginForm ,
53+ 'Select your Solid identity provider' ,
54+ )
55+
10256export default LoginPrompt
0 commit comments