import React, { useState } from "react"; import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea";
const LoginPage = ({ onLogin }) => { const [credentials, setCredentials] = useState({ email: "", password: "" }); const [error, setError] = useState(""); const [loading, setLoading] = useState(false);
const handleChange = (e) => { const { name, value } = e.target; setCredentials((prev) => ({ ...prev, [name]: value })); };
const handleSubmit = (e) => { e.preventDefault(); setLoading(true); if (!onLogin) { setError("Login function is missing."); setLoading(false); return; } setTimeout(() => { onLogin(credentials); setLoading(false); }, 1500); };
return (
{error &&{error}
} {loading ? "Logging in..." : "Login"}Forgot Password?
); };const AdoptionForm = ({ petId, petName }) => { const [formData, setFormData] = useState({ name: "", email: "", phone: "", address: "", governmentId: "", reason: "", }); const [submitted, setSubmitted] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState("");
const handleChange = (e) => { const { name, value } = e.target; setFormData((prev) => ({ ...prev, [name]: value })); };
const handleSubmit = async (e) => { e.preventDefault(); setLoading(true); setError(""); try { const response = await fetch("/api/adopt", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ petId, ...formData }), });
const result = await response.json();
if (response.ok) {
setSubmitted(true);
} else {
setError(result.message || "Failed to submit adoption request. Try again.");
}
} catch (error) {
console.error("Error submitting form:", error);
setError("Something went wrong. Please try again.");
} finally {
setLoading(false);
}
};
return (
{submitted ? (Adoption request submitted successfully!
) : ( {error &&{error}
} <Button type="submit" className="w-full bg-blue-600 text-white py-2 rounded-lg hover:bg-blue-700" disabled={loading}> {loading ? "Submitting..." : "Submit Application"} )} ); };export { LoginPage, AdoptionForm };