Skip to content

Commit

Permalink
Refactor to update streams on multiple crud. (#37)
Browse files Browse the repository at this point in the history
* Refactor to update streams on multiple crud.

* Capitalize new income on dashboard index
  • Loading branch information
neb417 authored Jan 14, 2024
1 parent 06fc825 commit a99ff28
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 172 deletions.
20 changes: 6 additions & 14 deletions app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,17 @@
<div class="primary-card">
<div class="mx-auto py-6 sm:px-6 lg:px-8">
<%= turbo_frame_tag "income_header_frame" do %>
<h3>Income</h3>
<h1>Income</h1>
<%= link_to "New Income", new_income_path, data: { turbo_frame: :incomes }, class: "btn btn-primary" %>
<% end %>

<div class="pt-4">
<%= turbo_frame_tag :incomes do %>
<%= render "incomes/index" %>
<% end %>
<%= render "incomes/index" %>
</div>

<div class="pt-4">
<%= turbo_frame_tag "taxed_incomes" do %>
<%= render partial: "shared/taxed_incomes",
locals: { salary_taxed: @salary_taxed, hourly_taxed: @hourly_taxed } %>
<% end %>
<%= render partial: "shared/taxed_incomes",
locals: { salary_taxed: @salary_taxed, hourly_taxed: @hourly_taxed } %>
</div>
</div>
</div>
Expand All @@ -79,13 +75,9 @@
<%= link_to "New Fixed Expense", new_fixed_expense_path, data: { turbo_frame: :fixed_expenses }, class: "btn btn-primary" %>
<% end %>

<%= turbo_frame_tag :fixed_expenses do %>
<%= render "fixed_expenses/index" %>
<% end %>
<%= render "fixed_expenses/index" %>

<%= turbo_frame_tag "total_costs" do %>
<%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %>
<% end %>
<%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %>
</div>
</div>
</div>
16 changes: 9 additions & 7 deletions app/views/fixed_expenses/_index.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<div id="fixed_expense_labels" class="grid grid-cols-5">
<% fixed_headings = %w[Expense Annual Monthly Bi-weekly] %>
<% fixed_headings.each do |fixed_heading| %>
<div class="px-5 pt-4"><strong><%= fixed_heading %></strong></div>
<% end %>
</div>
<%= turbo_frame_tag :fixed_expenses do %>
<div id="fixed_expense_labels" class="grid grid-cols-5">
<% fixed_headings = %w[Expense Annual Monthly Bi-weekly] %>
<% fixed_headings.each do |fixed_heading| %>
<div class="px-5 pt-4"><strong><%= fixed_heading %></strong></div>
<% end %>
</div>

<%= render @fixed_expenses %>
<%= render @fixed_expenses %>
<% end %>
51 changes: 24 additions & 27 deletions app/views/fixed_expenses/create.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
<%= turbo_stream.replace "fixed_expenses" do %>
<%= render @fixed_expenses %>
<%= turbo_stream.replace :fixed_expenses do %>
<%= render "fixed_expenses/index" %>
<% end %>

<%= turbo_stream.replace "total_costs" do %>
<%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %>
<% end %>
<%= turbo_stream.update "total_costs",
partial: "shared/total_costs",
locals: { total_cost: @total_cost }
%>

<%= turbo_stream.replace "salary_budget" do %>
<%= render partial: "budget/salary_budget",
locals: {
income: @salary_taxed,
total_cost: @total_cost,
investing_amount: @salary_invest,
savings_amount: @salary_saving,
guilt_free: @guilt_free_salary
}
%>
<% end %>
<%= turbo_stream.update "salary_budget",
partial: "budget/salary_budget",
locals: {
income: @salary_taxed,
total_cost: @total_cost,
investing_amount: @salary_invest,
savings_amount: @salary_saving,
guilt_free: @guilt_free_salary }
%>

<%= turbo_stream.replace "hourly_budget" do %>
<%= render partial: "budget/hourly_budget",
locals: {
income: @hourly_taxed,
total_cost: @total_cost,
investing_amount: @hourly_invest,
savings_amount: @hourly_saving,
guilt_free: @guilt_free_hourly
}
%>
<% end %>
<%= turbo_stream.update "hourly_budget",
partial: "budget/hourly_budget",
locals: {
income: @hourly_taxed,
total_cost: @total_cost,
investing_amount: @hourly_invest,
savings_amount: @hourly_saving,
guilt_free: @guilt_free_hourly }
%>
47 changes: 22 additions & 25 deletions app/views/fixed_expenses/destroy.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
<%= turbo_stream.remove @fixed_expense %>

<%= turbo_stream.replace "total_costs" do %>
<%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %>
<% end %>
<%= turbo_stream.update "total_costs",
partial: "shared/total_costs",
locals: { total_cost: @total_cost }
%>

<%= turbo_stream.replace "salary_budget" do %>
<%= render partial: "budget/salary_budget",
locals: {
income: @salary_taxed,
total_cost: @total_cost,
investing_amount: @salary_invest,
savings_amount: @salary_saving,
guilt_free: @guilt_free_salary
}
%>
<% end %>
<%= turbo_stream.update "salary_budget",
partial: "budget/salary_budget",
locals: {
income: @salary_taxed,
total_cost: @total_cost,
investing_amount: @salary_invest,
savings_amount: @salary_saving,
guilt_free: @guilt_free_salary }
%>

<%= turbo_stream.replace "hourly_budget" do %>
<%= render partial: "budget/hourly_budget",
locals: {
income: @hourly_taxed,
total_cost: @total_cost,
investing_amount: @hourly_invest,
savings_amount: @hourly_saving,
guilt_free: @guilt_free_hourly
}
%>
<% end %>
<%= turbo_stream.update "hourly_budget",
partial: "budget/hourly_budget",
locals: {
income: @hourly_taxed,
total_cost: @total_cost,
investing_amount: @hourly_invest,
savings_amount: @hourly_saving,
guilt_free: @guilt_free_hourly }
%>
47 changes: 22 additions & 25 deletions app/views/fixed_expenses/update.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
<%= turbo_stream.update @fixed_expense %>

<%= turbo_stream.replace "total_costs" do %>
<%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %>
<% end %>
<%= turbo_stream.update "total_costs",
partial: "shared/total_costs",
locals: { total_cost: @total_cost }
%>

<%= turbo_stream.replace "salary_budget" do %>
<%= render partial: "budget/salary_budget",
locals: {
income: @salary_taxed,
total_cost: @total_cost,
investing_amount: @salary_invest,
savings_amount: @salary_saving,
guilt_free: @guilt_free_salary
}
%>
<% end %>
<%= turbo_stream.update "salary_budget",
partial: "budget/salary_budget",
locals: {
income: @salary_taxed,
total_cost: @total_cost,
investing_amount: @salary_invest,
savings_amount: @salary_saving,
guilt_free: @guilt_free_salary }
%>

<%= turbo_stream.replace "hourly_budget" do %>
<%= render partial: "budget/hourly_budget",
locals: {
income: @hourly_taxed,
total_cost: @total_cost,
investing_amount: @hourly_invest,
savings_amount: @hourly_saving,
guilt_free: @guilt_free_hourly
}
%>
<% end %>
<%= turbo_stream.update "hourly_budget",
partial: "budget/hourly_budget",
locals: {
income: @hourly_taxed,
total_cost: @total_cost,
investing_amount: @hourly_invest,
savings_amount: @hourly_saving,
guilt_free: @guilt_free_hourly }
%>
18 changes: 10 additions & 8 deletions app/views/incomes/_index.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<h3>Net Income</h3>
<div class="grid grid-cols-5">
<% income_headings = ["Income Type", "Rate", "Hours", "Weekly Gross"] %>
<% income_headings.each do |income_heading| %>
<div class="px-5"><strong><%= income_heading %></strong></div>
<% end %>
</div>
<%= turbo_frame_tag :incomes do %>
<h3>Net Income</h3>
<div class="grid grid-cols-5">
<% income_headings = ["Income Type", "Rate", "Hours", "Weekly Gross"] %>
<% income_headings.each do |income_heading| %>
<div class="px-5"><strong><%= income_heading %></strong></div>
<% end %>
</div>

<%= render @incomes %>
<%= render @incomes %>
<% end %>
55 changes: 25 additions & 30 deletions app/views/incomes/update.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
<%= turbo_stream.update @income %>

<%= turbo_stream.replace "taxed_incomes" do %>
<%= render partial: "shared/taxed_incomes",
locals: {
salary_taxed: @salary_taxed,
hourly_taxed: @hourly_taxed
}
%>
<% end %>
<%= turbo_stream.update "taxed_incomes",
partial: "shared/taxed_incomes",
locals: {
salary_taxed: @salary_taxed,
hourly_taxed: @hourly_taxed
}
%>

<%= turbo_stream.replace "salary_budget" do %>
<%= render partial: "budget/salary_budget",
locals: {
income: @salary_taxed,
total_cost: @total_cost,
investing_amount: @salary_invest,
savings_amount: @salary_saving,
guilt_free: @guilt_free_salary
}
%>
<% end %>
<%= turbo_stream.update "salary_budget",
partial: "budget/salary_budget",
locals: {
income: @salary_taxed,
total_cost: @total_cost,
investing_amount: @salary_invest,
savings_amount: @salary_saving,
guilt_free: @guilt_free_salary }
%>

<%= turbo_stream.replace "hourly_budget" do %>
<%= render partial: "budget/hourly_budget",
locals: {
income: @hourly_taxed,
total_cost: @total_cost,
investing_amount: @hourly_invest,
savings_amount: @hourly_saving,
guilt_free: @guilt_free_hourly
}
%>
<% end %>
<%= turbo_stream.update "hourly_budget",
partial: "budget/hourly_budget",
locals: {
income: @hourly_taxed,
total_cost: @total_cost,
investing_amount: @hourly_invest,
savings_amount: @hourly_saving,
guilt_free: @guilt_free_hourly }
%>
64 changes: 33 additions & 31 deletions app/views/shared/_taxed_incomes.html.erb
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
<h3>Gross Income Annual</h3>
<div class="grid grid-cols-5">
<% fixed_headings = ["Income Type", "Federal Tax", "Fica Tax", "State Tax", "Annual"] %>
<% fixed_headings.each do |fixed_heading| %>
<div class="px-5"><strong><%= fixed_heading %></strong></div>
<% end %>
</div>
<%= turbo_frame_tag "taxed_incomes" do %>
<h3>Gross Income Annual</h3>
<div class="grid grid-cols-5">
<% fixed_headings = ["Income Type", "Federal Tax", "Fica Tax", "State Tax", "Annual"] %>
<% fixed_headings.each do |fixed_heading| %>
<div class="px-5"><strong><%= fixed_heading %></strong></div>
<% end %>
</div>

<div class="grid grid-cols-5">
<div class="px-5">Salary</div>
<%= render partial: "shared/taxed_income", locals: { taxed_income: salary_taxed, annual: true } %>
</div>
<div class="grid grid-cols-5">
<div class="px-5">Salary</div>
<%= render partial: "shared/taxed_income", locals: { taxed_income: salary_taxed, annual: true } %>
</div>

<div class="grid grid-cols-5">
<div class="px-5">Hourly</div>
<%= render partial: "shared/taxed_income", locals: { taxed_income: hourly_taxed, annual: true } %>
</div>
<div class="grid grid-cols-5">
<div class="px-5">Hourly</div>
<%= render partial: "shared/taxed_income", locals: { taxed_income: hourly_taxed, annual: true } %>
</div>

<br>
<br>

<h3>Gross Income Bi-Weekly</h3>
<div class="grid grid-cols-5">
<% fixed_headings = ["Income Type", "Federal Tax", "Fica Tax", "State Tax", "Bi-weekly"] %>
<% fixed_headings.each do |fixed_heading| %>
<div class="px-5"><strong><%= fixed_heading %></strong></div>
<% end %>
</div>
<h3>Gross Income Bi-Weekly</h3>
<div class="grid grid-cols-5">
<% fixed_headings = ["Income Type", "Federal Tax", "Fica Tax", "State Tax", "Bi-weekly"] %>
<% fixed_headings.each do |fixed_heading| %>
<div class="px-5"><strong><%= fixed_heading %></strong></div>
<% end %>
</div>

<div class="grid grid-cols-5">
<div class="px-5">Salary</div>
<%= render partial: "shared/taxed_income", locals: { taxed_income: salary_taxed, annual: false } %>
</div>
<div class="grid grid-cols-5">
<div class="px-5">Salary</div>
<%= render partial: "shared/taxed_income", locals: { taxed_income: salary_taxed, annual: false } %>
</div>

<div class="grid grid-cols-5">
<div class="px-5">Hourly</div>
<%= render partial: "shared/taxed_income", locals: { taxed_income: hourly_taxed, annual: false } %>
</div>
<div class="grid grid-cols-5">
<div class="px-5">Hourly</div>
<%= render partial: "shared/taxed_income", locals: { taxed_income: hourly_taxed, annual: false } %>
</div>
<% end %>
6 changes: 4 additions & 2 deletions app/views/shared/_total_costs.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div class="grid grid-cols-5">
<%= turbo_frame_tag "total_costs" do %>
<div class="grid grid-cols-5">
<div class="px-5">
<strong>Total</strong>
</div>
Expand All @@ -20,4 +21,5 @@
<%= render partial: "shared/total", locals: { total: total_cost.bi_weekly_cost } %>
</strong>
</div>
</div>
</div>
<% end %>
3 changes: 0 additions & 3 deletions spec/features/dashboard/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
end

it "has fixed expenses on the dashboard" do
# create(:income, :with_all_types)
# create(:federal_tax_bracket, :with_all_tiers)
# fixed_expenses = create_list(:fixed_expense, 2)
fixed1 = fixed_expenses.first
fixed2 = fixed_expenses.last

Expand Down

0 comments on commit a99ff28

Please sign in to comment.