import { useRouter } from "expo-router"; import React, { useContext, useState } from "react"; import { Alert, KeyboardAvoidingView, Platform, ScrollView, StyleSheet, TextInput, View, } from "react-native"; import { PageContainer } from "@/components/PageContainer"; import { ThemedText } from "@/components/ThemedText"; import { ThemedButton } from "@/components/ui/ThemedButton"; import { AuthContext } from "@/contexts/AuthContext"; import { useThemeColor } from "@/hooks/useThemeColor"; export default function SignupScreen() { const [displayName, setDisplayName] = useState(""); const [username, setUsername] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [isLoading, setIsLoading] = useState(false); const router = useRouter(); const authContext = useContext(AuthContext); if (!authContext) { throw new Error("SignupScreen must be used within an AuthProvider"); } const { register } = authContext; const backgroundColor = useThemeColor({}, "background"); const textColor = useThemeColor({}, "text"); const handleSignup = async () => { if (!displayName || !username || !email || !password || !confirmPassword) { Alert.alert("Error", "Please fill in all fields"); return; } if (password !== confirmPassword) { Alert.alert("Error", "Passwords do not match"); return; } if (password.length < 6) { Alert.alert("Error", "Password must be at least 6 characters long"); return; } setIsLoading(true); try { await register(email, password, { username: username, display_name: displayName, }); Alert.alert("Success", "Account created successfully!", [ { text: "OK", }, ]); } catch (error) { Alert.alert( "Registration Failed", error instanceof Error ? error.message : "An error occurred during registration" ); } finally { setIsLoading(false); } }; return ( Create Account Join us today Display Name Username Email Password Confirm Password Already have an account? {" "} router.push("/(auth)/login")} > Log In ); } const styles = StyleSheet.create({ container: { flex: 1, }, keyboardAvoidingView: { flex: 1, }, scrollContent: { flexGrow: 1, paddingVertical: 40, }, header: { alignItems: "center", marginBottom: 30, }, title: { marginBottom: 8, textAlign: "center", }, subtitle: { textAlign: "center", opacity: 0.7, }, inputContainer: { marginBottom: 20, }, label: { marginBottom: 8, }, input: { height: 50, borderRadius: 8, paddingHorizontal: 16, fontSize: 16, }, signupButton: { marginTop: 10, marginBottom: 20, }, footer: { flexDirection: "row", justifyContent: "center", alignItems: "center", }, footerText: { textAlign: "center", }, signInLink: { textDecorationLine: "underline", }, });