From 6a1917bd9a4d03332a3a7f0350c24570d3dca042 Mon Sep 17 00:00:00 2001 From: Mehar Khanna Date: Sat, 13 Sep 2025 17:26:51 -0400 Subject: [PATCH 1/3] add cart --- app/api/sync-products/route.ts | 42 ++++++-------- components/camera-scanner.tsx | 47 ++++++++------- components/cart/add-to-cart.tsx | 63 ++++++++++++++------- components/layout/navbar/scanner-button.tsx | 2 +- 4 files changed, 90 insertions(+), 64 deletions(-) diff --git a/app/api/sync-products/route.ts b/app/api/sync-products/route.ts index eb78c16..14cb39f 100644 --- a/app/api/sync-products/route.ts +++ b/app/api/sync-products/route.ts @@ -1,32 +1,26 @@ +'use server'; + import { NextRequest, NextResponse } from 'next/server'; -import { syncShopifyToSupabase } from 'lib/shopify-supabase-sync'; +import { syncShopifyToSupabase, syncShopifyProductByHandle } from 'lib/shopify-supabase-sync'; -export async function POST(request: NextRequest) { +export async function POST(req: NextRequest) { try { + const { searchParams } = new URL(req.url); + const handle = searchParams.get('handle'); + if (handle) { + const result = await syncShopifyProductByHandle(handle); + if (!result.success) { + return NextResponse.json({ error: 'Sync failed', details: result }, { status: 500 }); + } + return NextResponse.json({ success: true, count: result.count || 0 }); + } const result = await syncShopifyToSupabase(); - - if (result.success) { - return NextResponse.json({ - success: true, - message: `Synced ${result.count} products from Shopify`, - products: result.products - }); - } else { - return NextResponse.json( - { success: false, error: result.error }, - { status: 500 } - ); + if (!result.success) { + return NextResponse.json({ error: 'Sync failed', details: result }, { status: 500 }); } - } catch (error) { - console.error('Sync API error:', error); - return NextResponse.json( - { success: false, error: 'Sync failed' }, - { status: 500 } - ); + return NextResponse.json({ success: true, count: result.count || 0 }); + } catch (e: any) { + return NextResponse.json({ error: 'Unexpected error', details: e?.message || String(e) }, { status: 500 }); } } -export async function GET(request: NextRequest) { - // Trigger sync on GET for easy testing - return POST(request); -} diff --git a/components/camera-scanner.tsx b/components/camera-scanner.tsx index 9c0da3e..a81e6e3 100644 --- a/components/camera-scanner.tsx +++ b/components/camera-scanner.tsx @@ -19,6 +19,7 @@ export default function CameraScanner({ onDetected, onClose, autoCloseOnScan = t const streamRef = useRef(null); const timerRef = useRef(null); const [autoMode, setAutoMode] = useState(false); + const [showManual, setShowManual] = useState(false); useEffect(() => { startScanning(); @@ -219,6 +220,14 @@ export default function CameraScanner({ onDetected, onClose, autoCloseOnScan = t )} + {/* Manual input toggle */} + +