import React, { useState } from 'react';
import {View,Text,TextInput,TouchableOpacity,ScrollView,StyleSheet,SafeAreaView,Image,Pressable,} from 'react-native';
import { StatusBar } from 'expo-status-bar';
import { ArrowLeft, Eye, EyeOff, MapPin } from 'lucide-react-native';
import { doc, setDoc } from 'firebase/firestore';
import { db } from '../../../firebase/config';
import { signUp } from '../../../firebase/auth';
import { Alert } from 'react-native';
import { router } from "expo-router";
export default function App() {
const [step, setStep] = useState(1);
const [showPassword, setShowPassword] = useState(false);
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
const handlePress=() =>{
router.replace("/screens/auth/SignIn-Screen");
}
const [formData, setFormData] = useState({
fullName: '',
email: '',
phone: '',
password: '',
confirmPassword: '',
cafeName: '',
cafeAddress: '',
city: '',
delegation: '',
fiscalId: '',
acceptTerms: false,
});
const handleInputChange = (name: string, value: string | boolean) => {
setFormData(prev => ({
...prev,
[name]: value
}));
};
const handleNext = () => {
setStep(2);
};
const handleSubmit = async () => {
if (!formData.acceptTerms) {
Alert.alert("Erreur", "Vous devez accepter les conditions.");
return;
}
if (formData.password !== formData.confirmPassword) {
Alert.alert("Erreur", "Les mots de passe ne correspondent pas.");
return;
}
try {
const user = await signUp(formData.email, formData.password);
await setDoc(doc(db, 'users', user.uid), {
fullName: formData.fullName,
email: formData.email,
phone: formData.phone,
cafeName: formData.cafeName,
cafeAddress: formData.cafeAddress,
city: formData.city,
delegation: formData.delegation,
fiscalId: formData.fiscalId,
role: 'user',
createdAt: new Date(),
});
Alert.alert("Succès", "Compte créé avec succès !");
router.replace("/screens/user/UserHomeScreen");
} catch (error: any) {
Alert.alert("Erreur", error.message);
console.log(error);
}
};
const renderStep1 = () => (
Nom et Prénom
handleInputChange('fullName', value)}
/>
E-mail
handleInputChange('email', value)}
/>
Numéro de téléphone
handleInputChange('phone', value)}
/>
Mot de passe
handleInputChange('password', value)}
/>
setShowPassword(!showPassword)}
>
{showPassword ? : }
Confirmer votre mot de passe
handleInputChange('confirmPassword', value)}
/>
setShowConfirmPassword(!showConfirmPassword)}
>
{showConfirmPassword ? : }
Suivant
Vous avez déjà un compte?
Connexion
);
const renderStep2 = () => (
Nom de Café
handleInputChange('cafeName', value)}
/>
Adresse de Café
handleInputChange('cafeAddress', value)}
/>
Ville
{
// Add city picker logic here
}}
>
{formData.city || 'Sélectionner une ville'}
Délégation
{
// Add delegation picker logic here
}}
>
{formData.delegation || 'Sélectionner une délégation'}
Matricule Fiscale
handleInputChange('fiscalId', value)}
/>
handleInputChange('acceptTerms', !formData.acceptTerms)}
/>
J'accepte les conditions générales et la politique de confidentialité.
Valider
);
return (
{step > 1 && (
setStep(1)}
>
)}
Création de compte
{step === 1 ? renderStep1() : renderStep2()}
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
padding: 10,
},
scrollContainer: {
flexGrow: 1,
padding: 16,
},
header: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 25,
},
backButton: {
marginTop:10,
},
logoContainer: {
flex: 1,
alignItems: 'center',
},
logo: {
width: 80,
height: 80,
alignItems: 'center',
justifyContent: 'center',
verticalAlign:'middle',
marginTop:20,
marginBottom: 16,
},
title: {
fontSize: 24,
fontWeight: '600',
color: '#1f2937',
},
inputGroup: {
marginBottom: 16,
},
label: {
fontSize: 14,
fontWeight: '500',
color: '#374151',
marginBottom: 4,
},
input: {
borderWidth: 1,
borderColor: '#d1d5db',
borderRadius: 8,
padding: 12,
fontSize: 16,
color: '#1f2937',
},
passwordContainer: {
flexDirection: 'row',
alignItems: 'center',
borderWidth: 1,
borderColor: '#d1d5db',
borderRadius: 8,
},
passwordInput: {
flex: 1,
padding: 12,
fontSize: 16,
color: '#1f2937',
},
eyeIcon: {
padding: 12,
},
selectContainer: {
borderWidth: 1,
borderColor: '#d1d5db',
borderRadius: 8,
},
select: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
padding: 12,
},
selectText: {
fontSize: 16,
color: '#9ca3af',
},
checkboxContainer: {
flexDirection: 'row',
alignItems: 'flex-start',
marginBottom: 16,
},
checkbox: {
width: 20,
height: 20,
borderWidth: 2,
borderColor: '#d1d5db',
borderRadius: 4,
marginRight: 8,
marginTop: 2,
},
checkboxChecked: {
backgroundColor: '#22C55E',
borderColor: '#22C55E',
},
checkboxLabel: {
flex: 1,
fontSize: 14,
color: '#4b5563',
},
button: {
backgroundColor: '#B77729',
borderRadius: 8,
padding: 16,
alignItems: 'center',
marginBottom: 16,
},
buttonText: {
color: 'white',
fontSize: 16,
fontWeight: '500',
},
loginContainer: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
loginText: {
fontSize: 14,
color: '#4b5563',
},
loginLink: {
fontSize: 14,
color: '#B77729',
},
});