// React import { useState, useEffect } from 'react'; import { ScrollView, View, Text, StyleSheet, Image, Alert } from 'react-native'; // Expo import { useRouter } from 'expo-router'; // Components import { CustomButton } from '../src/components/button'; import { CustomImage } from '../src/components/image'; import { CustomTextInput } from '../src/components/input'; // Contexts import { useAuth } from "../src/contexts/authContext"; // Hooks import { usePickImage } from '../src/hooks/usePickImage'; // Services import { uploadTeamImage } from '../src/services/api/image'; import { getLocationAuthorization, stopLocationTracking } from '../src/services/tasks/backgroundLocation'; // Constants import { COLORS } from '../src/constants'; const Index = () => { const router = useRouter(); const { loggedIn, login } = useAuth(); const { image, pickImage } = usePickImage(); const [teamId, setTeamId] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); // Disbaling location tracking and asking permissions useEffect(() => { stopLocationTracking(); getLocationAuthorization(); }, []); // Routeur useEffect(() => { if (loggedIn) { router.replace("/interface"); } }, [router, loggedIn, image]); const handleSubmit = async () => { if (isSubmitting || !getLocationAuthorization()) return; setIsSubmitting(true); const regex = /^\d{6}$/; if (!regex.test(teamId)) { setTimeout(() => Alert.alert("Erreur", "Veuillez entrer un ID d'équipe valide."), 100); return; } try { const response = await login(teamId); if (response.isLoggedIn) { uploadTeamImage(teamId, image?.uri); setTeamId(""); } else { setTimeout(() => Alert.alert("Échec", "L'ID d'équipe est inconnu."), 100); } } catch (error) { setTimeout(() => Alert.alert("Échec", "La connexion au serveur a échoué."), 100); } finally { setIsSubmitting(false); } }; return ( LA TRAQUE Appuyer pour changer la photo d'équipe (Le haut du corps doit être visible) ); }; export default Index; const styles = StyleSheet.create({ container: { flexGrow: 1, alignItems: 'center', paddingVertical: 20, backgroundColor: COLORS.background }, transitionContainer: { flexGrow: 1, width: '80%', maxWidth: 600, alignItems: 'center', }, subContainer: { flexGrow: 1, width: "100%", alignItems: 'center', justifyContent: 'center', margin: 10, }, logoImage: { width: 130, height: 130, margin: 10, }, logoText: { fontSize: 50, fontWeight: 'bold', } });