Skip to content

feat(money): Early Bird reward tiers editor, public display, and pledge expiry handling - #325

Merged
JOY (JOY) merged 1 commit into
devfrom
antigravity/give-317-early-bird-tiers
Nov 22, 2026
Merged

JOY (JOY) merged 1 commit into
devfrom
antigravity/give-317-early-bird-tiers

Conversation

@JOY

@JOY JOY (JOY) commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Refs #317

Summary

Phase 2 (App) for Back conversion — Early Bird reward tiers (paired with merged Phase 1 DB migration DOS/DOS.Me#1885, 20261202110000_give_early_bird_reward_tiers.sql, live on Beta oyajkbadsykigtfrpdpg at 6b593617144fe4a4f77007238ef8775f00b0db43):

  1. Reward tier editor (/me/campaigns/[id]):
    • Added Early Bird checkbox (is_early_bird) and Vietnam-time (Asia/Ho_Chi_Minh) datetime-local deadline picker (available_until, bounded by campaign starts_at/ends_at) in RewardTiersSection.tsx.
    • Wired rewardTierSchema and saveRewardTier server action to the 13-arg give.save_reward_tier RPC (p_is_early_bird, p_available_until), validating Early Bird scarcity limit (slot cap and/or deadline) and schedule bounds while preserving #264 owner/editor parity.
    • Rendered "Ưu đãi Early Bird" (Badge tone="warning"), Vietnam-time deadline, and expired status (Badge tone="danger") in tier summaries.
  2. Public campaign & pledge flow (/campaigns/[slug], /campaigns/[slug]/pledge):
    • Updated give.public_reward_tiers / give.reward_tiers queries and types (PublicRewardTier, RewardTier) to select and normalize is_early_bird and available_until.
    • Displayed "Ưu đãi Early Bird" badge, remaining slots, and Vietnam-time deadline on /campaigns/[slug] (RewardTiers.tsx) and /campaigns/[slug]/pledge (PledgeForm.tsx), cleanly disabling selection after available_until passes (now() >= available_until).
    • Money invariant preserved: Backers with an existing open pledge on an expired Early Bird tier see a clear reassurance notice that their existing pledge remains valid, retain "Xem cam kết" and "Hủy cam kết", see "Mức hiện tại của bạn" on their expired tier (disabled from re-submitting a failing change_pledge), and can cleanly switch to another active tier or "Ủng hộ không nhận quà".
    • Fast-fail check in savePledge plus Vietnamese error mapping for GIVE_REWARD_EXPIRED and GIVE_REWARD_TIER_DATES_INVALID in lib/errors.ts and lib/pledges.ts (zero raw Postgres error leaks).
  3. Design & Verification:
    • Follows DESIGN.md tokens (Badge, rounded, text-sm minimum for non-badge copy, tabular-nums, calm Vietnamese copy, no accent misuse, no nested boxes).
    • pnpm format:check: PASS
    • pnpm lint: PASS
    • pnpm typecheck: PASS
    • pnpm test: 201/201 test files, 2,830/2,830 tests PASS
    • pnpm build: PASS
    • Fresh-context subagent review (361e342c-f3df-4016-bbfb-dba1c09e64cb): CLEAN_PASS.

📌 TL;DR

This PR introduces "Early Bird" reward tiers, allowing campaign organizers to set time-limited deadlines for specific tiers. It implements full-stack validation (ensuring deadlines fall within the campaign window), UI updates to display badges and disable expired tiers, and safeguards to ensure existing pledges on expired tiers remain valid while preventing new pledges.

🎯 Type of Change

  • 🚀 New feature
  • 🐛 Bugfix
  • 🧹 Refactor
  • ⚡ Performance
  • 📚 Documentation
  • ⚙️ CI / Configuration

🔍 Changes Walkthrough

File Summary of Changes
apps/web/src/lib/pledges.ts Added is_early_bird and available_until to PublicRewardTier. Implemented isTierExpired and isTierUnavailable helper functions. Added GIVE_REWARD_EXPIRED error message.
apps/web/src/lib/reward-tiers.ts Updated RewardTier interface and TIER_COLUMNS constant to include the new Early Bird fields.
apps/web/src/lib/validation.ts Extended rewardTierSchema to parse is_early_bird and available_until. Added logic to clear the deadline if Early Bird is disabled and a refinement to ensure Early Bird tiers have either a quantity limit or a deadline.
apps/web/src/lib/errors.ts Added Vietnamese error messages for GIVE_REWARD_EXPIRED and GIVE_REWARD_TIER_DATES_INVALID.
apps/web/src/server/pledges/index.ts Updated toTier mapper to include the new Early Bird fields from database rows.
apps/web/src/app/campaigns/[slug]/pledge/PledgeForm.tsx Updated the pledge form to accept currentTierId and nowIso. Renders "Early Bird" badges, displays deadlines, and disables radio buttons for expired or sold-out tiers.
apps/web/src/app/campaigns/[slug]/pledge/actions.ts Added a server-side check in savePledge to reject pledges if the selected tier is expired (isTierExpired).
apps/web/src/app/campaigns/[slug]/pledge/page.tsx Updated page logic to detect if a user's existing pledge is on an expired tier. Passes currentTierId and nowIso to the form. Displays a reassurance message that existing pledges remain valid despite tier expiry.
apps/web/src/components/RewardTiers.tsx Updated the public campaign tier list to show Early Bird badges, deadlines, and disable links for expired tiers.
apps/web/src/app/me/campaigns/[id]/RewardTiersSection.tsx Added UI controls for organizers to toggle Early Bird status and set a datetime-local deadline. Displays badges and deadline info in the tier summary.
apps/web/src/app/me/campaigns/reward-actions.ts Added validation in saveRewardTier to ensure Early Bird deadlines are in the future and within the campaign's start/end dates. Passes new fields to the database RPC.
apps/web/src/app/me/campaigns/[id]/page.tsx Passed startsAt and endsAt to RewardTiersSection to enable deadline validation bounds.
*.test.ts Added comprehensive tests for Early Bird expiry logic, form rendering, action validation, and error mapping.

📊 Architectural Flow

flowchart TD
    subgraph Organizer_UI [Organizer UI]
        A[RewardTiersSection] -->|is_early_bird, available_until| B[saveRewardTier Action]
    end

    subgraph Server_Validation [Server Validation]
        B --> C{Validate Deadline}
        C -->|Past Date| D[Error: Must be future]
        C -->|Outside Campaign Window| E[Error: Must be within campaign dates]
        C -->|Valid| F[RPC: save_reward_tier]
    end

    subgraph Database [Database]
        F --> G[(Reward Tiers Table)]
    end

    subgraph Backer_UI [Backer UI]
        H[RewardTiers Component] -->|Click Tier| I[Pledge Page]
        I --> J{Check Tier Status}
        J -->|Expired/Sold Out| K[Disable Selection]
        J -->|Active| L[PledgeForm]
        L -->|Submit| M[savePledge Action]
    end

    subgraph Pledge_Validation [Pledge Validation]
        M --> N{isTierExpired?}
        N -->|Yes| O[Error: GIVE_REWARD_EXPIRED]
        N -->|No| P[Create/Update Pledge]
    end

    G -.->|Read Tiers| H
    G -.->|Read Tiers| I
Loading

@JOY JOY (JOY) added line:money Product line: money po:agy Owned by Antigravity PO (mutual-exclusion parallel PO label) labels Nov 22, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
give Ready Ready Preview Nov 22, 2026 3:51pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: da94ef59-ac8a-4940-919a-4a423dbb7953

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

dos[bot]
dos Bot approved these changes Nov 22, 2026

@dos dos Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ Code Review completed (22 eligible files · 53,361 chars · 3 model call(s) · 2 PR unit(s))

Whole diff with bounded context at base 5ef3bb1 / head 098e13b.

✅ CLEAN_PASS: Complete diff reviewed

Context investigation was bounded to the explicitly requested snapshot paths.

@JOY

Copy link
Copy Markdown
Contributor Author

PO acceptance: merge at 098e13b

Independent PO flagship money-domain review (b5b1b2e2-2317-4f09-94a8-55ce55b730ed): APPROVE (0 P0/P1/P2 findings).

@JOY
JOY (JOY) merged commit 522730d into dev Nov 22, 2026
6 checks passed
@JOY
JOY (JOY) deleted the antigravity/give-317-early-bird-tiers branch November 22, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

line:money Product line: money po:agy Owned by Antigravity PO (mutual-exclusion parallel PO label)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant