Overview
ThePaymentModal component displays detailed information about a specific payment item. It shows the payment name, due date, and for completed payments, allows users to view and edit the payment date using an interactive date picker.
Component Location
src/components/modals/PaymentModal.jsx
Props
| Prop | Type | Required | Description |
|---|---|---|---|
isOpen | boolean | Yes | Controls the modal visibility state |
onClose | function | Yes | Callback function to close the modal |
paymentInfo | object | Yes | Payment item object containing payment details |
fechaVencimiento | Date | No | Due date for the payment |
mes | string | Yes | Month identifier for the payment |
checked | boolean | Yes | Whether the payment has been marked as paid |
Payment Info Object Structure
ThepaymentInfo prop expects an object with at least:
Features
Date Display
- Due Date: Always displayed, shows “No ingresada” (Not entered) if not set
- Payment Date: Only displayed when
checkedistrue(payment marked as completed)
Payment Date Editing
When a payment is marked as paid (checked={true}):
- The payment date is displayed with an edit button (pencil icon)
- Clicking the edit button opens an inline date picker
- Selected date is saved to localStorage automatically
- Date picker closes after selection
Hook Integration
The component uses the customusePago hook to manage payment state:
usePago Hook Functionality
TheusePago hook (from src/logic/usePago.js) provides:
- Persistent Storage: Stores payment dates in localStorage with key pattern:
paymentDate-{mes}-{pago.nombre}
- Date Management: Handles date selection and updates
- State Synchronization: Keeps UI in sync with localStorage
Usage Example
Workflow
Viewing Payment Details
- Open Modal: User clicks on a payment item
- View Information: Modal displays:
- Payment name in header
- Due date
- Payment date (if marked as paid)
- Close: User clicks close button or clicks outside modal
Editing Payment Date
- Payment Must Be Checked: Edit functionality only appears when
checked={true} - Click Edit Icon: User clicks the pencil icon next to payment date
- Select Date: Date picker appears inline
- Save Date:
- Selected date is immediately saved to localStorage
- Date picker closes automatically
- Display updates with new date
- Close Picker: Click outside or select a date to close
Date Picker Component
The modal uses theDatePickerElement component:
src/components/DatePickerElement.jsx
State Management
State is managed through theusePago hook and localStorage:
Conditional Rendering
The payment date section only renders when the payment is marked as paid:UI Components
The modal uses Chakra UI components:Modal,ModalOverlay,ModalContent- Modal structureModalHeader,ModalBody,ModalFooter- Content sectionsModalCloseButton- Close buttonButton- Close action buttonFlex- Layout for payment date and edit button
FontAwesomeIcon- Edit pencil iconDatePickerElement- Custom date picker component
Date Formatting
Dates are formatted using JavaScript’s built-intoLocaleDateString() method:
Event Handling
Stop Propagation
The edit button includese.stopPropagation() to prevent modal close events:
Accessibility
isCenteredprop centers modal on screenaria-label='Open Date Picker'on edit button- Keyboard navigation support via Chakra UI Modal
- Clear visual hierarchy with header, body, and footer
Data Persistence
All payment dates are persisted to localStorage with a composite key:- Per-month, per-payment date tracking
- Data persistence across browser sessions
- Independent date management for recurring payments
Integration Points
- usePago Hook (
src/logic/usePago.js): Payment state management - DatePickerElement (
src/components/DatePickerElement.jsx): Date selection UI - localStorage: Persistent data storage
- FontAwesome: Edit icon graphics
- Chakra UI: Modal and layout components
Read-Only Information
The modal displays these read-only fields:- Payment name (from
paymentInfo.nombre) - Due date (from
fechaVencimientoprop)
checked={true}.