1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00

New bank addition (mostly hashing out STI bits)

Messy and gross. Will get cleaned up in the next couple of commits.
This commit is contained in:
Josh Pigford 2024-02-02 10:39:16 -06:00
parent 9014c8e615
commit 3bf7b47040
8 changed files with 86 additions and 2 deletions

View file

@ -0,0 +1,3 @@
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.70679 16.7069C9.51926 16.8944 9.26495 16.9997 8.99979 16.9997C8.73462 16.9997 8.48031 16.8944 8.29279 16.7069L2.29279 10.7069C2.10532 10.5194 2 10.2651 2 9.99992C2 9.73475 2.10532 9.48045 2.29279 9.29292L8.29279 3.29292C8.48139 3.11076 8.73399 3.00997 8.99619 3.01224C9.25838 3.01452 9.5092 3.11969 9.6946 3.3051C9.88001 3.49051 9.98518 3.74132 9.98746 4.00352C9.98974 4.26571 9.88894 4.51832 9.70679 4.70692L5.41379 8.99992H16.9998C17.265 8.99992 17.5194 9.10528 17.7069 9.29281C17.8944 9.48035 17.9998 9.7347 17.9998 9.99992C17.9998 10.2651 17.8944 10.5195 17.7069 10.707C17.5194 10.8946 17.265 10.9999 16.9998 10.9999H5.41379L9.70679 15.2929C9.89426 15.4804 9.99957 15.7348 9.99957 15.9999C9.99957 16.2651 9.89426 16.5194 9.70679 16.7069Z"/>
</svg>

After

Width:  |  Height:  |  Size: 900 B

View file

@ -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

View file

@ -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

2
app/models/depository.rb Normal file
View file

@ -0,0 +1,2 @@
class Depository < Account
end

View file

@ -1,4 +1,8 @@
<div>
<h1 class="font-bold text-4xl">Accounts#index</h1>
<h1 class="text-4xl font-bold">Accounts#index</h1>
<p>Find me in app/views/accounts/index.html.erb</p>
</div>
<% @accounts.each do |account| %>
<%= account.name %>
<% end %>

View file

@ -2,7 +2,7 @@
<div class="grid grid-cols-2 gap-4 mt-8 text-sm sm:grid-cols-3 md:grid-cols-4">
<div class="relative flex-col items-center px-5 py-4 space-x-3 text-center bg-white border border-gray-100 shadow-sm rounded-xl hover:border-gray-200">
<%= 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 %>
<span class="absolute inset-0" aria-hidden="true"></span>
<span class="flex w-10 h-10 shrink-0 grow-0 items-center justify-center rounded-xl bg-[#EAF4FF] mb-2">
<%= inline_svg_tag('icon-bank-accounts.svg', class: 'text-[#3492FB] stroke-current') %>

View file

@ -0,0 +1,34 @@
<div class="relative flex items-center mb-5 space-x-2">
<%= link_to new_account_path, class: "" do %>
<%= inline_svg_tag('icon-arrow-left.svg', class: 'text-gray-500 fill-current') %>
<% end %>
<h2 class="text-2xl font-semibold font-display">Enter bank account</h2>
</div>
<%= form_with model: @account, url: accounts_path, scope: :account, html: { class: "space-y-4" } do |f| %>
<%= f.hidden_field :type, value: "Depository" %>
<div class="relative p-4 border border-gray-100 bg-offwhite rounded-xl focus-within:bg-white focus-within:shadow focus-within:opacity-100">
<%# <span class="absolute px-2 py-1 text-xs font-medium text-gray-400 uppercase bg-gray-200 rounded-full opacity-50 right-3">Optional</span> %>
<label for="account_name" class="block text-sm font-medium opacity-50 focus-within:opacity-100">Name</label>
<%= 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" %>
</div>
<div class="relative p-4 border border-gray-100 bg-offwhite rounded-xl focus-within:bg-white focus-within:shadow focus-within:opacity-100">
<label for="account_name" class="block text-sm font-medium opacity-50 focus-within:opacity-100">Type</label>
<%= 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" %>
</div>
<div class="relative p-4 border border-gray-100 bg-offwhite rounded-xl focus-within:bg-white focus-within:shadow focus-within:opacity-100">
<label for="account_name" class="block text-sm font-medium opacity-50 focus-within:opacity-100">Balance</label>
<div class="flex">
<%= 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" %>
</div>
</div>
<div class="absolute right-5 bottom-5">
<button type="submit" class="flex items-center justify-center w-12 h-12 mb-2 bg-black rounded-full shrink-0 grow-0 hover:bg-gray-600">
<i class="text-xl text-white fa-regular fa-check"></i>
</button>
</div>
<% end %>

View file

@ -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