Remove Admin Only tab logic

This commit is contained in:
François Turbelin
2025-01-05 20:33:18 +01:00
committed by Rachel Arnould
parent a007fdaab8
commit 3ef5b41282
10 changed files with 48 additions and 91 deletions

View File

@@ -56,7 +56,6 @@ module Admin
)
[
{ name: 'primary_details', icon_class: "icon-home", show: true, selected: 'selected' },
{ name: 'admin_only', icon_class: "icon-gear", show: spree_current_user.admin? },
{ name: 'address', icon_class: "icon-map-marker", show: true },
{ name: 'contact', icon_class: "icon-phone", show: true },
{ name: 'social', icon_class: "icon-twitter", show: true },

View File

@@ -1,12 +1,7 @@
- enterprise_side_menu_items(@enterprise).each do |item|
- case item[:name]
- when 'primary_details'
%fieldset.alpha.no-border-bottom{ id: "#{item[:name]}_panel", data: { controller: "primary-details", "primary-details-primary-producer-value": @enterprise.is_primary_producer.to_s, "tabs-and-panels-target": "panel default" }}
%legend= t(".#{ item[:name] }.legend")
= render "admin/enterprises/form/#{ item[:form_name] || item[:name] }", f: f
- when 'admin_only'
%fieldset.alpha.no-border-bottom{ id: "#{item[:name]}_panel", data: { controller: "admin-only", "admin-only-enterprise-sells-value": @enterprise.sells, "tabs-and-panels-target": "panel admin-only" }}
%fieldset.alpha.no-border-bottom{ id: "#{item[:name]}_panel", data: { controller: "primary-details", "primary-details-primary-producer-value": @enterprise.is_primary_producer.to_s, "primary-details-enterprise-sells-value": @enterprise.sells, "tabs-and-panels-target": "panel default" }}
%legend= t(".#{ item[:name] }.legend")
= render "admin/enterprises/form/#{ item[:form_name] || item[:name] }", f: f

View File

@@ -28,21 +28,21 @@
.row
.alpha.eleven.columns
.three.columns.alpha
= f.label :sells, t('admin_only.sells', scope: scope)
%div{'ofn-with-tip' => t('admin_only.sells_tip', scope: scope)}
= f.label :sells, t('primary_details.sells', scope: scope)
%div{'ofn-with-tip' => t('primary_details.sells_tip', scope: scope)}
%a What's this?
.two.columns
= f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells'
 
= f.label :sells, t('admin_only.none', scope: scope), value: "none"
= f.label :sells, t('primary_details.none', scope: scope), value: "none"
.two.columns
= f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells'
 
= f.label :sells, t('admin_only.own', scope: scope), value: "own"
= f.label :sells, t('primary_details.own', scope: scope), value: "own"
.four.columns.omega
= f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells'
 
= f.label :sells, t('admin_only.any', scope: scope), value: "any"
= f.label :sells, t('primary_details.any', scope: scope), value: "any"
.row
.alpha.three.columns

View File

@@ -1,24 +0,0 @@
.row
.three.columns.alpha
= f.label :sells, t('.sells')
= render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.sells_tip')}
.two.columns
= f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells', data: { action: "change->admin-only#enterpriseSellsChanged"}
= f.label :sells, t('.none'), value: "none"
.two.columns
= f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells', data: { action: "change->admin-only#enterpriseSellsChanged" }
= f.label :sells, t('.own'), value: "own"
.four.columns.omega
= f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: { action: "change->admin-only#enterpriseSellsChanged" }
= f.label :sells, t('.any'), value: "any"
%span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "admin-only-target": "spinner" } }
= render partial: "components/admin_spinner"
= render partial: 'admin/enterprises/form/permalink'
.row
.three.columns.alpha
= f.label :external_billing_id, t('.external_billing_id')
= render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.external_billing_id_tip')}
.four.columns
= f.text_field :external_billing_id, { placeholder: t('.external_billing_id_placeholder') }

View File

@@ -18,6 +18,28 @@
.five.columns.omega
= f.check_box :is_primary_producer, data: { action: "change->primary-details#primaryProducerChanged" }
= f.label :is_primary_producer, t('.producer')
- if spree_current_user.admin?
.row
.three.columns.alpha
= f.label :sells, t('.sells')
= render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.sells_tip')}
.two.columns
= f.radio_button :sells, "none", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"}
= f.label :sells, t('.none'), value: "none"
.two.columns
= f.radio_button :sells, "own", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"}
= f.label :sells, t('.own'), value: "own"
.four.columns.omega
= f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"}
= f.label :sells, t('.any'), value: "any"
%span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "primary-details-target": "spinner" } }
= render partial: "components/admin_spinner"
.row
.three.columns.alpha
= f.label :external_billing_id, t('.external_billing_id')
= render partial: 'admin/shared/whats_this_tooltip', locals: {tooltip_text: t('.external_billing_id_tip')}
.four.columns
= f.text_field :external_billing_id, { placeholder: t('.external_billing_id_placeholder') }
.row
.three.columns.alpha
%label= t('.visible_in_search')
@@ -31,3 +53,5 @@
.four.columns.omega
= f.radio_button :visible, "hidden", 'ng-model' => 'Enterprise.visible'
= f.label :visible, t('.hidden'), value: 'hidden'
= render partial: 'admin/enterprises/form/permalink'

View File

@@ -1,30 +0,0 @@
import { Controller } from "stimulus";
export default class extends Controller {
static values = { enterpriseSells: String };
static targets = ["spinner"];
enterpriseSellsChanged(event) {
console.log("enterpriseSellsChanged");
if (event.currentTarget.checked) {
this.enterpriseSellsValue = event.currentTarget.value;
this.spinnerTarget.classList.remove("hidden");
this.makeRequest();
}
}
makeRequest() {
fetch(
`?stimulus=true&enterprise_sells=${this.enterpriseSellsValue}`,
{
method: "GET",
headers: { "Content-type": "application/json; charset=UTF-8" },
}
)
.then((data) => data.json())
.then((operation) => {
CableReady.perform(operation);
this.spinnerTarget.classList.add("hidden");
});
}
}

View File

@@ -1,7 +1,7 @@
import { Controller } from "stimulus";
export default class extends Controller {
static values = { primaryProducer: String };
static values = { primaryProducer: String, enterpriseSells: String };
static targets = ["spinner"];
primaryProducerChanged(event) {
@@ -9,9 +9,17 @@ export default class extends Controller {
this.makeRequest();
}
enterpriseSellsChanged(event) {
if (event.currentTarget.checked) {
this.enterpriseSellsValue = event.currentTarget.value;
this.spinnerTarget.classList.remove("hidden");
this.makeRequest();
}
}
makeRequest() {
fetch(
`?stimulus=true&is_primary_producer=${this.primaryProducerValue}`,
`?stimulus=true&enterprise_sells=${this.enterpriseSellsValue}&is_primary_producer=${this.primaryProducerValue}`,
{
method: "GET",
headers: { "Content-type": "application/json; charset=UTF-8" },

View File

@@ -1187,16 +1187,6 @@ en:
desc_long_placeholder: Tell customers about yourself. This information appears on your public profile.
address:
legend: "Address"
admin_only:
legend: "Admin Only"
any: Any
none: None
own: Own
sells: Sells
sells_tip: "None - enterprise does not sell to customers directly.<br />Own - Enterprise sells own products to customers.<br />Any - Enterprise can sell own or other enterprises products.<br />"
external_billing_id: External Billing ID
external_billing_id_placeholder: eg. INV-2024-123456
external_billing_id_tip: "This is the ID used by the external billing system to identify this enterprise."
business_details:
legend: "Business Details"
upload: 'upload'
@@ -1289,6 +1279,14 @@ en:
primary_producer: Primary Producer?
primary_producer_tip: Select 'Producer' if you are a primary producer of food.
producer: Producer
any: Any
none: None
own: Own
sells: Sells
sells_tip: "None - enterprise does not sell to customers directly.<br />Own - Enterprise sells own products to customers.<br />Any - Enterprise can sell own or other enterprises products.<br />"
external_billing_id: External Billing ID
external_billing_id_placeholder: eg. INV-2024-123456
external_billing_id_tip: "This is the ID used by the external billing system to identify this enterprise."
visible_in_search: Visible in search?
visible_in_search_tip: "Shops can be <br />1. publicly visible, appearing on the OFN map and listings. <br />2. Hidden on maps and listings but referenced by other shops and linked in their profile. <br />3. Completely hidden."
visible: Public
@@ -1712,7 +1710,6 @@ en:
enterprise:
primary_details: "Primary Details"
address: "Address"
admin_only: "Admin Only"
contact: "Contact"
social: "Social"
about: "About"

View File

@@ -33,13 +33,5 @@ RSpec.describe Admin::EnterprisesHelper, type: :helper do
user.enterprises << enterprise
expect(visible_items.pluck(:name)).to include "connected_apps"
end
context 'when user is an admin' do
let(:user) { create(:admin_user) }
it "includes admin-only item" do
expect(visible_items.pluck(:name)).to include "admin_only"
end
end
end
end

View File

@@ -86,10 +86,6 @@ RSpec.describe '
end
fill_in 'enterprise_name', with: 'Eaterprises'
accept_alert do
click_link "Admin Only"
end
fill_in 'enterprise_permalink', with: 'eaterprises-permalink'
expect(page).to have_selector '.available'
choose 'Own'