Skip to content

Commit 455d4ca

Browse files
Copilotsyed-reza98
andcommitted
Fix code review feedback: standardize toast, add clipboard safety, remove unused vars
Co-authored-by: syed-reza98 <71028588+syed-reza98@users.noreply.github.com>
1 parent 33ccd82 commit 455d4ca

File tree

13 files changed

+42
-102
lines changed

13 files changed

+42
-102
lines changed

src/app/api/admin/activity/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export async function GET(request: NextRequest) {
2525
const { searchParams } = new URL(request.url);
2626
const page = parseInt(searchParams.get('page') || '1');
2727
const limit = parseInt(searchParams.get('limit') || '50');
28-
const userId = searchParams.get('userId') || '';
29-
const action = searchParams.get('action') || '';
30-
const resource = searchParams.get('resource') || '';
28+
// const userId = searchParams.get('userId') || '';
29+
// const action = searchParams.get('action') || '';
30+
// const resource = searchParams.get('resource') || '';
3131

3232
// Mock activity logs - In production, fetch from database/log system
3333
const activities = Array.from({ length: limit }, (_, i) => {

src/app/api/admin/users/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export async function GET(request: NextRequest) {
3030
const { searchParams } = new URL(request.url);
3131
const page = parseInt(searchParams.get('page') || '1');
3232
const limit = parseInt(searchParams.get('limit') || '20');
33-
const search = searchParams.get('search') || '';
34-
const role = searchParams.get('role') || '';
35-
const status = searchParams.get('status') || '';
33+
// const search = searchParams.get('search') || '';
34+
// const role = searchParams.get('role') || '';
35+
// const status = searchParams.get('status') || '';
3636

3737
// Mock users data - In production, fetch from database
3838
const users = Array.from({ length: limit }, (_, i) => ({

src/app/checkout/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default function CheckoutPage() {
4545
const router = useRouter();
4646
const [currentStep, setCurrentStep] = useState(0);
4747
const [shippingAddress, setShippingAddress] = useState<ShippingAddress | null>(null);
48-
const [paymentMethodId, setPaymentMethodId] = useState<string | null>(null);
48+
// const [paymentMethodId, setPaymentMethodId] = useState<string | null>(null);
4949
const [isProcessing, setIsProcessing] = useState(false);
5050

5151
const steps: CheckoutStep[] = [

src/components/cart/cart-list.tsx

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { Badge } from '@/components/ui/badge';
1414
import { Input } from '@/components/ui/input';
1515
import { Minus, Plus, Trash2, ShoppingCart, ArrowRight } from 'lucide-react';
16-
import { useToast } from '@/hooks/use-toast';
16+
import { toast } from 'sonner';
1717
import { useRouter } from 'next/navigation';
1818

1919
interface CartItem {
@@ -67,7 +67,6 @@ export function CartList() {
6767
const [cart, setCart] = useState<Cart | null>(null);
6868
const [loading, setLoading] = useState(true);
6969
const [updatingItems, setUpdatingItems] = useState<Set<string>>(new Set());
70-
const { toast } = useToast();
7170
const router = useRouter();
7271

7372
useEffect(() => {
@@ -121,15 +120,9 @@ export function CartList() {
121120
};
122121
});
123122

124-
toast({
125-
title: 'Cart updated',
126-
description: 'Item quantity updated successfully',
127-
});
123+
toast.success('Item quantity updated successfully');
128124
} catch {
129-
toast({
130-
title: 'Update failed',
131-
description: 'Failed to update item quantity',
132-
});
125+
toast.error('Failed to update item quantity');
133126
} finally {
134127
setUpdatingItems(prev => {
135128
const next = new Set(prev);
@@ -158,15 +151,9 @@ export function CartList() {
158151
};
159152
});
160153

161-
toast({
162-
title: 'Item removed',
163-
description: 'Item removed from cart',
164-
});
154+
toast.success('Item removed from cart');
165155
} catch {
166-
toast({
167-
title: 'Remove failed',
168-
description: 'Failed to remove item from cart',
169-
});
156+
toast.error('Failed to remove item from cart');
170157
} finally {
171158
setUpdatingItems(prev => {
172159
const next = new Set(prev);
@@ -188,15 +175,9 @@ export function CartList() {
188175

189176
setCart({ ...mockCart, items: [], itemCount: 0, subtotal: 0, total: 0 });
190177

191-
toast({
192-
title: 'Cart cleared',
193-
description: 'All items removed from cart',
194-
});
178+
toast.success('All items removed from cart');
195179
} catch {
196-
toast({
197-
title: 'Clear failed',
198-
description: 'Failed to clear cart',
199-
});
180+
toast.error('Failed to clear cart');
200181
}
201182
};
202183

src/components/coupons/coupons-list.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
DropdownMenuTrigger,
2626
} from '@/components/ui/dropdown-menu';
2727
import { Plus, MoreHorizontal, Copy, Edit, Trash2, Percent, DollarSign } from 'lucide-react';
28-
import { useToast } from '@/hooks/use-toast';
28+
import { toast } from 'sonner';
2929
import { CreateCouponDialog } from './create-coupon-dialog';
3030

3131
interface Coupon {
@@ -87,7 +87,6 @@ export function CouponsList() {
8787
const [coupons, setCoupons] = useState<Coupon[]>([]);
8888
const [loading, setLoading] = useState(true);
8989
const [isCreateOpen, setIsCreateOpen] = useState(false);
90-
const { toast } = useToast();
9190

9291
useEffect(() => {
9392
const fetchCoupons = async () => {
@@ -111,20 +110,18 @@ export function CouponsList() {
111110
}, []);
112111

113112
const handleCopyCode = (code: string) => {
114-
navigator.clipboard.writeText(code);
115-
toast({
116-
title: 'Code copied',
117-
description: `Coupon code "${code}" copied to clipboard`,
118-
});
113+
if (navigator.clipboard && navigator.clipboard.writeText) {
114+
navigator.clipboard.writeText(code);
115+
toast.success(`Coupon code "${code}" copied to clipboard`);
116+
} else {
117+
toast.error('Clipboard not available');
118+
}
119119
};
120120

121121
const handleDelete = async (couponId: string) => {
122122
if (!confirm('Are you sure you want to delete this coupon?')) return;
123123

124-
toast({
125-
title: 'Coupon deleted',
126-
description: 'The coupon has been removed',
127-
});
124+
toast.success('The coupon has been removed');
128125

129126
setCoupons(prev => prev.filter(c => c.id !== couponId));
130127
};

src/components/emails/edit-email-template-dialog.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
SelectTrigger,
2121
SelectValue,
2222
} from '@/components/ui/select';
23-
import { useToast } from '@/hooks/use-toast';
23+
import { toast } from 'sonner';
2424

2525
interface EmailTemplate {
2626
id: string;
@@ -69,7 +69,6 @@ export function EditEmailTemplateDialog({
6969
</div>
7070
</body>
7171
</html>`);
72-
const { toast } = useToast();
7372
const [isSaving, setIsSaving] = useState(false);
7473

7574
const handleSave = async () => {
@@ -78,10 +77,7 @@ export function EditEmailTemplateDialog({
7877
// Simulate API call
7978
await new Promise(resolve => setTimeout(resolve, 500));
8079

81-
toast({
82-
title: 'Template updated',
83-
description: `"${name}" has been updated successfully.`,
84-
});
80+
toast.success(`"${name}" has been updated successfully.`);
8581

8682
setIsSaving(false);
8783
onOpenChange(false);

src/components/emails/email-templates-list.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import { MoreHorizontal, Mail, Edit, Eye, Send } from 'lucide-react';
2020
import { EditEmailTemplateDialog } from './edit-email-template-dialog';
2121
import { PreviewEmailDialog } from './preview-email-dialog';
22-
import { useToast } from '@/hooks/use-toast';
22+
import { toast } from 'sonner';
2323

2424
interface EmailTemplate {
2525
id: string;
@@ -83,21 +83,14 @@ export function EmailTemplatesList() {
8383
const [templates] = useState<EmailTemplate[]>(mockTemplates);
8484
const [editingTemplate, setEditingTemplate] = useState<EmailTemplate | null>(null);
8585
const [previewTemplate, setPreviewTemplate] = useState<EmailTemplate | null>(null);
86-
const { toast } = useToast();
8786

8887
const handleSendTest = (template: EmailTemplate) => {
89-
toast({
90-
title: 'Test email sent',
91-
description: `Test email for "${template.name}" sent to your email address.`,
92-
});
88+
toast.success(`Test email for "${template.name}" sent to your email address.`);
9389
};
9490

9591
const handleToggleActive = (template: EmailTemplate) => {
9692
const newStatus = !template.active;
97-
toast({
98-
title: newStatus ? 'Template activated' : 'Template deactivated',
99-
description: `"${template.name}" is now ${newStatus ? 'active' : 'inactive'}.`,
100-
});
93+
toast.success(`"${template.name}" is now ${newStatus ? 'active' : 'inactive'}.`);
10194
};
10295

10396
return (

src/components/integrations/integrations-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import { useState, useEffect } from 'react';
1212
import { MoreHorizontal, CheckCircle, Settings } from 'lucide-react';
1313
import { Button } from '@/components/ui/button';
14-
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card';
14+
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '@/components/ui/card';
1515
import {
1616
DropdownMenu,
1717
DropdownMenuContent,

src/components/inventory/inventory-page-client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function InventoryPageClient() {
6868
const [loading, setLoading] = useState(true);
6969
const [search, setSearch] = useState('');
7070
const [lowStockOnly, setLowStockOnly] = useState(false);
71-
const [selectedStore, setSelectedStore] = useState<string>('');
71+
const [selectedStore] = useState<string>(''); // setSelectedStore removed - not yet implemented
7272
const [adjustDialogOpen, setAdjustDialogOpen] = useState(false);
7373
const [selectedItem, setSelectedItem] = useState<InventoryItem | null>(null);
7474
const [adjustmentType, setAdjustmentType] = useState<'ADD' | 'REMOVE' | 'SET'>('ADD');

src/components/notifications/notifications-list.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { Badge } from '@/components/ui/badge';
1313
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
1414
import { Bell, Package, ShoppingCart, Users, AlertCircle, CheckCircle, XCircle } from 'lucide-react';
15-
import { useToast } from '@/hooks/use-toast';
15+
import { toast } from 'sonner';
1616

1717
interface Notification {
1818
id: string;
@@ -107,34 +107,24 @@ const getPriorityColor = (priority: string) => {
107107

108108
export function NotificationsList() {
109109
const [notifications, setNotifications] = useState<Notification[]>(mockNotifications);
110-
const { toast } = useToast();
111110

112111
const unreadCount = notifications.filter((n) => !n.read).length;
113112

114113
const handleMarkAsRead = (id: string) => {
115114
setNotifications((prev) =>
116115
prev.map((n) => (n.id === id ? { ...n, read: true } : n))
117116
);
118-
toast({
119-
title: 'Marked as read',
120-
description: 'Notification marked as read.',
121-
});
117+
toast.success('Notification marked as read.');
122118
};
123119

124120
const handleMarkAllAsRead = () => {
125121
setNotifications((prev) => prev.map((n) => ({ ...n, read: true })));
126-
toast({
127-
title: 'All notifications read',
128-
description: 'All notifications have been marked as read.',
129-
});
122+
toast.success('All notifications have been marked as read.');
130123
};
131124

132125
const handleClearAll = () => {
133126
setNotifications([]);
134-
toast({
135-
title: 'Notifications cleared',
136-
description: 'All notifications have been removed.',
137-
});
127+
toast.success('All notifications have been removed.');
138128
};
139129

140130
const getRelativeTime = (dateString: string) => {

0 commit comments

Comments
 (0)