diff --git a/app/assets/stylesheets/components/forms.css b/app/assets/stylesheets/components/forms.css index 5603ba4..633c293 100644 --- a/app/assets/stylesheets/components/forms.css +++ b/app/assets/stylesheets/components/forms.css @@ -10,6 +10,10 @@ @apply inline-block; } + .field_with_errors input { + @apply w-full bg-red-100; + } + .error-msg { @apply text-red-700; } diff --git a/app/controllers/admin/donations_controller.rb b/app/controllers/admin/donations_controller.rb index c29fb80..0a90184 100644 --- a/app/controllers/admin/donations_controller.rb +++ b/app/controllers/admin/donations_controller.rb @@ -41,7 +41,7 @@ class Admin::DonationsController < Admin::BaseController end format.json { render :show, status: :created, location: @donation } else - format.html { render :new } + format.html { render :new, status: :unprocessable_entity } format.json { render json: @donation.errors, status: :unprocessable_entity } end end @@ -59,7 +59,7 @@ class Admin::DonationsController < Admin::BaseController end format.json { render :show, status: :ok, location: @donation } else - format.html { render :edit } + format.html { render :edit, status: :unprocessable_entity } format.json { render json: @donation.errors, status: :unprocessable_entity } end end diff --git a/app/models/donation.rb b/app/models/donation.rb index 30f13a0..1a374dd 100644 --- a/app/models/donation.rb +++ b/app/models/donation.rb @@ -3,7 +3,9 @@ class Donation < ApplicationRecord belongs_to :user # Validations + validates_presence_of :user validates_presence_of :amount_sats + validates_presence_of :paid_at # Hooks # TODO before_create :store_fiat_value diff --git a/app/views/admin/donations/_form.html.erb b/app/views/admin/donations/_form.html.erb index 0522cb0..b04562a 100644 --- a/app/views/admin/donations/_form.html.erb +++ b/app/views/admin/donations/_form.html.erb @@ -1,16 +1,16 @@ <%= form_with(url: url, model: donation, local: true) do |form| %> <% if donation.errors.any? %> -
- <%= form.submit class: 'btn-md btn-blue' %> -
++ <%= link_to 'Cancel', + @donation.id.present? ? admin_donation_path(@donation) : admin_donations_path, + class: 'btn-md btn-gray' %> + <%= form.submit class: 'ml-2 btn-md btn-blue' %> +
+- <%= link_to 'Cancel', admin_donation_path(@donation), class: 'btn-sm btn-gray' %> -
<% end %> diff --git a/app/views/admin/donations/new.html.erb b/app/views/admin/donations/new.html.erb index 176b659..49d4671 100644 --- a/app/views/admin/donations/new.html.erb +++ b/app/views/admin/donations/new.html.erb @@ -2,8 +2,4 @@ <%= render MainSimpleComponent.new do %> <%= render 'form', donation: @donation, url: admin_donations_path %> - -
- <%= link_to 'Back', admin_donations_path, class: 'ks-text-link' %> -
<% end %> diff --git a/app/views/admin/donations/show.html.erb b/app/views/admin/donations/show.html.erb index 1526789..bec899d 100644 --- a/app/views/admin/donations/show.html.erb +++ b/app/views/admin/donations/show.html.erb @@ -33,9 +33,9 @@- <%= link_to 'Edit', edit_admin_donation_path(@donation), class: 'btn-md btn-blue mr-1' %> +
<%= link_to 'Back', admin_donations_path, class: 'btn-md btn-gray' %> + <%= link_to 'Edit', edit_admin_donation_path(@donation), class: 'ml-2 btn-md btn-blue mr-1' %>