"use client" import { useEffect, useState } from "react" import { Building2, FileText, Loader2, AlertCircle, CheckCircle2, Save, Bell, BellOff } from "lucide-react" import { usePushNotifications } from "@/hooks/usePushNotifications" interface SupplierProfile { id: string companyName: string description: string | null user: { name: string | null email: string | null } _count: { products: number connections: number } } export default function SupplierSettingsPage() { const { permission, isSubscribed, loading: pushLoading, subscribe, unsubscribe } = usePushNotifications() const [pushActionLoading, setPushActionLoading] = useState(false) const [profile, setProfile] = useState(null) const [loading, setLoading] = useState(true) const [saving, setSaving] = useState(false) const [error, setError] = useState("") const [success, setSuccess] = useState("") const [formData, setFormData] = useState({ companyName: "", description: "" }) useEffect(() => { fetchProfile() }, []) useEffect(() => { if (success) { const timer = setTimeout(() => setSuccess(""), 5000) return () => clearTimeout(timer) } }, [success]) useEffect(() => { if (error) { const timer = setTimeout(() => setError(""), 5000) return () => clearTimeout(timer) } }, [error]) const fetchProfile = async () => { try { setLoading(true) const res = await fetch("/api/supplier/profile") if (!res.ok) throw new Error("Failed to fetch profile") const data = await res.json() setProfile(data.profile) setFormData({ companyName: data.profile.companyName || "", description: data.profile.description || "" }) setError("") } catch { setError("Failed to load profile") } finally { setLoading(false) } } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setSaving(true) setError("") try { const res = await fetch("/api/supplier/profile", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(formData) }) if (!res.ok) { const data = await res.json() throw new Error(data.message || "Failed to update profile") } setSuccess("Profile updated successfully") fetchProfile() } catch (err) { setError(err instanceof Error ? err.message : "Failed to update profile") } finally { setSaving(false) } } if (loading) { return (
) } return (

Settings

Manage your supplier account settings

{success && (
{success}
)} {error && (
{error}
)} {/* Profile Information */}

Company Information

setFormData({ ...formData, companyName: e.target.value })} className="w-full px-4 py-2 bg-white/5 border border-white/10 rounded-lg text-white placeholder:text-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/30 focus:border-indigo-500/50" placeholder="Your company name" />