Skip to content

Commit 926aa08

Browse files
fix: Resolve build errors and TypeScript issues for Railway deployment
1 parent dd8cf24 commit 926aa08

File tree

6 files changed

+70
-97
lines changed

6 files changed

+70
-97
lines changed

next.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ const nextConfig: NextConfig = {
44
images: {
55
domains: ['images.unsplash.com'],
66
},
7-
experimental: {
8-
serverComponentsExternalPackages: ['@prisma/client'],
9-
},
7+
serverExternalPackages: ['@prisma/client'],
108
output: 'standalone',
119
};
1210

src/app/api/cart/route.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { NextRequest, NextResponse } from "next/server"
2-
import { getServerSession } from "next-auth"
3-
import { authOptions } from "@/lib/auth"
2+
import { auth } from "@/lib/auth"
43
import { prisma } from "@/lib/prisma"
54

65
export async function GET() {
76
try {
8-
const session = await getServerSession(authOptions)
7+
const session = await auth()
98

109
if (!session?.user?.email) {
1110
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
@@ -44,7 +43,7 @@ export async function GET() {
4443

4544
export async function POST(request: NextRequest) {
4645
try {
47-
const session = await getServerSession(authOptions)
46+
const session = await auth()
4847

4948
if (!session?.user?.email) {
5049
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
@@ -68,7 +67,7 @@ export async function POST(request: NextRequest) {
6867
// Add new cart items
6968
if (items.length > 0) {
7069
await prisma.cartItem.createMany({
71-
data: items.map((item: any) => ({
70+
data: items.map((item: { productId: string; quantity: number }) => ({
7271
userId: user.id,
7372
productId: item.productId,
7473
quantity: item.quantity

src/app/products/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Notification } from "@/components/Notification";
77
import { SearchBar } from "@/components/SearchBar";
88
import { FeaturedCarousel } from "@/components/FeaturedCarousel";
99
import Image from "next/image";
10-
import { LoadingSpinner, ProductCardSkeleton, CategorySkeleton } from "@/components/LoadingSpinner";
10+
import { ProductCardSkeleton, CategorySkeleton } from "@/components/LoadingSpinner";
1111
import { useEffect, useState } from "react";
1212

1313
interface Product {

src/components/CartButton.tsx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,32 @@ export function CartButton({ userId }: CartButtonProps) {
1313
const [cartItemCount, setCartItemCount] = useState(0)
1414

1515
useEffect(() => {
16-
loadCartItemCount()
17-
}, [userId])
18-
19-
const loadCartItemCount = async () => {
20-
if (userId) {
21-
// Load from database for logged-in users
22-
try {
23-
const response = await fetch('/api/cart')
24-
if (response.ok) {
25-
const data = await response.json()
26-
const count = data.reduce((total: number, item: any) => total + item.quantity, 0)
16+
const loadCartItemCount = async () => {
17+
if (userId) {
18+
// Load from database for logged-in users
19+
try {
20+
const response = await fetch('/api/cart')
21+
if (response.ok) {
22+
const data = await response.json()
23+
const count = data.reduce((total: number, item: { quantity: number }) => total + item.quantity, 0)
24+
setCartItemCount(count)
25+
}
26+
} catch (error) {
27+
console.error('Error loading cart count:', error)
28+
}
29+
} else {
30+
// Load from localStorage for non-logged-in users
31+
const savedCart = localStorage.getItem('cartzy-cart')
32+
if (savedCart) {
33+
const cartItems = JSON.parse(savedCart)
34+
const count = cartItems.reduce((total: number, item: { quantity: number }) => total + item.quantity, 0)
2735
setCartItemCount(count)
2836
}
29-
} catch (error) {
30-
console.error('Error loading cart count:', error)
31-
}
32-
} else {
33-
// Load from localStorage for non-logged-in users
34-
const savedCart = localStorage.getItem('cartzy-cart')
35-
if (savedCart) {
36-
const cartItems = JSON.parse(savedCart)
37-
const count = cartItems.reduce((total: number, item: any) => total + item.quantity, 0)
38-
setCartItemCount(count)
3937
}
4038
}
41-
}
39+
40+
loadCartItemCount()
41+
}, [userId])
4242

4343
return (
4444
<>

src/components/Notification.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,32 @@ export function Notification({ userId }: NotificationProps) {
2222
const [unreadCount, setUnreadCount] = useState(0)
2323

2424
useEffect(() => {
25-
loadNotifications()
26-
}, [userId])
27-
28-
const loadNotifications = async () => {
29-
if (userId) {
30-
// Load from database for logged-in users
31-
try {
32-
const response = await fetch('/api/notifications')
33-
if (response.ok) {
34-
const data = await response.json()
25+
const loadNotifications = async () => {
26+
if (userId) {
27+
// Load from database for logged-in users
28+
try {
29+
const response = await fetch('/api/notifications')
30+
if (response.ok) {
31+
const data = await response.json()
32+
setNotifications(data)
33+
setUnreadCount(data.filter((n: Notification) => !n.read).length)
34+
}
35+
} catch (error) {
36+
console.error('Error loading notifications:', error)
37+
}
38+
} else {
39+
// Load from localStorage for non-logged-in users
40+
const savedNotifications = localStorage.getItem('cartzy-notifications')
41+
if (savedNotifications) {
42+
const data = JSON.parse(savedNotifications)
3543
setNotifications(data)
3644
setUnreadCount(data.filter((n: Notification) => !n.read).length)
3745
}
38-
} catch (error) {
39-
console.error('Error loading notifications:', error)
40-
}
41-
} else {
42-
// Load from localStorage for non-logged-in users
43-
const savedNotifications = localStorage.getItem('cartzy-notifications')
44-
if (savedNotifications) {
45-
const data = JSON.parse(savedNotifications)
46-
setNotifications(data)
47-
setUnreadCount(data.filter((n: Notification) => !n.read).length)
4846
}
4947
}
50-
}
48+
49+
loadNotifications()
50+
}, [userId])
5151

5252
const markAsRead = async (notificationId: string) => {
5353
const updatedNotifications = notifications.map(n =>

src/components/ShoppingCart.tsx

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,32 @@ interface ShoppingCartProps {
2121

2222
export function ShoppingCart({ isOpen, onClose, userId }: ShoppingCartProps) {
2323
const [cartItems, setCartItems] = useState<CartItem[]>([])
24-
const [isLoading, setIsLoading] = useState(false)
2524

2625
// Load cart items on mount
2726
useEffect(() => {
28-
loadCartItems()
29-
}, [userId])
30-
31-
const loadCartItems = async () => {
32-
if (userId) {
33-
// Load from database for logged-in users
34-
try {
35-
const response = await fetch('/api/cart')
36-
if (response.ok) {
37-
const data = await response.json()
38-
setCartItems(data)
27+
const loadCartItems = async () => {
28+
if (userId) {
29+
// Load from database for logged-in users
30+
try {
31+
const response = await fetch('/api/cart')
32+
if (response.ok) {
33+
const data = await response.json()
34+
setCartItems(data)
35+
}
36+
} catch (error) {
37+
console.error('Error loading cart:', error)
38+
}
39+
} else {
40+
// Load from localStorage for non-logged-in users
41+
const savedCart = localStorage.getItem('cartzy-cart')
42+
if (savedCart) {
43+
setCartItems(JSON.parse(savedCart))
3944
}
40-
} catch (error) {
41-
console.error('Error loading cart:', error)
42-
}
43-
} else {
44-
// Load from localStorage for non-logged-in users
45-
const savedCart = localStorage.getItem('cartzy-cart')
46-
if (savedCart) {
47-
setCartItems(JSON.parse(savedCart))
4845
}
4946
}
50-
}
47+
48+
loadCartItems()
49+
}, [userId])
5150

5251
const saveCartItems = async (items: CartItem[]) => {
5352
if (userId) {
@@ -67,30 +66,7 @@ export function ShoppingCart({ isOpen, onClose, userId }: ShoppingCartProps) {
6766
}
6867
}
6968

70-
const addToCart = async (product: any) => {
71-
const existingItem = cartItems.find(item => item.productId === product.id)
72-
73-
let newItems: CartItem[]
74-
if (existingItem) {
75-
newItems = cartItems.map(item =>
76-
item.productId === product.id
77-
? { ...item, quantity: item.quantity + 1 }
78-
: item
79-
)
80-
} else {
81-
newItems = [...cartItems, {
82-
id: Date.now().toString(),
83-
productId: product.id,
84-
name: product.name,
85-
price: product.price,
86-
quantity: 1,
87-
image: product.images[0]
88-
}]
89-
}
90-
91-
setCartItems(newItems)
92-
await saveCartItems(newItems)
93-
}
69+
9470

9571
const updateQuantity = async (itemId: string, newQuantity: number) => {
9672
if (newQuantity <= 0) {

0 commit comments

Comments
 (0)