All files / src/screens/authentificationSection/connection ConnectionScreen.tsx

75% Statements 3/4
50% Branches 1/2
50% Functions 1/2
75% Lines 3/4

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                                                                                4x   4x                                                                                                             1x                                                                                                                              
/**
 * @fileoverview Connection screen component
 * @module ConnectionScreen
 * @description Connection screen, it is the first screen that the user sees when opening the app.
 * @requires react react-native
 */
 
import React from 'react'
import { SafeAreaView, StyleSheet, Text, View, Image, TouchableOpacity } from 'react-native'
import images from '@global/images'
import { ConnectionScreenProps } from '@global/types/screensProps/AuthStackParams'
import { colors } from '@global/colors'
import Button from '@components/Button'
import LoadingModal from '@components/LoadingModal'
import OrSeparator from '../sharedViews/OrSeparator'
import SocialButtons from '../sharedViews/SocialButtons'
import ButtonChangeScreen from '../sharedViews/ButtonChangeScreen'
import Input from '../sharedViews/TextInput'
import HeaderTexts from './Views/HeaderTexts'
import useConnectionController from './useConnectionController'
 
/**
 * @function ConnectionScreen
 * @description Component that renders the connection screen.
 * @param {ConnectionScreenProps} props ConnectionScreen props
 * @param props.navigation Navigation props
 * @returns {React.JSX.Element} App component template
 */
export default function ConnectionScreen({ navigation }: ConnectionScreenProps): React.JSX.Element {
  const {
    email,
    setEmail,
    password,
    setPassword,
    showPassword,
    setShowPassword,
    connect,
    forgottenPassword,
    error,
    isLoading,
  } = useConnectionController({ navigation })
 
  return (
    <SafeAreaView style={styles.container}>
      <Image
        style={styles.logo}
        source={images.logos.nolosay()}
      />
      <View style={styles.connection}>
        <HeaderTexts />
        <View style={styles.inputContainer}>
          <View style={styles.textInputsContainer}>
            <Input
              placeholder="Email ou nom d'utilisateur"
              keyboardType='email-address'
              value={email}
              setValue={setEmail}
              leftIcon={images.icons.full.user()}
              returnKeyType='next'
            />
            <Input
              placeholder='Mot de passe'
              secureTextEntry={!showPassword}
              setSecureTextEntry={setShowPassword}
              value={password}
              setValue={setPassword}
              leftIcon={images.icons.full.shield()}
              rightIcon={images.icons.full.eye()}
              returnKeyType='done'
            />
            {error && <Text style={styles.errorText}>{error}</Text>}
            <TouchableOpacity
              onPress={forgottenPassword}
              style={styles.forgotPassword}
            >
              <Text style={styles.forgotPasswordText}>Un trou de mémoire ?</Text>
            </TouchableOpacity>
          </View>
          <OrSeparator />
          <SocialButtons />
        </View>
        <Button
          text='Se connecter'
          onPress={connect}
          style={styles.connectionButton}
        />
        <ButtonChangeScreen
          infoText='Pas de compte ?'
          clickableText="S'inscrire"
          onPress={() => navigation.navigate('Subscription')}
        />
      </View>
      <LoadingModal visible={isLoading} />
    </SafeAreaView>
  )
}
 
const styles = StyleSheet.create({
  logo: {
    flex: 1,
    width: 200,
    resizeMode: 'contain',
    alignSelf: 'center',
  },
  connection: {
    flex: 10,
    justifyContent: 'center',
    alignItems: 'center',
  },
  input: {
    borderRadius: 12,
    backgroundColor: colors.darkGrey,
    paddingHorizontal: 12,
    paddingVertical: 20,
    fontSize: 12,
    color: colors.lightGrey,
    fontFamily: 'Poppins-Medium',
    width: '100%',
  },
  socialButton: {
    width: 36,
    height: 36,
    borderRadius: 4,
    justifyContent: 'center',
    alignItems: 'center',
  },
  container: {
    backgroundColor: colors.white,
    flex: 1,
  },
  inputContainer: {
    flexDirection: 'column',
    paddingVertical: 24,
  },
  textInputsContainer: {
    marginBottom: 12,
  },
  errorText: {
    color: colors.error,
    fontFamily: 'Poppins-Medium',
    alignSelf: 'flex-end',
    paddingRight: '16%',
    fontSize: 12,
  },
  forgotPassword: {
    alignSelf: 'flex-end',
    marginHorizontal: 52,
    marginTop: 8,
  },
  forgotPasswordText: {
    color: colors.accent,
    fontFamily: 'Poppins',
    textDecorationLine: 'underline',
    fontWeight: '600',
  },
  connectionButton: {
    marginVertical: 12,
    marginHorizontal: 48,
  },
})