All files / src/screens/authentificationSection/subscription SubscriptionScreen.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                                                                                      1x   1x                                                                                                                                       1x                                                                                        
/**
 * @fileoverview Subscription screen component
 * @module SubscriptionScreen
 * @description Subscription screen, it is the first screen that the user sees when opening the app.
 * @requires react react-native
 */
 
import React from 'react'
import { SafeAreaView, View, Image, StyleSheet, Text } from 'react-native'
import { SubscriptionScreenProps } from '@global/types/screensProps/AuthStackParams'
import images from '@global/images'
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 HeaderTexts from './Views/HeaderTexts'
import useSubscriptionController from './useSubscriptionController'
import Input from '../sharedViews/TextInput'
 
/**
 * @function SubscriptionScreen
 * @description Component that renders the Subscription screen.
 * @returns {React.JSX.Element} App component template
 */
export default function SubscriptionScreen({ navigation }: SubscriptionScreenProps): React.JSX.Element {
  const {
    email,
    setEmail,
    username,
    setUsername,
    password,
    setPassword,
    passwordConfirmation,
    setPasswordConfirmation,
    showPassword,
    setShowPassword,
    showPasswordConfirmation,
    setShowPasswordConfirmation,
    subscribe,
    error,
    isLoading,
  } = useSubscriptionController({ navigation })
 
  return (
    <SafeAreaView
      style={{
        backgroundColor: colors.white,
        flex: 1,
      }}
    >
      <Image
        style={styles.logo}
        source={images.logos.nolosay()}
      />
      <View style={styles.connection}>
        <HeaderTexts />
        <View style={styles.inputContainer}>
          <View style={styles.textInputsContainer}>
            <Input
              placeholder='Email'
              keyboardType='email-address'
              value={email}
              setValue={setEmail}
              leftIcon={images.icons.full.username()}
            />
            <Input
              placeholder="Nom d'utilisateur"
              keyboardType='email-address'
              value={username}
              setValue={setUsername}
              leftIcon={images.icons.full.user()}
            />
            <Input
              placeholder='Mot de passe'
              secureTextEntry={!showPassword}
              setSecureTextEntry={setShowPassword}
              value={password}
              setValue={setPassword}
              leftIcon={images.icons.full.shield()}
              rightIcon={images.icons.full.eye()}
            />
            <Input
              placeholder='Confirmation'
              secureTextEntry={!showPasswordConfirmation}
              setSecureTextEntry={setShowPasswordConfirmation}
              value={passwordConfirmation}
              setValue={setPasswordConfirmation}
              leftIcon={images.icons.full.shield()}
              rightIcon={images.icons.full.eye()}
            />
            {error && <Text style={styles.errorText}>{error}</Text>}
          </View>
          <OrSeparator />
          <SocialButtons />
        </View>
        <Button
          text="S'inscrire"
          onPress={subscribe}
          style={{ marginVertical: 12, marginHorizontal: 48 }}
        />
        <ButtonChangeScreen
          infoText='Déjà un compte ?'
          clickableText='Se connecter'
          onPress={() => navigation.navigate('Connection')}
        />
      </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',
  },
  errorText: {
    color: colors.error,
    fontFamily: 'Poppins-Medium',
    alignSelf: 'flex-end',
    paddingRight: '16%',
    fontSize: 12,
  },
  inputContainer: {
    flexDirection: 'column',
    paddingVertical: 24,
  },
  textInputsContainer: {
    marginBottom: 12,
  },
})