From 521fb1f8a879ef34c24fa98112e477867228a970 Mon Sep 17 00:00:00 2001 From: Moheeb Zara Date: Sun, 17 May 2026 01:18:05 -0700 Subject: [PATCH] fix(payments): prepend synced rows instead of full page reload PayPal sync route now returns the inserted rows; the client prepends them (mirrors handleLogCash) instead of window.location.reload(), preserving scroll/filter state. Was the only full reload in the app. --- app/(app)/payments/payments-client.tsx | 10 +++++++--- app/api/paypal/sync/route.ts | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/(app)/payments/payments-client.tsx b/app/(app)/payments/payments-client.tsx index eb946cf..eb7c6ca 100644 --- a/app/(app)/payments/payments-client.tsx +++ b/app/(app)/payments/payments-client.tsx @@ -65,9 +65,13 @@ export function PaymentsClient({ payments: initialPayments, members, integration const data = await res.json() if (!res.ok) { toast.error(data.error ?? 'Sync failed'); return } toast.success(`PayPal sync complete: ${data.imported} transactions imported`) - if (data.imported > 0) { - // Reload page to show new transactions - window.location.reload() + if (data.imported > 0 && Array.isArray(data.rows)) { + // Prepend the freshly imported (unlinked) rows; no full reload, so + // scroll/filter state is preserved (mirrors handleLogCash). + setPayments(prev => [ + ...(data.rows as Payment[]).map(r => ({ ...r, space_members: null })), + ...prev, + ]) } } catch { toast.error('PayPal sync failed') diff --git a/app/api/paypal/sync/route.ts b/app/api/paypal/sync/route.ts index b37ad16..8e1e15b 100644 --- a/app/api/paypal/sync/route.ts +++ b/app/api/paypal/sync/route.ts @@ -144,7 +144,7 @@ export async function POST(req: NextRequest) { .select() if (insertError) throw new Error(insertError.message) - return NextResponse.json({ imported: imported?.length ?? newRows.length }) + return NextResponse.json({ imported: imported?.length ?? newRows.length, rows: imported ?? [] }) } catch (err: any) { console.error('[PayPal sync error]', err) return NextResponse.json({ error: err.message ?? 'Sync failed' }, { status: 500 })