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.
This commit is contained in:
@@ -65,9 +65,13 @@ export function PaymentsClient({ payments: initialPayments, members, integration
|
|||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
if (!res.ok) { toast.error(data.error ?? 'Sync failed'); return }
|
if (!res.ok) { toast.error(data.error ?? 'Sync failed'); return }
|
||||||
toast.success(`PayPal sync complete: ${data.imported} transactions imported`)
|
toast.success(`PayPal sync complete: ${data.imported} transactions imported`)
|
||||||
if (data.imported > 0) {
|
if (data.imported > 0 && Array.isArray(data.rows)) {
|
||||||
// Reload page to show new transactions
|
// Prepend the freshly imported (unlinked) rows; no full reload, so
|
||||||
window.location.reload()
|
// scroll/filter state is preserved (mirrors handleLogCash).
|
||||||
|
setPayments(prev => [
|
||||||
|
...(data.rows as Payment[]).map(r => ({ ...r, space_members: null })),
|
||||||
|
...prev,
|
||||||
|
])
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
toast.error('PayPal sync failed')
|
toast.error('PayPal sync failed')
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ export async function POST(req: NextRequest) {
|
|||||||
.select()
|
.select()
|
||||||
if (insertError) throw new Error(insertError.message)
|
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) {
|
} catch (err: any) {
|
||||||
console.error('[PayPal sync error]', err)
|
console.error('[PayPal sync error]', err)
|
||||||
return NextResponse.json({ error: err.message ?? 'Sync failed' }, { status: 500 })
|
return NextResponse.json({ error: err.message ?? 'Sync failed' }, { status: 500 })
|
||||||
|
|||||||
Reference in New Issue
Block a user