Skip to content

Conversation

@abhimanyurajeesh
Copy link
Contributor

@abhimanyurajeesh abhimanyurajeesh commented Jan 21, 2026

Proposed Changes

Fixes #15255

image

Now a warning dialog will appear when the payment amount exceeds the invoice amount by more than 1 unit of the currency. This means:

Small decimal differences (like ₹0.50 or ₹0.99) will be ignored and the payment will proceed without warning
Significant overpayments (like ₹2.00 or more) will still trigger the warning dialog

Tagging: @ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate the bug or test the new feature.
  • Update product documentation.
  • Ensure that UI text is placed in I18n files.
  • Prepare a screenshot or demo video for the changelog entry and attach it to the issue.
  • Request peer reviews.
  • Complete QA on mobile devices.
  • Complete QA on desktop devices.
  • Add or update Playwright tests for related changes

Summary by CodeRabbit

  • New Features

    • Added a payment validation flow that warns when a payment exceeds an invoice total.
    • Added a confirmation dialog showing invoice total, entered amount, and the difference; users can confirm to proceed with over-amount payments.
  • Localization

    • Added new English UI strings for the confirmation and warning messages (proceed/yes, difference, payment exceeds warning).

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 21, 2026

Walkthrough

Adds five English localization keys and implements a payment-exceeds-invoice check in PaymentReconciliationSheet that shows a confirmation dialog with invoice total, entered amount, and the difference; submission is paused until user confirms.

Changes

Cohort / File(s) Summary
Localization Keys
public/locale/en.json
Added 5 new translation keys: confirm_to_proceed_with_payment, difference, payment_amount_exceeds_invoice_warning, payment_exceeds_invoice_amount, yes_proceed.
Payment Reconciliation Component
src/pages/Facility/billing/PaymentReconciliationSheet.tsx
Added local state (showExceedsWarning, pendingFormData), detection of payment > invoice total, integration of ConfirmActionDialog to show invoice total, entered amount, and difference, and handleConfirmExceedingPayment to submit pending data after confirmation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a payment confirmation dialog for exceeding invoice amounts.
Description check ✅ Passed The description includes the issue reference, explanation of the feature, a visual screenshot, and tags reviewers, though several merge checklist items remain unchecked.
Linked Issues check ✅ Passed The PR implementation addresses issue #15255 by adding a warning dialog for overpayments, including logic to ignore small decimal differences and trigger warnings for amounts exceeding 1 currency unit.
Out of Scope Changes check ✅ Passed All changes are scoped to the payment confirmation feature: translation keys for dialog text and the PaymentReconciliationSheet component logic for detecting and handling overpayments.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch manyu/add_confomation_for_exceeding_payment

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a confirmation dialog when a payment amount exceeds the invoice total by more than 1 currency unit, helping prevent accidental overpayments while allowing small decimal differences to proceed without interruption.

Changes:

  • Added warning dialog that triggers when payment exceeds invoice by >1 unit
  • Displays invoice total, payment amount, and difference for user verification
  • Added new i18n strings for the warning dialog messages

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/pages/Facility/billing/PaymentReconciliationSheet.tsx Implements payment validation logic and confirmation dialog with state management for pending form data
public/locale/en.json Adds i18n strings for payment warning dialog text and buttons

Comment on lines 182 to 187
const [pendingFormData, setPendingFormData] = useState<z.infer<
typeof formSchema
> | null>(null);
useShortcutSubContext();

const formSchema = createFormSchema();
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The formSchema is defined after these state declarations (at line 187), creating a temporal dead zone issue. The type reference z.infer<typeof formSchema> will fail because formSchema doesn't exist yet at this point in the code. Move the state declarations after the formSchema definition.

Suggested change
const [pendingFormData, setPendingFormData] = useState<z.infer<
typeof formSchema
> | null>(null);
useShortcutSubContext();
const formSchema = createFormSchema();
const formSchema = createFormSchema();
const [pendingFormData, setPendingFormData] = useState<z.infer<
typeof formSchema
> | null>(null);
useShortcutSubContext();

Copilot uses AI. Check for mistakes.
Comment on lines 262 to 270
if (
!isCreditNote &&
invoice &&
invoice.total_gross &&
data.amount &&
new Decimal(data.amount)
.minus(new Decimal(invoice.total_gross))
.greaterThan(1)
) {
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The threshold value 1 is a magic number without context. Consider extracting this to a named constant like PAYMENT_EXCESS_THRESHOLD with a comment explaining it represents 1 currency unit, making the business rule explicit and easier to maintain.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/pages/Facility/billing/PaymentReconciliationSheet.tsx`:
- Around line 181-184: Extract a named type for the form schema and use it for
pendingFormData to improve readability: define a type alias like
PaymentReconciliationFormData using z.infer<ReturnType<typeof createFormSchema>>
(place this alias near the createFormSchema definition) and then change the
pendingFormData state to use PaymentReconciliationFormData | null instead of
z.infer<typeof formSchema>; update any other references to the anonymous
inferred type to use the new alias (symbols to touch: createFormSchema,
formSchema, pendingFormData).
- Around line 262-274: The overpayment threshold is hardcoded as 1 in the
comparison inside PaymentReconciliationSheet; extract this magic number into a
clearly named constant (e.g., OVERPAYMENT_THRESHOLD) and use that constant in
the Decimal comparison (new Decimal(data.amount).minus(new
Decimal(invoice.total_gross)).greaterThan(new Decimal(OVERPAYMENT_THRESHOLD)) or
initialize the constant as a Decimal) so the business rule is explicit and
easier to change; update any related logic that references this value (the if
that calls setPendingFormData and setShowExceedsWarning) to use the new
constant.

Comment on lines +181 to +184
const [showExceedsWarning, setShowExceedsWarning] = useState(false);
const [pendingFormData, setPendingFormData] = useState<z.infer<
typeof formSchema
> | null>(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider extracting the form schema type for clarity.

The type z.infer<typeof formSchema> references formSchema which is defined below (line 187). While TypeScript resolves this correctly at compile time, it reduces readability. Consider extracting the type near createFormSchema:

type PaymentReconciliationFormData = z.infer<ReturnType<typeof createFormSchema>>;

Then use PaymentReconciliationFormData | null for pendingFormData.

🤖 Prompt for AI Agents
In `@src/pages/Facility/billing/PaymentReconciliationSheet.tsx` around lines 181 -
184, Extract a named type for the form schema and use it for pendingFormData to
improve readability: define a type alias like PaymentReconciliationFormData
using z.infer<ReturnType<typeof createFormSchema>> (place this alias near the
createFormSchema definition) and then change the pendingFormData state to use
PaymentReconciliationFormData | null instead of z.infer<typeof formSchema>;
update any other references to the anonymous inferred type to use the new alias
(symbols to touch: createFormSchema, formSchema, pendingFormData).

Comment on lines 262 to 274
if (
!isCreditNote &&
invoice &&
invoice.total_gross &&
data.amount &&
new Decimal(data.amount)
.minus(new Decimal(invoice.total_gross))
.greaterThan(1)
) {
setPendingFormData(data);
setShowExceedsWarning(true);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider extracting the threshold as a named constant.

The hardcoded 1 represents the minimum overpayment amount that triggers the warning dialog. Extracting it as a named constant improves readability and makes the business rule explicit:

♻️ Suggested refactor
+const OVERPAYMENT_WARNING_THRESHOLD = 1; // Warn when payment exceeds invoice by more than 1 currency unit
+
// Then in handleSubmit:
-        .greaterThan(1)
+        .greaterThan(OVERPAYMENT_WARNING_THRESHOLD)
🤖 Prompt for AI Agents
In `@src/pages/Facility/billing/PaymentReconciliationSheet.tsx` around lines 262 -
274, The overpayment threshold is hardcoded as 1 in the comparison inside
PaymentReconciliationSheet; extract this magic number into a clearly named
constant (e.g., OVERPAYMENT_THRESHOLD) and use that constant in the Decimal
comparison (new Decimal(data.amount).minus(new
Decimal(invoice.total_gross)).greaterThan(new Decimal(OVERPAYMENT_THRESHOLD)) or
initialize the constant as a Decimal) so the business rule is explicit and
easier to change; update any related logic that references this value (the if
that calls setPendingFormData and setShowExceedsWarning) to use the new
constant.

@github-actions
Copy link

github-actions bot commented Jan 21, 2026

🎭 Playwright Test Results

Status: ❌ Failed
Test Shards: 3

Metric Count
Total Tests 171
✅ Passed 145
❌ Failed 26
⏭️ Skipped 0

📊 Detailed results are available in the playwright-final-report artifact.

Run: #5331

@abhimanyurajeesh abhimanyurajeesh added the P1 breaking issue or vital feature label Jan 21, 2026
@github-actions github-actions bot added the Merge Conflict pull requests with merge conflict label Jan 21, 2026
@github-actions
Copy link

Conflicts have been detected against the base branch. Please merge the base branch into your branch.
cc: @abhimanyurajeesh

See: https://docs.ohc.network/docs/contributing#how-to-resolve-merge-conflicts

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 27, 2026

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: e9fe982
Status: ✅  Deploy successful!
Preview URL: https://4df38633.care-preview-a7w.pages.dev
Branch Preview URL: https://manyu-add-confomation-for-ex.care-preview-a7w.pages.dev

View logs

@github-actions github-actions bot removed the Merge Conflict pull requests with merge conflict label Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review needs testing P1 breaking issue or vital feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show a warning when you try to pay more than the invoice amount on the invoice page.

2 participants