-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Desktop, Mobile: Add Joplin Cloud account information to configuratio…
…n screen (#10553)
- Loading branch information
Showing
10 changed files
with
173 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/app-mobile/components/screens/ConfigScreen/JoplinCloudConfig.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { _ } from '@joplin/lib/locale'; | ||
import * as React from 'react'; | ||
import { useCallback } from 'react'; | ||
import { View, Text, Linking } from 'react-native'; | ||
import Clipboard from '@react-native-clipboard/clipboard'; | ||
import SettingsButton from './SettingsButton'; | ||
import { accountTypeToString } from '@joplin/lib/utils/joplinCloud/types'; | ||
import { LinkButton } from '../../buttons'; | ||
import { ConfigScreenStyles } from './configScreenStyles'; | ||
import { Divider } from 'react-native-paper'; | ||
import Logger from '@joplin/utils/Logger'; | ||
|
||
const logger = Logger.create('JoplinCloudConfig'); | ||
|
||
type JoplinCloudConfigProps = { | ||
styles: ConfigScreenStyles; | ||
accountType: string; | ||
inboxEmail: string; | ||
website: string; | ||
userEmail: string; | ||
}; | ||
|
||
export const emailToNoteLabel = () => _('Email to note'); | ||
export const emailToNoteDescription = () => _('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'); | ||
|
||
const JoplinCloudConfig = (props: JoplinCloudConfigProps) => { | ||
|
||
const isEmailToNoteAvailableInAccount = props.accountType !== '1'; | ||
const inboxEmailValue = props.inboxEmail ?? '-'; | ||
|
||
const goToJoplinCloudProfile = useCallback(async () => { | ||
await Linking.openURL(`${props.website}/users/me`); | ||
}, [props.website]); | ||
|
||
const accountTypeName = () => { | ||
try { | ||
if (!props.accountType) return 'Unknown'; | ||
return accountTypeToString(parseInt(props.accountType, 10)); | ||
} catch (error) { | ||
logger.error(error); | ||
return 'Unknown'; | ||
} | ||
}; | ||
|
||
return ( | ||
<View> | ||
<View style={props.styles.styleSheet.settingContainerNoBottomBorder}> | ||
<Text style={props.styles.styleSheet.settingTextEmphasis}>{_('Account information')}</Text> | ||
</View> | ||
<View style={props.styles.styleSheet.settingContainerNoBottomBorder}> | ||
<Text style={props.styles.styleSheet.settingText}>{_('Account type')}</Text> | ||
<Text style={props.styles.styleSheet.settingTextEmphasis}>{accountTypeName()}</Text> | ||
</View> | ||
<View style={props.styles.styleSheet.settingContainerNoBottomBorder}> | ||
<Text style={props.styles.styleSheet.settingText}>{_('Email')}</Text> | ||
<Text selectable style={props.styles.styleSheet.settingTextEmphasis}>{props.userEmail}</Text> | ||
</View> | ||
<LinkButton onPress={goToJoplinCloudProfile}> | ||
{_('Go to Joplin Cloud profile')} | ||
</LinkButton> | ||
<Divider bold /> | ||
|
||
<View style={props.styles.styleSheet.settingContainerNoBottomBorder}> | ||
<Text style={props.styles.styleSheet.settingText}>{emailToNoteLabel()}</Text> | ||
<Text style={props.styles.styleSheet.settingTextEmphasis}>{inboxEmailValue}</Text> | ||
</View> | ||
{ | ||
!isEmailToNoteAvailableInAccount && ( | ||
<View style={props.styles.styleSheet.settingContainerNoBottomBorder}> | ||
<Text style={props.styles.styleSheet.descriptionAlert}>{_('Your account doesn\'t have access to this feature')}</Text> | ||
</View> | ||
) | ||
} | ||
<SettingsButton | ||
title={_('Copy to clipboard')} | ||
clickHandler={() => isEmailToNoteAvailableInAccount && Clipboard.setString(props.inboxEmail)} | ||
description={emailToNoteDescription()} | ||
statusComponent={undefined} | ||
styles={props.styles} | ||
disabled={!isEmailToNoteAvailableInAccount} | ||
/> | ||
</View> | ||
); | ||
|
||
}; | ||
|
||
export default JoplinCloudConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/lib/utils/joplinCloud.ts → packages/lib/utils/joplinCloud/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
enum AccountType { | ||
Default = 0, | ||
Basic = 1, | ||
Pro = 2, | ||
Team = 3, | ||
} | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function accountTypeToString(accountType: AccountType): string { | ||
if (accountType === AccountType.Default) return 'Default'; | ||
if (accountType === AccountType.Basic) return 'Basic'; | ||
if (accountType === AccountType.Pro) return 'Pro'; | ||
if (accountType === AccountType.Team) return 'Team'; | ||
const exhaustivenessCheck: never = accountType; | ||
throw new Error(`Invalid type: ${exhaustivenessCheck}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters