RegisterMeasurements.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import React from 'react';
  2. import { TextInput, StyleSheet, View, TouchableOpacity , Dimensions, Alert, ImageBackground, } from 'react-native';
  3. import { RadioButton, Text, ActivityIndicator } from 'react-native-paper';
  4. import 'react-native-vector-icons';
  5. import 'react-native-get-random-values';
  6. import { Controller, useForm } from 'react-hook-form';
  7. import { useRegistrationFormState } from '../contexts/RegisterContext';
  8. const RegisterMeasurements = ({navigation}) => {
  9. const { dispatch, state: { height, weight, sagitta, isSubmitLoading } } = useRegistrationFormState();
  10. const { control, handleSubmit, formState: {errors} } = useForm({
  11. mode: 'all'
  12. });
  13. const goBack = (formData) => {
  14. dispatch({ type: "HEIGHT_CHANGE", payload: formData.height })
  15. dispatch({ type: "WEIGHT_CHANGE", payload: formData.weight })
  16. navigation.navigate("Credentials");
  17. }
  18. const toggleSagitta = (value) => {
  19. dispatch({ type: "SAGITTA_CHANGE", payload: value })
  20. }
  21. const register = async (formData) => {
  22. dispatch({ type: "HEIGHT_CHANGE", payload: formData.height })
  23. dispatch({ type: "WEIGHT_CHANGE", payload: formData.weight })
  24. navigation.navigate("RegisterImage");
  25. }
  26. return (
  27. <ImageBackground style={styles.container} source={require('../assets/cover-dark.png')}>
  28. <View>
  29. <View style={styles.brandContainer}>
  30. <Text style={styles.title} >Will you be using a sagitta?</Text>
  31. <View style={styles.sagittaCheck}>
  32. <RadioButton uncheckedColor="white" color="#df3f3f" status={sagitta ? 'unchecked' : 'checked'} onPress={() => {toggleSagitta(false)}} />
  33. <Text style={styles.radioLabel}>No</Text>
  34. <RadioButton uncheckedColor="white" color="#df3f3f" status={sagitta ? 'checked' : 'unchecked'} onPress={() => {toggleSagitta(true)}} />
  35. <Text style={styles.radioLabel} >Yes</Text>
  36. </View>
  37. </View>
  38. { sagitta ?
  39. <View style={{margin: 20}}>
  40. <Text style={{color: 'white', marginBottom: 20, fontSize: 15}} >We'll also need some body measurements.</Text>
  41. <Controller
  42. defaultValue={height}
  43. control={control}
  44. render={({ field: { onChange, value }}) => (
  45. <TextInput
  46. mode="outlined"
  47. style={[styles.textInput, errors.height && styles.errorInput]}
  48. placeholder="Height"
  49. value={value}
  50. onChangeText={value => onChange(value)}
  51. ></TextInput>
  52. )}
  53. name="height"
  54. rules={{
  55. required: true,
  56. pattern:
  57. {
  58. value: /^[0-9]*$/i
  59. }}}
  60. />
  61. {errors.height?.type === "required" && <Text style={styles.errorText}>Height is required.</Text>}
  62. {errors.height?.type === "pattern" && <Text style={styles.errorText}>Must be a number.</Text>}
  63. <Controller
  64. defaultValue={weight}
  65. control={control}
  66. render={({ field: { onChange, value }}) => (
  67. <TextInput
  68. mode="outlined"
  69. style={[styles.textInput, errors.weight && styles.errorInput]}
  70. placeholder="Weight"
  71. value={value}
  72. onChangeText={value => onChange(value)} />
  73. )}
  74. rules={{
  75. required: true,
  76. pattern:
  77. {
  78. value: /^[0-9]*$/i
  79. }}}
  80. name="weight"/>
  81. {errors.weight?.type === "required" && <Text style={styles.errorText}>Weight is required.</Text>}
  82. {errors.weight?.type === "pattern" && <Text style={styles.errorText}>Must be a number.</Text>}
  83. </View> : null }
  84. <TouchableOpacity onPress={goBack} style={styles.backBtn} >
  85. <Text style={{ color: 'white', fontSize: 20 }}>Back</Text>
  86. </TouchableOpacity>
  87. <TouchableOpacity onPress={handleSubmit(register)} style={styles.nextBtn} >
  88. <Text style={{ color: 'white', fontSize: 20 }}>Next</Text>
  89. </TouchableOpacity>
  90. </View>
  91. </ImageBackground>
  92. )
  93. }
  94. const styles = StyleSheet.create({
  95. container: {
  96. backgroundColor: 'transparent',
  97. position: 'absolute',
  98. width: Dimensions.get('window').width,
  99. height: Dimensions.get('window').height,
  100. flex: 1,
  101. flexDirection: 'column',
  102. resizeMode: 'cover',
  103. },
  104. brandContainer: {
  105. marginTop: 70,
  106. height: 120,
  107. marginLeft: 25,
  108. flexDirection: 'column',
  109. justifyContent: 'space-evenly'
  110. },
  111. title: {
  112. fontFamily: 'RacingSansOne-Regular',
  113. color: 'white',
  114. fontSize: 20
  115. },
  116. sagittaCheck: {
  117. flexDirection: 'row',
  118. margin: 20
  119. },
  120. radioLabel: {
  121. marginTop: 7, marginRight: 20, color: 'white'
  122. },
  123. subtitle: {
  124. fontFamily: 'RacingSansOne-Regular',
  125. color: 'white',
  126. fontSize: 15,
  127. marginHorizontal: 20,
  128. marginTop: 20
  129. },
  130. textContainer: {
  131. marginHorizontal: 20,
  132. marginBottom: 30,
  133. borderRadius: 50,
  134. },
  135. textInput: {
  136. marginVertical: 7,
  137. paddingLeft: 30,
  138. borderRadius: 50,
  139. overflow: 'hidden',
  140. backgroundColor: 'white',
  141. height: 50
  142. },
  143. errorText: {
  144. alignSelf: 'flex-end',
  145. color: 'red',
  146. fontSize: 15
  147. },
  148. errorInput: {
  149. borderWidth: 2,
  150. borderColor: 'red'
  151. },
  152. nextBtn: {
  153. marginHorizontal: 20,
  154. marginBottom: 100,
  155. borderRadius: 50,
  156. justifyContent: 'center',
  157. backgroundColor: '#df3f3f',
  158. margin: 5,
  159. height: 50,
  160. alignItems: 'center'
  161. },
  162. backBtn: {
  163. marginHorizontal: 20,
  164. marginBottom: 10,
  165. borderRadius: 50,
  166. borderColor: 'white',
  167. borderWidth: 2,
  168. justifyContent: 'center',
  169. backgroundColor: 'transparent',
  170. margin: 5,
  171. height: 50,
  172. alignItems: 'center'
  173. },
  174. })
  175. export default RegisterMeasurements;