Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RegisterScreen.jsx 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import React, { useState, useContext } from "react";
  2. import {
  3. SafeAreaView,
  4. ScrollView,
  5. View,
  6. Text,
  7. TextInput,
  8. TouchableOpacity,
  9. StyleSheet,
  10. Platform,
  11. } from "react-native";
  12. // import DateTimePicker from "@react-native-community/datetimepicker";
  13. import InputField from "../components/InputField";
  14. import MaterialIcons from "@expo/vector-icons/MaterialIcons";
  15. import Ionicons from "@expo/vector-icons/Ionicons";
  16. import RegistrationSVG from "../assets/images/registration.svg";
  17. import GoogleSVG from "../assets/images/google.svg";
  18. import FacebookSVG from "../assets/images/facebook.svg";
  19. import TwitterSVG from "../assets/images/twitter.svg";
  20. import CustomButton from "../components/Buttons/CustomButton";
  21. import { globalStyles } from "../styles/global";
  22. import { AuthContext } from "../context/AuthContext";
  23. import Loader from "../components/Loader";
  24. import { Formik } from "formik";
  25. import { registerSchema } from "../schemas/registerSchema";
  26. const RegisterScreen = ({ navigation }) => {
  27. const { isLoading, register, googleAuth } = useContext(AuthContext);
  28. const [date, setDate] = useState(new Date());
  29. const [open, setOpen] = useState(false);
  30. // const [dateOfBirthLabel, setDateOfBirthLabel] = useState("Date of Birth");
  31. const [error, setError] = useState(null);
  32. // BIRTHDAY DATETIME PICKER
  33. // const onChange = (event, selectedDate) => {
  34. // const currentDate = selectedDate || date;
  35. // setDate(currentDate);
  36. // let tempDate = new Date(currentDate);
  37. // let fDate =
  38. // tempDate.getDate() +
  39. // "/" +
  40. // (tempDate.getMonth() + 1) +
  41. // "/" +
  42. // tempDate.getFullYear();
  43. // setDateOfBirthLabel(fDate);
  44. // setOpen(false);
  45. // };
  46. const handleSignup = (values) => {
  47. register(values.username, values.email, values.password, function (result) {
  48. setError(result.error.message);
  49. });
  50. };
  51. return (
  52. <SafeAreaView style={globalStyles.safeArea}>
  53. <Loader visible={isLoading} />
  54. <ScrollView
  55. showsVerticalScrollIndicator={false}
  56. style={{ paddingHorizontal: 25 }}
  57. >
  58. <View style={{ alignItems: "center" }}>
  59. <RegistrationSVG width={300} height={300} />
  60. </View>
  61. <Text style={globalStyles.boldText}>Sign Up</Text>
  62. <View style={styles.providersContainer}>
  63. <TouchableOpacity
  64. onPress={googleAuth}
  65. style={globalStyles.iconButton}
  66. >
  67. <GoogleSVG height={24} width={24} />
  68. </TouchableOpacity>
  69. <TouchableOpacity onPress={() => {}} style={globalStyles.iconButton}>
  70. <FacebookSVG height={24} width={24} />
  71. </TouchableOpacity>
  72. <TouchableOpacity onPress={() => {}} style={globalStyles.iconButton}>
  73. <TwitterSVG height={24} width={24} />
  74. </TouchableOpacity>
  75. </View>
  76. <Text style={globalStyles.regularCenteredText}>
  77. Or, sign up with email...
  78. </Text>
  79. <Formik
  80. initialValues={{
  81. username: "",
  82. email: "",
  83. password: "",
  84. confirmPassword: "",
  85. }}
  86. validationSchema={registerSchema}
  87. onSubmit={handleSignup}
  88. validateOnChange={false}
  89. validateOnBlur={false}
  90. >
  91. {({
  92. handleChange,
  93. handleBlur,
  94. handleSubmit,
  95. values,
  96. isValid,
  97. errors,
  98. }) => (
  99. <>
  100. <InputField
  101. name={"username"}
  102. text={values.username}
  103. onChangeText={handleChange("username")}
  104. label={"Username"}
  105. handleBlur={handleBlur("username")}
  106. icon={
  107. <Ionicons
  108. name="person-outline"
  109. size={20}
  110. color="#666"
  111. style={{ marginRight: 5 }}
  112. />
  113. }
  114. />
  115. {errors.username && (
  116. <Text style={styles.errorMessage}>{errors.username}</Text>
  117. )}
  118. <InputField
  119. name={"email"}
  120. text={values.email}
  121. onChangeText={handleChange("email")}
  122. label={"Email"}
  123. handleBlur={handleBlur("email")}
  124. icon={
  125. <MaterialIcons
  126. name="alternate-email"
  127. size={20}
  128. color="#666"
  129. style={{ marginRight: 5 }}
  130. />
  131. }
  132. keyboardType="email-address"
  133. />
  134. {errors.email && (
  135. <Text style={styles.errorMessage}>{errors.email}</Text>
  136. )}
  137. <InputField
  138. name={"password"}
  139. text={values.password}
  140. onChangeText={handleChange("password")}
  141. label={"Password"}
  142. handleBlur={handleBlur("password")}
  143. icon={
  144. <Ionicons
  145. name="ios-lock-closed-outline"
  146. size={20}
  147. color="#666"
  148. style={{ marginRight: 5 }}
  149. />
  150. }
  151. inputType="password"
  152. />
  153. {errors.password && (
  154. <Text style={styles.errorMessage}>{errors.password}</Text>
  155. )}
  156. <InputField
  157. name={"confirmPassword"}
  158. text={values.confirmPassword}
  159. onChangeText={handleChange("confirmPassword")}
  160. label={"Confirm Password"}
  161. handleBlur={handleBlur("confirmPassword")}
  162. icon={
  163. <Ionicons
  164. name="ios-lock-closed-outline"
  165. size={20}
  166. color="#666"
  167. style={{ marginRight: 5 }}
  168. />
  169. }
  170. inputType="password"
  171. />
  172. {errors.confirmPassword && <Text style={styles.errorMessage}>{errors.confirmPassword}</Text>}
  173. {/* <View style={styles.dateOfBirthContainer}>
  174. <Ionicons name='calendar-outline' size={20} color="#666" style={{marginRight: 5}} />
  175. <TouchableOpacity onPress={() => setOpen(true)}>
  176. <Text style={styles.dateOfBirthLabel}>{dateOfBirthLabel}</Text>
  177. {open && <DateTimePicker testID='dateTimePicker' value={date} mode="date" display='spinner' onChange={onChange} textColor="#000" />}
  178. </TouchableOpacity>
  179. </View> */}
  180. {error && <Text style={styles.errorMessage}>{error}</Text>}
  181. <CustomButton label={"Sign Up"} onPress={handleSubmit} />
  182. </>
  183. )}
  184. </Formik>
  185. <View style={styles.alreadyRegistered}>
  186. <Text style={globalStyles.regularText}>Already Registered? </Text>
  187. <TouchableOpacity onPress={() => navigation.goBack()}>
  188. <Text style={globalStyles.primaryBold}>Sign In</Text>
  189. </TouchableOpacity>
  190. </View>
  191. </ScrollView>
  192. </SafeAreaView>
  193. );
  194. };
  195. const styles = StyleSheet.create({
  196. providersContainer: {
  197. flexDirection: "row",
  198. justifyContent: "space-between",
  199. marginBottom: 30,
  200. },
  201. dateOfBirthContainer: {
  202. flexDirection: "row",
  203. borderBottomColor: "#ccc",
  204. borderBottomWidth: 1,
  205. paddingBottom: 8,
  206. marginBottom: 30,
  207. },
  208. dateOfBirthLabel: {
  209. color: "#666",
  210. marginLeft: 5,
  211. marginTop: 5,
  212. },
  213. alreadyRegistered: {
  214. flexDirection: "row",
  215. justifyContent: "center",
  216. marginBottom: 30,
  217. },
  218. errorMessage: {
  219. marginBottom: 30,
  220. color: "red",
  221. },
  222. });
  223. export default RegisterScreen;