import { Label } from "@/components/ui/label" import { Input } from "@/components/ui/input" import { Button } from "@/components/ui/button" import { useState, useEffect } from 'react'; import { auth, db } from '../firebase/firebase_config'; import { createUserWithEmailAndPassword } from 'firebase/auth'; import { Navigate, redirect } from "react-router-dom"; import { addDoc, collection } from "firebase/firestore"; const SignUp = () => { const [isSignedUp, setIsSignedUp] = useState(false) const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [name, setName] = useState('') const [phoneNumber, setPhoneNumber] = useState('') const [carBrand, setCarBrand] = useState('') const [carModel, setCarModel] = useState('') const [carColor, setCarColor] = useState('') const [plateNumber, setPlateNumber] = useState('') useEffect(() => { const unsubscribe = auth.onAuthStateChanged((user) => { if (user) { // User is signed in. console.log('User is signed in:', user); // TODO: redirect the user to another page or perform some other action } else { // No user is signed in. console.log('No user is signed in'); } }); return () => { unsubscribe(); }; }, []); const handleSignUp = async () => { try { // The onAuthStateChanged listener will handle the signed-in user state. const userCredential = await createUserWithEmailAndPassword(auth, email, password); const usersCollection = collection(db, 'users'); const userUid = userCredential.user.uid; // Get the user's UID console.log(userUid, name, phoneNumber, carBrand, carModel, carColor, plateNumber) addDoc(usersCollection, { uid: userUid, name: name, phoneNumber: phoneNumber, carBrand: carBrand, carModel: carModel, carColor: carColor, plateNumber: plateNumber, }) console.log('User signed up:', userCredential.user); setIsSignedUp(true) } catch (error) { // TODO: Handle error messages or display them to the user. console.error('Error signing up:', error); } }; return ( isSignedUp ? () : (

Sign Up

setEmail(e.target.value)} />
setPassword(e.target.value)} />
setName(e.target.value)} />
setPhoneNumber(e.target.value)} />
setCarBrand(e.target.value)} />
setCarModel(e.target.value)} />
setCarColor(e.target.value)} />
setPlateNumber(e.target.value)} />
) ); }; export default SignUp;