Skip to content

feat: Add explicit fund allocation system to goals - #192

Merged
khanirfan18 merged 4 commits into
khanirfan18:mainfrom
TanCodeX:feature/goal-fund-allocation
Jun 13, 2026
Merged

feat: Add explicit fund allocation system to goals#192
khanirfan18 merged 4 commits into
khanirfan18:mainfrom
TanCodeX:feature/goal-fund-allocation

Conversation

@TanCodeX

@TanCodeX TanCodeX commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #191

This PR replaces the previous goal progress calculation model with an envelope-style allocation system. Instead of calculating goal progress from the user's global savings balance, each goal now maintains its own allocated savings amount, allowing users to explicitly reserve funds for individual goals.

This prevents unrelated spending from causing all goals to regress and provides a more accurate representation of progress toward savings objectives.

Changes

Database Updates

File: supabase/schema.sql

  • Added a new column to the goals table:
saved_amount NUMERIC DEFAULT 0

This field stores the amount of savings explicitly allocated to each goal.

Migration Required

To enable this feature in existing environments, run:

ALTER TABLE public.goals
ADD COLUMN saved_amount NUMERIC DEFAULT 0;

Important

Existing Supabase deployments must apply this migration before using the new goal allocation functionality.


Goals Page Enhancements

File: src/pages/Goals.jsx

New Savings Metrics

Added calculations for:

  • totalAllocated – total funds allocated across all goals.
  • unallocatedSavings – available savings not yet assigned to a goal.

Calculation:

unallocatedSavings = totalSavings - totalAllocated

Updated Summary Cards

Replaced the previous single savings summary with:

  1. Total Savings
  2. Unallocated (Available)
  3. Average Monthly Savings

This provides better visibility into both reserved and available funds.


Goal Progress Tracking

Goal progress is now based on each goal's allocated balance (saved_amount) instead of the global savings pool.

Previous Behavior

progress = totalSavings / targetAmount

This caused all goals to move together whenever savings increased or decreased.

New Behavior

progress = savedAmount / targetAmount

Each goal now tracks progress independently based on funds intentionally assigned to it.


Goal Fund Management

Added a new Manage Funds action to active goals.

Users can now:

Add Funds

  • Move available unallocated savings into a goal.
  • Progress updates immediately after allocation.

Withdraw Funds

  • Remove allocated funds from a goal.
  • Return them to the unallocated savings pool.

Validation

Added safeguards to prevent:

  • Allocating more than available unallocated savings.
  • Withdrawing more than a goal currently contains.
  • Invalid or negative transfer amounts.

Validation feedback is surfaced through the existing showModal workflow.


State & Persistence

Fund transfers now:

  • Update local React state immediately for responsive UI feedback.
  • Persist changes to Supabase via update() calls.
  • Recalculate allocation totals and available savings automatically.

Testing

Functional Verification

  • Verified allocation and withdrawal workflows.
  • Verified goal progress updates correctly based on saved_amount.
  • Verified unallocatedSavings recalculates after every transfer.
  • Verified inline fund management UI toggles correctly using allocationGoalId.

Validation Testing

Confirmed proper handling of:

  • Over-allocation attempts.
  • Over-withdrawal attempts.
  • Negative values.
  • Empty or invalid inputs.

Persistence Testing

  • Verified goal allocations persist after page refresh.
  • Verified Supabase updates reflect transferred amounts correctly.

Benefits

  • Goals are funded independently from one another.
  • Goal progress no longer regresses due to unrelated spending activity.
  • Users gain explicit control over how savings are distributed.
  • Better alignment with envelope budgeting and savings-goal best practices.
  • Improved transparency between available and reserved funds.

@netlify

netlify Bot commented Jun 8, 2026

Copy link
Copy Markdown

👷 Deploy request for finnboard0 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit bf31c1f

@netlify

netlify Bot commented Jun 8, 2026

Copy link
Copy Markdown

Deploy Preview for finnboard ready!

Name Link
🔨 Latest commit bf31c1f
🔍 Latest deploy log https://app.netlify.com/projects/finnboard/deploys/6a2d10cc6f66a00009e14b02
😎 Deploy Preview https://deploy-preview-192--finnboard.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@TanCodeX

Copy link
Copy Markdown
Contributor Author

@khanirfan18 Please review.

@khanirfan18

Copy link
Copy Markdown
Owner

@TanCodeX resolve the conflicts..

@TanCodeX

Copy link
Copy Markdown
Contributor Author

@khanirfan18 merge conflicts resolved.

@khanirfan18

khanirfan18 commented Jun 13, 2026

Copy link
Copy Markdown
Owner

@TanCodeX Has this migration been added as a Supabase migration file, or do i need to run it manually after merge? and yeah do fix the header issues too...

@TanCodeX

Copy link
Copy Markdown
Contributor Author

@TanCodeX Has this migration been added as a Supabase migration file, or do i need to run it manually after merge? and yeah do fix the header issues too...

@khanirfan18 This PR introduces a new saved_amount column to public.goals. After merging, the database migration must be applied manually in the Supabase SQL Editor:

ALTER TABLE public.goals
ADD COLUMN saved_amount numeric DEFAULT 0;

@khanirfan18
khanirfan18 merged commit 040a88d into khanirfan18:main Jun 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Goal Progress Regresses Based on Total Savings Instead of Goal Allocations

2 participants