import AsyncStorage from "@react-native-async-storage/async-storage"; import * as AppleAuthentication from "expo-apple-authentication"; import React, { useCallback, useEffect, useState } from "react"; import { ActivityIndicator, KeyboardAvoidingView, Platform, Pressable, StyleSheet, Text, View, } from "react-native"; import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"; import Svg, { Path } from "react-native-svg"; import { background } from "../assets"; import BorderGradientButton from "../components/BorderGradientButton"; import { Input } from "../components/Input"; import ItemContainer from "../components/ItemContainer/ItemContainer"; import firebase from "../config/firebase"; import { isWeb } from "../hooks/useLayoutType"; import useSocialAuth from "../hooks/useSocialAuth"; import Page from "../layouts/Page"; import { Routes } from "../navigation"; import { navigate, reset } from "../navigation/NavigationService"; import { Palette } from "../styles"; import { FONT_FAMILY } from "../styles/Fonts"; const LANGUAGE_STORAGE_KEY = "preferredLanguage"; const Register = () => { const [email, setEmail] = useState(""); const [firstName, setFirstName] = useState(""); const [preferredLanguage, setPreferredLanguage] = useState(null); const afterSocialAuth = useCallback(async () => { const uid = firebase.auth().currentUser?.uid; if (!uid) throw new Error("Aucun utilisateur après connexion"); reset({ index: 0, routes: [{ name: Routes.BottomTab }] }); }, []); const { signInWithGoogle, signInWithApple, isAppleSignInAvailable, isLoading: socialLoading, } = useSocialAuth({ onSuccess: afterSocialAuth, }); const isBusy = socialLoading; useEffect(() => { AsyncStorage.getItem(LANGUAGE_STORAGE_KEY) .then((storedLanguage) => { if (storedLanguage) { setPreferredLanguage(storedLanguage); } }) .catch((error) => { console.warn("Register: failed to load preferred language", error); }); }, []); const isFormValid = email.trim().length > 0 && firstName.trim().length > 0; const renderFormContent = () => ( Renseigne tes informations {preferredLanguage && !isWeb ? ( Langue choisie :{" "} {preferredLanguage === "fr" ? "Français" : "English"} ) : null} navigate(Routes.CreatePassword, { email: email.trim(), firstName: firstName.trim(), preferredLanguage, }) } disabled={!isFormValid || isBusy} /> {isAppleSignInAvailable ? ( ) : null} En t’inscrivant, tu acceptes nos conditions générales{"\n"} d’utilisation et notre politique de confidentialité. Tu as déjà un compte ?{" "} navigate(Routes.Login)} > Se connecter ); return ( {isWeb ? ( renderFormContent() ) : ( {renderFormContent()} )} ); }; const AppleAuthButton = ({ onPress, disabled, loading }) => { if (isWeb) { return null; } return ( {loading ? ( ) : null} ); }; const GoogleAuthButton = ({ onPress, disabled, loading }) => ( [ styles.socialButton, pressed && !disabled ? styles.socialButtonPressed : null, disabled ? styles.socialButtonDisabled : null, ]} > Continuer avec Google {loading ? ( ) : ( )} ); const GoogleLogo = () => ( ); export default Register; const styles = StyleSheet.create({ pageContent: { flex: 1, justifyContent: "center", alignItems: "center", }, webItemContainer: { width: "100%", maxWidth: 680, }, mobileItemContainer: { width: "100%", minHeight: 720, }, mobileAvoider: { flex: 1, }, mobileScrollContent: { flexGrow: 1, justifyContent: "center", paddingVertical: 24, }, formContent: { gap: 32, paddingTop: 5, paddingHorizontal: 5, }, title: { fontSize: 22, color: Palette.white, fontFamily: FONT_FAMILY.InterSemiBold, }, languageInfo: { fontSize: 14, color: Palette.gray, fontFamily: FONT_FAMILY.InterRegular, }, languageInfoValue: { color: Palette.white, fontFamily: FONT_FAMILY.InterSemiBold, }, footer: { alignItems: "center", gap: 4, }, terms: { fontSize: 12, color: Palette.gray, fontFamily: FONT_FAMILY.HelveticaNeueRegular, textAlign: "center", }, loginText: { fontSize: 14, color: Palette.white, fontFamily: FONT_FAMILY.HelveticaNeueRegular, }, loginLink: { fontFamily: FONT_FAMILY.InterSemiBold, }, bottomLoginPrompt: { marginTop: 16, paddingHorizontal: 24, marginBottom: 30, }, bottomFooterText: { fontSize: 15, color: Palette.white, fontFamily: FONT_FAMILY.HelveticaNeueRegular, textAlign: "center", }, bottomFooterLink: { fontFamily: FONT_FAMILY.InterBold, color: Palette.white, fontSize: 16, }, socialWrapper: { width: "100%", gap: 16, alignItems: "center", }, socialButton: { alignSelf: "center", borderRadius: 12, width: "90%", backgroundColor: Palette.white, borderWidth: 1, borderColor: "#E3E7EF", paddingVertical: 12, paddingHorizontal: 20, shadowColor: "rgba(12, 6, 34, 0.08)", shadowOffset: { width: 0, height: 8 }, shadowOpacity: 0.3, shadowRadius: 16, elevation: 2, }, socialButtonPressed: { backgroundColor: "#F4F7FF", }, socialButtonDisabled: { opacity: 0.7, }, socialButtonContent: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", gap: 12, }, socialIconContainer: { justifyContent: "center", alignItems: "center", width: 28, height: 28, }, socialButtonText: { flex: 1, textAlign: "center", fontSize: 15, color: "#202124", fontFamily: FONT_FAMILY.InterSemiBold, }, socialRightSpacer: { width: 24, height: 24, }, nativeButtonWrapper: { alignSelf: "center", width: "90%", height: 50, justifyContent: "center", }, nativeButton: { width: "100%", height: 50, }, nativeLoadingOverlay: { ...StyleSheet.absoluteFillObject, alignItems: "center", justifyContent: "center", }, });