Skip to content

refactor: change year format in both SaveCardDialog and SubscriptionPaymentDialog - #63

Merged
CowboyGH merged 2 commits into
developfrom
refactor/card-payment-dialog-year-format
Apr 4, 2026
Merged

CowboyGH merged 2 commits into
developfrom
refactor/card-payment-dialog-year-format

Conversation

@CowboyGH

@CowboyGH CowboyGH commented Apr 4, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Expiry year inputs now accept 2-digit years (e.g., "26" for 2026) and automatically normalize common 4-digit entries starting with "20".
  • Refactor

    • Expiry date validation and submission flow updated to interpret and normalize 2-digit years consistently.
    • Tests updated to reflect the new 2-digit year format and validation rules.

@CowboyGH CowboyGH self-assigned this Apr 4, 2026
@CowboyGH CowboyGH added type: refactor Code improvements without changing behavior area: ui/ux Widgets, layout, animations, or design labels Apr 4, 2026
@coderabbitai

coderabbitai Bot commented Apr 4, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0ce5ebfd-1291-4efa-b8b9-a49024fe1c9d

📥 Commits

Reviewing files that changed from the base of the PR and between 3447d42 and 1fa6263.

📒 Files selected for processing (2)
  • lib/features/cards/presentation/widgets/save_card_dialog.dart
  • lib/features/subscriptions/presentation/widgets/subscription_payment_dialog.dart
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/features/cards/presentation/widgets/save_card_dialog.dart

📝 Walkthrough

Walkthrough

This PR changes expiry-year handling from a 4-digit to a 2-digit short-year format across card and subscription payment flows. Validators now use a new private _parseFullYear(String?) that enforces exactly two numeric digits and maps them to full years via 2000 + shortYear. Input formatting in save/subscription dialogs was replaced with _ExpiryYearTextInputFormatter (accepts 1–2 digits, collapses 20xx to xx), and dialogs now convert the short year back to a backend full-year string via _buildBackendExpiryYear(...). Tests were updated to expect 2-digit year inputs.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TextField
    participant Formatter as _ExpiryYearTextInputFormatter
    participant Validator as _parseFullYear / Validators
    participant Dialog as Save/Subscription Dialog
    participant Cubit as PaymentCubit
    participant Backend

    User->>TextField: type expiry year
    TextField->>Formatter: new input
    Formatter-->>TextField: sanitized/short-year value
    TextField->>Validator: validation triggered (month/year checks)
    Validator-->>TextField: validation result (uses _parseFullYear)
    User->>Dialog: submit form
    Dialog->>Dialog: _buildBackendExpiryYear(shortYear)
    Dialog->>Cubit: pay(expiryYear: fullYear)
    Cubit->>Backend: send payment payload (expiryYear "20xx")
    Backend-->>Cubit: response
    Cubit-->>Dialog: result (success/failure)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I nibble digits, two not four,
I hop them into "20" at the door.
Validators tidy, formatters sing,
Backend-ready years hop on a string.
Cards and subs now twirl in view—cheer!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring year format handling across both payment dialogs (SaveCardDialog and SubscriptionPaymentDialog) from 4-digit to 2-digit format.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/card-payment-dialog-year-format

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/features/cards/presentation/widgets/save_card_dialog.dart`:
- Around line 223-226: The current inputFormatters for the expiry year field use
LengthLimitingTextInputFormatter(2) which clips pasted 4-digit years (e.g.,
"2026") to "20" causing incorrect validation; replace that with a custom
TextInputFormatter (implement a class like _ExpiryYearTextInputFormatter) that
strips non-digits, allows <=2 digits as-is, and when it detects exactly 4 digits
starting with "20" returns the last two digits (normalized) rather than
truncating—then use _ExpiryYearTextInputFormatter in the inputFormatters list
instead of LengthLimitingTextInputFormatter(2) so pastes of "2026" become "26"
and validations pass.

In
`@lib/features/subscriptions/presentation/widgets/subscription_payment_dialog.dart`:
- Around line 235-238: The expiry-year field currently applies
FilteringTextInputFormatter.digitsOnly and LengthLimitingTextInputFormatter(2)
which clips a pasted "2026" to "20" before validation; add a custom
TextInputFormatter (e.g. _ExpiryYearTextInputFormatter) that normalizes 4-digit
"20YY" input to the 2-digit "YY" form in formatEditUpdate before the
LengthLimitingTextInputFormatter runs, then replace/add this formatter in
subscription_payment_dialog.dart (and the save-card dialog equivalent) so pasted
full years are transformed to short years prior to length limiting and
validation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d4ebbf6f-88b4-431e-bc42-40a0c09afcd1

📥 Commits

Reviewing files that changed from the base of the PR and between a1151c4 and 3447d42.

📒 Files selected for processing (6)
  • lib/features/cards/presentation/validators/card_form_validators.dart
  • lib/features/cards/presentation/widgets/save_card_dialog.dart
  • lib/features/subscriptions/presentation/validators/subscription_payment_validators.dart
  • lib/features/subscriptions/presentation/widgets/subscription_payment_dialog.dart
  • test/features/cards/presentation/validators/card_form_validators_test.dart
  • test/features/subscriptions/presentation/validators/subscription_payment_validators_test.dart

Comment thread lib/features/cards/presentation/widgets/save_card_dialog.dart
@CowboyGH
CowboyGH merged commit 43994f7 into develop Apr 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui/ux Widgets, layout, animations, or design type: refactor Code improvements without changing behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant