diff --git a/app/assets/images/icon-arrow-left.svg b/app/assets/images/icon-arrow-left.svg new file mode 100644 index 00000000..c5d4629c --- /dev/null +++ b/app/assets/images/icon-arrow-left.svg @@ -0,0 +1,3 @@ + + + diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 3c32bd59..52e05739 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -1,10 +1,40 @@ class AccountsController < ApplicationController + before_action :authenticate_user! + def index + @accounts = current_family.accounts end def new end + def new_bank + @account = DepositoryAccount.new + end + def show end + + def create + @account = account_type_class.new(account_params) + @account.family = current_family + + if @account.save + redirect_to accounts_path + else + render :new + end + end + + private + + def account_params + params.require(:account).permit(:name, :balance, :type, :subtype) + end + + def account_type_class + params[:type].constantize + rescue + Account # Default to Account if type is not provided or invalid + end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2bfc19d9..f349b44e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,6 +13,11 @@ class ApplicationController < ActionController::Base end helper_method :current_user + def current_family + current_user.family + end + helper_method :current_family + def authenticate_user_from_session User.find_by(id: session[:user_id]) end diff --git a/app/models/depository.rb b/app/models/depository.rb new file mode 100644 index 00000000..64413a49 --- /dev/null +++ b/app/models/depository.rb @@ -0,0 +1,2 @@ +class Depository < Account +end \ No newline at end of file diff --git a/app/views/accounts/index.html.erb b/app/views/accounts/index.html.erb index d2281b00..24ad03e5 100644 --- a/app/views/accounts/index.html.erb +++ b/app/views/accounts/index.html.erb @@ -1,4 +1,8 @@
-

Accounts#index

+

Accounts#index

Find me in app/views/accounts/index.html.erb

+<% @accounts.each do |account| %> + <%= account.name %> +<% end %> + diff --git a/app/views/accounts/new.html.erb b/app/views/accounts/new.html.erb index 600265df..7056e431 100644 --- a/app/views/accounts/new.html.erb +++ b/app/views/accounts/new.html.erb @@ -2,7 +2,7 @@
- <%= link_to "new_bank_path", class: "flex flex-col items-center justify-center w-full text-center focus:outline-none" do %> + <%= link_to new_bank_path, class: "flex flex-col items-center justify-center w-full text-center focus:outline-none" do %> <%= inline_svg_tag('icon-bank-accounts.svg', class: 'text-[#3492FB] stroke-current') %> diff --git a/app/views/accounts/new_bank.html.erb b/app/views/accounts/new_bank.html.erb new file mode 100644 index 00000000..efd5e7f9 --- /dev/null +++ b/app/views/accounts/new_bank.html.erb @@ -0,0 +1,34 @@ +
+ <%= link_to new_account_path, class: "" do %> + <%= inline_svg_tag('icon-arrow-left.svg', class: 'text-gray-500 fill-current') %> + <% end %> +

Enter bank account

+
+ +<%= form_with model: @account, url: accounts_path, scope: :account, html: { class: "space-y-4" } do |f| %> + <%= f.hidden_field :type, value: "Depository" %> + +
+ <%# Optional %> + + <%= f.text_field :name, placeholder: "Account name", required: 'required', class: "p-0 mt-1 bg-transparent border-none opacity-50 focus:outline-none focus:ring-0 focus-within:opacity-100" %> +
+ +
+ + <%= f.select :subtype, options_for_select([["Checking", "checking"], ["Savings", "savings"]], selected: ""), {}, class: "block w-full p-0 mt-1 bg-transparent border-none focus:outline-none focus:ring-0" %> +
+ +
+ +
+ <%= f.number_field :balance, placeholder: "$0.00", in: 0.00..100000000.00, required: 'required', class: "p-0 mt-1 bg-transparent border-none opacity-50 focus:outline-none focus:ring-0 focus-within:opacity-100" %> +
+
+ +
+ +
+<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9f9b58cf..0a4af242 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,12 @@ Rails.application.routes.draw do resources :accounts + scope 'accounts/new' do + scope 'bank' do + get '', to: 'accounts#new_bank', as: 'new_bank' + end + end + # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. # Can be used by load balancers and uptime monitors to verify that the app is live. get "up" => "rails/health#show", as: :rails_health_check