Skip to content

Commit 00e39de

Browse files
authored
Deploy v1.1 (#10)
* 🐛 fixed account form * 🔧 configured i18n * ✨ handled expense edit * 🐛 budgets are now created on user registration * 🐛 user now has to fill name and surname in order to connect * :style: restyled sign up/in views * 🐛 fixed submit button disappearing on sign up/in page * ✨ new user are now redirected to account creation * ✅ added test for signup redirection
1 parent 5ef478c commit 00e39de

30 files changed

+7978
-105
lines changed

app/components/entry_card_component.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class='flex flex-row p-4 w-full items-center space-x-4'>
1+
<%= link_to @link, class:'flex flex-row p-4 w-full items-center space-x-4' do %>
22
<div style="background-color: <%= @color %>" class="flex items-center justify-center rounded-xl h-12 w-12 text-white">
33
<%= @icon.html_safe %>
44
</div>
@@ -9,5 +9,5 @@
99
</div>
1010
<%= content_tag :p, @amount, class: "#{@amount_color} font-semibold" %>
1111
</div>
12-
</div>
12+
<% end %>
1313
<hr style="width:100%;border-color: #e3e3e3;text-align:left;margin-left:0">

app/components/entry_card_component.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
class EntryCardComponent < ViewComponent::Base
22
attr_reader :entry
3+
4+
def before_render
5+
@link =
6+
if entry.class.name == 'Transfer'
7+
edit_transfer_path(@id)
8+
else
9+
edit_expense_path(@id)
10+
end
11+
end
12+
313
def initialize(entry: nil)
14+
@id = entry.id
415
@title =
516
if entry.class.name == 'Expense'
617
entry.title

app/controllers/accounts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def create
1414
end
1515

1616
def account_params
17-
params.require(:account).permit(:title, :balance, :main_account)
17+
params.require(:account).permit(:title, :balance, :main_account, :user_id)
1818
end
1919

2020
def find_account
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
class ApplicationController < ActionController::Base
22
before_action :authenticate_user!
3+
before_action :configure_permitted_parameters, if: :devise_controller?
4+
5+
protected
6+
7+
def configure_permitted_parameters
8+
devise_parameter_sanitizer.permit(:sign_up) do |u|
9+
u.permit(:name, :surname, :email, :password)
10+
end
11+
12+
devise_parameter_sanitizer.permit(:account_update) do |u|
13+
u.permit(:name, :surname, :email, :password, :current_password)
14+
end
15+
end
316
end

app/controllers/expenses_controller.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ def create
1717
end
1818
end
1919

20-
def edit
21-
@expense.update(expense_params)
20+
def edit; end
21+
22+
def update
23+
if @expense.update(expense_params)
24+
redirect_to url_for(controller: :users, action: :index)
25+
else
26+
render :edit
27+
end
2228
end
2329

2430
def find_expense
25-
@expense = Expense.includes(:budget).find(params[:id])
31+
@expense = Expense.find(params[:id])
2632
end
2733

2834
def expense_params
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class RegistrationsController < Devise::RegistrationsController
2+
protected
3+
4+
def after_sign_up_path_for(resource)
5+
new_account_path # Or :prefix_to_your_route
6+
end
7+
8+
def after_inactive_sign_up_path_for(resource)
9+
new_account_path # Or :prefix_to_your_route
10+
end
11+
end

app/models/budget.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Budget < ApplicationRecord
22
belongs_to :user
33
belongs_to :category
4-
has_many :expenses, through: :category
4+
has_many :expenses, through: :user
55

66
validates :target_amount, presence: true, numericality: { greater_than: 0 }
77

app/models/user.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,23 @@ class User < ApplicationRecord
1313
has_many :sent_transfers,
1414
class_name: 'Transfer',
1515
foreign_key: 'from_account_id'
16+
validates :name, :surname, presence: true
17+
before_create :create_budgets
1618

1719
def total_balance
1820
accounts.sum(:balance)
1921
end
2022

2123
def transfers
22-
accounts.includes([:sent_transfers]).map { |account| account.sent_transfers }.flatten
24+
accounts
25+
.includes([:sent_transfers])
26+
.map { |account| account.sent_transfers }
27+
.flatten
28+
end
29+
30+
def create_budgets
31+
Category.all.find_each do |category|
32+
self.budgets.build(category: category, target_amount: 100, monthly: true)
33+
end
2334
end
2435
end

app/views/accounts/_form.html.erb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
<%= form_with(model: account, local: true, class: 'flex flex-col w-full h-full') do |f| %>
22
<%= render "shared/form_errors", form: f %>
33
<div class="flex flex-col p-4 space-y-3">
4+
5+
<%= f.hidden_field :user_id, value: current_user.id %>
6+
47
<fieldset class='flex flex-col'>
58
<%= f.label :title, class: 'font-semibold' %>
69
<%= f.text_field :title, class: 'rounded border-gray-400' %>
710
</fieldset>
811

9-
<% yield %>
12+
<% if @account.new_record? %>
13+
<fieldset class='flex flex-col'>
14+
<%= f.label :initial_balance, class: 'font-semibold' %>
15+
<%= f.number_field :balance, class: 'rounded border-gray-400' %>
16+
</fieldset>
17+
<% end %>
1018

11-
<fieldset class='flex flex-col'>
19+
<fieldset class='flex flex-row items-center'>
20+
<%= f.check_box :main_account, class: 'rounded border-gray-400 mr-2' %>
1221
<%= f.label :main_account, class: 'font-semibold' %>
13-
<%= f.check_box :main_account, class: 'rounded border-gray-400' %>
1422
</fieldset>
1523

1624
<%= f.submit %>

app/views/accounts/edit.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<%= render 'shared/header' %>
1+
<%= render 'shared/header', title: t(:edit_account) %>
22
<%= render 'form', account: @account %>

0 commit comments

Comments
 (0)