Spaces:
Sleeping
Sleeping
File size: 8,581 Bytes
bea55e2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | 'use client';
import { useEffect, useState } from 'react';
import { api } from '@/lib/api';
import { useAuth } from '@/components/auth-provider';
import { ChevronLeft, ChevronRight, Bell, Globe, Shield, Store, LogOut,
HelpCircle, Mail, Phone, User, Star, Sparkles } from 'lucide-react';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { PageSkeleton } from '@/components/page-skeleton';
import { API_BASE } from '@/lib/api';
export default function SettingsPage() {
const { user, loading: authLoading, logout } = useAuth();
const router = useRouter();
const [profile, setProfile] = useState<any>(null);
const [isSeller, setIsSeller] = useState(false);
useEffect(() => {
if (!authLoading && !user) {
router.push('/login?next=/settings');
return;
}
if (user) {
(async () => {
const profileResp = await api.profile.get();
if (profileResp.success && profileResp.profile) {
setProfile(profileResp.profile);
}
// Check seller status
try {
const sellerResp = await fetch(`${API_BASE}/api/seller-profile`, {
credentials: 'include',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ op: 'get' }),
});
if (sellerResp.ok) {
const sellerData = await sellerResp.json();
if (sellerData.success && sellerData.seller) {
setIsSeller(true);
}
}
} catch {}
})();
}
}, [user, authLoading, router]);
if (authLoading) { return <PageSkeleton variant="settings" />; }
const handleLogout = async () => {
await logout();
router.push('/');
};
const sectionLabel = "text-xs font-semibold text-slate-400 uppercase tracking-wide px-4 mb-2";
return (
<div className="ig-container min-h-screen pb-24 ig-topbar-offset">
{/* Top bar */}
<div className="fx-topbar ig-topbar">
<button onClick={() => router.push('/profile')} className="ig-icon-btn" aria-label="Back">
<ChevronLeft className="w-6 h-6" />
</button>
<h1 className="text-base font-semibold flex-1 ml-2">Settings</h1>
</div>
{/* Account section */}
<div className="pt-4">
<h2 className={sectionLabel}>Account</h2>
<div className="divide-y divide-white/5 border-y border-white/5">
<Link href="/profile" className="flex items-center gap-3 px-4 py-3.5 hover:bg-white/5 transition-colors">
<User className="w-5 h-5 text-white shrink-0" />
<div className="flex-1">
<div className="font-medium text-sm">Edit Profile</div>
<div className="text-xs text-slate-400">{profile?.full_name || user?.email}</div>
</div>
<ChevronRight className="w-4 h-4 text-slate-600" />
</Link>
<div className="flex items-center gap-3 px-4 py-3.5">
<Mail className="w-5 h-5 text-slate-400 shrink-0" />
<div className="flex-1">
<div className="font-medium text-sm">Email</div>
<div className="text-xs text-slate-400">{user?.email}</div>
</div>
</div>
<div className="flex items-center gap-3 px-4 py-3.5">
<Phone className="w-5 h-5 text-slate-400 shrink-0" />
<div className="flex-1">
<div className="font-medium text-sm">Phone</div>
<div className="text-xs text-slate-400">{profile?.phone || 'Not set'}</div>
</div>
</div>
</div>
</div>
{/* Preferences */}
<div className="pt-6">
<h2 className={sectionLabel}>Preferences</h2>
<div className="divide-y divide-white/5 border-y border-white/5">
<ToggleRow icon={Bell} label="Push Notifications" desc="Order updates & deals" defaultOn />
<ToggleRow icon={Star} label="Email Digest" desc="Weekly recommendation" defaultOn />
<ToggleRow icon={Globe} label="Location Services" desc="For local product suggestions" />
</div>
</div>
{/* Seller section */}
<div className="pt-6">
<h2 className={sectionLabel}>Selling</h2>
<div className="divide-y divide-white/5 border-y border-white/5">
{isSeller ? (
<Link href="/seller" className="flex items-center gap-3 px-4 py-3.5 hover:bg-white/5 transition-colors">
<Store className="w-5 h-5 text-white shrink-0" />
<div className="flex-1">
<div className="font-medium text-sm">Seller Dashboard</div>
<div className="text-xs text-slate-400">Manage your products, orders & analytics</div>
</div>
<ChevronRight className="w-4 h-4 text-slate-600" />
</Link>
) : (
<Link href="/become-seller" className="flex items-center gap-3 px-4 py-3.5 hover:bg-white/5 transition-colors">
<Store className="w-5 h-5 text-white shrink-0" />
<div className="flex-1">
<div className="font-medium text-sm">Become a Seller</div>
<div className="text-xs text-slate-400">Start selling on Cellex — it's free</div>
</div>
<ChevronRight className="w-4 h-4 text-slate-600" />
</Link>
)}
</div>
</div>
{/* Support */}
<div className="pt-6">
<h2 className={sectionLabel}>Support</h2>
<div className="divide-y divide-white/5 border-y border-white/5">
<Link href="/telegram" className="flex items-center gap-3 px-4 py-3.5 hover:bg-white/5 transition-colors">
<HelpCircle className="w-5 h-5 text-white shrink-0" />
<div className="flex-1">
<div className="font-medium text-sm">Help & Support</div>
<div className="text-xs text-slate-400">Get help via Telegram</div>
</div>
<ChevronRight className="w-4 h-4 text-slate-600" />
</Link>
<Link href="/ai-chat" className="flex items-center gap-3 px-4 py-3.5 hover:bg-white/5 transition-colors">
<Sparkles className="w-5 h-5 text-white shrink-0" />
<div className="flex-1">
<div className="font-medium text-sm">Ask AI Assistant</div>
<div className="text-xs text-slate-400">Get instant help from our AI</div>
</div>
<ChevronRight className="w-4 h-4 text-slate-600" />
</Link>
</div>
</div>
{/* Security */}
<div className="pt-6">
<h2 className={sectionLabel}>Security</h2>
<div className="divide-y divide-white/5 border-y border-white/5">
<div className="flex items-center gap-3 px-4 py-3.5">
<Shield className="w-5 h-5 text-slate-400 shrink-0" />
<div className="flex-1">
<div className="font-medium text-sm">Account Security</div>
<div className="text-xs text-slate-400">HTTP-only cookie auth · 7-day session</div>
</div>
</div>
</div>
</div>
{/* Logout */}
<div className="px-4 mt-6">
<button onClick={handleLogout} className="w-full text-red-400 border border-white/10 hover:bg-white/5 rounded-md py-2.5 text-sm font-semibold">
<LogOut className="w-4 h-4 inline mr-2" /> Logout
</button>
</div>
<div className="text-center text-[10px] text-slate-500 pt-4">
Cellex v0.2.15 · Nigeria's #1 social marketplace
</div>
</div>
);
}
function ToggleRow({ icon: Icon, label, desc, defaultOn }: { icon: any; label: string; desc: string; defaultOn?: boolean }) {
const [on, setOn] = useState(!!defaultOn);
return (
<div className="flex items-center gap-3 px-4 py-3.5">
<Icon className="w-5 h-5 text-slate-400 shrink-0" />
<div className="flex-1">
<div className="font-medium text-sm">{label}</div>
<div className="text-xs text-slate-400">{desc}</div>
</div>
<button
type="button"
onClick={() => setOn(!on)}
className={`relative w-11 h-6 rounded-full transition-colors shrink-0 ${on ? 'bg-indigo-600' : 'bg-white/10'}`}
aria-pressed={on}
aria-label={label}
>
<span
className={`absolute top-0.5 left-0.5 w-5 h-5 rounded-full bg-white/10 shadow transition-transform ${
on ? 'translate-x-5' : 'translate-x-0'
}`}
/>
</button>
</div>
);
}
|