mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
fix: payment dashboard date handling, chart rendering, and sidebar padding (#466)
@coderabbitai ignore
## Summary
- **Revenue chart showed nothing**: `store_payment()` used
`datetime.utcnow()` for `created_at` instead of the Stripe session's
actual `created` timestamp. All backfilled payments appeared on a single
date. Fixed to use `session["created"]`.
- **Single data point invisible**: Recharts AreaChart doesn't render a
visible area with only one point. Added `dot={chart.length === 1}` so
single points show as dots.
- **Payment detail sidebar had no padding**: `SheetContent` had no
padding class. Added `p-6`.
- **Backfill date fix script**: Added `scripts/fix_backfill_dates.py`
(already run against production to correct 32 records).
## Test plan
- [x] All 32 payment tests pass locally
- [x] Revenue chart verified visually via dev server — shows proper date
distribution (Dec 2025 - Mar 2026)
- [x] Payment detail sidebar verified visually — proper padding on all
sides
- [x] Production API confirmed returning correct date-bucketed data
after fix script
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
0d4b50b9e6
commit
b4be5968c2
6 files changed
+94
-4
No files matched your search
@@ -622,6 +622,9 @@ jobs:
|
||||
distribution: "temurin"
|
||||
java-version: "21"
|
||||
|
||||
- name: Install Firestore emulator
|
||||
run: sudo apt-get install -y google-cloud-cli-firestore-emulator
|
||||
|
||||
- name: Install dependencies
|
||||
run: poetry install
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ class StripeAdminService:
|
||||
"refunded_at": None,
|
||||
"refund_reason": None,
|
||||
# Timestamps
|
||||
"created_at": datetime.utcnow(),
|
||||
"created_at": datetime.utcfromtimestamp(session["created"]) if session.get("created") else datetime.utcnow(),
|
||||
"processed_at": datetime.utcnow(),
|
||||
# Metadata
|
||||
"is_test": is_test,
|
||||
|
||||
@@ -266,7 +266,7 @@ function RevenueOverviewTab() {
|
||||
<Skeleton className="h-[250px] w-full" />
|
||||
) : chart.length > 0 ? (
|
||||
<ChartContainer config={chartConfig} className="h-[250px] w-full">
|
||||
<AreaChart data={chart}>
|
||||
<AreaChart data={chart} margin={{ top: 5, right: 5, bottom: 5, left: 5 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" />
|
||||
<XAxis
|
||||
dataKey="date"
|
||||
@@ -291,6 +291,7 @@ function RevenueOverviewTab() {
|
||||
fill="var(--color-gross)"
|
||||
fillOpacity={0.2}
|
||||
name="Gross"
|
||||
dot={chart.length === 1}
|
||||
/>
|
||||
<Area
|
||||
type="monotone"
|
||||
@@ -299,6 +300,7 @@ function RevenueOverviewTab() {
|
||||
fill="var(--color-net)"
|
||||
fillOpacity={0.2}
|
||||
name="Net"
|
||||
dot={chart.length === 1}
|
||||
/>
|
||||
</AreaChart>
|
||||
</ChartContainer>
|
||||
|
||||
@@ -80,7 +80,7 @@ export function PaymentDetailSheet({ payment, onClose, onRefund }: PaymentDetail
|
||||
|
||||
return (
|
||||
<Sheet open={!!payment} onOpenChange={(open) => !open && onClose()}>
|
||||
<SheetContent className="overflow-y-auto">
|
||||
<SheetContent className="overflow-y-auto p-6">
|
||||
<SheetHeader>
|
||||
<SheetTitle>Payment Details</SheetTitle>
|
||||
<SheetDescription>
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "karaoke-gen"
|
||||
version = "0.125.1"
|
||||
version = "0.125.2"
|
||||
description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens."
|
||||
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
|
||||
license = "MIT"
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fix backfilled stripe_payments created_at dates.
|
||||
|
||||
The initial backfill stored datetime.utcnow() instead of the original
|
||||
Stripe session creation timestamp. This script fetches the real `created`
|
||||
timestamp from each Stripe session and updates the Firestore documents.
|
||||
|
||||
Usage:
|
||||
STRIPE_SECRET_KEY=... GOOGLE_CLOUD_PROJECT=nomadkaraoke python scripts/fix_backfill_dates.py [--dry-run]
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import stripe
|
||||
from datetime import datetime, timezone
|
||||
from google.cloud import firestore
|
||||
|
||||
def main():
|
||||
dry_run = "--dry-run" in sys.argv
|
||||
|
||||
stripe.api_key = os.environ.get("STRIPE_SECRET_KEY")
|
||||
if not stripe.api_key:
|
||||
print("ERROR: STRIPE_SECRET_KEY not set")
|
||||
sys.exit(1)
|
||||
|
||||
db = firestore.Client()
|
||||
collection = db.collection("stripe_payments")
|
||||
|
||||
# Get all payment docs
|
||||
docs = list(collection.stream())
|
||||
print(f"Found {len(docs)} payment documents")
|
||||
|
||||
updated = 0
|
||||
skipped = 0
|
||||
errors = 0
|
||||
|
||||
for doc in docs:
|
||||
data = doc.to_dict()
|
||||
session_id = data.get("session_id", doc.id)
|
||||
|
||||
try:
|
||||
# Fetch the Stripe session to get the real created timestamp
|
||||
session = stripe.checkout.Session.retrieve(session_id)
|
||||
real_created = datetime.fromtimestamp(session.created, tz=timezone.utc)
|
||||
|
||||
current_created = data.get("created_at")
|
||||
# Check if dates differ by more than 1 hour (backfill vs real)
|
||||
if current_created:
|
||||
if hasattr(current_created, 'timestamp'):
|
||||
diff = abs(current_created.timestamp() - session.created)
|
||||
else:
|
||||
diff = 999999 # force update if not a datetime
|
||||
|
||||
if diff < 3600:
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
if dry_run:
|
||||
print(f" [DRY RUN] {session_id}: would update created_at to {real_created}")
|
||||
updated += 1
|
||||
else:
|
||||
collection.document(doc.id).update({"created_at": real_created})
|
||||
print(f" Updated {session_id}: created_at -> {real_created}")
|
||||
updated += 1
|
||||
|
||||
# Rate limit
|
||||
time.sleep(0.1)
|
||||
|
||||
except stripe.error.InvalidRequestError as e:
|
||||
if "No such checkout.session" in str(e):
|
||||
skipped += 1
|
||||
else:
|
||||
print(f" ERROR {session_id}: {e}")
|
||||
errors += 1
|
||||
except Exception as e:
|
||||
print(f" ERROR {session_id}: {e}")
|
||||
errors += 1
|
||||
|
||||
prefix = "[DRY RUN] " if dry_run else ""
|
||||
print(f"\n{prefix}Done: {updated} updated, {skipped} skipped, {errors} errors")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user