623 Use translation library in password section

This commit is contained in:
Lisa Hillebrand
2022-10-23 11:27:20 +02:00
parent edc6f350c5
commit 1d5737d8a9
4 changed files with 58 additions and 45 deletions
+44 -30
View File
@@ -10,26 +10,31 @@ import Header from './header'
import { saveEncryptionFlag } from '../local-storage' import { saveEncryptionFlag } from '../local-storage'
import { deleteDbAndOpenNew, openDb } from '../db' import { deleteDbAndOpenNew, openDb } from '../db'
import { passwordPrompt as labels, shared } from '../i18n/en/labels'
import { Containers, Spacing } from '../styles' import { Containers, Spacing } from '../styles'
import { useTranslation } from 'react-i18next'
const cancelButton = { text: shared.cancel, style: 'cancel' }
const PasswordPrompt = ({ enableShowApp }) => { const PasswordPrompt = ({ enableShowApp }) => {
const [password, setPassword] = useState(null) const [password, setPassword] = useState(null)
const isPasswordEntered = Boolean(password)
const { t } = useTranslation()
const cancelButton = { text: t('common:cancel'), style: 'cancel' }
const unlockApp = async () => { const unlockApp = async () => {
const hash = new SHA512().hex(password) const hash = new SHA512().hex(password)
const connected = await openDb(hash) const connected = await openDb(hash)
if (!connected) { if (!connected) {
Alert.alert(shared.incorrectPassword, shared.incorrectPasswordMessage, [ Alert.alert(
{ t('common:incorrectPassword'),
text: shared.tryAgain, t('common:incorrectPasswordMessage'),
onPress: () => setPassword(null), [
}, {
]) text: t('common:tryAgain'),
onPress: () => setPassword(null),
},
]
)
return return
} }
enableShowApp() enableShowApp()
@@ -42,20 +47,31 @@ const PasswordPrompt = ({ enableShowApp }) => {
} }
const onDeleteData = () => { const onDeleteData = () => {
Alert.alert(labels.areYouSureTitle, labels.areYouSure, [ Alert.alert(
cancelButton, t('password.confirmationDialog.title'),
{ t('password.confirmationDialog.text'),
text: labels.reallyDeleteData, [
onPress: onDeleteDataConfirmation, cancelButton,
}, {
]) text: t('password.confirmationDialog.confirm'),
onPress: onDeleteDataConfirmation,
},
]
)
} }
const onConfirmDeletion = async () => { const onConfirmDeletion = async () => {
Alert.alert(labels.deleteDatabaseTitle, labels.deleteDatabaseExplainer, [ Alert.alert(
cancelButton, t('password.forgotPassword'),
{ text: labels.deleteData, onPress: onDeleteData }, t('password.forgotPasswordDialog.text'),
]) [
cancelButton,
{
text: t('password.forgotPasswordDialog.confirm'),
onPress: onDeleteData,
},
]
)
} }
return ( return (
@@ -65,17 +81,15 @@ const PasswordPrompt = ({ enableShowApp }) => {
<KeyboardAvoidingView behavior="padding" keyboardVerticalOffset={150}> <KeyboardAvoidingView behavior="padding" keyboardVerticalOffset={150}>
<AppTextInput <AppTextInput
onChangeText={setPassword} onChangeText={setPassword}
secureTextEntry={true} secureTextEntry
placeholder={labels.enterPassword} placeholder={t('password.enterPassword')}
/> />
<View style={styles.containerButtons}> <View style={styles.containerButtons}>
<Button onPress={onConfirmDeletion}>{labels.forgotPassword}</Button> <Button onPress={onConfirmDeletion}>
<Button {t('password.forgotPassword')}
disabled={!isPasswordEntered} </Button>
isCTA={isPasswordEntered} <Button disabled={!password} isCTA={!!password} onPress={unlockApp}>
onPress={unlockApp} {t('password.unlockApp')}
>
{labels.title}
</Button> </Button>
</View> </View>
</KeyboardAvoidingView> </KeyboardAvoidingView>
-1
View File
@@ -1 +0,0 @@
{}
+14
View File
@@ -132,6 +132,20 @@
"title": "Settings" "title": "Settings"
} }
}, },
"password": {
"confirmationDialog": {
"confirm": "Yes, I am sure",
"text": "Are you absolutely sure you want to permanently delete all your data?",
"title": "Are you sure?"
},
"enterPassword": "Enter password here",
"forgotPassword": "Forgot your password?",
"forgotPasswordDialog": {
"confirm": "Yes, delete all my data",
"text": "If you've forgotten your password, unfortunately, there is nothing we can do to recover your data, because it is encrypted with the password only you know. You can, however, delete all your encrypted data and start fresh. Once all data has been erased, you can set a new password in the settings, if you like."
},
"unlockApp": "Unlock app"
},
"stats": { "stats": {
"noData": "At least one completed cycle is needed to display stats.", "noData": "At least one completed cycle is needed to display stats.",
"intro": "Basic statistics about the length of your cycles.", "intro": "Basic statistics about the length of your cycles.",
-14
View File
@@ -38,20 +38,6 @@ export const bleedingPrediction = {
`Based on your documented data, your period was likely to start between ${startDate} and ${endDate}.`, `Based on your documented data, your period was likely to start between ${startDate} and ${endDate}.`,
} }
export const passwordPrompt = {
title: 'Unlock app',
enterPassword: 'Enter password here',
deleteDatabaseExplainer:
"If you've forgotten your password, unfortunately, there is nothing we can do to recover your data, because it is encrypted with the password only you know. You can, however, delete all your encrypted data and start fresh. Once all data has been erased, you can set a new password in the settings, if you like.",
forgotPassword: 'Forgot your password?',
deleteDatabaseTitle: 'Forgot your password?',
deleteData: 'Yes, delete all my data',
areYouSureTitle: 'Are you sure?',
areYouSure:
'Are you absolutely sure you want to permanently delete all your data?',
reallyDeleteData: 'Yes, I am sure',
}
export const fertilityStatus = { export const fertilityStatus = {
fertile: 'fertile', fertile: 'fertile',
infertile: 'infertile', infertile: 'infertile',