Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | 2x 2x 2x 2x 6x 8x 1x | /**
* @fileoverview Settings screen component
* @module SettingsScreen
* @description Settings screen, it is the screen that the user will use to change his preferences.
* @requires react react-native
*/
import React from 'react'
import { SafeAreaView, ScrollView, StyleSheet, Switch, Text, View } from 'react-native'
import images from '@global/images'
import { colors } from '@global/colors'
import LoadingModal from '@components/LoadingModal'
import useSettingsScreenController from './useSettingsScreenController'
import TopBar from '../SharedViews/TopBar'
import MainInfos from './Views/MainInfos'
import SettingCategoryDisplay from './Views/SettingCategoryDisplay'
import HelpModal from './Views/HelpModal'
type Props = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
navigation: any
}
type SettingsCategory = {
id: number
title: string
subtitle?: string
onPress?: () => void
icon?: React.ReactNode
childrenIcon?: React.ReactNode
backIconColor?: string
iconColor?: string
}
/**
* @function SettingsScreen
* @description Component that renders the Settings screen.
* @returns {React.JSX.Element} App component template
*/
export default function SettingsScreen({ navigation }: Props): React.JSX.Element {
const {
account,
username,
isHelpModalVisible,
showHelpModal,
hideHelpModal,
goToMail,
isBiometryEnabled,
toggleBiometry,
logoutUser,
aboutApp,
openTerms,
openAccountSettings,
removeAccount,
error,
isLoading,
} = useSettingsScreenController({ navigation })
/**
* @constant MainSettingsCategories
* @description The main settings categories
* @type {SettingsCategory[]} The main settings categories
* @property {number} id The id of the category
* @property {string} title The title of the category
* @property {string} subtitle The subtitle of the category
* @property {() => void} onPress The function that is called when the category is pressed
* @property {React.ReactNode} icon The icon of the category
* @property {React.ReactNode} childrenIcon The icon of the category's children
* @property {string} backIconColor The color of the back icon
* @property {string} iconColor The color of the icon
*/
const MainSettingsCategories: SettingsCategory[] = [
{
id: 1,
title: 'Mon compte',
subtitle: 'Faire des changements sur mon compte',
onPress: openAccountSettings,
icon: images.icons.twoTones.profile(),
},
{
id: 2,
title: 'Biométrie',
subtitle: 'Se connecter avec des données biométriques',
icon: images.icons.twoTones.lock(),
childrenIcon: (
<Switch
trackColor={{ false: colors.veryLightGrey, true: colors.accent }}
thumbColor={colors.white}
ios_backgroundColor={colors.veryLightGrey}
onValueChange={toggleBiometry}
value={!isBiometryEnabled}
/>
),
},
{
id: 3,
title: 'Se déconnecter',
onPress: logoutUser,
backIconColor: colors.veryLightGrey,
iconColor: colors.darkGrey,
icon: images.icons.twoTones.logout(),
},
]
/**
* @constant MoreSettingsCategories
* @description The additional settings categories
* @type {SettingsCategory[]} The main settings categories
* @property {number} id The id of the category
* @property {string} title The title of the category
* @property {string} subtitle The subtitle of the category
* @property {() => void} onPress The function that is called when the category is pressed
* @property {React.ReactNode} icon The icon of the category
* @property {React.ReactNode} childrenIcon The icon of the category's children
* @property {string} backIconColor The color of the back icon
* @property {string} iconColor The color of the icon
*/
const MoreSettingsCategories: SettingsCategory[] = [
{
id: 4,
title: 'Aide et support',
onPress: showHelpModal,
icon: images.icons.twoTones.bell(),
},
{
id: 5,
title: "À propos de l'application",
onPress: aboutApp,
icon: images.icons.twoTones.heart(),
},
{
id: 6,
title: 'CGU',
onPress: openTerms,
icon: images.icons.outline.contract(),
},
{
id: 7,
title: 'Supprimer mon compte',
backIconColor: colors.veryLightGrey,
iconColor: colors.error,
onPress: removeAccount,
icon: images.icons.outline.trash(),
},
]
return (
<SafeAreaView style={styles.container}>
<TopBar
navigation={navigation}
title='Mon profil'
/>
<ScrollView style={styles.scrollview}>
<MainInfos
accountImage={account.image}
email={account.email}
username={username}
/>
<View style={styles.settingsCategoriesContainer}>
{MainSettingsCategories.map(category => (
<SettingCategoryDisplay
key={category.title + category.id}
id={category.id}
title={category.title}
subtitle={category.subtitle}
onPress={category.onPress}
icon={category.icon}
childrenIcon={category.childrenIcon}
backIconColor={category.backIconColor}
iconColor={category.iconColor}
/>
))}
</View>
<Text style={styles.moreText}>Plus</Text>
<View style={styles.settingsCategoriesContainer}>
{MoreSettingsCategories.map(category => (
<SettingCategoryDisplay
key={category.title + category.id}
id={category.id}
title={category.title}
subtitle={category.subtitle}
onPress={category.onPress}
icon={category.icon}
childrenIcon={category.childrenIcon}
backIconColor={category.backIconColor}
iconColor={category.iconColor}
/>
))}
</View>
{error && (
<Text style={{ textAlign: 'right', color: colors.error, marginTop: 4, fontWeight: '700' }}>{error}</Text>
)}
</ScrollView>
<HelpModal
isVisible={isHelpModalVisible}
hideModal={hideHelpModal}
onValidate={goToMail}
/>
<LoadingModal visible={isLoading} />
</SafeAreaView>
)
}
const styles = StyleSheet.create({
container: {
backgroundColor: colors.veryLightGrey,
flex: 1,
paddingHorizontal: '10%',
},
scrollview: {
paddingHorizontal: 16,
},
settingsCategoriesContainer: {
marginTop: 16,
borderRadius: 8,
backgroundColor: colors.white,
},
moreText: {
fontFamily: 'Poppins',
fontSize: 16,
fontWeight: '500',
marginTop: 32,
},
})
|