diff --git a/src/pages/AccountConfirmation.tsx b/src/pages/AccountConfirmation.tsx index d7bf9a0..cd8a9fa 100644 --- a/src/pages/AccountConfirmation.tsx +++ b/src/pages/AccountConfirmation.tsx @@ -1,45 +1,153 @@ +import { useState, useEffect } from "react"; import { useNavigate } from "react-router-dom"; import { Button } from "@/components/ui/button"; -import { CheckCircle } from "lucide-react"; +import { CheckCircle, Package } from "lucide-react"; import Header from "@/components/Header"; +import { useAuth } from "@/hooks/useAuth"; +import { supabase } from "@/integrations/supabase/client"; + +interface ProfileData { + street_address: string; + postal_code: string; + city: string; +} const AccountConfirmation = () => { const navigate = useNavigate(); + const { user, loading: authLoading } = useAuth(); + const [profile, setProfile] = useState(null); + const [isLoading, setIsLoading] = useState(true); + + useEffect(() => { + if (!authLoading && !user) { + navigate("/"); + return; + } + + if (user) { + fetchProfile(); + } + }, [user, authLoading, navigate]); + + const fetchProfile = async () => { + try { + const { data } = await supabase + .from("profiles") + .select("street_address, postal_code, city") + .eq("user_id", user!.id) + .maybeSingle(); + + if (data) { + setProfile({ + street_address: data.street_address || "", + postal_code: data.postal_code || "", + city: data.city || "", + }); + } + } finally { + setIsLoading(false); + } + }; + + if (authLoading || isLoading) { + return ( +
+
+
+

Laddar...

+
+
+ ); + } return (
-
-
-
- -
- -

- Uppgifter sparade! -

- -

- Dina kontuppgifter har sparats. Du kan nu beställa abonnemang med dessa uppgifter. -

+ {/* Back link */} +
+ +
-
- - - +
+ {/* Success message */} +
+
+ +
+

+ Uppgifter sparade! +

+

+ Dina kontuppgifter har uppdaterats. +

+
+ + {profile && (profile.street_address || profile.postal_code || profile.city) && ( +
+

Leveransadress:

+

+ {profile.street_address && {profile.street_address}
} + {(profile.postal_code || profile.city) && ( + {profile.postal_code} {profile.city} + )} +

+
+ )} +
+ + {/* Subscription status */} +
+
+ +

Mitt abonnemang

+
+ +
+

+ Du har inget aktivt abonnemang just nu. +

+
+ + +
+ + {/* Actions */} +
+ +