-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistorical_context.txt
More file actions
5742 lines (5563 loc) · 297 KB
/
Copy pathhistorical_context.txt
File metadata and controls
5742 lines (5563 loc) · 297 KB
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
>(() => id ? categoryStore.getByRestaurant(id) : []);
24 const [showItemDialog, setShowItemDialog] = useState(false);
25 const [showCatDialog, setShowCatDialog] = useState(false);
26 const [editItem, setEditItem] = useState<MenuItem | null>(null);
27 const [editCat, setEditCat] = useState<Category | null>(null);
28
29 // Item form state
30 const [itemName, setItemName] = useState('');
31 const [itemPrice, setItemPrice] = useState('');
32 const [itemDesc, setItemDesc] = useState('');
33 const [itemImage, setItemImage] = useState('');
34 const [itemCategory, setItemCategory] = useState('none');
35 const [catName, setCatName] = useState('');
36 const fileRef = useRef<HTMLInputElement>(null);
37
38 if (!owner || !restaurant) { navigate('/owner/dashboard'); return null; }
39 const plan = getOwnerPlan(owner);
40 const canAddMore = items.length < maxMenuItems(plan);
41 const hasCategories = planHas(plan, 'categories');
42
43 const refresh = useCallback(() => {
44 if (id) { setItems(menuStore.getByRestaurant(id)); setCategories(categoryStore.getByRestaurant(id)); }
45 }, [id]);
46
47 const openAddItem = () => {
48 setEditItem(null); setItemName(''); setItemPrice(''); setItemDesc(''); setItemImage(''); setItemCategory('none');
49 setShowItemDialog(true);
50 };
51
52 const openEditItem = (item: MenuItem) => {
53 setEditItem(item); setItemName(item.name); setItemPrice(String(item.price));
54 setItemDesc(item.description || ''); setItemImage(item.image); setItemCategory(item.categoryId || 'none');
55 setShowItemDialog(true);
56 };
57
58 const handleImageUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
59 const file = e.target.files?.[0];
60 if (!file) return;
61 if (!file.type.startsWith('image/')) { toast.error('Please upload an image file'); return; }
62 setItemImage(await fileToBase64(file));
63 };
64
65 const saveItem = () => {
66 if (!itemName.trim()) { toast.error('Item name is required'); return; }
67 const price = parseFloat(itemPrice);
68 if (!itemPrice || isNaN(price) || price < 0) { toast.error('Valid price is required'); return; }
69 if (!itemImage && !editItem) { toast.error('Item image is required'); return; }
70 if (!canAddMore && !editItem) { toast.error(`Free plan limit: max ${maxMenuItems('free')} items`); return; }
71
72 const m: MenuItem = {
73 id: editItem?.id || uuid(),
74 restaurantId: restaurant.id,
75 categoryId: itemCategory === 'none' ? undefined : itemCategory,
76 name: itemName.trim(),
77 description: itemDesc.trim() || undefined,
78 image: itemImage || editItem?.image || '',
79 price,
80 createdAt: editItem?.createdAt || new Date().toISOString(),
81 };
82 menuStore.save(m);
83 refresh();
84 setShowItemDialog(false);
85 toast.success(editItem ? 'Item updated' : 'Item added');
86 };
87
88 const deleteItem = (item: MenuItem) => {
89 menuStore.delete(item.id);
90 refresh();
91 toast.success('Item deleted');
92 };
93
94 const saveCat = () => {
95 if (!catName.trim()) { toast.error('Category name required'); return; }
96 categoryStore.save({
97 id: editCat?.id || uuid(),
98 restaurantId: restaurant.id,
99 name: catName.trim(),
100 createdAt: editCat?.createdAt || new Date().toISOString(),
101 });
102 refresh(); setShowCatDialog(false); toast.success(editCat ? 'Category updated' : 'Category added');
103 };
104
105 const deleteCat = (cat: Category) => {
106 categoryStore.delete(cat.id);
107 // unassign items from this category
108 menuStore.getByRestaurant(restaurant.id)
109 .filter((i) => i.categoryId === cat.id)
110 .forEach((i) => menuStore.save({ ...i, categoryId: undefined }));
111 refresh();
112 toast.success('Category deleted');
113 };
114
115 // Group display
116 const groups = categories.length > 0
117 ? [
118 ...categories.map((cat) => ({ label: cat.name, items: items.filter((i) => i.categoryId === cat.id) })),
119 { label: 'Uncategorized', items: items.filter((i) => !i.categoryId) },
120 ].filter((g) => g.items.length > 0)
121 : [{ label: '', items }];
122
123 return (
124 <div className="p-4 md:p-6 max-w-4xl mx-auto">
125 <Button variant="ghost" size="sm" className="gap-2 mb-2 -ml-2" onClick={() => navigate(-1)}>
126 <ArrowLeft size={14} strokeWidth={2} /> Back
127 </Button>
128 <div className="flex items-start justify-between mb-6">
129 <div>
130 <h1 className="text-2xl font-bold">Menu</h1>
131 <p className="text-sm text-muted-foreground">{restaurant.name} · {items.length} items</p>
132 </div>
133 <div className="flex gap-2">
134 {hasCategories ? (
135 <Button variant="outline" size="sm" className="gap-1" onClick={() => { setEditCat(null); setCatName(''); setShowCatDialog(true); }}>
136 <Plus size={14} strokeWidth={2} /> Category
137 </Button>
138 ) : (
139 <span className="inline-flex items-center gap-1 rounded-md border border-input bg-background px-3 py-1.5 text-sm font-medium opacity-50 cursor-not-allowed select-none" title="Basic plan required">
140 <Lock size={12} strokeWidth={2} /> Category
141 </span>
142 )}
143 <Button size="sm" className="gap-1" onClick={openAddItem} disabled={!canAddMore}>
144 <Plus size={14} strokeWidth={2} /> Add Item
145 </Button>
146 </div>
147 </div>
148
149 {!canAddMore && (
150 <div className="mb-4 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded text-sm text-yellow-700 dark:text-yellow-400">
151 Free plan limit: {maxMenuItems('free')} items reached. <button className="underline" onClick={() => navigate('/owner/profile')}>Upgrade</button> for unlimited items.
152 </div>
153 )}
154
155 {/* Categories list */}
156 {categories.length > 0 && (
157 <div className="mb-6 flex flex-wrap gap-2">
158 {categories.map((cat) => (
159 <div key={cat.id} className="flex items-center gap-1 border border-border rounded px-2 py-1 bg-card text-sm">
160 {cat.name}
161 <button onClick={() => { setEditCat(cat); setCatName(cat.name); setShowCatDialog(true); }} className="ml-1 text-muted-foreground hover:text-foreground">
162 <Pencil size={11} strokeWidth={2} />
163 </button>
164 <AlertDialog>
165 <AlertDialogTrigger asChild>
166 <button className="text-muted-foreground hover:text-destructive"><X size={11} strokeWidth={2} /></button>
167 </AlertDialogTrigger>
168 <AlertDialogContent className="max-w-[calc(100%-2rem)] md:max-w-lg">
169 <AlertDialogHeader>
170 <AlertDialogTitle>Delete Category?</AlertDialogTitle>
171 <AlertDialogDescription>Items in this category will become uncategorized.</AlertDialogDescription>
172 </AlertDialogHeader>
173 <AlertDialogFooter>
174 <AlertDialogCancel>Cancel</AlertDialogCancel>
175 <AlertDialogAction onClick={() => deleteCat(cat)} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">Delete</AlertDialogAction>
176 </AlertDialogFooter>
177 </AlertDialogContent>
178 </AlertDialog>
179 </div>
180 ))}
181 </div>
182 )}
183
184 {items.length === 0 ? (
185 <div className="text-center py-16 border border-dashed rounded">
186 <p className="text-muted-foreground">No menu items yet.</p>
187 <Button className="mt-4" onClick={openAddItem}>Add First Item</Button>
188 </div>
189 ) : (
190 groups.map(({ label, items: groupItems }) => (
191 <div key={label} className="mb-6">
192 {label && <h3 className="text-sm font-semibold uppercase tracking-wider text-muted-foreground mb-3">{label}</h3>}
193 <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
194 {groupItems.map((item) => (
195 <Card key={item.id}>
196 <CardContent className="p-3 flex gap-3">
197 <div className="w-16 h-16 rounded overflow-hidden bg-muted flex items-center justify-center shrink-0">
198 {item.image
199 ? <img src={item.image} alt={item.name} className="w-full h-full object-cover" />
200 : <span className="font-bold text-muted-foreground">{item.name[0]}</span>}
201 </div>
202 <div className="flex-1 min-w-0">
203 <p className="font-medium text-sm truncate">{item.name}</p>
204 {item.description && <p className="text-xs text-muted-foreground line-clamp-1">{item.description}</p>}
205 <p className="text-primary font-bold text-sm mt-0.5">₹{item.price}</p>
206 </div>
207 <div className="flex flex-col gap-1 shrink-0">
208 <Button size="icon" variant="ghost" className="h-7 w-7" onClick={() => openEditItem(item)}>
209 <Pencil size={13} strokeWidth={2} />
210 </Button>
211 <AlertDialog>
212 <AlertDialogTrigger asChild>
213 <Button size="icon" variant="ghost" className="h-7 w-7 text-destructive hover:text-destructive"><Trash2 size={13} strokeWidth={2} /></Button>
214 </AlertDialogTrigger>
215 <AlertDialogContent className="max-w-[calc(100%-2rem)] md:max-w-lg">
216 <AlertDialogHeader><AlertDialogTitle>Delete item?</AlertDialogTitle><AlertDialogDescription>This cannot be undone.</AlertDialogDescription></AlertDialogHeader>
217 <AlertDialogFooter><AlertDialogCancel>Cancel</AlertDialogCancel><AlertDialogAction onClick={() => deleteItem(item)} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">Delete</AlertDialogAction></AlertDialogFooter>
218 </AlertDialogContent>
219 </AlertDialog>
220 </div>
221 </CardContent>
222 </Card>
223 ))}
224 </div>
225 </div>
226 ))
227 )}
228
229 {/* Item dialog */}
230 <Dialog open={showItemDialog} onOpenChange={setShowItemDialog}>
231 <DialogContent className="max-w-[calc(100%-2rem)] md:max-w-lg">
232 <DialogHeader><DialogTitle>{editItem ? 'Edit Item' : 'Add Menu Item'}</DialogTitle></DialogHeader>
233 <div className="space-y-3">
234 <div className="flex items-center gap-4">
235 <div className="w-20 h-20 rounded border border-border bg-muted flex items-center justify-center overflow-hidden shrink-0">
236 {itemImage
237 ? <img src={itemImage} alt="preview" className="w-full h-full object-cover" />
238 : <Upload size={20} strokeWidth={1.5} className="text-muted-foreground" />}
239 </div>
240 <div>
241 <Button variant="outline" size="sm" onClick={() => fileRef.current?.click()}>
242 {itemImage ? 'Change Image' : 'Upload Image'}
243 </Button>
244 <input ref={fileRef} type="file" accept="image/*" className="hidden" onChange={handleImageUpload} />
245 </div>
246 </div>
247 <div>
248 <Label>Name *</Label>
249 <Input placeholder="Item name" value={itemName} onChange={(e) => setItemName(e.target.value)} className="mt-1" />
250 </div>
251 <div>
252 <Label>Price (₹) *</Label>
253 <Input type="number" placeholder="0" value={itemPrice} onChange={(e) => setItemPrice(e.target.value)} className="mt-1" min="0" step="0.5" />
254 </div>
255 <div>
256 <Label>Description</Label>
257 <Input placeholder="Short description (optional)" value={itemDesc} onChange={(e) => setItemDesc(e.target.value)} className="mt-1" />
258 </div>
259 {categories.length > 0 && (
260 <div>
261 <Label>Category</Label>
262 <Select value={itemCategory} onValueChange={setItemCategory}>
263 <SelectTrigger className="mt-1"><SelectValue /></SelectTrigger>
264 <SelectContent>
265 <SelectItem value="none">No Category</SelectItem>
266 {categories.map((c) => <SelectItem key={c.id} value={c.id}>{c.name}</SelectItem>)}
267 </SelectContent>
268 </Select>
269 </div>
270 )}
271 <div className="flex gap-2 pt-1">
272 <Button variant="outline" className="flex-1" onClick={() => setShowItemDialog(false)}>Cancel</Button>
273 <Button className="flex-1" onClick={saveItem}>Save</Button>
274 </div>
275 </div>
276 </DialogContent>
277 </Dialog>
278
279 {/* Category dialog */}
280 <Dialog open={showCatDialog} onOpenChange={setShowCatDialog}>
281 <DialogContent className="max-w-[calc(100%-2rem)] md:max-w-sm">
282 <DialogHeader><DialogTitle>{editCat ? 'Edit Category' : 'Add Category'}</DialogTitle></DialogHeader>
283 <div className="space-y-3">
284 <Input placeholder="Category name" value={catName} onChange={(e) => setCatName(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && saveCat()} />
285 <div className="flex gap-2">
286 <Button variant="outline" className="flex-1" onClick={() => setShowCatDialog(false)}>Cancel</Button>
287 <Button className="flex-1" onClick={saveCat}>Save</Button>
288 </div>
289 </div>
290 </DialogContent>
291 </Dialog>
292 </div>
293 );
294 }
295
</observation>
<action>
FileReadAction(path='/workspace/app-cg8nvxlqtuyq/src/pages/owner/QRPage.tsx', start=0, end=-1, thought='', action=<ActionType.READ: 'read'>, security_risk=None, impl_source=<FileReadSource.OH_ACI: 'oh_aci'>, view_range=None, user_hidden=False)
</action>
<observation>
[Read from /workspace/app-cg8nvxlqtuyq/src/pages/owner/QRPage.tsx is successful.]
Here's the result of running `cat -n` on the file: /workspace/app-cg8nvxlqtuyq/src/pages/owner/QRPage.tsx:
1 import { useRef, useCallback } from 'react';
2 import { useNavigate, useParams } from 'react-router-dom';
3 import { ArrowLeft, Download } from 'lucide-react';
4 import { QRCodeSVG } from 'qrcode.react';
5 import { Button } from '@/components/ui/button';
6 import { Card, CardContent } from '@/components/ui/card';
7 import { restaurantStore, ownerStore, LOGO_URL, settingsStore } from '@/store';
8 import html2canvas from 'html2canvas';
9 import jsPDF from 'jspdf';
10
11 export default function QRPage() {
12 const { id } = useParams<{ id: string }>();
13 const navigate = useNavigate();
14 const owner = ownerStore.getCurrent();
15 const restaurant = id ? restaurantStore.getById(id) : null;
16 const qrRef = useRef<HTMLDivElement>(null);
17 const settings = settingsStore.get();
18
19 if (!owner || !restaurant) { navigate('/owner/dashboard'); return null; }
20
21 const menuUrl = `${window.location.origin}/m/${restaurant.slug}`;
22 const siteName = settings.siteName || 'Saksham Digi QR Menu';
23
24 const downloadPNG = useCallback(async () => {
25 if (!qrRef.current) return;
26 const canvas = await html2canvas(qrRef.current, { scale: 3, backgroundColor: '#ffffff', useCORS: true });
27 const link = document.createElement('a');
28 link.download = `qr-${restaurant.slug}.png`;
29 link.href = canvas.toDataURL('image/png');
30 link.click();
31 }, [restaurant.slug]);
32
33 const downloadPDF = useCallback(async () => {
34 if (!qrRef.current) return;
35 const canvas = await html2canvas(qrRef.current, { scale: 3, backgroundColor: '#ffffff', useCORS: true });
36 const img = canvas.toDataURL('image/png');
37 const pdf = new jsPDF({ unit: 'mm', format: [100, 120] });
38 const w = pdf.internal.pageSize.getWidth();
39 const h = (canvas.height / canvas.width) * w;
40 pdf.addImage(img, 'PNG', 0, 0, w, h);
41 pdf.save(`qr-${restaurant.slug}.pdf`);
42 }, [restaurant.slug]);
43
44 return (
45 <div className="p-4 md:p-6 max-w-lg mx-auto">
46 <Button variant="ghost" size="sm" className="gap-2 mb-4 -ml-2" onClick={() => navigate(-1)}>
47 <ArrowLeft size={14} strokeWidth={2} /> Back
48 </Button>
49 <h1 className="text-2xl font-bold mb-6">QR Code</h1>
50
51 {/* Branded QR card */}
52 <Card className="mb-6 overflow-hidden">
53 <CardContent className="p-0">
54 <div ref={qrRef} className="flex flex-col items-center p-6 bg-white text-gray-900">
55 {/* Header */}
56 <div className="flex items-center gap-2 mb-3">
57 <img
58 src={restaurant.logo || LOGO_URL}
59 alt={restaurant.name}
60 className="h-10 w-10 object-contain rounded"
61 crossOrigin="anonymous"
62 />
63 <div>
64 <p className="font-bold text-lg leading-tight">{restaurant.name}</p>
65 <p className="text-gray-500 text-xs">{restaurant.location}</p>
66 </div>
67 </div>
68
69 {/* QR */}
70 <div className="p-3 border-2 border-gray-200 rounded-lg my-2">
71 <QRCodeSVG value={menuUrl} size={200} />
72 </div>
73
74 <p className="text-gray-500 text-xs mt-2">Scan to view menu & order</p>
75 <p className="text-gray-400 text-xs">{restaurant.phone}</p>
76
77 {/* Footer branding */}
78 <div className="flex items-center gap-1 mt-3 pt-3 border-t border-gray-100 w-full justify-center">
79 <img src={LOGO_URL} alt={siteName} className="h-5 w-5 object-contain" crossOrigin="anonymous" />
80 <span className="text-gray-400 text-xs">By {siteName}</span>
81 </div>
82 </div>
83 </CardContent>
84 </Card>
85
86 <div className="grid grid-cols-2 gap-3">
87 <Button variant="outline" className="gap-2" onClick={downloadPNG}>
88 <Download size={15} strokeWidth={2} /> Download PNG
89 </Button>
90 <Button className="gap-2" onClick={downloadPDF}>
91 <Download size={15} strokeWidth={2} /> Download PDF
92 </Button>
93 </div>
94
95 <p className="text-xs text-muted-foreground text-center mt-4">
96 Menu URL: <a href={menuUrl} target="_blank" rel="noreferrer" className="text-primary underline break-all">{menuUrl}</a>
97 </p>
98 </div>
99 );
100 }
101
</observation>
<action>
**FileEditAction**
Path: [/workspace/app-cg8nvxlqtuyq/src/pages/owner/OrdersPage.tsx]
Thought: Good. Now apply glassmorphism redesigns to owner pages, fix OrdersPage with ding.mp3 Web Audio fallback, and update MenuManagementPage + QRPage — all in parallel:
Command: str_replace
Old String: ```
import { useState, useEffect, useRef, useCallback } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { ArrowLeft, CheckCircle, XCircle, Package, Clock } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Textarea } from '@/components/ui/textarea';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { ownerStore, restaurantStore, orderStore, getOwnerPlan, planHas } from '@/store';
import { toast } from 'sonner';
import type { Order, OrderStatus } from '@/types';
```
New String: ```
import { useState, useEffect, useRef, useCallback } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { ArrowLeft, CheckCircle, XCircle, Package, Clock, Bell } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Textarea } from '@/components/ui/textarea';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { ownerStore, restaurantStore, orderStore, getOwnerPlan, planHas } from '@/store';
import { toast } from 'sonner';
import type { Order, OrderStatus } from '@/types';
const statusColor: Record<OrderStatus, string> = {
pending: 'bg-yellow-500/10 text-yellow-700 dark:text-yellow-400 border-yellow-500/30',
accepted: 'bg-green-500/10 text-green-700 dark:text-green-400 border-green-500/30',
rejected: 'bg-destructive/10 text-destructive border-destructive/30',
completed: 'bg-primary/10 text-primary border-primary/30',
};
// Play ding — try /ding.mp3 first, fallback to Web Audio API tone
function playDing() {
const audio = new Audio('/ding.mp3');
audio.play().catch(() => {
// Web Audio API fallback — pleasant 880Hz tone
try {
const ctx = new (window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext)();
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.connect(gain);
gain.connect(ctx.destination);
osc.type = 'sine';
osc.frequency.setValueAtTime(880, ctx.currentTime);
gain.gain.setValueAtTime(0.4, ctx.currentTime);
gain.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + 0.6);
osc.start(ctx.currentTime);
osc.stop(ctx.currentTime + 0.6);
} catch {}
});
}
export default function OrdersPage() {
const { id } = useParams<{ id: string }>();
const navigate = useNavigate();
const owner = ownerStore.getCurrent();
const restaurant = id ? restaurantStore.getById(id) : null;
const plan = owner ? getOwnerPlan(owner) : 'free';
const canFilter = planHas(plan, 'orderFilter');
const [orders, setOrders] = useState<Order[]>([]);
const [filter, setFilter] = useState<string>('all');
const [rejectDialog, setRejectDialog] = useState<{ open: boolean; orderId: string }>({ open: false, orderId: '' });
const [rejectReason, setRejectReason] = useState('');
const prevCount = useRef(0);
const refresh = useCallback(() => {
if (!id) return;
const fresh = orderStore.getByRestaurant(id).sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
const newPending = fresh.filter((o) => o.status === 'pending').length;
if (prevCount.current > 0 && newPending > prevCount.current) {
toast.info('New order received!', { icon: <Bell size={16} strokeWidth={2} /> });
playDing();
}
prevCount.current = newPending;
setOrders(fresh);
}, [id]);
useEffect(() => {
if (!owner || !restaurant) { navigate('/owner/dashboard'); return; }
refresh();
const interval = setInterval(refresh, 2000);
return () => clearInterval(interval);
}, [owner, restaurant, navigate, refresh]);
const updateStatus = (orderId: string, status: OrderStatus, reason?: string) => {
const order = orders.find((o) => o.id === orderId);
if (!order) return;
orderStore.save({ ...order, status, rejectionReason: reason, updatedAt: new Date().toISOString() });
refresh();
toast.success(`Order marked as ${status}`);
};
const handleReject = () => {
if (!rejectReason.trim()) { toast.error('Please enter a rejection reason'); return; }
updateStatus(rejectDialog.orderId, 'rejected', rejectReason);
setRejectDialog({ open: false, orderId: '' });
setRejectReason('');
};
const filtered = canFilter && filter !== 'all'
? orders.filter((o) => o.status === filter)
: orders;
if (!restaurant) return null;
const pending = orders.filter((o) => o.status === 'pending').length;
return (
<div className="p-4 md:p-6 max-w-4xl mx-auto animate-fade-up">
<Button variant="ghost" size="sm" className="gap-2 mb-3 -ml-2 rounded-xl" onClick={() => navigate(-1)}>
<ArrowLeft size={14} strokeWidth={2} /> Back
</Button>
<div className="flex items-start justify-between mb-6 gap-3 flex-wrap">
<div>
<h1 className="text-2xl font-bold flex items-center gap-2">
Orders
{pending > 0 && (
<span className="inline-flex items-center justify-center w-6 h-6 rounded-full bg-primary text-primary-foreground text-xs font-bold animate-badge-bounce">
{pending}
</span>
)}
</h1>
<p className="text-sm text-muted-foreground">{restaurant.name}</p>
</div>
{canFilter ? (
<Select value={filter} onValueChange={setFilter}>
<SelectTrigger className="w-36 rounded-xl"><SelectValue placeholder="Filter" /></SelectTrigger>
<SelectContent>
<SelectItem value="all">All Orders</SelectItem>
<SelectItem value="pending">Pending</SelectItem>
<SelectItem value="accepted">Accepted</SelectItem>
<SelectItem value="rejected">Rejected</SelectItem>
<SelectItem value="completed">Completed</SelectItem>
</SelectContent>
</Select>
) : (
<span className="inline-flex items-center gap-1 rounded-xl border border-input bg-background px-3 py-1.5 text-sm font-medium opacity-50 cursor-not-allowed select-none">
Filter (Basic+)
</span>
)}
</div>
{filtered.length === 0 ? (
<div className="text-center py-16 border border-dashed rounded-2xl animate-fade-in">
<Clock size={40} strokeWidth={1.5} className="mx-auto mb-3 text-muted-foreground opacity-40" />
<p className="text-muted-foreground font-medium">No orders yet</p>
<p className="text-sm text-muted-foreground mt-1">Orders appear here in real-time</p>
</div>
) : (
<div className="space-y-3">
{filtered.map((order, i) => (
<Card
key={order.id}
className={`rounded-2xl border-border/60 hover:shadow-md transition-all duration-200 animate-fade-up stagger-${Math.min(i + 1, 9)} ${order.status === 'pending' ? 'ring-1 ring-yellow-500/30' : ''}`}
>
<CardContent className="p-4">
<div className="flex items-start justify-between gap-3 mb-3">
<div className="min-w-0">
<div className="flex items-center gap-2 flex-wrap">
<p className="font-semibold text-sm font-mono">#{order.id.slice(0, 8).toUpperCase()}</p>
<Badge variant="outline" className={`text-xs border capitalize rounded-full ${statusColor[order.status]}`}>
{order.status}
</Badge>
</div>
<p className="text-sm mt-0.5 font-medium">{order.customerName}</p>
<p className="text-xs text-muted-foreground">{order.customerPhone} · {new Date(order.createdAt).toLocaleString()}</p>
</div>
<p className="font-bold text-primary shrink-0 text-lg">₹{order.total.toFixed(0)}</p>
</div>
<div className="bg-muted/50 rounded-xl p-3 mb-3 text-sm space-y-1.5">
{order.items.map((item) => (
<div key={item.menuItemId} className="flex justify-between text-sm">
<span>{item.name} <span className="text-muted-foreground text-xs">x{item.quantity}</span></span>
<span className="font-medium">₹{(item.price * item.quantity).toFixed(0)}</span>
</div>
))}
</div>
<p className="text-xs text-muted-foreground mb-3">
Payment: <span className="font-medium text-foreground">{order.paymentMethod === 'cash' ? 'Cash on Delivery' : 'Online'}</span>
</p>
{order.status === 'pending' && (
<div className="flex gap-2">
<Button size="sm" className="gap-1.5 flex-1 h-9 rounded-xl press-active" onClick={() => updateStatus(order.id, 'accepted')}>
<CheckCircle size={13} strokeWidth={2} /> Accept
</Button>
<Button size="sm" variant="destructive" className="gap-1.5 flex-1 h-9 rounded-xl press-active" onClick={() => { setRejectDialog({ open: true, orderId: order.id }); setRejectReason(''); }}>
<XCircle size={13} strokeWidth={2} /> Reject
</Button>
</div>
)}
{order.status === 'accepted' && (
<Button size="sm" className="gap-1.5 h-9 w-full rounded-xl press-active" onClick={() => updateStatus(order.id, 'completed')}>
<Package size={13} strokeWidth={2} /> Mark as Completed
</Button>
)}
{order.status === 'rejected' && order.rejectionReason && (
<p className="text-xs text-destructive bg-destructive/10 rounded-xl px-3 py-2">Reason: {order.rejectionReason}</p>
)}
</CardContent>
</Card>
))}
</div>
)}
<Dialog open={rejectDialog.open} onOpenChange={(o) => setRejectDialog((p) => ({ ...p, open: o }))}>
<DialogContent className="max-w-[calc(100%-2rem)] md:max-w-md rounded-3xl">
<DialogHeader><DialogTitle>Reject Order</DialogTitle></DialogHeader>
<div className="space-y-3">
<p className="text-sm text-muted-foreground">The customer will see this reason.</p>
<Textarea
placeholder="e.g. Item unavailable, kitchen closed..."
value={rejectReason}
onChange={(e) => setRejectReason(e.target.value)}
rows={3}
className="rounded-xl"
/>
<div className="flex gap-2">
<Button variant="outline" className="flex-1 rounded-xl" onClick={() => setRejectDialog({ open: false, orderId: '' })}>Cancel</Button>
<Button variant="destructive" className="flex-1 rounded-xl press-active" onClick={handleReject}>Reject Order</Button>
</div>
</div>
</DialogContent>
</Dialog>
</div>
);
}
```
</action>
<observation>
The file /workspace/app-cg8nvxlqtuyq/src/pages/owner/OrdersPage.tsx has been edited.
</observation>
<action>
**FileEditAction**
Path: [/workspace/app-cg8nvxlqtuyq/src/pages/owner/MenuManagementPage.tsx]
Thought:
Command: str_replace
Old String: ```
<div className="p-4 md:p-6 max-w-4xl mx-auto">
<Button variant="ghost" size="sm" className="gap-2 mb-2 -ml-2" onClick={() => navigate(-1)}>
<ArrowLeft size={14} strokeWidth={2} /> Back
</Button>
<div className="flex items-start justify-between mb-6">
<div>
<h1 className="text-2xl font-bold">Menu</h1>
<p className="text-sm text-muted-foreground">{restaurant.name} · {items.length} items</p>
</div>
<div className="flex gap-2">
{hasCategories ? (
<Button variant="outline" size="sm" className="gap-1" onClick={() => { setEditCat(null); setCatName(''); setShowCatDialog(true); }}>
<Plus size={14} strokeWidth={2} /> Category
</Button>
) : (
<span className="inline-flex items-center gap-1 rounded-md border border-input bg-background px-3 py-1.5 text-sm font-medium opacity-50 cursor-not-allowed select-none" title="Basic plan required">
<Lock size={12} strokeWidth={2} /> Category
</span>
)}
<Button size="sm" className="gap-1" onClick={openAddItem} disabled={!canAddMore}>
<Plus size={14} strokeWidth={2} /> Add Item
</Button>
</div>
</div>
{!canAddMore && (
<div className="mb-4 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded text-sm text-yellow-700 dark:text-yellow-400">
Free plan limit: {maxMenuItems('free')} items reached. <button className="underline" onClick={() => navigate('/owner/profile')}>Upgrade</button> for unlimited items.
</div>
)}
{/* Categories list */}
{categories.length > 0 && (
<div className="mb-6 flex flex-wrap gap-2">
{categories.map((cat) => (
<div key={cat.id} className="flex items-center gap-1 border border-border rounded px-2 py-1 bg-card text-sm">
{cat.name}
<button onClick={() => { setEditCat(cat); setCatName(cat.name); setShowCatDialog(true); }} className="ml-1 text-muted-foreground hover:text-foreground">
<Pencil size={11} strokeWidth={2} />
</button>
<AlertDialog>
<AlertDialogTrigger asChild>
<button className="text-muted-foreground hover:text-destructive"><X size={11} strokeWidth={2} /></button>
</AlertDialogTrigger>
<AlertDialogContent className="max-w-[calc(100%-2rem)] md:max-w-lg">
<AlertDialogHeader>
<AlertDialogTitle>Delete Category?</AlertDialogTitle>
<AlertDialogDescription>Items in this category will become uncategorized.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={() => deleteCat(cat)} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">Delete</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
))}
</div>
)}
{items.length === 0 ? (
<div className="text-center py-16 border border-dashed rounded">
<p className="text-muted-foreground">No menu items yet.</p>
<Button className="mt-4" onClick={openAddItem}>Add First Item</Button>
</div>
) : (
groups.map(({ label, items: groupItems }) => (
<div key={label} className="mb-6">
{label && <h3 className="text-sm font-semibold uppercase tracking-wider text-muted-foreground mb-3">{label}</h3>}
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
{groupItems.map((item) => (
<Card key={item.id}>
<CardContent className="p-3 flex gap-3">
<div className="w-16 h-16 rounded overflow-hidden bg-muted flex items-center justify-center shrink-0">
{item.image
? <img src={item.image} alt={item.name} className="w-full h-full object-cover" />
: <span className="font-bold text-muted-foreground">{item.name[0]}</span>}
</div>
<div className="flex-1 min-w-0">
<p className="font-medium text-sm truncate">{item.name}</p>
{item.description && <p className="text-xs text-muted-foreground line-clamp-1">{item.description}</p>}
<p className="text-primary font-bold text-sm mt-0.5">₹{item.price}</p>
</div>
<div className="flex flex-col gap-1 shrink-0">
<Button size="icon" variant="ghost" className="h-7 w-7" onClick={() => openEditItem(item)}>
<Pencil size={13} strokeWidth={2} />
</Button>
<AlertDialog>
<AlertDialogTrigger asChild>
<Button size="icon" variant="ghost" className="h-7 w-7 text-destructive hover:text-destructive"><Trash2 size={13} strokeWidth={2} /></Button>
</AlertDialogTrigger>
<AlertDialogContent className="max-w-[calc(100%-2rem)] md:max-w-lg">
<AlertDialogHeader><AlertDialogTitle>Delete item?</AlertDialogTitle><AlertDialogDescription>This cannot be undone.</AlertDialogDescription></AlertDialogHeader>
<AlertDialogFooter><AlertDialogCancel>Cancel</AlertDialogCancel><AlertDialogAction onClick={() => deleteItem(item)} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">Delete</AlertDialogAction></AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</CardContent>
</Card>
))}
</div>
</div>
))
)}
{/* Item dialog */}
<Dialog open={showItemDialog} onOpenChange={setShowItemDialog}>
<DialogContent className="max-w-[calc(100%-2rem)] md:max-w-lg">
<DialogHeader><DialogTitle>{editItem ? 'Edit Item' : 'Add Menu Item'}</DialogTitle></DialogHeader>
<div className="space-y-3">
<div className="flex items-center gap-4">
<div className="w-20 h-20 rounded border border-border bg-muted flex items-center justify-center overflow-hidden shrink-0">
{itemImage
? <img src={itemImage} alt="preview" className="w-full h-full object-cover" />
: <Upload size={20} strokeWidth={1.5} className="text-muted-foreground" />}
</div>
<div>
<Button variant="outline" size="sm" onClick={() => fileRef.current?.click()}>
{itemImage ? 'Change Image' : 'Upload Image'}
</Button>
<input ref={fileRef} type="file" accept="image/*" className="hidden" onChange={handleImageUpload} />
</div>
</div>
<div>
<Label>Name *</Label>
<Input placeholder="Item name" value={itemName} onChange={(e) => setItemName(e.target.value)} className="mt-1" />
</div>
<div>
<Label>Price (₹) *</Label>
<Input type="number" placeholder="0" value={itemPrice} onChange={(e) => setItemPrice(e.target.value)} className="mt-1" min="0" step="0.5" />
</div>
<div>
<Label>Description</Label>
<Input placeholder="Short description (optional)" value={itemDesc} onChange={(e) => setItemDesc(e.target.value)} className="mt-1" />
</div>
{categories.length > 0 && (
<div>
<Label>Category</Label>
<Select value={itemCategory} onValueChange={setItemCategory}>
<SelectTrigger className="mt-1"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="none">No Category</SelectItem>
{categories.map((c) => <SelectItem key={c.id} value={c.id}>{c.name}</SelectItem>)}
</SelectContent>
</Select>
</div>
)}
<div className="flex gap-2 pt-1">
<Button variant="outline" className="flex-1" onClick={() => setShowItemDialog(false)}>Cancel</Button>
<Button className="flex-1" onClick={saveItem}>Save</Button>
</div>
</div>
</DialogContent>
</Dialog>
{/* Category dialog */}
<Dialog open={showCatDialog} onOpenChange={setShowCatDialog}>
<DialogContent className="max-w-[calc(100%-2rem)] md:max-w-sm">
<DialogHeader><DialogTitle>{editCat ? 'Edit Category' : 'Add Category'}</DialogTitle></DialogHeader>
<div className="space-y-3">
<Input placeholder="Category name" value={catName} onChange={(e) => setCatName(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && saveCat()} />
<div className="flex gap-2">
<Button variant="outline" className="flex-1" onClick={() => setShowCatDialog(false)}>Cancel</Button>
<Button className="flex-1" onClick={saveCat}>Save</Button>
</div>
</div>
</DialogContent>
</Dialog>
</div>
```
New String: ```
<div className="p-4 md:p-6 max-w-4xl mx-auto animate-fade-up">
<Button variant="ghost" size="sm" className="gap-2 mb-3 -ml-2 rounded-xl" onClick={() => navigate(-1)}>
<ArrowLeft size={14} strokeWidth={2} /> Back
</Button>
<div className="flex items-start justify-between mb-6">
<div>
<h1 className="text-2xl font-bold">Menu</h1>
<p className="text-sm text-muted-foreground">{restaurant.name} · {items.length} items</p>
</div>
<div className="flex gap-2">
{hasCategories ? (
<Button variant="outline" size="sm" className="gap-1 rounded-xl" onClick={() => { setEditCat(null); setCatName(''); setShowCatDialog(true); }}>
<Plus size={14} strokeWidth={2} /> Category
</Button>
) : (
<span className="inline-flex items-center gap-1 rounded-xl border border-input bg-background px-3 py-1.5 text-sm font-medium opacity-50 cursor-not-allowed select-none" title="Basic plan required">
<Lock size={12} strokeWidth={2} /> Category
</span>
)}
<Button size="sm" className="gap-1 rounded-xl press-active" onClick={openAddItem} disabled={!canAddMore}>
<Plus size={14} strokeWidth={2} /> Add Item
</Button>
</div>
</div>
{!canAddMore && (
<div className="mb-4 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-xl text-sm text-yellow-700 dark:text-yellow-400">
Free plan limit: {maxMenuItems('free')} items reached.{' '}
<button className="underline font-medium" onClick={() => navigate('/owner/profile')}>Upgrade</button> for unlimited items.
</div>
)}
{categories.length > 0 && (
<div className="mb-6 flex flex-wrap gap-2">
{categories.map((cat) => (
<div key={cat.id} className="flex items-center gap-1 border border-border rounded-full px-3 py-1.5 bg-card text-sm">
{cat.name}
<button onClick={() => { setEditCat(cat); setCatName(cat.name); setShowCatDialog(true); }} className="ml-1 text-muted-foreground hover:text-foreground transition-colors">
<Pencil size={11} strokeWidth={2} />
</button>
<AlertDialog>
<AlertDialogTrigger asChild>
<button className="text-muted-foreground hover:text-destructive transition-colors"><X size={11} strokeWidth={2} /></button>
</AlertDialogTrigger>
<AlertDialogContent className="max-w-[calc(100%-2rem)] md:max-w-lg rounded-3xl">
<AlertDialogHeader>
<AlertDialogTitle>Delete Category?</AlertDialogTitle>
<AlertDialogDescription>Items will become uncategorized.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={() => deleteCat(cat)} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">Delete</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
))}
</div>
)}
{items.length === 0 ? (
<div className="text-center py-16 border border-dashed rounded-2xl animate-fade-in">
<p className="text-muted-foreground font-medium">No menu items yet</p>
<Button className="mt-4 rounded-xl press-active" onClick={openAddItem}>Add First Item</Button>
</div>
) : (
groups.map(({ label, items: groupItems }) => (
<div key={label} className="mb-6">
{label && <h3 className="text-xs font-semibold uppercase tracking-widest text-muted-foreground mb-3 px-1">{label}</h3>}
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
{groupItems.map((item, i) => (
<Card key={item.id} className={`rounded-2xl border-border/60 hover:shadow-md transition-all duration-200 animate-fade-up stagger-${Math.min(i + 1, 9)}`}>
<CardContent className="p-3 flex gap-3">
<div className="w-16 h-16 rounded-xl overflow-hidden bg-muted flex items-center justify-center shrink-0">
{item.image
? <img src={item.image} alt={item.name} className="w-full h-full object-cover" />
: <span className="font-bold text-muted-foreground">{item.name[0]}</span>}
</div>
<div className="flex-1 min-w-0">
<p className="font-medium text-sm truncate">{item.name}</p>
{item.description && <p className="text-xs text-muted-foreground line-clamp-1">{item.description}</p>}
<p className="text-primary font-bold text-sm mt-0.5">₹{item.price}</p>
</div>
<div className="flex flex-col gap-1 shrink-0">
<Button size="icon" variant="ghost" className="h-7 w-7 rounded-lg" onClick={() => openEditItem(item)}>
<Pencil size={13} strokeWidth={2} />
</Button>
<AlertDialog>
<AlertDialogTrigger asChild>
<Button size="icon" variant="ghost" className="h-7 w-7 rounded-lg text-destructive hover:text-destructive"><Trash2 size={13} strokeWidth={2} /></Button>
</AlertDialogTrigger>
<AlertDialogContent className="max-w-[calc(100%-2rem)] md:max-w-lg rounded-3xl">
<AlertDialogHeader><AlertDialogTitle>Delete item?</AlertDialogTitle><AlertDialogDescription>This cannot be undone.</AlertDialogDescription></AlertDialogHeader>
<AlertDialogFooter><AlertDialogCancel>Cancel</AlertDialogCancel><AlertDialogAction onClick={() => deleteItem(item)} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">Delete</AlertDialogAction></AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</CardContent>
</Card>
))}
</div>
</div>
))
)}
<Dialog open={showItemDialog} onOpenChange={setShowItemDialog}>
<DialogContent className="max-w-[calc(100%-2rem)] md:max-w-lg rounded-3xl">
<DialogHeader><DialogTitle>{editItem ? 'Edit Item' : 'Add Menu Item'}</DialogTitle></DialogHeader>
<div className="space-y-3">
<div className="flex items-center gap-4">
<div className="w-20 h-20 rounded-2xl border border-border bg-muted flex items-center justify-center overflow-hidden shrink-0">
{itemImage
? <img src={itemImage} alt="preview" className="w-full h-full object-cover" />
: <Upload size={20} strokeWidth={1.5} className="text-muted-foreground" />}
</div>
<Button variant="outline" size="sm" className="rounded-xl" onClick={() => fileRef.current?.click()}>
{itemImage ? 'Change Image' : 'Upload Image'}
</Button>
<input ref={fileRef} type="file" accept="image/*" className="hidden" onChange={handleImageUpload} />
</div>
<div>
<Label className="text-sm font-normal text-muted-foreground">Name *</Label>
<Input placeholder="Item name" value={itemName} onChange={(e) => setItemName(e.target.value)} className="mt-1 rounded-xl" />
</div>
<div>
<Label className="text-sm font-normal text-muted-foreground">Price (₹) *</Label>
<Input type="number" placeholder="0" value={itemPrice} onChange={(e) => setItemPrice(e.target.value)} className="mt-1 rounded-xl" min="0" step="0.5" />
</div>
<div>
<Label className="text-sm font-normal text-muted-foreground">Description</Label>
<Input placeholder="Short description (optional)" value={itemDesc} onChange={(e) => setItemDesc(e.target.value)} className="mt-1 rounded-xl" />
</div>
{categories.length > 0 && (
<div>
<Label className="text-sm font-normal text-muted-foreground">Category</Label>
<Select value={itemCategory} onValueChange={setItemCategory}>
<SelectTrigger className="mt-1 rounded-xl"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="none">No Category</SelectItem>
{categories.map((c) => <SelectItem key={c.id} value={c.id}>{c.name}</SelectItem>)}
</SelectContent>
</Select>
</div>
)}
<div className="flex gap-2 pt-1">
<Button variant="outline" className="flex-1 rounded-xl" onClick={() => setShowItemDialog(false)}>Cancel</Button>
<Button className="flex-1 rounded-xl press-active" onClick={saveItem}>Save</Button>
</div>
</div>
</DialogContent>
</Dialog>
<Dialog open={showCatDialog} onOpenChange={setShowCatDialog}>
<DialogContent className="max-w-[calc(100%-2rem)] md:max-w-sm rounded-3xl">
<DialogHeader><DialogTitle>{editCat ? 'Edit Category' : 'Add Category'}</DialogTitle></DialogHeader>
<div className="space-y-3">
<Input placeholder="Category name" value={catName} onChange={(e) => setCatName(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && saveCat()} className="rounded-xl" />
<div className="flex gap-2">
<Button variant="outline" className="flex-1 rounded-xl" onClick={() => setShowCatDialog(false)}>Cancel</Button>
<Button className="flex-1 rounded-xl press-active" onClick={saveCat}>Save</Button>
</div>
</div>
</DialogContent>
</Dialog>
</div>
```
</action>
<observation>
The file /workspace/app-cg8nvxlqtuyq/src/pages/owner/MenuManagementPage.tsx has been edited.
</observation>
<action>
FileReadAction(path='/workspace/app-cg8nvxlqtuyq/src/pages/owner/OwnerRestaurantsPage.tsx', start=0, end=-1, thought='Now read the remaining owner pages and admin pages, and update CSS animations + store to ensure random 16-char slug generation:', action=<ActionType.READ: 'read'>, security_risk=None, impl_source=<FileReadSource.OH_ACI: 'oh_aci'>, view_range=None, user_hidden=False)
</action>
<observation>
[Read from /workspace/app-cg8nvxlqtuyq/src/pages/owner/OwnerRestaurantsPage.tsx is successful.]
Here's the result of running `cat -n` on the file: /workspace/app-cg8nvxlqtuyq/src/pages/owner/OwnerRestaurantsPage.tsx:
1 import { useNavigate } from 'react-router-dom';
2 import { Plus, QrCode, ClipboardList, UtensilsCrossed, Pencil } from 'lucide-react';
3 import { Button } from '@/components/ui/button';
4 import { Card, CardContent } from '@/components/ui/card';
5 import { Badge } from '@/components/ui/badge';
6 import { ownerStore, restaurantStore, menuStore, orderStore, getOwnerPlan, maxRestaurants } from '@/store';
7 import { useEffect, useState } from 'react';
8 import type { Restaurant } from '@/types';
9
10 export default function OwnerRestaurantsPage() {
11 const navigate = useNavigate();
12 const owner = ownerStore.getCurrent();
13 const [restaurants, setRestaurants] = useState<Restaurant[]>([]);