"use client"; import { ArrowLeft, Key, Shield, User } from "lucide-react"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { useToast } from "@/hooks/use-toast"; // Platform session hook - same as in dashboard function usePlatformSession() { const [session, setSession] = useState<{ user: { id: string; email: string; name?: string; role: string; companyId?: string; }; } | null>(null); const [status, setStatus] = useState< "loading" | "authenticated" | "unauthenticated" >("loading"); useEffect(() => { const fetchSession = async () => { try { const response = await fetch("/api/platform/auth/session"); const sessionData = await response.json(); if (sessionData?.user?.isPlatformUser) { setSession(sessionData); setStatus("authenticated"); } else { setSession(null); setStatus("unauthenticated"); } } catch (error) { console.error("Platform session fetch error:", error); setSession(null); setStatus("unauthenticated"); } }; fetchSession(); }, []); return { data: session, status }; } export default function PlatformSettings() { const { data: session, status } = usePlatformSession(); const router = useRouter(); const { toast } = useToast(); const [isLoading, setIsLoading] = useState(false); const [profileData, setProfileData] = useState({ name: "", email: "", }); const [passwordData, setPasswordData] = useState({ currentPassword: "", newPassword: "", confirmPassword: "", }); useEffect(() => { if (status === "unauthenticated") { router.push("/platform/login"); } }, [status, router]); useEffect(() => { if (session?.user) { setProfileData({ name: session.user.name || "", email: session.user.email || "", }); } }, [session]); const handleProfileUpdate = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); try { // TODO: Implement profile update API endpoint toast({ title: "Profile Updated", description: "Your profile has been updated successfully.", }); } catch (_error) { toast({ title: "Error", description: "Failed to update profile. Please try again.", variant: "destructive", }); } finally { setIsLoading(false); } }; const handlePasswordChange = async (e: React.FormEvent) => { e.preventDefault(); if (passwordData.newPassword !== passwordData.confirmPassword) { toast({ title: "Error", description: "New passwords do not match.", variant: "destructive", }); return; } if (passwordData.newPassword.length < 12) { toast({ title: "Error", description: "Password must be at least 12 characters long.", variant: "destructive", }); return; } setIsLoading(true); try { // TODO: Implement password change API endpoint toast({ title: "Password Changed", description: "Your password has been changed successfully.", }); setPasswordData({ currentPassword: "", newPassword: "", confirmPassword: "", }); } catch (_error) { toast({ title: "Error", description: "Failed to change password. Please try again.", variant: "destructive", }); } finally { setIsLoading(false); } }; if (status === "loading") { return (
Loading...
Manage your platform account settings
You are logged in as a{" "} {session.user.platformRole || "Platform User"}
User ID: {session.user.id}
Session Type: Platform
Advanced administrative options are available in the individual company management pages.