# All files / atlas/src/components/Auth/Registration RegisterMeasurements.js

10.53% Statements 2/19
0% Branches 0/18
0% Functions 0/10
10.53% Lines 2/19

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

    3x

    3x

     import React from 'react';
    import { Controller, useForm } from 'react-hook-form';
    import { Dimensions, StyleSheet, TextInput, TouchableOpacity, View } from 'react-native';
    import 'react-native-get-random-values';
    import { RadioButton, Text } from 'react-native-paper';
    import 'react-native-vector-icons';
    import { useRegistrationFormState } from '../../../contexts/RegisterContext';

    const RegisterMeasurements = ({changeStep}) => {
      const { dispatch, state: { height, weight, sagitta, isSubmitLoading } } = useRegistrationFormState();
      const { control, handleSubmit, formState: {errors} } = useForm({
        mode: 'all'
      });

      const goBack = (formData) => {
        changeStep(2, "Next, we'll have you set a password.")
      }

      const toggleSagitta = (value) => {
        dispatch({ type: "SAGITTA_CHANGE", payload: value })
      }

      const next = async (formData) => {
        dispatch({ type: "HEIGHT_CHANGE", payload: formData.height })
        dispatch({ type: "WEIGHT_CHANGE", payload: formData.weight })
        changeStep(4, "Lastly, pick a photo you'd like everyone to get to know you by.")
      }

      return (
          <View>
            <View style={styles.sagittaCheck}>
              <RadioButton uncheckedColor="white" color="#df3f3f" status={sagitta ? 'unchecked' : 'checked'} onPress={() => {toggleSagitta(false)}} />
              <Text style={styles.radioLabel}>No</Text>
              <RadioButton uncheckedColor="white" color="#df3f3f" status={sagitta ? 'checked' : 'unchecked'} onPress={() => {toggleSagitta(true)}} />
              <Text style={styles.radioLabel} >Yes</Text>
            </View>
          { sagitta ?
          <View style={{margin: 20}}>
            <Text style={{color: 'white', marginBottom: 20, fontSize: 15}} >We'll also need some body measurements.</Text>
            <Controller
              defaultValue={height}
              control={control}
              render={({ field: { onChange, value }}) => (
                <TextInput
                  mode="outlined"
                  style={[styles.textInput, errors.height && styles.errorInput]}
                  placeholder="Height"
                  value={value}
                  onChangeText={value => onChange(value)}
                ></TextInput>
              )}
              name="height"
              rules={{
                required: true,
                pattern:
                {
                  value: /^[0-9]*$/i
                }}}
              />
            {errors.height?.type === "required" && <Text style={styles.errorText}>Height is required.</Text>}
            {errors.height?.type === "pattern" && <Text style={styles.errorText}>Must be a number.</Text>}
            <Controller
              defaultValue={weight}
              control={control}
              render={({ field: { onChange, value }}) => (
                <TextInput
                  mode="outlined"
                  style={[styles.textInput, errors.weight && styles.errorInput]}
                  placeholder="Weight"
                  value={value}
                  onChangeText={value => onChange(value)} />
            )}
            rules={{
              required: true,
              pattern:
              {
                value: /^[0-9]*$/i
              }}}
            name="weight"/>
            {errors.weight?.type === "required" && <Text style={styles.errorText}>Weight is required.</Text>}
            {errors.weight?.type === "pattern" && <Text style={styles.errorText}>Must be a number.</Text>}
          </View> : null }
          <TouchableOpacity onPress={handleSubmit(next)} style={styles.nextBtn} >
              <Text style={{ color: 'white', fontSize: 20 }}>Next</Text>
          </TouchableOpacity>
          <TouchableOpacity onPress={goBack} style={styles.backBtn} >
              <Text style={{ color: 'white', fontSize: 20 }}>Back</Text>
          </TouchableOpacity>
          </View>
      )
    }

    const styles = StyleSheet.create({
      container: {
        backgroundColor: 'transparent',

        position: 'absolute',
        width: Dimensions.get('window').width,
        height: Dimensions.get('window').height,
        flex: 1,
        flexDirection: 'column',
        resizeMode: 'cover',
      },

      brandContainer: {
        marginTop: 70,
        height: 120,
        marginLeft: 25,
        flexDirection: 'column',
        justifyContent: 'space-evenly'
      },

      title: {

        color: 'white',
        fontSize: 20
      },

      sagittaCheck: {
        flexDirection: 'row',
        margin: 20
      },

      radioLabel: {
        marginTop: 7, marginRight: 20, color: 'white'
      },

      subtitle: {

          color: 'white',
          fontSize: 15,
          marginHorizontal: 20,
          marginTop: 20
      },

      textContainer: {
        marginHorizontal: 20,
        marginBottom: 30,
        borderRadius: 50,
      },

      textInput: {
        marginVertical: 7,
        paddingLeft: 30,
        borderRadius: 50,
        overflow: 'hidden',
        backgroundColor: 'white',
        height: 50
      },

      errorText: {
        alignSelf: 'flex-end',
        color: 'red',
        fontSize: 15
      },

      errorInput: {
        borderWidth: 2,
        borderColor: 'red'
      },

      nextBtn: {
        marginHorizontal: 20,

        borderRadius: 50,
        justifyContent: 'center',
        backgroundColor: '#df3f3f',
        margin: 5,
        height: 50,
        alignItems: 'center'
      },

      backBtn: {
        marginHorizontal: 20,
        marginBottom: 10,
        borderRadius: 50,
        borderColor: 'white',
        borderWidth: 2,
        justifyContent: 'center',
        backgroundColor: 'transparent',
        margin: 5,
        height: 50,
        alignItems: 'center'
      },
    })

    export default RegisterMeasurements;