import React, { useState } from 'react'; import axios from 'axios'; import { useNavigate } from 'react-router-dom'; import 'bootstrap/dist/css/bootstrap.min.css'; import classNames from 'classnames'; import MembershipsEnum from './MembershipsEnum'; const AuthForm = () => { const navigate = useNavigate(); const [activeTab, setActiveTab] = useState('login'); const [credentials, setCredentials] = useState({ firstName: '', lastName: '', email: '', password: '', phone: '', address: '', membershipLevel: '' }); const [error, setError] = useState(''); const handleChange = (e) => { const { name, value } = e.target; setCredentials({ ...credentials, [name]: value }); }; const handleLogin = async (e) => { e.preventDefault(); try { const response = await axios.post('http://localhost:8081/api/login', { email: credentials.email, password: credentials.password }); const { token } = response.data; localStorage.setItem('token', token); navigate('/'); } catch (err) { setError('Login failed. Please check your credentials.'); } }; const handleRegister = async (e) => { e.preventDefault(); try { await axios.post('http://localhost:8081/api/register', { firstName: credentials.firstName, lastName: credentials.lastName, email: credentials.email, password: credentials.password, phone: credentials.phone, address: credentials.address, membershipLevel: credentials.membershipLevel }); setActiveTab('login'); alert('Registration successful. Please log in.'); } catch (err) { setError('Registration failed. Please try again.'); } }; return (