2023-07-18 21:15:45 +02:00
const { connect } = require ( 'react-redux' ) ;
import { AppState } from '../app.reducer' ;
import { _ } from '@joplin/lib/locale' ;
import { clipboard } from 'electron' ;
import Button from './Button/Button' ;
2024-04-18 15:29:49 +02:00
import { Fragment } from 'react' ;
2024-06-12 16:14:32 +02:00
import { accountTypeToString } from '@joplin/lib/utils/joplinCloud/types' ;
import bridge from '../services/bridge' ;
2023-07-18 21:15:45 +02:00
type JoplinCloudConfigScreenProps = {
inboxEmail : string ;
2024-04-18 15:29:49 +02:00
joplinCloudAccountType : number ;
2024-06-12 16:14:32 +02:00
userEmail : string ;
joplinCloudWebsite : string ;
2023-07-18 21:15:45 +02:00
} ;
const JoplinCloudConfigScreen = ( props : JoplinCloudConfigScreenProps ) = > {
const copyToClipboard = ( ) = > {
clipboard . writeText ( props . inboxEmail ) ;
} ;
2024-04-18 15:29:49 +02:00
const isEmailToNoteAvailableInAccount = props . joplinCloudAccountType !== 1 ;
2024-06-12 16:14:32 +02:00
const goToJoplinCloudProfile = async ( ) = > {
await bridge ( ) . openExternal ( ` ${ props . joplinCloudWebsite } /users/me ` ) ;
} ;
2023-07-18 21:15:45 +02:00
return (
< div >
2024-06-12 16:14:32 +02:00
< div className = "joplin-cloud-account-information" >
< h2 > { _ ( 'Account information' ) } < / h2 >
< table >
< tbody >
< tr >
< td > < strong > { _ ( 'Account type' ) } < / strong > < / td >
< td > { accountTypeToString ( props . joplinCloudAccountType ) } < / td >
< / tr >
< tr >
< td > < strong > { _ ( 'Email' ) } < / strong > < / td >
< td > { props . userEmail } < / td >
< / tr >
< / tbody >
< / table >
< Button onClick = { goToJoplinCloudProfile } title = { _ ( 'Go to Joplin Cloud profile' ) } / >
< / div >
2023-07-18 21:15:45 +02:00
< h2 > { _ ( 'Email to note' ) } < / h2 >
< p > { _ ( 'Any email sent to this address will be converted into a note and added to your collection. The note will be saved into the Inbox notebook' ) } < / p >
2024-04-18 15:29:49 +02:00
{
isEmailToNoteAvailableInAccount ? < Fragment >
< p className = 'inbox-email-value' > { props . inboxEmail } < / p >
< Button onClick = { copyToClipboard } title = { _ ( 'Copy to clipboard' ) } / >
< / Fragment >
: < div className = 'alert-warn' >
< p > { _ ( 'Your account doesn\'t have access to this feature' ) } < / p >
< / div >
}
2023-07-18 21:15:45 +02:00
< / div >
) ;
} ;
const mapStateToProps = ( state : AppState ) = > {
return {
2023-07-23 16:57:55 +02:00
inboxEmail : state.settings [ 'sync.10.inboxEmail' ] ,
2024-04-18 15:29:49 +02:00
joplinCloudAccountType : state.settings [ 'sync.10.accountType' ] ,
2024-06-12 16:14:32 +02:00
userEmail : state.settings [ 'sync.10.userEmail' ] ,
joplinCloudWebsite : state.settings [ 'sync.10.website' ] ,
2023-07-18 21:15:45 +02:00
} ;
} ;
export default connect ( mapStateToProps ) ( JoplinCloudConfigScreen ) ;