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.

Open source new Dashboard and Getting Started screens (#12388)

Damian Legawiec7528f38b31ba
diff --git a/admin/app/controllers/spree/admin/dashboard_controller.rb b/admin/app/controllers/spree/admin/dashboard_controller.rb
new file mode 100644
index 0000000000..4e39331686
--- /dev/null
+++ b/admin/app/controllers/spree/admin/dashboard_controller.rb
@@ -0,0 +1,137 @@
+module Spree
+ module Admin
+ class DashboardController < BaseController
+ include Spree::Admin::AnalyticsConcern
+
+ before_action :set_analytics_defaults, only: %i[analytics]
+ before_action :load_vendor
+ before_action :clear_return_to, only: %i[show]
+
+ def show; end
+
+ def getting_started; end
+
+ def analytics
+ @orders_scope = current_store.orders.complete.where(currency: params[:analytics_currency])
+ @products_scope = current_store.products
+
+ if defined?(Spree::Vendor)
+ # for vendors we need to count there sub-orders
+ # for admins we need to counnt only the main orders (the ones that are splitted)
+ @orders_scope = if @vendor.present?
+ @orders_scope.with_vendor(@vendor.id)
+ else
+ @orders_scope.without_vendor if @orders_scope.respond_to?(:without_vendor)
+ end
+ end
+
+ load_top_products
+
+ sales_total_sum = @orders_scope.where(completed_at: analytics_time_range).sum(:total)
+ @sales_total = Spree::Money.new(sales_total_sum, currency: params[:analytics_currency])
+ previous_sales_total = @orders_scope.where(completed_at: previous_analytics_time_range).sum(:total)
+ @sales_growth_rate = calc_growth_rate(sales_total_sum, previous_sales_total)
+
+ @orders_total = @orders_scope.where(completed_at: analytics_time_range).count
+ previous_orders_total = @orders_scope.where(completed_at: previous_analytics_time_range).count
+ @orders_growth_rate = calc_growth_rate(@orders_total, previous_orders_total)
+
+ orders_avg = @orders_scope.where(completed_at: analytics_time_range).average(:total).to_f
+ @orders_average = Spree::Money.new(orders_avg, currency: params[:analytics_currency])
+ previous_orders_average = @orders_scope.where(completed_at: previous_analytics_time_range).average(:total).to_f
+ @orders_average_growth_rate = calc_growth_rate(orders_avg, previous_orders_average)
+
+ @grouped_orders_scope = if same_day?
+ @orders_scope.group_by_hour(:completed_at, range: analytics_time_range, time_zone: current_store.preferred_timezone,
+ default_value: 0.0)
+ else
+ @orders_scope.group_by_day(:completed_at, range: analytics_time_range, time_zone: current_store.preferred_timezone,
+ default_value: 0.0)
+ end
+
+ load_analytics_data
+ end
+
+ private
+
+ def load_vendor
+ return unless defined?(Spree::Vendor)
+
+ @vendor = current_vendor || (Spree::Vendor.find(params[:vendor_id]) if params[:vendor_id].present?)
+ end
+
+ def load_top_products
+ line_items_grouped = Spree::LineItem.
+ select('
+ sum(quantity) AS all_quantity,
+ sum(quantity * price) AS all_amount,
+ spree_variants.product_id AS variant_product_id
+ ').
+ joins(:variant).
+ where(order: current_store.orders.complete.where('spree_orders.currency': params[:analytics_currency]).where('spree_orders.completed_at': analytics_time_range)).
+ order('all_amount desc, all_quantity desc').
+ group('variant_product_id')
+
+ line_items_grouped = line_items_grouped.joins(:product).where('spree_products.vendor_id': @vendor.id) if @vendor.present?
+ line_items_grouped = line_items_grouped.limit(5)
+
+ product_ids = line_items_grouped.map(&:variant_product_id).uniq.compact
+
+ return if product_ids.empty?
+
+ products = current_store.products.with_deleted.includes(:vendor).where(id: product_ids)
+
+ @top_products = line_items_grouped.map do |li|
+ product = products.find { |p| p.id == li.variant_product_id }
+ next unless product.present?
+
+ {
+ product: product,
+ quantity: li.all_quantity,
+ amount: Spree::Money.new(li.all_amount, currency: params[:analytics_currency])
+ }
+ end.compact
+ end
+
+ def load_analytics_data
+ @audience_scope = Spree.user_class.where(created_at: analytics_time_range)
+ @audience_total = @audience_scope.count
+ previous_audience_total = Spree.user_class.where(created_at: previous_analytics_time_range).count
+ @audience_growth_rate = calc_growth_rate(@audience_total, previous_audience_total)
+
+ @audience = if same_day?
+ @audience_scope.group_by_hour(:created_at, range: analytics_time_range, time_zone: current_store.preferred_timezone, default_value: 0)
+ else
+ @audience_scope.group_by_day(:created_at, range: analytics_time_range, time_zone: current_store.preferred_timezone, default_value: 0)
+ end
+
+ return unless defined?(Ahoy)
+
+ @visits_scope = Ahoy::Visit.where(started_at: analytics_time_range)
+ @visits_total = @visits_scope.count
+ previous_visits_total = Ahoy::Visit.where(started_at: previous_analytics_time_range).count
+ @visits_growth_rate = calc_growth_rate(@visits_total, previous_visits_total)
+
+ @visits_scope = Ahoy::Visit.where(started_at: analytics_time_range)
+ @visits_total = @visits_scope.count
+ previous_visits_total = Ahoy::Visit.where(started_at: previous_analytics_time_range).count
+ @visits_growth_rate = calc_growth_rate(@visits_total, previous_visits_total)
+
+ @visits = if same_day?
+ @visits_scope.group_by_hour(:started_at, range: analytics_time_range, time_zone: current_store.preferred_timezone, default_value: 0)
+ else
+ @visits_scope.group_by_day(:started_at, range: analytics_time_range, time_zone: current_store.preferred_timezone, default_value: 0)
+ end
+
+ @top_landing_pages = @visits_scope.where.not(landing_page_title: [nil, '']).top(:landing_page_title, 10)
+ @top_referrers = @visits_scope.where.not(referring_domain: current_store.custom_domains.pluck(:url) << current_store.url).top(
+ :referring_domain, 10
+ )
+ @top_locations = @visits_scope.top(:country, 10)
+ @top_devices = @visits_scope.group(:device_type).count.transform_keys do |device|
+ device.nil? ? 'N/A' : device
+ end.map { |series| [series.first, (series.second.to_f / @visits_scope.count) * 100] }
+ end
+ end
+ end
+end
diff --git a/admin/app/views/spree/admin/dashboard/_analytics.html.erb b/admin/app/views/spree/admin/dashboard/_analytics.html.erb
new file mode 100644
index 0000000000..7af3c6d353
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/_analytics.html.erb
@@ -0,0 +1,3 @@
+<%= turbo_frame_tag :analytics, src: spree.admin_dashboard_analytics_path, loading: :eager do %>
+ <%= render 'spree/admin/shared/analytics_loader_skeleton' %>
+<% end %>
diff --git a/admin/app/views/spree/admin/dashboard/_setup_progress.html.erb b/admin/app/views/spree/admin/dashboard/_setup_progress.html.erb
new file mode 100644
index 0000000000..8b77598230
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/_setup_progress.html.erb
@@ -0,0 +1,13 @@
+<div class="mb-3 card rounded-lg" id="setup_progress">
+ <div class="card-body">
+ <div class="mb-3">
+ Your overall setup progress
+ <span class="float-right text-muted">
+ <%= current_store.setup_tasks_done %> of <%= current_store.setup_tasks_total %> steps done
+ </span>
+ </div>
+ <div class="progress">
+ <div class="progress-bar bg-success" style="width: <%= current_store.setup_percentage %>%" role="progressbar" aria-valuenow="<%= current_store.setup_percentage %>" aria-valuemin="0" aria-valuemax="100"></div>
+ </div>
+ </div>
+</div>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/dashboard/_setup_tasks.html.erb b/admin/app/views/spree/admin/dashboard/_setup_tasks.html.erb
new file mode 100644
index 0000000000..5663a703ff
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/_setup_tasks.html.erb
@@ -0,0 +1,24 @@
+<div id="setup_tasks">
+ <% task_in_progress = nil %>
+ <% current_store.setup_tasks_list.each_with_index do |task, index| %>
+ <% done = current_store.setup_task_done?(task) %>
+ <% unless done %>
+ <% task_in_progress ||= task %>
+ <% end %>
+
+ <div class="collapsable-card mb-3">
+ <h5 class="card-header border-0 p-0 h-auto hover-light">
+ <a class="<% if task_in_progress != task %>collapsed<% end %> text-decoration-none d-flex align-items-center p-4 text-dark font-weight-normal w-100 card-title" data-toggle="collapse" href="#collapse<%= index %>-collapsed" aria-expanded="true" aria-controls="collapse<%= index %>-collapsed" id="heading<%= index %>-collapsed">
+ <%= onboarding_check_circle(done) %>
+ <span class="ml-3"><%= Spree.t("admin.store_setup_tasks.#{task}") %></span>
+ <%= icon('chevron-down', class: 'arrow ml-auto') %>
+ </a>
+ </h5>
+ <div id="collapse<%= index %>-collapsed" class="collapse <% if task_in_progress == task %>show<% end %>" aria-labelledby="heading<%= index %>-collapsed">
+ <div class="card-body">
+ <%= render "spree/admin/dashboard/setup_tasks/#{task}", done: done %>
+ </div>
+ </div>
+ </div>
+ <% end %>
+</div>
diff --git a/admin/app/views/spree/admin/dashboard/_store_preview.html.erb b/admin/app/views/spree/admin/dashboard/_store_preview.html.erb
new file mode 100644
index 0000000000..b5e02547e7
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/_store_preview.html.erb
@@ -0,0 +1,59 @@
+<% if current_store.default_theme %>
+ <div class="card mb-4">
+ <%= link_to spree.edit_admin_theme_path(current_store.default_theme), class: 'd-block card-img-top border-bottom overflow-auto bg-light position-relative store-preview-link', style: "height: 220px" do %>
+ <div class="position-absolute w-100 h-100 align-items-center justify-content-center overlay-background store-preview-actions">
+ <button class="btn btn-outline-primary">
+ <%= icon('tools') %>
+ <%= Spree.t(:edit_theme) %>
+ </button>
+ </div>
+ <% if current_store.default_theme.screenshot.attached? && current_store.default_theme.screenshot.variable? %>
+ <%= image_tag(
+ main_app.cdn_image_url(
+ current_store.default_theme.screenshot.variant(
+ spree_image_variant_options(resize_to_fill: [400, 250])
+ )
+ ),
+ class: 'w-100 h-100 bg-light',
+ loading: :lazy,
+ style: 'height: 220px'
+ ) %>
+ <% else %>
+ <div class="w-100 h-100 d-flex flex-column align-items-center justify-content-center bg-light text-muted">
+ <%= icon('camera-off', class: 'text-muted', height: 24) %>
+ </div>
+ <% end %>
+ <% end %>
+
+ <div class="card-body pt-2">
+ <div class="flex my-2 p-1 w-100 rounded bg-light" data-controller="clipboard" data-clipboard-success-content-value="Copied!">
+ <% if current_store.default_custom_domain&.active? %>
+ <%= text_field_tag :custom_domain, current_store.default_custom_domain.url, readonly: true, class: 'form-control-plaintext py-0 text-muted', data: { clipboard_target: 'source' } %>
+ <% else %>
+ <%= text_field_tag :domain, current_store.url, readonly: true, class: 'form-control-plaintext py-0 text-muted', data: { clipboard_target: 'source' } %>
+ <% end %>
+ <button data-action="clipboard#copy" data-clipboard-target="button" class="btn btn-sm py-1 hover-gray">
+ Copy
+ </button>
+ </div>
+
+ <div class="d-flex">
+ <%= link_to current_store.formatted_url_or_custom_domain, class: 'btn btn-light w-50 mr-3', target: '_blank' do %>
+ <%= icon 'eye', class: 'mr-1' %>
+ &nbsp;
+ <%= Spree.t(:view_store) %>
+ <% end %>
+ <%= link_to spree.edit_admin_theme_path(current_store.default_theme), class: 'btn btn-light w-50' do %>
+ <%= icon 'tools', class: 'mr-1' %>
+ &nbsp;
+ <%= Spree.t(:edit_theme) %>
+ <% end %>
+ </div>
+ </div>
+ <% unless current_store.default_custom_domain&.active? %>
+ <div class="card-footer border-top">
+ <%= link_to_with_icon 'world-www', 'Connect your own domain', spree.admin_custom_domains_path, class: 'btn btn-link w-100 py-2' %>
+ </div>
+ <% end %>
+ </div>
+<% end %>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/dashboard/_top_products.html.erb b/admin/app/views/spree/admin/dashboard/_top_products.html.erb
new file mode 100644
index 0000000000..35d49cde7b
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/_top_products.html.erb
@@ -0,0 +1,68 @@
+<div class="card mt-3 mb-4">
+ <div class="card-header pb-3">
+ <h5 class="card-title">
+ Top products
+ </h5>
+ </div>
+ <div class="card-body m-0 p-0">
+ <div class="table-responsive">
+ <table class="table">
+ <thead>
+ <tr class="border-bottom">
+ <th>
+ <%= Spree.t(:product) %>
+ </th>
+ <% unless @vendor %>
+ <th>
+ <%= Spree.t(:vendor) %>
+ </th>
+ <% end %>
+ <th>
+ <%= Spree.t(:price) %>
+ </th>
+ <th class="text-center">
+ <%= Spree.t(:quantity) %>
+ </th>
+ <th class="text-right">
+ <%= Spree.t(:total_sales) %>
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @top_products.each do |list_item| %>
+ <% product = list_item[:product] %>
+ <tr>
+ <% cache_unless @vendor, spree_base_cache_scope.call(product) do %>
+ <td>
+ <%= link_to spree.edit_admin_product_path(product), class: 'd-flex align-items-center font-weight-bold', data: { 'turbo-frame': '_top' } do %>
+ <div class="mr-3">
+ <%= render 'spree/admin/shared/product_image', object: product %>
+ </div>
+ <%= product.name %>
+ <% end %>
+ </td>
+ <% unless @vendor %>
+ <td>
+ <%= vendor_logo_link(product.vendor) if product.vendor.present? %>
+ </td>
+ <% end %>
+ <td>
+ <%= display_admin_price(product) %>
+ </td>
+ <% end %>
+ <td class="text-center">
+ <%= list_item[:quantity] %>
+ </td>
+ <td class="text-right">
+ <%= list_item[:amount] %>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+ </div>
+ <p class="text-center mt-0 border-top py-2 mb-0">
+ <%= link_to 'Show full report', spree.new_admin_report_path(type: 'products_performance', date_from: params[:date_from], date_to: params[:date_to], vendor_id: @vendor.try(:id)), class: 'm-2 w-50 btn btn-light mt-2', data: { turbo_frame: '_top' } %>
+ </p>
+ </div>
+</div>
diff --git a/admin/app/views/spree/admin/dashboard/_visits.html.erb b/admin/app/views/spree/admin/dashboard/_visits.html.erb
new file mode 100644
index 0000000000..167be5b853
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/_visits.html.erb
@@ -0,0 +1,112 @@
+<div class="row row-cols-1 row-cols-md-2">
+ <div class="col mb-4">
+ <div class="card h-100">
+ <div class="card-header">
+ <h5 class="card-title">
+ Where are visitors coming from?
+ </h5>
+ </div>
+ <% if @top_referrers.any? %>
+ <ul class="list-group list-group-flush small rounded-0">
+ <% @top_referrers.each do |referrer| %>
+ <li class="list-group-item d-flex justify-content-between hover-light">
+ <span><%= referrer.first %></span>
+ <span><%= referrer.second %></span>
+ </li>
+ <% end %>
+ </ul>
+ <% else %>
+ <p class="m-5 text-center text-muted">
+ <%= icon 'share', height: 50, class: 'mb-3', style: 'opacity: 0.5' %>
+ <br />
+ <strong>No data</strong>
+ <br />
+ No data available for this period.
+ </p>
+ <% end %>
+ </div>
+ </div>
+ <div class="col mb-4">
+ <div class="card h-100">
+ <div class="card-header">
+ <h5 class="card-title">
+ Top landing pages
+ </h5>
+ </div>
+ <% if @top_landing_pages.any? %>
+ <ul class="list-group list-group-flush small rounded-0">
+ <% @top_landing_pages.each do |landing_page| %>
+ <li class="list-group-item d-flex justify-content-between hover-light">
+ <span><%= landing_page.first %></span>
+ <span><%= landing_page.second %></span>
+ </li>
+ <% end %>
+ </ul>
+ <% else %>
+ <p class="m-5 text-center text-muted">
+ <%= icon 'pointer', height: 50, class: 'mb-3', style: 'opacity: 0.5' %>
+ <br />
+ <strong>No data</strong>
+ <br />
+ No data available for this period.
+ </p>
+ <% end %>
+ </div>
+ </div>
+ <div class="col mb-4">
+ <div class="card h-100">
+ <div class="card-header">
+ <h5 class="card-title">
+ Visitor location
+ </h5>
+ </div>
+ <% if @top_locations.any? %>
+ <ul class="list-group list-group-flush small rounded-0">
+ <% @top_locations.each do |location| %>
+ <li class="list-group-item d-flex justify-content-between hover-light">
+ <% cache [*spree_base_cache_key, "visits-country/#{location.first}"] do %>
+ <span>
+ <span class="mr-1">
+ <%= flag_emoji(Country.find_by_name(location.first)&.first) %>
+ </span>
+ <%= location.first %>
+ </span>
+ <% end %>
+ <span><%= location.second %></span>
+ </li>
+ <% end %>
+ </ul>
+ <% else %>
+ <p class="m-5 text-center text-muted">
+ <%= icon 'world', height: 50, class: 'mb-3', style: 'opacity: 0.5' %>
+ <br />
+ <strong>No data</strong>
+ <br />
+ No data available for this period.
+ </p>
+ <% end %>
+ </div>
+ </div>
+ <div class="col mb-4">
+ <div class="card">
+ <div class="card-header">
+ <h5 class="card-title">
+ Visitor devices
+ </h5>
+ </div>
+ <% if @top_devices.count > 0 %>
+ <div class="card-body">
+ <%= pie_chart @top_devices, legend: "bottom", suffix: "%" %>
+ </div>
+ <% else %>
+ <p class="m-5 text-center text-muted">
+ <%= icon 'device-mobile', height: 50, class: 'mb-3', style: 'opacity: 0.5' %>
+ <br />
+ <strong>No data</strong>
+ <br />
+ No data available for this period.
+ </p>
+ <% end %>
+ </div>
+ </div>
+</div>
diff --git a/admin/app/views/spree/admin/dashboard/analytics.html.erb b/admin/app/views/spree/admin/dashboard/analytics.html.erb
new file mode 100644
index 0000000000..88e67db1d2
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/analytics.html.erb
@@ -0,0 +1,114 @@
+<% content_for(:page_title) do %>
+ <%= Spree.t(:analytics) %>
+<% end %>
+
+<%= turbo_frame_tag :analytics do %>
+ <div class="card mb-4"
+ data-controller="tabs"
+ data-tabs-active-tab-class="active">
+ <div class="card-header d-block border-0 h-auto">
+ <div class="row">
+ <div class="col-6 col-lg-4 pr-2">
+ <div class="rounded cursor-pointer p-2 hover-light h-100 active" data-tabs-target="tab" data-action="click->tabs#change">
+ <div class="d-flex justify-content-center flex-column mb-3 mb-lg-0">
+ <span class="font-size-sm text-muted">Total Sales</span>
+ <span class="font-size-lg text-dark font-weight-bold mt-1">
+ <%= @sales_total %>
+ </span>
+ <div>
+ <%= render 'spree/admin/shared/growth_rate_badge', growth_rate: @sales_growth_rate %>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="col-6 col-lg-2 pl-0 pr-2">
+ <div class="rounded cursor-pointer p-2 hover-light h-100" data-tabs-target="tab" data-action="click->tabs#change">
+ <div class="d-flex justify-content-center flex-column mb-3 mb-lg-0">
+ <span class="font-size-sm text-muted">Avg. Order Value</span>
+ <span class="font-size-lg text-dark font-weight-bold mt-1 me-3"><%= @orders_average %></span>
+ <div>
+ <%= render 'spree/admin/shared/growth_rate_badge', growth_rate: @orders_average_growth_rate %>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="col-6 col-lg-2 pl-0 pr-2">
+ <div class="rounded cursor-pointer p-2 hover-light h-100" data-tabs-target="tab" data-action="click->tabs#change">
+ <div class="d-flex justify-content-center flex-column mb-3 mb-lg-0">
+ <span class="font-size-sm text-muted">Total Orders</span>
+ <span class="font-size-lg text-dark font-weight-bold mt-1 me-3"><%= @orders_total %></span>
+ <div>
+ <%= render 'spree/admin/shared/growth_rate_badge', growth_rate: @orders_growth_rate %>
+ </div>
+ </div>
+ </div>
+ </div>
+ <% if @visits_total && @visits_growth_rate %>
+ <div class="col-6 col-lg-2 pl-0 pr-2">
+ <div class="rounded cursor-pointer p-2 hover-light h-100" data-tabs-target="tab" data-action="click->tabs#change">
+ <div class="d-flex justify-content-center flex-column">
+ <span class="font-size-sm text-muted">Visits</span>
+ <span class="font-size-lg text-dark font-weight-bold mt-1 me-3"><%= @visits_total %></span>
+ <div>
+ <%= render 'spree/admin/shared/growth_rate_badge', growth_rate: @visits_growth_rate %>
+ </div>
+ </div>
+ </div>
+ </div>
+ <% end %>
+
+ <div class="col-6 col-lg-2 pl-0">
+ <div class="rounded cursor-pointer p-2 hover-light h-100" data-tabs-target="tab" data-action="click->tabs#change">
+ <div class="d-flex justify-content-center flex-column">
+ <span class="font-size-sm text-muted">Sign-ups</span>
+ <span class="font-size-lg text-dark font-weight-bold mt-1 me-3"><%= @audience_total %></span>
+ <div>
+ <%= render 'spree/admin/shared/growth_rate_badge', growth_rate: @audience_growth_rate %>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="card-body">
+ <div class="tab-content">
+ <div data-tabs-target="panel" data-index="1">
+ <% if currency_money(current_currency).symbol_first? %>
+ <%= line_chart @grouped_orders_scope.sum(:total), prefix: currency_money(current_currency).symbol, zeros: true, library: {
+ animation: {
+ duration: 300,
+ easing: "linear"
+ }
+ } %>
+ <% else %>
+ <%= line_chart @grouped_orders_scope.sum(:total), suffix: currency_money(current_currency).symbol, zeros: true, library: {
+ animation: {
+ duration: 300,
+ easing: "linear"
+ }
+ } %>
+ <% end %>
+ </div>
+ <div data-tabs-target="panel" data-index="2">
+ <%= line_chart @grouped_orders_scope.average(:total), suffix: currency_money(current_currency).symbol, zeros: true %>
+ </div>
+ <div data-tabs-target="panel" data-index="3">
+ <%= line_chart @grouped_orders_scope.count %>
+ </div>
+ <% if @visits %>
+ <div data-tabs-target="panel" data-index="4">
+ <%= line_chart @visits.count %>
+ </div>
+ <% end %>
+ <div data-tabs-target="panel" data-index="5">
+ <%= line_chart @audience.count %>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <%= render 'top_products' if @top_products.present? %>
+ <%= render 'visits' if @visits %>
+<% end %>
diff --git a/admin/app/views/spree/admin/dashboard/getting_started.html.erb b/admin/app/views/spree/admin/dashboard/getting_started.html.erb
new file mode 100644
index 0000000000..41ab2d8043
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/getting_started.html.erb
@@ -0,0 +1,23 @@
+<div class="row pt-3">
+ <div class="col-lg-8 mb-4">
+ <h2 class="page-header-title">
+ <%= Spree.t('admin.getting_started.title') %>
+ </h2>
+ <p class="">
+ <%= Spree.t('admin.getting_started.description') %>
+ </p>
+
+ <%= turbo_frame_tag :onboarding_tasks do %>
+ <% if defined?(current_vendor) && current_vendor %>
+ <%= render 'vendor_onboarding_progress', vendor: current_vendor %>
+ <%= render 'vendor_onboarding_tasks', vendor: current_vendor %>
+ <% else %>
+ <%= render 'setup_progress' %>
+ <%= render 'setup_tasks' %>
+ <% end %>
+ <% end %>
+ </div>
+ <div class="col-lg-4">
+
+ </div>
+</div>
diff --git a/admin/app/views/spree/admin/dashboard/setup_tasks/_add_products.html.erb b/admin/app/views/spree/admin/dashboard/setup_tasks/_add_products.html.erb
new file mode 100644
index 0000000000..3891576392
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/setup_tasks/_add_products.html.erb
@@ -0,0 +1,22 @@
+<% if done %>
+ <p>
+ Good job, you've added products to your store!
+ </p>
+ <p>
+ Remember you can always add more!
+ </p>
+<% else %>
+ <p>
+ Add products to your store, either your own or invite 3rd party vendors to sell together.
+ </p>
+ <p>
+ You can also import products in bulk from a CSV or Excel file.
+ </p>
+<% end %>
+
+<div class="d-flex gap-3">
+ <%= link_to_with_icon 'plus', Spree.t(:add_product), spree.new_admin_product_path, class: 'btn btn-primary', data: { turbo_frame: '_top' } %>
+
+ <%= render 'spree/admin/products/import_button' %>
+ <%= invite_vendor_button(class: 'btn-light') if defined?(invite_vendor_button) %>
+</div>
diff --git a/admin/app/views/spree/admin/dashboard/setup_tasks/_set_customer_support_email.html.erb b/admin/app/views/spree/admin/dashboard/setup_tasks/_set_customer_support_email.html.erb
new file mode 100644
index 0000000000..636af56e0f
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/setup_tasks/_set_customer_support_email.html.erb
@@ -0,0 +1,23 @@
+<%= turbo_frame_tag :set_customer_support_email, class: 'w-100' do %>
+ <div class="alert alert-info">
+ We need your customer support email to display on your storefront.
+ This email will work as a contact point for your customers to reach out to you for any queries or support.
+ </div>
+
+ <% if done %>
+ <p>
+ Your customer support email is <strong><%= current_store.customer_support_email %>.</strong>
+ </p>
+ <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_emails_admin_store_path, class: 'btn btn-light' %>
+ <% else %>
+ <%= form_for current_store, url: spree.admin_store_path, as: :store do |f| %>
+ <div class="form-group">
+ <%= f.label :customer_support_email, 'Customer support email' %>
+ <%= f.email_field :customer_support_email, class: 'form-control', required: true %>
+ </div>
+ <div class="d-flex justify-content-between">
+ <%= turbo_save_button_tag %>
+ </div>
+ <% end %>
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/dashboard/setup_tasks/_setup_payment_method.html.erb b/admin/app/views/spree/admin/dashboard/setup_tasks/_setup_payment_method.html.erb
new file mode 100644
index 0000000000..a5217374fd
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/setup_tasks/_setup_payment_method.html.erb
@@ -0,0 +1,6 @@
+<% if done %>
+ <%= Spree.t('admin.store_setup_tasks.payment_methods.done', link: spree.admin_payment_methods_path).html_safe %>
+<% else %>
+ <p><%= Spree.t('admin.store_setup_tasks.payment_methods.copy') %></p>
+ <%= link_to Spree.t('admin.store_setup_tasks.payment_methods.setup'), spree.admin_payment_methods_path, class: 'btn btn-primary', data: { turbo_frame: '_top' } %>
+<% end %>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/dashboard/setup_tasks/_setup_taxes_collection.html.erb b/admin/app/views/spree/admin/dashboard/setup_tasks/_setup_taxes_collection.html.erb
new file mode 100644
index 0000000000..26b09dc84c
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/setup_tasks/_setup_taxes_collection.html.erb
@@ -0,0 +1,6 @@
+<% if current_store.setup_task_done?(:setup_taxes_collection) %>
+ <%= Spree.t('admin.store_setup_tasks.taxes.done', link: spree.admin_tax_rates_path).html_safe %>
+<% else %>
+ <p><%= Spree.t('admin.store_setup_tasks.taxes.copy') %></p>
+ <%= link_to Spree.t('admin.store_setup_tasks.taxes.setup'), spree.admin_tax_rates_path, class: 'btn btn-primary', data: { turbo_frame: '_top' } %>
+<% end %>
diff --git a/admin/app/views/spree/admin/dashboard/show.html.erb b/admin/app/views/spree/admin/dashboard/show.html.erb
new file mode 100644
index 0000000000..fbd529271c
--- /dev/null
+++ b/admin/app/views/spree/admin/dashboard/show.html.erb
@@ -0,0 +1,31 @@
+<div class="row pt-3">
+ <div class="col-12">
+ <h2 class="page-header-title">
+ <%= Spree.t('admin.dashboard.hi') %> <%= try_spree_current_user.first_name %>!
+ </h2>
+ <p>
+ <%= Spree.t('admin.dashboard.whats_happening_on', store_name: current_store.name).html_safe %>
+ </p>
+ </div>
+</div>
+
+<div class="row">
+ <div class="col-lg-8">
+ <div class="mb-2 d-flex gap-2">
+ <%= form_tag spree.admin_dashboard_analytics_path, method: :get, data: { turbo_frame: :analytics } do %>
+ <%= hidden_field_tag :vendor_id, @vendor.id if @vendor.present? %>
+ <%= render 'spree/admin/shared/calendar_range_picker',
+ date_from_value: params[:date_from] || 1.month.ago.beginning_of_month,
+ date_to_value: params[:date_to] || 1.month.ago.end_of_month %>
+ <% end %>
+ </div>
+ <%= render 'analytics' %>
+ </div>
+ <div class="col-lg-4">
+ <% if defined?(current_vendor) && current_vendor %>
+ <%= render 'spree/admin/shared/vendor_faq' %>
+ <% else %>
+ <%= render 'store_preview' %>
+ <%= render 'vendors' if defined?(Spree::Vendor) %>
+ <% end %>
+</div>
diff --git a/admin/app/views/spree/admin/products/_import_button.html.erb b/admin/app/views/spree/admin/products/_import_button.html.erb
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/admin/app/views/spree/admin/shared/_analytics_loader_skeleton.html.erb b/admin/app/views/spree/admin/shared/_analytics_loader_skeleton.html.erb
new file mode 100644
index 0000000000..53438f5ee6
--- /dev/null
+++ b/admin/app/views/spree/admin/shared/_analytics_loader_skeleton.html.erb
@@ -0,0 +1,76 @@
+ <div class="card mb-4">
+ <div class="card-header d-block border-0 h-auto">
+ <div class="row">
+ <div class="col-6 col-lg-4 pr-1">
+ <div class="rounded cursor-pointer p-2 hover-light h-100 active">
+ <div class="d-flex justify-content-center flex-column mb-3 mb-lg-0">
+ <span class="font-size-sm text-muted">Total Sales</span>
+ <span class="font-size-lg text-dark font-weight-bold mt-1">
+ <%= @sales_total %>
+ </span>
+ <div>
+ <%= render 'spree/admin/shared/growth_rate_badge', growth_rate: 0 %>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="col-6 col-lg-2 pl-0 pr-2">
+ <div class="rounded cursor-pointer p-2 hover-light h-100" >
+ <div class="d-flex justify-content-center flex-column mb-3 mb-lg-0">
+ <span class="font-size-sm text-muted">Avg. Order Value</span>
+ <span class="font-size-lg text-dark font-weight-bold mt-1 me-3"><%= @orders_average %></span>
+ <div>
+ <%= render 'spree/admin/shared/growth_rate_badge', growth_rate: 0 %>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="col-6 col-lg-2 pl-0 pr-2">
+ <div class="rounded cursor-pointer p-2 hover-light h-100" >
+ <div class="d-flex justify-content-center flex-column mb-3 mb-lg-0">
+ <span class="font-size-sm text-muted">Total Orders</span>
+ <span class="font-size-lg text-dark font-weight-bold mt-1 me-3"><%= @orders_total %></span>
+ <div>
+ <%= render 'spree/admin/shared/growth_rate_badge', growth_rate: 0 %>
+ </div>
+ </div>
+ </div>
+ </div>
+ <% if defined?(Ahoy) %>
+ <div class="col-6 col-lg-2 pl-0 pr-2">
+ <div class="rounded cursor-pointer p-2 hover-light h-100" >
+ <div class="d-flex justify-content-center flex-column">
+ <span class="font-size-sm text-muted">Visits</span>
+ <span class="font-size-lg text-dark font-weight-bold mt-1 me-3"><%= @visits_total %></span>
+ <div>
+ <%= render 'spree/admin/shared/growth_rate_badge', growth_rate: 0 %>
+ </div>
+ </div>
+ </div>
+ </div>
+ <% end %>
+
+ <div class="col-6 col-lg-2 pl-0">
+ <div class="rounded cursor-pointer p-2 hover-light h-100" >
+ <div class="d-flex justify-content-center flex-column">
+ <span class="font-size-sm text-muted">Sign-ups</span>
+ <span class="font-size-lg text-dark font-weight-bold mt-1 me-3"><%= @audience_total %></span>
+ <div>
+ <%= render 'spree/admin/shared/growth_rate_badge', growth_rate: 0 %>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="card-body">
+ <div class="tab-content d-flex align-items-center justify-content-center" id="pills-tabContent" style="height: 300px">
+ <div class="spinner-border text-muted align-middle opacity-50" role="status">
+ <span class="sr-only"><%= Spree.t(:loading) %>...</span>
+ </div>
+ </div>
+ </div>
+ <!-- End Body -->
+</div>
diff --git a/admin/app/views/spree/admin/shared/_growth_rate_badge.html.erb b/admin/app/views/spree/admin/shared/_growth_rate_badge.html.erb
new file mode 100644
index 0000000000..2ae49a8dcd
--- /dev/null
+++ b/admin/app/views/spree/admin/shared/_growth_rate_badge.html.erb
@@ -0,0 +1,17 @@
+<% growth_rate ||= 0 %>
+
+<div class="d-flex">
+ <% if growth_rate == 0 %>
+ <svg viewBox="0 0 11 16" height="16" width="11" role="img" class="_SVG_1ou8g_150" tabindex="-1"><title>No change</title><path d="M0.519531 1.79395H12.0039V0.249023H0.519531V1.79395Z" fill="var(--p-icon-subdued, #8c9196)" transform="translate(0, 7)"></path></svg>
+ <% elsif growth_rate > 0 %>
+ <span class="text-success">
+ <%= icon 'arrow-up', class: 'mr-1 font-size-base' %>
+ <%= number_to_percentage(growth_rate, strip_insignificant_zeros: true) %>
+ </span>
+ <% else %>
+ <span class="text-danger">
+ <%= icon 'arrow-down', class: 'mr-1 font-size-base' %>
+ <%= number_to_percentage(growth_rate.abs, strip_insignificant_zeros: true) %>
+ </span>
+ <% end %>
+</div>
diff --git a/admin/app/views/spree/admin/shared/_spinner.html.erb b/admin/app/views/spree/admin/shared/_spinner.html.erb
new file mode 100644
index 0000000000..e6502cc4de
--- /dev/null
+++ b/admin/app/views/spree/admin/shared/_spinner.html.erb
@@ -0,0 +1,7 @@
+<% spinner_id = defined?(id) ? id : 'turbo-spinner' %>
+
+<div class="d-flex w-100 align-items-center justify-content-center" id="<%= spinner_id %>">
+ <div class="spinner-border text-muted align-middle" role="status">
+ <span class="sr-only"><%= Spree.t(:loading) %>...</span>
+ </div>
+</div>
diff --git a/admin/app/views/spree/admin/taxons/_form.html.erb b/admin/app/views/spree/admin/taxons/_form.html.erb
index 68609ac396..df3455b362 100644
--- a/admin/app/views/spree/admin/taxons/_form.html.erb
+++ b/admin/app/views/spree/admin/taxons/_form.html.erb
@@ -87,7 +87,7 @@
<div class="card-body p-2" style="min-height: 300px">
<div class="d-block overflow-y-auto overflow-x-hidden" style="max-height: 300px">
<%= turbo_frame_tag :classifications, src: spree.admin_taxon_classifications_path(@taxon.id), loading: :lazy do %>
- <%= render 'shared/spinner' %>
+ <%= render 'spree/admin/shared/spinner' %>
<% end %>
</div>
</div>
diff --git a/admin/app/views/spree/admin/users/_billing.html.erb b/admin/app/views/spree/admin/users/_billing.html.erb
index 149d73f12b..f56e4fb694 100644
--- a/admin/app/views/spree/admin/users/_billing.html.erb
+++ b/admin/app/views/spree/admin/users/_billing.html.erb
@@ -63,7 +63,7 @@
<% end %>
<%= turbo_frame_tag :edit_address_billing, src: spree.edit_admin_address_path(@user.billing_address, type: 'billing'), loading: :lazy do %>
- <%= render 'shared/spinner', id: 'edit-address-billing-spinner' %>
+ <%= render 'spree/admin/shared/spinner', id: 'edit-address-billing-spinner' %>
<% end %>
<% end %>
</div>
diff --git a/admin/app/views/spree/admin/users/_tabs.html.erb b/admin/app/views/spree/admin/users/_tabs.html.erb
index 6d7889e743..a19d65c55f 100644
--- a/admin/app/views/spree/admin/users/_tabs.html.erb
+++ b/admin/app/views/spree/admin/users/_tabs.html.erb
@@ -33,7 +33,7 @@
<div class="tab-pane fade <%= 'show active pt-3' unless spree.respond_to?(:admin_user_visits_path) %>" id="pills-orders2" role="tabpanel" aria-labelledby="pills-orders2">
<div class="card-lg p-0" style="min-height: 200px">
<%= turbo_frame_tag :orders_list, src: spree.admin_user_orders_path(@user, frame_name: :orders_list), loading: :lazy, autoscroll: true, data: { autoscroll_block: :nearest, autoscroll_behavior: :smooth } do %>
- <%= render 'shared/spinner' %>
+ <%= render 'spree/admin/shared/spinner' %>
<% end %>
</div>
</div>
@@ -41,7 +41,7 @@
<div class="tab-pane fade" id="pills-checkouts" role="tabpanel" aria-labelledby="pills-checkouts">
<div class="card-lg p-0" style="min-height: 200px">
<%= turbo_frame_tag :orders_list, src: spree.admin_user_checkouts_path(@user, frame_name: :orders_list), loading: :lazy, autoscroll: true, data: { autoscroll_block: :nearest, autoscroll_behavior: :smooth } do %>
- <%= render 'shared/spinner' %>
+ <%= render 'spree/admin/shared/spinner' %>
<% end %>
</div>
</div>
@@ -50,7 +50,7 @@
<div class="tab-pane fade" id="pills-gift-cards" role="tabpanel" aria-labelledby="pills-gift-cards">
<div class="card-lg p-0" style="min-height: 200px">
<%= turbo_frame_tag :gift_cards_list, src: spree.admin_user_gift_cards_path(@user, frame_name: :gift_cards_list), loading: :lazy, autoscroll: true, data: { autoscroll_block: :nearest, autoscroll_behavior: :smooth } do %>
- <%= render 'shared/spinner' %>
+ <%= render 'spree/admin/shared/spinner' %>
<% end %>
</div>
</div>
@@ -59,7 +59,7 @@
<div class="tab-pane fade" id="pills-store-credits" role="tabpanel" aria-labelledby="pills-store-credits">
<div class="card-lg p-0" style="min-height: 200px">
<%= turbo_frame_tag :store_credits_list, src: spree.admin_user_store_credits_path(@user, frame_name: :store_credits_list), loading: :lazy, autoscroll: true, data: { autoscroll_block: :nearest, autoscroll_behavior: :smooth } do %>
- <%= render 'shared/spinner' %>
+ <%= render 'spree/admin/shared/spinner' %>
<% end %>
</div>
</div>
diff --git a/admin/config/locales/en.yml b/admin/config/locales/en.yml
index edd632e4bc..1f551952e6 100644
--- a/admin/config/locales/en.yml
+++ b/admin/config/locales/en.yml
@@ -17,6 +17,12 @@ en:
kind: Kind
home: Home
copy_to_clipboard: Copy to clipboard
+ dashboard:
+ hi: Hi
+ whats_happening_on: Here's what's happening on <strong>%{store_name}</strong> today.
+ getting_started:
+ title: Getting started
+ description: Everything you need to set up to start selling.
data_feeds:
data_feeds: Data Feeds
type: Type
diff --git a/admin/config/routes.rb b/admin/config/routes.rb
index b12c3eeb11..de389dfec2 100644
--- a/admin/config/routes.rb
+++ b/admin/config/routes.rb
@@ -202,7 +202,11 @@ Spree::Core::Engine.add_routes do
# dashboard
resource :dashboard, controller: 'dashboard'
+ get '/dashboard/analytics', to: 'dashboard#analytics', as: :dashboard_analytics
+ get '/getting-started', to: 'dashboard#getting_started', as: :getting_started
root to: 'dashboard#show'
end
+
+ get Spree.admin_path, to: 'admin/dashboard#show', as: :admin
end
diff --git a/admin/spec/controllers/spree/admin/dashboard_controller_spec.rb b/admin/spec/controllers/spree/admin/dashboard_controller_spec.rb
new file mode 100644
index 0000000000..fa13d5df3b
--- /dev/null
+++ b/admin/spec/controllers/spree/admin/dashboard_controller_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe Spree::Admin::DashboardController, type: :controller do
+ stub_authorization!
+ render_views
+
+ let(:store) { Spree::Store.default }
+
+ describe '#show' do
+ it 'renders welcome page' do
+ get :show
+ expect(response).to render_template(:show)
+ end
+ end
+
+ describe '#analytics' do
+ context 'view' do
+ it 'renders analytics' do
+ get :analytics
+ expect(response).to render_template(:analytics)
+ end
+ end
+ end
+
+ describe '#getting_started' do
+ it 'renders getting started' do
+ get :getting_started
+ expect(response).to render_template(:getting_started)
+ end
+ end
+end