diff --git a/src/components/Header.tsx b/src/components/Header.tsx new file mode 100644 index 0000000..c094a76 --- /dev/null +++ b/src/components/Header.tsx @@ -0,0 +1,140 @@ +import { useState, useEffect } from "react"; +import { Link } from "react-router-dom"; +import { Button } from "@/components/ui/button"; +import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet"; +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogTrigger } from "@/components/ui/dialog"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Menu, Heart, Activity, User } from "lucide-react"; +import { ThemeToggle } from "@/components/ThemeToggle"; +import { useAuth } from "@/hooks/use-tygarun"; +import { toast } from "sonner"; + +function PatientPortal({ trigger }: { trigger: React.ReactNode }) { + const { user, isSignedIn, signup, signin, signout } = useAuth(); + const [openAuth, setOpenAuth] = useState(false); + const [mode, setMode] = useState<"signin" | "signup">("signin"); + const [name, setName] = useState(""); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [busy, setBusy] = useState(false); + + if (isSignedIn) { + return ( + { signout(); toast.success("Signed out of patient portal"); }}> + Sign Out{user?.email ? ` (\${user.email})` : ""} + + ); + } + + const submit = async (e: React.FormEvent) => { + e.preventDefault(); + setBusy(true); + try { + if (mode === "signup") await signup({ name, email, password }); + else await signin(email, password); + toast.success(mode === "signup" ? "Patient account created!" : "Welcome back!"); + setOpenAuth(false); + setName(""); setEmail(""); setPassword(""); + } catch { + toast.error("Authentication failed. Please try again."); + } finally { + setBusy(false); + } + }; + + return ( + + {trigger} + + + {mode === "signup" ? "Create Patient Account" : "Patient Portal Login"} + {mode === "signup" ? "Register to book appointments and manage your care." : "Sign in to access your appointments and records."} + + + {mode === "signup" && ( + + Name + setName(e.target.value)} required /> + + )} + + Email + setEmail(e.target.value)} required /> + + + Password + setPassword(e.target.value)} required /> + + + {busy ? "Please wait…" : mode === "signup" ? "Create Account" : "Sign In"} + + + setMode(mode === "signup" ? "signin" : "signup")}> + {mode === "signup" ? "Already registered? Sign in" : "New patient? Create an account"} + + + + ); +} + +export default function Header() { + const [open, setOpen] = useState(false); + const [scrolled, setScrolled] = useState(false); + + useEffect(() => { + const fn = () => setScrolled(window.scrollY > 20); + window.addEventListener("scroll", fn); + return () => window.removeEventListener("scroll", fn); + }, []); + + const links = [ + { label: "Services", to: "/services" }, + { label: "Doctors", to: "/doctors" }, + { label: "About", to: "/about" }, + { label: "Contact", to: "/contact" }, + ]; + + return ( + + + + + + + + Vitality Medical Center + + + {links.map((l) => ( + {l.label} + ))} + + + + Portal} /> + + Book Appointment + + + + + + + + + {links.map((l) => ( + setOpen(false)}>{l.label} + ))} + + setOpen(false)}>Book Appointment + + Patient Portal} /> + + + + + + + ); +} \ No newline at end of file