Refactor admin donation pages, fix errors
All checks were successful
continuous-integration/drone/push Build is passing

Not sending the right response codes for Turbo to handle.
This commit is contained in:
Râu Cao 2023-03-15 15:24:00 +07:00
parent 95fac38b53
commit f050d010fd
Signed by: raucao
GPG Key ID: 15E65F399D084BA9
7 changed files with 23 additions and 20 deletions

View File

@ -10,6 +10,10 @@
@apply inline-block; @apply inline-block;
} }
.field_with_errors input {
@apply w-full bg-red-100;
}
.error-msg { .error-msg {
@apply text-red-700; @apply text-red-700;
} }

View File

@ -41,7 +41,7 @@ class Admin::DonationsController < Admin::BaseController
end end
format.json { render :show, status: :created, location: @donation } format.json { render :show, status: :created, location: @donation }
else else
format.html { render :new } format.html { render :new, status: :unprocessable_entity }
format.json { render json: @donation.errors, status: :unprocessable_entity } format.json { render json: @donation.errors, status: :unprocessable_entity }
end end
end end
@ -59,7 +59,7 @@ class Admin::DonationsController < Admin::BaseController
end end
format.json { render :show, status: :ok, location: @donation } format.json { render :show, status: :ok, location: @donation }
else else
format.html { render :edit } format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @donation.errors, status: :unprocessable_entity } format.json { render json: @donation.errors, status: :unprocessable_entity }
end end
end end

View File

@ -3,7 +3,9 @@ class Donation < ApplicationRecord
belongs_to :user belongs_to :user
# Validations # Validations
validates_presence_of :user
validates_presence_of :amount_sats validates_presence_of :amount_sats
validates_presence_of :paid_at
# Hooks # Hooks
# TODO before_create :store_fiat_value # TODO before_create :store_fiat_value

View File

@ -1,16 +1,16 @@
<%= form_with(url: url, model: donation, local: true) do |form| %> <%= form_with(url: url, model: donation, local: true) do |form| %>
<% if donation.errors.any? %> <% if donation.errors.any? %>
<div id="error_explanation"> <section id="error_explanation">
<h3><%= pluralize(donation.errors.count, "error") %> prohibited this donation from being saved:</h3> <h3><%= pluralize(donation.errors.count, "error") %> prohibited this donation from being saved:</h3>
<ul> <ul class="list-disc list-inside">
<% donation.errors.full_messages.each do |message| %> <% donation.errors.full_messages.each do |message| %>
<li><%= message %></li> <li><%= message %></li>
<% end %> <% end %>
</ul> </ul>
</div> </section>
<% end %> <% end %>
<div class="sm:w-1/2 grid grid-cols-2 items-center gap-y-2"> <section class="sm:w-1/2 grid grid-cols-2 items-center gap-y-2">
<%= form.label :user_id %> <%= form.label :user_id %>
<%= form.collection_select :user_id, User.where(ou: "kosmos.org").order(:cn), :id, :cn, {} %> <%= form.collection_select :user_id, User.where(ou: "kosmos.org").order(:cn), :id, :cn, {} %>
@ -28,9 +28,14 @@
<%= form.label :paid_at %> <%= form.label :paid_at %>
<%= form.text_field :paid_at %> <%= form.text_field :paid_at %>
</div> </section>
<p class="mt-8"> <section>
<%= form.submit class: 'btn-md btn-blue' %> <p class="pt-6 border-t border-gray-200 text-right">
</p> <%= 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' %>
</p>
</section>
<% end %> <% end %>

View File

@ -2,8 +2,4 @@
<%= render MainSimpleComponent.new do %> <%= render MainSimpleComponent.new do %>
<%= render 'form', donation: @donation, url: admin_donation_path(@donation) %> <%= render 'form', donation: @donation, url: admin_donation_path(@donation) %>
<p class="mt-8">
<%= link_to 'Cancel', admin_donation_path(@donation), class: 'btn-sm btn-gray' %>
<p>
<% end %> <% end %>

View File

@ -2,8 +2,4 @@
<%= render MainSimpleComponent.new do %> <%= render MainSimpleComponent.new do %>
<%= render 'form', donation: @donation, url: admin_donations_path %> <%= render 'form', donation: @donation, url: admin_donations_path %>
<p class="mt-8">
<%= link_to 'Back', admin_donations_path, class: 'ks-text-link' %>
</p>
<% end %> <% end %>

View File

@ -33,9 +33,9 @@
</section> </section>
<section> <section>
<p> <p class="pt-6 border-t border-gray-200 text-right">
<%= 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 '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' %>
</p> </p>
</section> </section>
<% end %> <% end %>