Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Admin: Improve promotion page

Damian Legawieccf37954136e9
diff --git a/admin/app/assets/stylesheets/spree/admin/components/_main.scss b/admin/app/assets/stylesheets/spree/admin/components/_main.scss
index 305a824872..430b5e1bf8 100644
--- a/admin/app/assets/stylesheets/spree/admin/components/_main.scss
+++ b/admin/app/assets/stylesheets/spree/admin/components/_main.scss
@@ -40,6 +40,10 @@ turbo-frame[loading] .spinner-border, turbo-frame[busy] .spinner-border {
}
}
+#page-header {
+ min-height: 74px;
+}
+
.page-header-title {
font-size: 1.5rem;
font-weight: 700;
diff --git a/admin/app/controllers/spree/admin/coupon_codes_controller.rb b/admin/app/controllers/spree/admin/coupon_codes_controller.rb
index 9d58f7055f..058b17771a 100644
--- a/admin/app/controllers/spree/admin/coupon_codes_controller.rb
+++ b/admin/app/controllers/spree/admin/coupon_codes_controller.rb
@@ -13,7 +13,7 @@ module Spree
@collection = if request.format.csv?
@search.result
else
- @search.result.page(params[:page]).per(50)
+ @search.result.page(params[:page])
end
end
end
diff --git a/admin/app/views/spree/admin/coupon_codes/_coupon_code.html.erb b/admin/app/views/spree/admin/coupon_codes/_coupon_code.html.erb
index 2c4f071243..3c2d59068a 100644
--- a/admin/app/views/spree/admin/coupon_codes/_coupon_code.html.erb
+++ b/admin/app/views/spree/admin/coupon_codes/_coupon_code.html.erb
@@ -1,7 +1,12 @@
-<tr id="">
- <td class="w-50"><code><%= coupon_code[1].upcase %></code></td>
- <td class="w-25"><%= active_badge(coupon_code[2] == 'used') %></td>
- <td class="w-25"><%= local_time(coupon_code[3]) %></td>
- <td class="actions w-35 text-right">
+<tr id="spree_coupon_code_<%= coupon_code[0] %>">
+ <td class="w-50">
+ <div data-controller="clipboard">
+ <code data-clipboard-target="source"><%= coupon_code[1].upcase %></code>
+ <button type="button" class="btn btn-link p-1 ml-2 with-tip" data-action="clipboard#copy" title="<%= Spree.t(:copy_to_clipboard) %>">
+ <%= icon('copy', class: 'mr-0 font-size-sm') %>
+ </button>
+ </div>
</td>
+ <td class="w-25 font-size-sm"><%= active_badge(coupon_code[2] == 'used') %></td>
+ <td class="w-25 font-size-sm"><%= local_time(coupon_code[3]) %></td>
</tr>
diff --git a/admin/app/views/spree/admin/coupon_codes/index.html.erb b/admin/app/views/spree/admin/coupon_codes/index.html.erb
index 9c68fc5ec8..0ac9607c24 100644
--- a/admin/app/views/spree/admin/coupon_codes/index.html.erb
+++ b/admin/app/views/spree/admin/coupon_codes/index.html.erb
@@ -1,59 +1,70 @@
-<% content_for :page_title do %>
- <%= page_header_back_button spree.admin_promotions_path, @promotion %>
- <%= @promotion.name %>
-<% end %>
+<%= render 'spree/admin/promotions/header' %>
-<% content_for :page_actions do %>
- <%= link_to spree.admin_promotion_coupon_codes_path(@promotion, format: :csv), class: 'btn btn-light bg-transparent with-tip', title: 'Download coupons ad a CSV file' do %>
- <%= icon 'download' %>
- <%= Spree.t(:download) %>
- <% end %>
-<% end %>
+<div class="row">
+ <div class="col-12 col-lg-8">
+ <div class="card-lg p-0">
+ <%= search_form_for [:admin, @promotion, @search], class: "filter-wrap border-bottom" do |f| %>
+ <div class="d-flex flex-column flex-lg-row gap-2">
+ <%= render 'spree/admin/shared/filters_search_bar', param: :code_eq %>
-<%= turbo_frame_tag :coupon_codes do %>
+ <div class="d-flex align-items-center justify-content-between">
+ <div class="dropdown h-100">
+ <button class="btn btn-light h-100 dropdown-toggle" type="button" data-toggle="dropdown" data-display="static" data-flip="false" aria-expanded="false">
+ <span class="text-muted font-weight-normal">
+ <%= Spree.t(:show) %>
+ </span>
+ <%= Spree.t(:all) if (params[:q] || {}).values_at(:state_eq).all?(&:blank?) %>
+ <%= Spree.t('admin.coupon_codes.used') if params.dig(:q, :state_eq) == 'used' %>
+ <%= Spree.t('admin.coupon_codes.unused') if params.dig(:q, :state_eq) == 'unused' %>
+ </button>
+ <div class="dropdown-menu w-100 font-size-sm" style="min-width: 200px">
+ <%= active_link_to Spree.t('admin.orders.all'),
+ spree.admin_promotion_coupon_codes_path,
+ class: 'dropdown-item',
+ active: (params[:q] || {}).values_at(:state_eq).all?(&:blank?) %>
+ <%= link_to Spree.t('admin.coupon_codes.used'),
+ params.merge({q: {state_eq: :used}}).permit!,
+ class: "dropdown-item #{'active' if params.dig(:q, :state_eq) == 'used'}" %>
+ <%= link_to Spree.t('admin.coupon_codes.unused'),
+ params.merge({q: {state_eq: :unused}}).permit!,
+ class: "dropdown-item #{'active' if params.dig(:q, :state_eq) == 'unused'}" %>
+ </div>
+ </div>
+ </div>
- <ul id="table-tabs" class="nav nav-pills d-inline-flex mb-3">
- <li class="nav-item">
- <%= link_to Spree.t('admin.orders.all'),
- spree.admin_promotion_coupon_codes_path,
- class: "nav-link #{'active' if (params[:q] || {}).values_at(:state_eq ).all?(&:blank?)}" %>
- </li>
+ <%= link_to spree.admin_promotion_coupon_codes_path(@promotion, format: :csv), class: 'btn btn-light bg-transparent with-tip', title: 'Download coupons as a CSV file' do %>
+ <%= icon 'download' %>
+ <%= Spree.t(:download) %>
+ <% end %>
+ </div>
+ <% end %>
- <li class="nav-item">
- <%= link_to Spree.t('admin.coupon_codes.used'),
- params.merge({q: {state_eq: :used}}).permit!,
- class: "nav-link #{'active' if params.dig(:q, :state_eq) == 'used'}" %>
- </li>
-
- <li class="nav-item">
- <%= link_to Spree.t('admin.coupon_codes.unused'),
- params.merge({q: {state_eq: :unused}}).permit!,
- class: "nav-link #{'active' if params.dig(:q, :state_eq) == 'unused'}" %>
- </li>
- </ul>
-
- <div class="table-responsive card-lg p-0">
- <% if @coupon_codes.any? %>
- <table class="table">
- <thead class="text-muted">
- <tr data-hook="rate_header">
- <th><%= Spree.t(:code) %></th>
- <th><%= Spree.t(:used) %></th>
- <th><%= Spree.t(:created_at) %></th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- <%= render collection: @coupon_codes.pluck(:id, :code, :state, :created_at), partial: 'spree/admin/coupon_codes/coupon_code', cached: spree_base_cache_scope %>
- </tbody>
- </table>
- <% else %>
- <div class="text-muted p-5 d-flex align-items-center w-100 justify-content-center">
- <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::CouponCode)) %>
+ <div class="table-responsive">
+ <% if @coupon_codes.any? %>
+ <table class="table">
+ <thead class="text-muted">
+ <tr data-hook="rate_header">
+ <th><%= Spree.t(:code) %></th>
+ <th><%= Spree.t(:used) %></th>
+ <th><%= Spree.t(:created_at) %></th>
+ </tr>
+ </thead>
+ <tbody>
+ <%= render collection: @coupon_codes.pluck(:id, :code, :state, :created_at), partial: 'spree/admin/coupon_codes/coupon_code', cached: spree_base_cache_scope %>
+ </tbody>
+ </table>
+ <% else %>
+ <div class="text-muted p-5 d-flex align-items-center w-100 justify-content-center">
+ <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::CouponCode)) %>
+ </div>
+ <% end %>
</div>
- <% end %>
- </div>
+ <%= render 'spree/admin/shared/index_table_options', collection: @coupon_codes, simple: true if @coupon_codes.any? %>
+ </div>
+ </div>
- <%= render 'spree/admin/shared/index_table_options', collection: @coupon_codes, simple: true if @coupon_codes.any? %>
-<% end %>
\ No newline at end of file
+ <div class="col-12 col-lg-4">
+ <%= render 'spree/admin/promotions/sidebar' %>
+ </div>
+</div>
diff --git a/admin/app/views/spree/admin/promotions/_header.html.erb b/admin/app/views/spree/admin/promotions/_header.html.erb
new file mode 100644
index 0000000000..794ab45cd3
--- /dev/null
+++ b/admin/app/views/spree/admin/promotions/_header.html.erb
@@ -0,0 +1,16 @@
+<% content_for :page_title do %>
+ <%= page_header_back_button spree.admin_promotions_path, @promotion %>
+ <%= @promotion.name %>
+ <div class="ml-3">
+ <%= render 'spree/admin/promotions/status', promotion: @promotion %>
+ </div>
+<% end %>
+
+<% content_for :page_tabs do %>
+ <li class="nav-item">
+ <%= active_link_to Spree.t(:settings), spree.admin_promotion_path(@promotion), class: "nav-link", active: controller_name == 'promotions' %>
+ </li>
+ <li class="nav-item">
+ <%= active_link_to Spree.t(:coupon_codes), spree.admin_promotion_coupon_codes_path(@promotion), class: "nav-link" %>
+ </li>
+<% end if @promotion.multi_codes? %>
diff --git a/admin/app/views/spree/admin/promotions/_sidebar.html.erb b/admin/app/views/spree/admin/promotions/_sidebar.html.erb
new file mode 100644
index 0000000000..b5c41758cd
--- /dev/null
+++ b/admin/app/views/spree/admin/promotions/_sidebar.html.erb
@@ -0,0 +1,116 @@
+<% if @promotion.multi_codes? %>
+ <% coupon_codes_count = @promotion.coupon_codes.count %>
+ <% if coupon_codes_count.positive? %>
+ <% used_coupon_codes_count = @promotion.coupon_codes.used.count %>
+ <% remaining_coupon_codes_count = coupon_codes_count - used_coupon_codes_count %>
+
+ <div class="card mb-4">
+ <div class="card-header d-flex justify-content-between">
+ <h5 class="card-title">
+ <%= Spree.t(:coupon_codes) %>
+ </h5>
+ </div>
+ <div class="card-body">
+ <div class="progress">
+ <div class="progress-bar" role="progressbar" style="width: <%= (used_coupon_codes_count.to_f / coupon_codes_count * 100).round %>%" aria-valuenow="<%= used_coupon_codes_count %>" aria-valuemin="0" aria-valuemax="<%= coupon_codes_count %>"></div>
+ </div>
+ </div>
+ <div class="card-footer d-flex justify-content-between">
+ <span class="badge badge-light">
+ Used: <%= used_coupon_codes_count %> / <%= coupon_codes_count %>
+ </span>
+ <span class="badge badge-light">
+ Remaining: <%= coupon_codes_count - used_coupon_codes_count %>
+ </span>
+ </div>
+ </div>
+ <% end %>
+<% end %>
+
+<%= turbo_frame_tag :promotion_edit_details do %>
+ <div class="card mb-4">
+ <div class="card-header d-flex justify-content-between">
+ <h5 class="card-title">
+ <%= Spree.t(:details) %>
+ </h5>
+ <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_promotion_path(@promotion), icon: 'pencil', class: 'btn btn-sm btn-light' %>
+ </div>
+ <div class="card-body">
+ <ul class="list-group">
+ <li class="list-group-item d-flex justify-content-between">
+ <span class="text-muted">
+ <%= Spree.t(:name) %>
+ </span>
+ <span>
+ <%= @promotion.name %>
+ </span>
+ </li>
+
+ <li class="list-group-item d-flex justify-content-between">
+ <span class="text-muted">
+ <%= Spree.t(:kind) %>
+ </span>
+ <span class="badge badge-light">
+ <%= @promotion.kind.titleize %>
+ </span>
+ </li>
+
+ <% if @promotion.code.present? %>
+ <li class="list-group-item d-flex justify-content-between" data-controller="clipboard" data-clipboard-success-content="Copied!">
+ <%= Spree.t(:coupon_code) %>
+ <span>
+ <span class="p-2 bg-light rounded mr-2 h-100">
+ <span data-clipboard-target="source"><%= @promotion.code.upcase %></span>
+ </span>
+
+ <button type="button" class="btn btn-light btn-sm with-tip p-1" data-action="clipboard#copy" title="<%= Spree.t(:copy) %>">
+ <%= icon 'copy', class: 'mr-0' %>
+ </button>
+ </span>
+ </li>
+ <% end %>
+ </ul>
+ </div>
+ </div>
+<% end%>
+
+<%= turbo_frame_tag :promotion_edit_settings do %>
+ <div class="card">
+ <div class="card-header d-flex justify-content-between">
+ <h5 class="card-title">
+ <%= Spree.t(:settings) %>
+ </h5>
+ <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_promotion_path(@promotion), icon: 'pencil', class: 'btn btn-sm btn-light' %>
+ </div>
+ <div class="card-body">
+ <ul class="list-group">
+ <% unless @promotion.multi_codes? %>
+ <li class="list-group-item d-flex justify-content-between">
+ <%= Spree.t(:usage_limit) %>
+ <%= render 'spree/admin/promotions/usage_limit', promotion: @promotion %>
+ </li>
+ <% end %>
+ <li class="list-group-item d-flex justify-content-between">
+ <span class="text-muted">
+ <%= I18n.t('activerecord.attributes.spree/promotion.starts_at') %>
+ </span>
+ <% if @promotion.starts_at %>
+ <span><%= local_time(@promotion.starts_at) %></span>
+ <% else %>
+ <span class="text-muted"><%= Spree.t(:no_start_date) %></span>
+ <% end %>
+ </li>
+ <li class="list-group-item d-flex justify-content-between">
+ <span class="text-muted">
+ <%= I18n.t('activerecord.attributes.spree/promotion.expires_at') %>
+ </span>
+ <% if @promotion.expires_at %>
+ <span><%= local_time(@promotion.expires_at) %></span>
+ <% else %>
+ <span class="text-muted"><%= Spree.t(:no_expiration) %></span>
+ <% end %>
+ </li>
+ </ul>
+ </div>
+ </div>
+<% end %>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/promotions/edit.html.erb b/admin/app/views/spree/admin/promotions/edit.html.erb
index 4331ee940e..98588034de 100644
--- a/admin/app/views/spree/admin/promotions/edit.html.erb
+++ b/admin/app/views/spree/admin/promotions/edit.html.erb
@@ -1,7 +1,4 @@
-<% content_for :page_title do %>
- <%= page_header_back_button spree.admin_promotions_path, @promotion %>
- <%= @promotion.name %>
-<% end %>
+<%= render 'spree/admin/promotions/header' %>
<%= turbo_frame_tag :promotion_edit_details do %>
<%= form_for @promotion, url: object_url, method: :put, data: { turbo_frame: '_top' } do |f| %>
diff --git a/admin/app/views/spree/admin/promotions/show.html.erb b/admin/app/views/spree/admin/promotions/show.html.erb
index 22fe2db458..124ca1c7a5 100644
--- a/admin/app/views/spree/admin/promotions/show.html.erb
+++ b/admin/app/views/spree/admin/promotions/show.html.erb
@@ -1,127 +1,10 @@
-<% content_for :page_title do %>
-<%= page_header_back_button spree.admin_promotions_path, @promotion %>
-<%= @promotion.name %>
-<div class="ml-3">
- <%= render 'spree/admin/promotions/status', promotion: @promotion %>
-</div>
-<% end %>
+<%= render 'spree/admin/promotions/header' %>
<div class="row">
<div class="col-12 col-lg-8">
- <% if @promotion.multi_codes? %>
- <%= turbo_frame_tag :coupon_codes, src: spree.admin_promotion_coupon_codes_path(@promotion) %>
- <% end %>
</div>
<div class="col-12 col-lg-4">
- <% if @promotion.multi_codes? %>
- <% coupon_codes_count = @promotion.coupon_codes.count %>
- <% if coupon_codes_count.positive? %>
- <% used_coupon_codes_count = @promotion.coupon_codes.used.count %>
- <% remaining_coupon_codes_count = coupon_codes_count - used_coupon_codes_count %>
-
- <div class="card mb-4">
- <div class="card-body">
- <progress max="<%= coupon_codes_count %>" value="<%= used_coupon_codes_count %>" class="w-100"></progress>
- </div>
- <div class="card-footer d-flex justify-content-between">
- <div>
- Used: <%= used_coupon_codes_count %> / <%= coupon_codes_count %>
- </div>
- <div>
- Remaining: <%= coupon_codes_count - used_coupon_codes_count %>
- </div>
- </div>
- </div>
- <% end %>
- <% end %>
-
- <%= turbo_frame_tag :promotion_edit_details do %>
- <div class="card mb-4">
- <div class="card-header d-flex justify-content-between">
- <h5 class="card-title">
- <%= Spree.t(:details) %>
- </h5>
- <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_promotion_path(@promotion), icon: 'pencil', class: 'btn btn-sm btn-light' %>
- </div>
- <div class="card-body">
- <ul class="list-group">
- <li class="list-group-item d-flex justify-content-between">
- <span class="text-muted">
- <%= Spree.t(:name) %>
- </span>
- <span>
- <%= @promotion.name %>
- </span>
- </li>
-
- <li class="list-group-item d-flex justify-content-between">
- <span class="text-muted">
- <%= Spree.t(:kind) %>
- </span>
- <span class="badge badge-light">
- <%= @promotion.kind.titleize %>
- </span>
- </li>
-
- <% if @promotion.code.present? %>
- <li class="list-group-item d-flex justify-content-between" data-controller="clipboard" data-clipboard-success-content="Copied!">
- <%= Spree.t(:coupon_code) %>
- <span>
- <span class="p-2 bg-light rounded mr-2 h-100">
- <span data-clipboard-target="source"><%= @promotion.code.upcase %></span>
- </span>
-
- <button type="button" class="btn btn-light btn-sm with-tip p-1" data-action="clipboard#copy" title="<%= Spree.t(:copy) %>">
- <%= icon 'copy', class: 'mr-0' %>
- </button>
- </span>
- </li>
- <% end %>
- </ul>
- </div>
- </div>
- <% end%>
-
- <%= turbo_frame_tag :promotion_edit_settings do %>
- <div class="card">
- <div class="card-header d-flex justify-content-between">
- <h5 class="card-title">
- <%= Spree.t(:settings) %>
- </h5>
- <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_promotion_path(@promotion), icon: 'pencil', class: 'btn btn-sm btn-light' %>
- </div>
- <div class="card-body">
- <ul class="list-group">
- <% unless @promotion.multi_codes? %>
- <li class="list-group-item d-flex justify-content-between">
- <%= Spree.t(:usage_limit) %>
- <%= render 'spree/admin/promotions/usage_limit', promotion: @promotion %>
- </li>
- <% end %>
- <li class="list-group-item d-flex justify-content-between">
- <span class="text-muted">
- <%= I18n.t('activerecord.attributes.spree/promotion.starts_at') %>
- </span>
- <% if @promotion.starts_at %>
- <span><%= local_time(@promotion.starts_at) %></span>
- <% else %>
- <span class="text-muted"><%= Spree.t(:no_start_date) %></span>
- <% end %>
- </li>
- <li class="list-group-item d-flex justify-content-between">
- <span class="text-muted">
- <%= I18n.t('activerecord.attributes.spree/promotion.expires_at') %>
- </span>
- <% if @promotion.expires_at %>
- <span><%= local_time(@promotion.expires_at) %></span>
- <% else %>
- <span class="text-muted"><%= Spree.t(:no_expiration) %></span>
- <% end %>
- </li>
- </ul>
- </div>
- </div>
- <% end %>
+ <%= render 'spree/admin/promotions/sidebar' %>
</div>
</div>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/shared/_content_header.html.erb b/admin/app/views/spree/admin/shared/_content_header.html.erb
index 9ac2a5b1f4..4f0c0d7262 100644
--- a/admin/app/views/spree/admin/shared/_content_header.html.erb
+++ b/admin/app/views/spree/admin/shared/_content_header.html.erb
@@ -7,7 +7,7 @@
<% end if show_record_subtitle && !content_for(:page_subtitle) %>
<% if content_for?(:page_title) %>
- <div class="pt-3 pb-4 d-flex align-items-center">
+ <div class="pt-3 pb-4 d-flex align-items-center" id="page-header">
<h3 class="page-header-title mb-0 d-flex align-items-center">
<%= yield :page_title %>
</h3>