diff --git a/app/api/products/[id]/route.ts b/app/api/ingredients/[id]/route.ts similarity index 84% rename from app/api/products/[id]/route.ts rename to app/api/ingredients/[id]/route.ts index da616ff..469e850 100644 --- a/app/api/products/[id]/route.ts +++ b/app/api/ingredients/[id]/route.ts @@ -13,7 +13,7 @@ export async function GET( } const db = await getDb(); - const product = await db.collection('products').aggregate([ + const ingredient = await db.collection('ingredients').aggregate([ { $match: { _id: new ObjectId(id) } }, { $lookup: { @@ -56,11 +56,11 @@ export async function GET( }, ]).next(); - if (!product) { - return NextResponse.json({ error: 'Product not found' }, { status: 404 }); + if (!ingredient) { + return NextResponse.json({ error: 'Ingredient not found' }, { status: 404 }); } - return NextResponse.json(product); + return NextResponse.json(ingredient); } export async function PUT( @@ -87,14 +87,14 @@ export async function PUT( if (body.supplierId !== undefined) update.supplierId = new ObjectId(body.supplierId); const db = await getDb(); - const result = await db.collection('products').findOneAndUpdate( + const result = await db.collection('ingredients').findOneAndUpdate( { _id: new ObjectId(id) }, { $set: update }, { returnDocument: 'after' } ); if (!result) { - return NextResponse.json({ error: 'Product not found' }, { status: 404 }); + return NextResponse.json({ error: 'Ingredient not found' }, { status: 404 }); } return NextResponse.json(result); @@ -111,10 +111,10 @@ export async function DELETE( } const db = await getDb(); - const result = await db.collection('products').deleteOne({ _id: new ObjectId(id) }); + const result = await db.collection('ingredients').deleteOne({ _id: new ObjectId(id) }); if (result.deletedCount === 0) { - return NextResponse.json({ error: 'Product not found' }, { status: 404 }); + return NextResponse.json({ error: 'Ingredient not found' }, { status: 404 }); } return NextResponse.json({ success: true }); diff --git a/app/api/products/route.ts b/app/api/ingredients/route.ts similarity index 95% rename from app/api/products/route.ts rename to app/api/ingredients/route.ts index a1afdc8..77d5c8d 100644 --- a/app/api/products/route.ts +++ b/app/api/ingredients/route.ts @@ -72,12 +72,12 @@ export async function GET(request: NextRequest) { ]; const [data, countResult] = await Promise.all([ - db.collection('products') + db.collection('ingredients') .aggregate(pipeline) .skip((page - 1) * limit) .limit(limit) .toArray(), - db.collection('products') + db.collection('ingredients') .countDocuments(matchStage), ]); @@ -113,7 +113,7 @@ export async function POST(request: Request) { updatedAt: now, }; - const result = await db.collection('products').insertOne(doc); + const result = await db.collection('ingredients').insertOne(doc); return NextResponse.json({ _id: result.insertedId, ...doc }, { status: 201 }); } diff --git a/app/dashboard/products/page.tsx b/app/dashboard/ingredients/page.tsx similarity index 92% rename from app/dashboard/products/page.tsx rename to app/dashboard/ingredients/page.tsx index b044ed9..102f1d1 100644 --- a/app/dashboard/products/page.tsx +++ b/app/dashboard/ingredients/page.tsx @@ -2,7 +2,7 @@ import React, { useState, useEffect, useCallback } from 'react'; import Sidebar from '@/components/Sidebar'; -import ProductTable, { Product } from '@/components/ProductTable'; +import IngredientTable, { Ingredient } from '@/components/IngredientTable'; interface Category { _id: string; @@ -15,16 +15,16 @@ interface Subcategory { categoryId: string; } -interface ProductsResponse { - data: Product[]; +interface IngredientsResponse { + data: Ingredient[]; total: number; page: number; limit: number; } -export default function ProductsPage() { +export default function IngredientsPage() { const [isSidebarOpen, setIsSidebarOpen] = useState(false); - const [products, setProducts] = useState([]); + const [ingredients, setIngredients] = useState([]); const [total, setTotal] = useState(0); const [page, setPage] = useState(1); const [search, setSearch] = useState(''); @@ -53,8 +53,8 @@ export default function ProductsPage() { ? allSubcategories.filter(s => s.categoryId === categoryId) : allSubcategories; - // Fetch products - const fetchProducts = useCallback(async () => { + // Fetch ingredients + const fetchIngredients = useCallback(async () => { setLoading(true); const params = new URLSearchParams(); params.set('page', String(page)); @@ -63,16 +63,16 @@ export default function ProductsPage() { if (categoryId) params.set('categoryId', categoryId); if (subcategoryId) params.set('subcategoryId', subcategoryId); - const res = await fetch(`/api/products?${params}`); - const data: ProductsResponse = await res.json(); - setProducts(data.data); + const res = await fetch(`/api/ingredients?${params}`); + const data: IngredientsResponse = await res.json(); + setIngredients(data.data); setTotal(data.total); setLoading(false); }, [page, search, categoryId, subcategoryId]); useEffect(() => { - fetchProducts(); - }, [fetchProducts]); + fetchIngredients(); + }, [fetchIngredients]); // Reset page when filters change useEffect(() => { @@ -136,13 +136,13 @@ export default function ProductsPage() {
{/* Header */}
-

Product Management

+

Ingredient Management

@@ -151,7 +151,7 @@ export default function ProductsPage() {
{/* Search */} -
+
- {/* Product Table */} + {/* Ingredient Table */} {loading ? (
-

Loading products...

+

Loading ingredients...

- ) : products.length === 0 ? ( + ) : ingredients.length === 0 ? (
-

No products found.

+

No ingredients found.

) : ( - + )} {/* Pagination */} @@ -268,7 +268,6 @@ export default function ProductsPage() { {Array.from({ length: totalPages }, (_, i) => i + 1) .filter(p => { - // Show first, last, current, and neighbors if (p === 1 || p === totalPages) return true; if (Math.abs(p - page) <= 1) return true; return false; @@ -280,7 +279,7 @@ export default function ProductsPage() { )}
diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx index d60f63d..f835135 100644 --- a/components/Sidebar.tsx +++ b/components/Sidebar.tsx @@ -11,7 +11,7 @@ interface NavItem { const navItems: NavItem[] = [ { label: 'Dashboard', icon: '📊', href: '/dashboard' }, - { label: 'Products', icon: '📦', active: true, href: '/dashboard/products' }, + { label: 'Ingredients', icon: '📦', active: true, href: '/dashboard/ingredients' }, { label: 'Categories', icon: '🏷️', href: '/dashboard/categories' }, { label: 'Subcategories', icon: '🔖', href: '/dashboard/subcategories' }, { label: 'Suppliers', icon: '🚚', href: '/dashboard/suppliers' }, diff --git a/lib/types.ts b/lib/types.ts index 4a3f94e..9e5caff 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -22,7 +22,7 @@ export interface Supplier { updatedAt: Date; } -export interface ProductDoc { +export interface IngredientDoc { _id: ObjectId; code: string; name: string; @@ -37,7 +37,7 @@ export interface ProductDoc { updatedAt: Date; } -export interface ProductWithRefs { +export interface IngredientWithRefs { _id: string; code: string; name: string; diff --git a/scripts/seed.ts b/scripts/seed.ts index 97e4f89..494e555 100644 --- a/scripts/seed.ts +++ b/scripts/seed.ts @@ -14,7 +14,7 @@ async function seed() { db.collection('categories').deleteMany({}), db.collection('subcategories').deleteMany({}), db.collection('suppliers').deleteMany({}), - db.collection('products').deleteMany({}), + db.collection('ingredients').deleteMany({}), ]); const now = new Date(); @@ -71,10 +71,10 @@ async function seed() { ]); console.log('Inserted 5 suppliers'); - // Insert products - await db.collection('products').insertMany([ + // Insert ingredients + await db.collection('ingredients').insertMany([ { - code: 'PRD-001', + code: 'ING-001', name: 'Organic Butter', categoryId: categoryIds.dairy, subcategoryId: subcategoryIds.butterSpreads, @@ -87,7 +87,7 @@ async function seed() { updatedAt: new Date('2026-02-10'), }, { - code: 'PRD-002', + code: 'ING-002', name: 'All-Purpose Flour', categoryId: categoryIds.dryGoods, subcategoryId: subcategoryIds.flours, @@ -100,7 +100,7 @@ async function seed() { updatedAt: new Date('2026-02-09'), }, { - code: 'PRD-003', + code: 'ING-003', name: 'Atlantic Salmon Fillet', categoryId: categoryIds.seafood, subcategoryId: subcategoryIds.freshFish, @@ -113,7 +113,7 @@ async function seed() { updatedAt: new Date('2026-02-11'), }, { - code: 'PRD-004', + code: 'ING-004', name: 'Madagascar Vanilla Extract', categoryId: categoryIds.dryGoods, subcategoryId: subcategoryIds.spicesExtracts, @@ -126,7 +126,7 @@ async function seed() { updatedAt: new Date('2026-02-08'), }, { - code: 'PRD-005', + code: 'ING-005', name: 'Fresh Avocados', categoryId: categoryIds.produce, subcategoryId: subcategoryIds.fruits, @@ -139,7 +139,7 @@ async function seed() { updatedAt: new Date('2026-02-11'), }, ]); - console.log('Inserted 5 products'); + console.log('Inserted 5 ingredients'); console.log('Seeding complete!'); await client.close();