eeshaAI commited on
Commit
d20e8cb
·
1 Parent(s): 61e536d

feat: upgraded account page + settings + become-a-seller flow

Browse files
package.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "nextjs_tailwind_shadcn_ts",
3
- "version": "0.2.14",
4
  "private": true,
5
  "scripts": {
6
  "dev": "next dev -p 3000 2>&1 | tee dev.log",
 
1
  {
2
  "name": "nextjs_tailwind_shadcn_ts",
3
+ "version": "0.2.15",
4
  "private": true,
5
  "scripts": {
6
  "dev": "next dev -p 3000 2>&1 | tee dev.log",
src/app/become-seller/loading.tsx ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import { PageSkeleton } from '@/components/page-skeleton';
2
+ export default function Loading() { return <PageSkeleton variant="minimal" />; }
src/app/become-seller/page.tsx ADDED
@@ -0,0 +1,351 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import { useRouter } from 'next/navigation';
5
+ import Link from 'next/link';
6
+ import { Button } from '@/components/ui/button';
7
+ import { Card } from '@/components/ui/card';
8
+ import { Input } from '@/components/ui/input';
9
+ import { Label } from '@/components/ui/label';
10
+ import { Textarea } from '@/components/ui/textarea';
11
+ import { useToast } from '@/hooks/use-toast';
12
+ import {
13
+ ChevronLeft, Store, Upload, Check, User, Building, Sprout,
14
+ Camera, MapPin, FileText, Loader2
15
+ } from 'lucide-react';
16
+
17
+ const CATEGORIES = [
18
+ 'Electronics', 'Fashion', 'Home', 'Beauty', 'Farm', 'Sports',
19
+ 'Books', 'Food', 'Toys', 'General'
20
+ ];
21
+
22
+ const SELLER_TYPES = [
23
+ { value: 'individual', label: 'Individual', icon: User, desc: 'Selling personal items' },
24
+ { value: 'business', label: 'Business', icon: Building, desc: 'Registered business' },
25
+ { value: 'farmer', label: 'Farmer', icon: Sprout, desc: 'Farm-fresh produce' },
26
+ ];
27
+
28
+ export default function BecomeSellerPage() {
29
+ const router = useRouter();
30
+ const { toast } = useToast();
31
+
32
+ const [step, setStep] = useState(1);
33
+ const [saving, setSaving] = useState(false);
34
+
35
+ // Form state
36
+ const [businessName, setBusinessName] = useState('');
37
+ const [sellerType, setSellerType] = useState('business');
38
+ const [businessCategory, setBusinessCategory] = useState('Electronics');
39
+ const [businessLocation, setBusinessLocation] = useState('');
40
+ const [businessDescription, setBusinessDescription] = useState('');
41
+ const [farmName, setFarmName] = useState('');
42
+ const [profileImage, setProfileImage] = useState('');
43
+
44
+ const handleImageUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
45
+ const file = e.target.files?.[0];
46
+ if (!file) return;
47
+ if (file.size > 2 * 1024 * 1024) {
48
+ toast({ title: 'Image too large', description: 'Max 2MB', variant: 'destructive' });
49
+ return;
50
+ }
51
+ const reader = new FileReader();
52
+ reader.onloadend = () => setProfileImage(reader.result as string);
53
+ reader.readAsDataURL(file);
54
+ };
55
+
56
+ const canProceedStep1 = businessName.trim().length >= 2;
57
+ const canProceedStep2 = businessLocation.trim().length >= 3;
58
+ const canSubmit = canProceedStep1 && canProceedStep2;
59
+
60
+ const submit = async () => {
61
+ if (!canSubmit) return;
62
+ setSaving(true);
63
+ try {
64
+ const resp = await fetch('/api/seller-profile', {
65
+ method: 'POST',
66
+ headers: { 'Content-Type': 'application/json' },
67
+ body: JSON.stringify({
68
+ op: 'update',
69
+ business_name: businessName,
70
+ business_description: businessDescription,
71
+ business_category: businessCategory,
72
+ business_location: businessLocation,
73
+ seller_type: sellerType,
74
+ farm_name: sellerType === 'farmer' ? farmName : '',
75
+ profile_image: profileImage,
76
+ }),
77
+ });
78
+ const data = await resp.json();
79
+ if (data.success) {
80
+ toast({ title: 'Welcome to Cellex Selling! 🎉', description: 'Your seller account is ready' });
81
+ router.push('/seller');
82
+ } else {
83
+ toast({ title: 'Error', description: data.error || 'Failed to create seller account', variant: 'destructive' });
84
+ }
85
+ } catch (err) {
86
+ toast({ title: 'Error', description: 'Network error. Please try again.', variant: 'destructive' });
87
+ }
88
+ setSaving(false);
89
+ };
90
+
91
+ return (
92
+ <div className="max-w-md mx-auto px-4 py-4 pb-24">
93
+ {/* Header */}
94
+ <div className="flex items-center gap-3 mb-6">
95
+ <Link href="/settings" className="w-9 h-9 rounded-full hover:bg-slate-100 flex items-center justify-center transition-colors">
96
+ <ChevronLeft className="w-5 h-5" />
97
+ </Link>
98
+ <div className="flex-1">
99
+ <h1 className="text-lg font-bold">Become a Seller</h1>
100
+ <p className="text-xs text-slate-500">Step {step} of 3</p>
101
+ </div>
102
+ </div>
103
+
104
+ {/* Progress bar */}
105
+ <div className="flex gap-1.5 mb-6">
106
+ {[1, 2, 3].map((s) => (
107
+ <div
108
+ key={s}
109
+ className={`h-1.5 flex-1 rounded-full transition-colors ${s <= step ? 'bg-black' : 'bg-slate-200'}`}
110
+ />
111
+ ))}
112
+ </div>
113
+
114
+ {/* Step 1: Store identity */}
115
+ {step === 1 && (
116
+ <div className="space-y-5">
117
+ <div>
118
+ <h2 className="text-xl font-bold mb-1">Set up your store</h2>
119
+ <p className="text-sm text-slate-500">Tell us about your business</p>
120
+ </div>
121
+
122
+ {/* Profile image */}
123
+ <div className="flex flex-col items-center gap-2">
124
+ <label className="cursor-pointer">
125
+ <div className="w-24 h-24 rounded-full bg-slate-100 border-2 border-dashed border-slate-300 flex items-center justify-center overflow-hidden hover:border-black transition-colors">
126
+ {profileImage ? (
127
+ <img src={profileImage} alt="" className="w-full h-full object-cover" />
128
+ ) : (
129
+ <Camera className="w-8 h-8 text-slate-400" />
130
+ )}
131
+ </div>
132
+ <input type="file" accept="image/*" className="hidden" onChange={handleImageUpload} />
133
+ </label>
134
+ <span className="text-xs text-slate-500">Tap to upload store logo</span>
135
+ </div>
136
+
137
+ {/* Store name */}
138
+ <div className="space-y-1.5">
139
+ <Label className="text-xs font-bold">Store Name *</Label>
140
+ <Input
141
+ value={businessName}
142
+ onChange={(e) => setBusinessName(e.target.value)}
143
+ placeholder="e.g. Ada's Fashion Store"
144
+ className="h-11"
145
+ />
146
+ </div>
147
+
148
+ {/* Seller type */}
149
+ <div className="space-y-2">
150
+ <Label className="text-xs font-bold">Seller Type</Label>
151
+ <div className="grid grid-cols-3 gap-2">
152
+ {SELLER_TYPES.map((type) => {
153
+ const Icon = type.icon;
154
+ const isActive = sellerType === type.value;
155
+ return (
156
+ <button
157
+ key={type.value}
158
+ onClick={() => setSellerType(type.value)}
159
+ className={`flex flex-col items-center gap-1 p-3 rounded-xl border-2 transition-all ${
160
+ isActive ? 'border-black bg-slate-50' : 'border-slate-200'
161
+ }`}
162
+ >
163
+ <Icon className={`w-5 h-5 ${isActive ? 'text-black' : 'text-slate-400'}`} />
164
+ <span className={`text-xs font-bold ${isActive ? 'text-black' : 'text-slate-500'}`}>{type.label}</span>
165
+ </button>
166
+ );
167
+ })}
168
+ </div>
169
+ <p className="text-xs text-slate-500">
170
+ {SELLER_TYPES.find(t => t.value === sellerType)?.desc}
171
+ </p>
172
+ </div>
173
+
174
+ {/* Farm name (conditional) */}
175
+ {sellerType === 'farmer' && (
176
+ <div className="space-y-1.5">
177
+ <Label className="text-xs font-bold">Farm Name</Label>
178
+ <Input
179
+ value={farmName}
180
+ onChange={(e) => setFarmName(e.target.value)}
181
+ placeholder="e.g. Green Valley Farms"
182
+ className="h-11"
183
+ />
184
+ </div>
185
+ )}
186
+
187
+ <Button
188
+ onClick={() => setStep(2)}
189
+ disabled={!canProceedStep1}
190
+ className="w-full h-11 bg-black text-white"
191
+ >
192
+ Continue
193
+ </Button>
194
+ </div>
195
+ )}
196
+
197
+ {/* Step 2: Location & category */}
198
+ {step === 2 && (
199
+ <div className="space-y-5">
200
+ <div>
201
+ <h2 className="text-xl font-bold mb-1">Location & Category</h2>
202
+ <p className="text-sm text-slate-500">Help buyers find you</p>
203
+ </div>
204
+
205
+ {/* Location */}
206
+ <div className="space-y-1.5">
207
+ <Label className="text-xs font-bold flex items-center gap-1.5">
208
+ <MapPin className="w-3 h-3" /> Business Location *
209
+ </Label>
210
+ <Input
211
+ value={businessLocation}
212
+ onChange={(e) => setBusinessLocation(e.target.value)}
213
+ placeholder="e.g. Lagos, Nigeria"
214
+ className="h-11"
215
+ />
216
+ </div>
217
+
218
+ {/* Category */}
219
+ <div className="space-y-2">
220
+ <Label className="text-xs font-bold">Primary Category</Label>
221
+ <div className="grid grid-cols-3 gap-2">
222
+ {CATEGORIES.map((cat) => {
223
+ const isActive = businessCategory === cat;
224
+ return (
225
+ <button
226
+ key={cat}
227
+ onClick={() => setBusinessCategory(cat)}
228
+ className={`px-3 py-2.5 rounded-lg border-2 text-xs font-bold transition-all ${
229
+ isActive ? 'border-black bg-slate-50 text-black' : 'border-slate-200 text-slate-500'
230
+ }`}
231
+ >
232
+ {cat}
233
+ </button>
234
+ );
235
+ })}
236
+ </div>
237
+ </div>
238
+
239
+ {/* Description */}
240
+ <div className="space-y-1.5">
241
+ <Label className="text-xs font-bold flex items-center gap-1.5">
242
+ <FileText className="w-3 h-3" /> Store Description
243
+ </Label>
244
+ <Textarea
245
+ value={businessDescription}
246
+ onChange={(e) => setBusinessDescription(e.target.value)}
247
+ rows={3}
248
+ placeholder="Tell buyers what makes your store special..."
249
+ className="resize-none"
250
+ />
251
+ <p className="text-[10px] text-slate-400">{businessDescription.length}/300 characters</p>
252
+ </div>
253
+
254
+ <div className="flex gap-2">
255
+ <Button onClick={() => setStep(1)} variant="outline" className="h-11 flex-1">
256
+ Back
257
+ </Button>
258
+ <Button
259
+ onClick={() => setStep(3)}
260
+ disabled={!canProceedStep2}
261
+ className="h-11 flex-1 bg-black text-white"
262
+ >
263
+ Continue
264
+ </Button>
265
+ </div>
266
+ </div>
267
+ )}
268
+
269
+ {/* Step 3: Review & submit */}
270
+ {step === 3 && (
271
+ <div className="space-y-5">
272
+ <div>
273
+ <h2 className="text-xl font-bold mb-1">Review & Launch</h2>
274
+ <p className="text-sm text-slate-500">Confirm your store details</p>
275
+ </div>
276
+
277
+ {/* Summary card */}
278
+ <Card className="p-5 border-slate-200 space-y-3">
279
+ <div className="flex items-center gap-3 pb-3 border-b border-slate-100">
280
+ <div className="w-14 h-14 rounded-full bg-slate-100 flex items-center justify-center overflow-hidden shrink-0">
281
+ {profileImage ? (
282
+ <img src={profileImage} alt="" className="w-full h-full object-cover" />
283
+ ) : (
284
+ <Store className="w-6 h-6 text-slate-400" />
285
+ )}
286
+ </div>
287
+ <div className="flex-1 min-w-0">
288
+ <div className="font-bold text-sm truncate">{businessName}</div>
289
+ <div className="text-xs text-slate-500 capitalize">{sellerType} · {businessCategory}</div>
290
+ </div>
291
+ </div>
292
+
293
+ <ReviewRow label="Location" value={businessLocation} />
294
+ {sellerType === 'farmer' && farmName && <ReviewRow label="Farm" value={farmName} />}
295
+ {businessDescription && <ReviewRow label="Description" value={businessDescription} />}
296
+ </Card>
297
+
298
+ {/* What happens next */}
299
+ <div className="bg-slate-50 rounded-xl p-4 space-y-2">
300
+ <div className="text-xs font-bold text-slate-700 mb-2">What happens next?</div>
301
+ {[
302
+ 'Add your first product',
303
+ 'Set up payment methods',
304
+ 'Start receiving orders',
305
+ 'Go live to showcase products',
306
+ ].map((item, i) => (
307
+ <div key={i} className="flex items-center gap-2 text-xs text-slate-600">
308
+ <div className="w-4 h-4 rounded-full bg-black text-white flex items-center justify-center text-[9px] font-bold shrink-0">
309
+ {i + 1}
310
+ </div>
311
+ {item}
312
+ </div>
313
+ ))}
314
+ </div>
315
+
316
+ <div className="flex gap-2">
317
+ <Button onClick={() => setStep(2)} variant="outline" className="h-11 flex-1">
318
+ Back
319
+ </Button>
320
+ <Button
321
+ onClick={submit}
322
+ disabled={!canSubmit || saving}
323
+ className="h-11 flex-1 bg-black text-white"
324
+ >
325
+ {saving ? (
326
+ <>
327
+ <Loader2 className="w-4 h-4 mr-2 animate-spin" />
328
+ Launching...
329
+ </>
330
+ ) : (
331
+ <>
332
+ <Check className="w-4 h-4 mr-2" />
333
+ Launch Store
334
+ </>
335
+ )}
336
+ </Button>
337
+ </div>
338
+ </div>
339
+ )}
340
+ </div>
341
+ );
342
+ }
343
+
344
+ function ReviewRow({ label, value }: { label: string; value: string }) {
345
+ return (
346
+ <div className="flex gap-2 text-sm">
347
+ <span className="text-xs text-slate-500 w-20 shrink-0 pt-0.5">{label}</span>
348
+ <span className="text-slate-800 flex-1">{value}</span>
349
+ </div>
350
+ );
351
+ }
src/app/profile/page.tsx CHANGED
@@ -9,7 +9,9 @@ import { Input } from '@/components/ui/input';
9
  import { Label } from '@/components/ui/label';
10
  import { Textarea } from '@/components/ui/textarea';
11
  import {
12
- User, Package, Heart, Store, LogOut, Link2, Send, ChevronRight, Mail, Phone, MapPin
 
 
13
  } from 'lucide-react';
14
  import Link from 'next/link';
15
  import { useRouter } from 'next/navigation';
@@ -22,6 +24,7 @@ export default function ProfilePage() {
22
  const [profile, setProfile] = useState<any>(null);
23
  const [ordersCount, setOrdersCount] = useState(0);
24
  const [wishlistCount, setWishlistCount] = useState(0);
 
25
  const [editing, setEditing] = useState(false);
26
  const [saving, setSaving] = useState(false);
27
  const [fullName, setFullName] = useState('');
@@ -48,6 +51,21 @@ export default function ProfilePage() {
48
  }
49
  if (ordersResp.success) setOrdersCount(ordersResp.orders?.length || 0);
50
  if (wishResp.success) setWishlistCount(wishResp.items?.length || 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  })();
52
  }
53
  }, [user, authLoading, router]);
@@ -81,23 +99,43 @@ export default function ProfilePage() {
81
  const menuItems = [
82
  { href: '/orders', icon: Package, label: 'My Orders', sub: `${ordersCount} order(s)`, color: 'bg-blue-100 text-blue-600' },
83
  { href: '/wishlist', icon: Heart, label: 'Wishlist', sub: `${wishlistCount} item(s)`, color: 'bg-red-100 text-red-600' },
84
- { href: '/seller', icon: Store, label: 'Seller Dashboard', sub: 'Manage your store', color: 'bg-green-100 text-green-600' },
 
 
 
85
  { href: '/link-account', icon: Link2, label: 'Link WhatsApp', sub: 'Shop via WhatsApp', color: 'bg-emerald-100 text-emerald-600' },
86
  { href: '/telegram', icon: Send, label: 'Telegram Alerts', sub: 'Get deals on Telegram', color: 'bg-cyan-100 text-cyan-600' },
87
  ];
88
 
89
  return (
90
- <div className="max-w-3xl mx-auto px-3 sm:px-4 lg:px-6 py-4 space-y-4">
91
- <h1 className="text-xl font-bold">My Account</h1>
 
 
 
 
 
 
92
 
93
  {/* User card */}
94
- <Card className="p-4 border-slate-100">
95
  <div className="flex items-center gap-3 mb-4">
96
- <div className="w-14 h-14 rounded-full brand-gradient flex items-center justify-center text-white font-bold text-xl">
97
- {(user?.email || '?').charAt(0).toUpperCase()}
 
 
 
 
98
  </div>
99
  <div className="flex-1 min-w-0">
100
- <div className="font-bold text-sm truncate">{fullName || user?.email?.split('@')[0]}</div>
 
 
 
 
 
 
 
101
  <div className="text-xs text-slate-500 truncate">{user?.email}</div>
102
  </div>
103
  {!editing && (
@@ -120,7 +158,7 @@ export default function ProfilePage() {
120
  <Textarea value={address} onChange={(e) => setAddress(e.target.value)} rows={2} placeholder="House, street, area, city" />
121
  </div>
122
  <div className="flex gap-2">
123
- <Button onClick={saveProfile} disabled={saving} className="brand-gradient text-primary-foreground flex-1">
124
  {saving ? 'Saving...' : 'Save'}
125
  </Button>
126
  <Button variant="outline" onClick={() => setEditing(false)}>Cancel</Button>
@@ -148,27 +186,53 @@ export default function ProfilePage() {
148
  )}
149
  </Card>
150
 
151
- {/* Quick menu */}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  <div className="space-y-2">
153
  {menuItems.map((item) => {
154
  const Icon = item.icon;
155
  return (
156
  <Link key={item.href} href={item.href}>
157
  <Card className="p-3 border-slate-100 hover:shadow-md transition-shadow flex items-center gap-3">
158
- <div className={`w-10 h-10 rounded-xl ${item.color} flex items-center justify-center`}>
159
  <Icon className="w-5 h-5" />
160
  </div>
161
- <div className="flex-1">
162
  <div className="font-bold text-sm">{item.label}</div>
163
- <div className="text-xs text-slate-500">{item.sub}</div>
164
  </div>
165
- <ChevronRight className="w-4 h-4 text-slate-300" />
166
  </Card>
167
  </Link>
168
  );
169
  })}
170
  </div>
171
 
 
172
  <Button onClick={handleLogout} variant="outline" className="w-full text-red-500 border-red-200 hover:bg-red-50">
173
  <LogOut className="w-4 h-4 mr-2" /> Logout
174
  </Button>
 
9
  import { Label } from '@/components/ui/label';
10
  import { Textarea } from '@/components/ui/textarea';
11
  import {
12
+ User, Package, Heart, Store, LogOut, Link2, Send, ChevronRight,
13
+ Mail, Phone, MapPin, Settings, ShoppingBag, Star, Bell, Globe,
14
+ Shield, HelpCircle, ChevronLeft
15
  } from 'lucide-react';
16
  import Link from 'next/link';
17
  import { useRouter } from 'next/navigation';
 
24
  const [profile, setProfile] = useState<any>(null);
25
  const [ordersCount, setOrdersCount] = useState(0);
26
  const [wishlistCount, setWishlistCount] = useState(0);
27
+ const [isSeller, setIsSeller] = useState(false);
28
  const [editing, setEditing] = useState(false);
29
  const [saving, setSaving] = useState(false);
30
  const [fullName, setFullName] = useState('');
 
51
  }
52
  if (ordersResp.success) setOrdersCount(ordersResp.orders?.length || 0);
53
  if (wishResp.success) setWishlistCount(wishResp.items?.length || 0);
54
+
55
+ // Check if user is already a seller
56
+ try {
57
+ const sellerResp = await fetch('/api/seller-profile', {
58
+ method: 'POST',
59
+ headers: { 'Content-Type': 'application/json' },
60
+ body: JSON.stringify({ op: 'get' }),
61
+ });
62
+ if (sellerResp.ok) {
63
+ const sellerData = await sellerResp.json();
64
+ if (sellerData.success && sellerData.seller) {
65
+ setIsSeller(true);
66
+ }
67
+ }
68
+ } catch {}
69
  })();
70
  }
71
  }, [user, authLoading, router]);
 
99
  const menuItems = [
100
  { href: '/orders', icon: Package, label: 'My Orders', sub: `${ordersCount} order(s)`, color: 'bg-blue-100 text-blue-600' },
101
  { href: '/wishlist', icon: Heart, label: 'Wishlist', sub: `${wishlistCount} item(s)`, color: 'bg-red-100 text-red-600' },
102
+ ...(isSeller
103
+ ? [{ href: '/seller', icon: Store, label: 'Seller Dashboard', sub: 'Manage your store', color: 'bg-green-100 text-green-600' }]
104
+ : [{ href: '/become-seller', icon: Store, label: 'Become a Seller', sub: 'Start selling on Cellex', color: 'bg-green-100 text-green-600' }]
105
+ ),
106
  { href: '/link-account', icon: Link2, label: 'Link WhatsApp', sub: 'Shop via WhatsApp', color: 'bg-emerald-100 text-emerald-600' },
107
  { href: '/telegram', icon: Send, label: 'Telegram Alerts', sub: 'Get deals on Telegram', color: 'bg-cyan-100 text-cyan-600' },
108
  ];
109
 
110
  return (
111
+ <div className="max-w-3xl mx-auto px-3 sm:px-4 lg:px-6 py-4 pb-24 space-y-4">
112
+ {/* Header with back + settings */}
113
+ <div className="flex items-center justify-between">
114
+ <h1 className="text-xl font-bold">My Account</h1>
115
+ <Link href="/settings" className="w-9 h-9 rounded-full hover:bg-slate-100 flex items-center justify-center transition-colors">
116
+ <Settings className="w-5 h-5 text-slate-600" />
117
+ </Link>
118
+ </div>
119
 
120
  {/* User card */}
121
+ <Card className="p-4 border-slate-100 shadow-sm">
122
  <div className="flex items-center gap-3 mb-4">
123
+ <div className="w-16 h-16 rounded-full bg-black flex items-center justify-center text-white font-bold text-xl shrink-0">
124
+ {profile?.profile_image ? (
125
+ <img src={profile.profile_image} alt="" className="w-full h-full object-cover rounded-full" />
126
+ ) : (
127
+ (user?.email || '?').charAt(0).toUpperCase()
128
+ )}
129
  </div>
130
  <div className="flex-1 min-w-0">
131
+ <div className="font-bold text-sm truncate flex items-center gap-1.5">
132
+ {fullName || user?.email?.split('@')[0]}
133
+ {isSeller && (
134
+ <span className="inline-flex items-center gap-0.5 text-[9px] font-bold bg-black text-white px-1.5 py-0.5 rounded-full">
135
+ <Store className="w-2.5 h-2.5" /> SELLER
136
+ </span>
137
+ )}
138
+ </div>
139
  <div className="text-xs text-slate-500 truncate">{user?.email}</div>
140
  </div>
141
  {!editing && (
 
158
  <Textarea value={address} onChange={(e) => setAddress(e.target.value)} rows={2} placeholder="House, street, area, city" />
159
  </div>
160
  <div className="flex gap-2">
161
+ <Button onClick={saveProfile} disabled={saving} className="bg-black text-white flex-1">
162
  {saving ? 'Saving...' : 'Save'}
163
  </Button>
164
  <Button variant="outline" onClick={() => setEditing(false)}>Cancel</Button>
 
186
  )}
187
  </Card>
188
 
189
+ {/* Quick stats */}
190
+ <div className="grid grid-cols-3 gap-2">
191
+ <Link href="/orders">
192
+ <Card className="p-3 border-slate-100 text-center hover:shadow-md transition-shadow">
193
+ <Package className="w-5 h-5 mx-auto text-blue-500 mb-1" />
194
+ <div className="text-lg font-bold">{ordersCount}</div>
195
+ <div className="text-[10px] text-slate-500">Orders</div>
196
+ </Card>
197
+ </Link>
198
+ <Link href="/wishlist">
199
+ <Card className="p-3 border-slate-100 text-center hover:shadow-md transition-shadow">
200
+ <Heart className="w-5 h-5 mx-auto text-red-500 mb-1" />
201
+ <div className="text-lg font-bold">{wishlistCount}</div>
202
+ <div className="text-[10px] text-slate-500">Wishlist</div>
203
+ </Card>
204
+ </Link>
205
+ <Link href={isSeller ? "/seller" : "/become-seller"}>
206
+ <Card className="p-3 border-slate-100 text-center hover:shadow-md transition-shadow">
207
+ <Store className="w-5 h-5 mx-auto text-green-500 mb-1" />
208
+ <div className="text-lg font-bold">{isSeller ? 'Active' : 'Start'}</div>
209
+ <div className="text-[10px] text-slate-500">Seller</div>
210
+ </Card>
211
+ </Link>
212
+ </div>
213
+
214
+ {/* Menu items */}
215
  <div className="space-y-2">
216
  {menuItems.map((item) => {
217
  const Icon = item.icon;
218
  return (
219
  <Link key={item.href} href={item.href}>
220
  <Card className="p-3 border-slate-100 hover:shadow-md transition-shadow flex items-center gap-3">
221
+ <div className={`w-10 h-10 rounded-xl ${item.color} flex items-center justify-center shrink-0`}>
222
  <Icon className="w-5 h-5" />
223
  </div>
224
+ <div className="flex-1 min-w-0">
225
  <div className="font-bold text-sm">{item.label}</div>
226
+ <div className="text-xs text-slate-500 truncate">{item.sub}</div>
227
  </div>
228
+ <ChevronRight className="w-4 h-4 text-slate-300 shrink-0" />
229
  </Card>
230
  </Link>
231
  );
232
  })}
233
  </div>
234
 
235
+ {/* Logout */}
236
  <Button onClick={handleLogout} variant="outline" className="w-full text-red-500 border-red-200 hover:bg-red-50">
237
  <LogOut className="w-4 h-4 mr-2" /> Logout
238
  </Button>
src/app/settings/loading.tsx ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import { PageSkeleton } from '@/components/page-skeleton';
2
+ export default function Loading() { return <PageSkeleton variant="minimal" />; }
src/app/settings/page.tsx ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use client';
2
+
3
+ import { useEffect, useState } from 'react';
4
+ import { api } from '@/lib/api';
5
+ import { useAuth } from '@/components/auth-provider';
6
+ import { Button } from '@/components/ui/button';
7
+ import { Card } from '@/components/ui/card';
8
+ import {
9
+ ChevronLeft, ChevronRight, Bell, Globe, Shield, Store, LogOut,
10
+ HelpCircle, Mail, Phone, User, Star, Sparkles
11
+ } from 'lucide-react';
12
+ import Link from 'next/link';
13
+ import { useRouter } from 'next/navigation';
14
+
15
+ export default function SettingsPage() {
16
+ const { user, loading: authLoading, logout } = useAuth();
17
+ const router = useRouter();
18
+ const [profile, setProfile] = useState<any>(null);
19
+ const [isSeller, setIsSeller] = useState(false);
20
+
21
+ useEffect(() => {
22
+ if (!authLoading && !user) {
23
+ router.push('/login?next=/settings');
24
+ return;
25
+ }
26
+ if (user) {
27
+ (async () => {
28
+ const profileResp = await api.profile.get();
29
+ if (profileResp.success && profileResp.profile) {
30
+ setProfile(profileResp.profile);
31
+ }
32
+ // Check seller status
33
+ try {
34
+ const sellerResp = await fetch('/api/seller-profile', {
35
+ method: 'POST',
36
+ headers: { 'Content-Type': 'application/json' },
37
+ body: JSON.stringify({ op: 'get' }),
38
+ });
39
+ if (sellerResp.ok) {
40
+ const sellerData = await sellerResp.json();
41
+ if (sellerData.success && sellerData.seller) {
42
+ setIsSeller(true);
43
+ }
44
+ }
45
+ } catch {}
46
+ })();
47
+ }
48
+ }, [user, authLoading, router]);
49
+
50
+ if (authLoading) {
51
+ return (
52
+ <div className="flex items-center justify-center min-h-[60vh]">
53
+ <div className="w-8 h-8 border-3 border-slate-200 border-t-primary rounded-full animate-spin" />
54
+ </div>
55
+ );
56
+ }
57
+
58
+ const handleLogout = async () => {
59
+ await logout();
60
+ router.push('/');
61
+ };
62
+
63
+ return (
64
+ <div className="max-w-2xl mx-auto px-3 sm:px-4 py-4 pb-24 space-y-4">
65
+ {/* Header */}
66
+ <div className="flex items-center gap-3">
67
+ <Link href="/profile" className="w-9 h-9 rounded-full hover:bg-slate-100 flex items-center justify-center transition-colors">
68
+ <ChevronLeft className="w-5 h-5" />
69
+ </Link>
70
+ <h1 className="text-xl font-bold">Settings</h1>
71
+ </div>
72
+
73
+ {/* Account section */}
74
+ <div>
75
+ <h2 className="text-xs font-bold text-slate-500 uppercase tracking-wide px-1 mb-2">Account</h2>
76
+ <Card className="border-slate-100 divide-y divide-slate-100">
77
+ {/* Edit profile */}
78
+ <Link href="/profile" className="flex items-center gap-3 p-4 hover:bg-slate-50 transition-colors">
79
+ <div className="w-9 h-9 rounded-lg bg-blue-100 text-blue-600 flex items-center justify-center shrink-0">
80
+ <User className="w-4 h-4" />
81
+ </div>
82
+ <div className="flex-1">
83
+ <div className="font-medium text-sm">Edit Profile</div>
84
+ <div className="text-xs text-slate-500">{profile?.full_name || user?.email}</div>
85
+ </div>
86
+ <ChevronRight className="w-4 h-4 text-slate-300" />
87
+ </Link>
88
+
89
+ {/* Email */}
90
+ <div className="flex items-center gap-3 p-4">
91
+ <div className="w-9 h-9 rounded-lg bg-slate-100 text-slate-500 flex items-center justify-center shrink-0">
92
+ <Mail className="w-4 h-4" />
93
+ </div>
94
+ <div className="flex-1">
95
+ <div className="font-medium text-sm">Email</div>
96
+ <div className="text-xs text-slate-500">{user?.email}</div>
97
+ </div>
98
+ </div>
99
+
100
+ {/* Phone */}
101
+ <div className="flex items-center gap-3 p-4">
102
+ <div className="w-9 h-9 rounded-lg bg-slate-100 text-slate-500 flex items-center justify-center shrink-0">
103
+ <Phone className="w-4 h-4" />
104
+ </div>
105
+ <div className="flex-1">
106
+ <div className="font-medium text-sm">Phone</div>
107
+ <div className="text-xs text-slate-500">{profile?.phone || 'Not set'}</div>
108
+ </div>
109
+ </div>
110
+ </Card>
111
+ </div>
112
+
113
+ {/* Preferences */}
114
+ <div>
115
+ <h2 className="text-xs font-bold text-slate-500 uppercase tracking-wide px-1 mb-2">Preferences</h2>
116
+ <Card className="border-slate-100 divide-y divide-slate-100">
117
+ <ToggleRow icon={Bell} label="Push Notifications" desc="Order updates & deals" defaultOn />
118
+ <ToggleRow icon={Star} label="Email Digest" desc="Weekly recommendations" defaultOn />
119
+ <ToggleRow icon={Globe} label="Location Services" desc="For local product suggestions" />
120
+ </Card>
121
+ </div>
122
+
123
+ {/* Seller section */}
124
+ <div>
125
+ <h2 className="text-xs font-bold text-slate-500 uppercase tracking-wide px-1 mb-2">Selling</h2>
126
+ <Card className="border-slate-100 divide-y divide-slate-100">
127
+ {isSeller ? (
128
+ <Link href="/seller" className="flex items-center gap-3 p-4 hover:bg-slate-50 transition-colors">
129
+ <div className="w-9 h-9 rounded-lg bg-green-100 text-green-600 flex items-center justify-center shrink-0">
130
+ <Store className="w-4 h-4" />
131
+ </div>
132
+ <div className="flex-1">
133
+ <div className="font-medium text-sm">Seller Dashboard</div>
134
+ <div className="text-xs text-slate-500">Manage your products, orders & analytics</div>
135
+ </div>
136
+ <ChevronRight className="w-4 h-4 text-slate-300" />
137
+ </Link>
138
+ ) : (
139
+ <Link href="/become-seller" className="flex items-center gap-3 p-4 hover:bg-slate-50 transition-colors">
140
+ <div className="w-9 h-9 rounded-lg bg-green-100 text-green-600 flex items-center justify-center shrink-0">
141
+ <Store className="w-4 h-4" />
142
+ </div>
143
+ <div className="flex-1">
144
+ <div className="font-medium text-sm">Become a Seller</div>
145
+ <div className="text-xs text-slate-500">Start selling on Cellex — it's free</div>
146
+ </div>
147
+ <ChevronRight className="w-4 h-4 text-slate-300" />
148
+ </Link>
149
+ )}
150
+ </Card>
151
+ </div>
152
+
153
+ {/* Support */}
154
+ <div>
155
+ <h2 className="text-xs font-bold text-slate-500 uppercase tracking-wide px-1 mb-2">Support</h2>
156
+ <Card className="border-slate-100 divide-y divide-slate-100">
157
+ <Link href="/telegram" className="flex items-center gap-3 p-4 hover:bg-slate-50 transition-colors">
158
+ <div className="w-9 h-9 rounded-lg bg-cyan-100 text-cyan-600 flex items-center justify-center shrink-0">
159
+ <HelpCircle className="w-4 h-4" />
160
+ </div>
161
+ <div className="flex-1">
162
+ <div className="font-medium text-sm">Help & Support</div>
163
+ <div className="text-xs text-slate-500">Get help via Telegram</div>
164
+ </div>
165
+ <ChevronRight className="w-4 h-4 text-slate-300" />
166
+ </Link>
167
+ <Link href="/ai-chat" className="flex items-center gap-3 p-4 hover:bg-slate-50 transition-colors">
168
+ <div className="w-9 h-9 rounded-lg bg-purple-100 text-purple-600 flex items-center justify-center shrink-0">
169
+ <Sparkles className="w-4 h-4" />
170
+ </div>
171
+ <div className="flex-1">
172
+ <div className="font-medium text-sm">Ask AI Assistant</div>
173
+ <div className="text-xs text-slate-500">Get instant help from our AI</div>
174
+ </div>
175
+ <ChevronRight className="w-4 h-4 text-slate-300" />
176
+ </Link>
177
+ </Card>
178
+ </div>
179
+
180
+ {/* Security */}
181
+ <div>
182
+ <h2 className="text-xs font-bold text-slate-500 uppercase tracking-wide px-1 mb-2">Security</h2>
183
+ <Card className="border-slate-100 divide-y divide-slate-100">
184
+ <div className="flex items-center gap-3 p-4">
185
+ <div className="w-9 h-9 rounded-lg bg-slate-100 text-slate-500 flex items-center justify-center shrink-0">
186
+ <Shield className="w-4 h-4" />
187
+ </div>
188
+ <div className="flex-1">
189
+ <div className="font-medium text-sm">Account Security</div>
190
+ <div className="text-xs text-slate-500">HTTP-only cookie auth · 7-day session</div>
191
+ </div>
192
+ </div>
193
+ </Card>
194
+ </div>
195
+
196
+ {/* Logout */}
197
+ <Button onClick={handleLogout} variant="outline" className="w-full text-red-500 border-red-200 hover:bg-red-50">
198
+ <LogOut className="w-4 h-4 mr-2" /> Logout
199
+ </Button>
200
+
201
+ <div className="text-center text-[10px] text-slate-400 pt-2">
202
+ Cellex v0.2.15 · Nigeria's #1 social marketplace
203
+ </div>
204
+ </div>
205
+ );
206
+ }
207
+
208
+ function ToggleRow({ icon: Icon, label, desc, defaultOn }: { icon: any; label: string; desc: string; defaultOn?: boolean }) {
209
+ const [on, setOn] = useState(!!defaultOn);
210
+ return (
211
+ <div className="flex items-center gap-3 p-4">
212
+ <div className="w-9 h-9 rounded-lg bg-slate-100 text-slate-500 flex items-center justify-center shrink-0">
213
+ <Icon className="w-4 h-4" />
214
+ </div>
215
+ <div className="flex-1">
216
+ <div className="font-medium text-sm">{label}</div>
217
+ <div className="text-xs text-slate-500">{desc}</div>
218
+ </div>
219
+ <button
220
+ type="button"
221
+ onClick={() => setOn(!on)}
222
+ className={`relative w-11 h-6 rounded-full transition-colors shrink-0 ${on ? 'bg-black' : 'bg-slate-200'}`}
223
+ aria-pressed={on}
224
+ >
225
+ <span
226
+ className={`absolute top-0.5 left-0.5 w-5 h-5 rounded-full bg-white shadow transition-transform ${
227
+ on ? 'translate-x-5' : 'translate-x-0'
228
+ }`}
229
+ />
230
+ </button>
231
+ </div>
232
+ );
233
+ }