Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 Spinner from "react-native-loading-spinner-overlay/lib";
  24. import Loader from "../components/Loader";
  25. const RegisterScreen = ({ navigation }) => {
  26. const { isLoading, register } = useContext(AuthContext);
  27. const [date, setDate] = useState(new Date());
  28. const [open, setOpen] = useState(false);
  29. const [dateOfBirthLabel, setDateOfBirthLabel] = useState("Date of Birth");
  30. const [username, setUsername] = useState(null);
  31. const [email, setEmail] = useState(null);
  32. const [password, setPassword] = useState(null);
  33. const [confirmPassword, setConfirmPassword] = useState(null);
  34. const [error, setError] = useState(null);
  35. const onChange = (event, selectedDate) => {
  36. const currentDate = selectedDate || date;
  37. setDate(currentDate);
  38. let tempDate = new Date(currentDate);
  39. let fDate =
  40. tempDate.getDate() +
  41. "/" +
  42. (tempDate.getMonth() + 1) +
  43. "/" +
  44. tempDate.getFullYear();
  45. setDateOfBirthLabel(fDate);
  46. setOpen(false);
  47. };
  48. const handleSignup = () => {
  49. if (password !== confirmPassword) {
  50. setError("Passwords must match");
  51. return;
  52. }
  53. register(username, email, password, function (result) {
  54. setError(result.error.message);
  55. });
  56. };
  57. return (
  58. <SafeAreaView style={globalStyles.safeArea}>
  59. <Loader visible={isLoading} />
  60. <ScrollView
  61. showsVerticalScrollIndicator={false}
  62. style={{ paddingHorizontal: 25 }}
  63. >
  64. <View style={{ alignItems: "center" }}>
  65. <RegistrationSVG width={300} height={300} />
  66. </View>
  67. <Text style={globalStyles.boldText}>Sign Up</Text>
  68. <View style={styles.providersContainer}>
  69. <TouchableOpacity onPress={() => {}} style={globalStyles.iconButton}>
  70. <GoogleSVG height={24} width={24} />
  71. </TouchableOpacity>
  72. <TouchableOpacity onPress={() => {}} style={globalStyles.iconButton}>
  73. <FacebookSVG height={24} width={24} />
  74. </TouchableOpacity>
  75. <TouchableOpacity onPress={() => {}} style={globalStyles.iconButton}>
  76. <TwitterSVG height={24} width={24} />
  77. </TouchableOpacity>
  78. </View>
  79. <Text style={globalStyles.regularCenteredText}>
  80. Or, sign up with email...
  81. </Text>
  82. <InputField
  83. text={username}
  84. onChangeText={(text) => setUsername(text)}
  85. label={"Full Name"}
  86. icon={
  87. <Ionicons
  88. name="person-outline"
  89. size={20}
  90. color="#666"
  91. style={{ marginRight: 5 }}
  92. />
  93. }
  94. />
  95. <InputField
  96. text={email}
  97. onChangeText={(text) => setEmail(text)}
  98. label={"Email"}
  99. icon={
  100. <MaterialIcons
  101. name="alternate-email"
  102. size={20}
  103. color="#666"
  104. style={{ marginRight: 5 }}
  105. />
  106. }
  107. keyboardType="email-address"
  108. />
  109. <InputField
  110. text={password}
  111. onChangeText={(text) => setPassword(text)}
  112. label={"Password"}
  113. icon={
  114. <Ionicons
  115. name="ios-lock-closed-outline"
  116. size={20}
  117. color="#666"
  118. style={{ marginRight: 5 }}
  119. />
  120. }
  121. inputType="password"
  122. />
  123. <InputField
  124. text={confirmPassword}
  125. onChangeText={(text) => setConfirmPassword(text)}
  126. label={"Confirm Password"}
  127. icon={
  128. <Ionicons
  129. name="ios-lock-closed-outline"
  130. size={20}
  131. color="#666"
  132. style={{ marginRight: 5 }}
  133. />
  134. }
  135. inputType="password"
  136. />
  137. {/* <View style={styles.dateOfBirthContainer}>
  138. <Ionicons name='calendar-outline' size={20} color="#666" style={{marginRight: 5}} />
  139. <TouchableOpacity onPress={() => setOpen(true)}>
  140. <Text style={styles.dateOfBirthLabel}>{dateOfBirthLabel}</Text>
  141. {open && <DateTimePicker testID='dateTimePicker' value={date} mode="date" display='spinner' onChange={onChange} textColor="#000" />}
  142. </TouchableOpacity>
  143. </View> */}
  144. {error && <Text style={styles.errorMessage}>{error}</Text>}
  145. <CustomButton label={"Sign Up"} onPress={handleSignup} />
  146. <View style={styles.alreadyRegistered}>
  147. <Text style={globalStyles.regularText}>Already Registered? </Text>
  148. <TouchableOpacity onPress={() => navigation.goBack()}>
  149. <Text style={globalStyles.primaryBold}>Sign In</Text>
  150. </TouchableOpacity>
  151. </View>
  152. </ScrollView>
  153. </SafeAreaView>
  154. );
  155. };
  156. const styles = StyleSheet.create({
  157. providersContainer: {
  158. flexDirection: "row",
  159. justifyContent: "space-between",
  160. marginBottom: 30,
  161. },
  162. dateOfBirthContainer: {
  163. flexDirection: "row",
  164. borderBottomColor: "#ccc",
  165. borderBottomWidth: 1,
  166. paddingBottom: 8,
  167. marginBottom: 30,
  168. },
  169. dateOfBirthLabel: {
  170. color: "#666",
  171. marginLeft: 5,
  172. marginTop: 5,
  173. },
  174. alreadyRegistered: {
  175. flexDirection: "row",
  176. justifyContent: "center",
  177. marginBottom: 30,
  178. },
  179. errorMessage: {
  180. marginBottom: 30,
  181. color: "red",
  182. },
  183. });
  184. export default RegisterScreen;