Skip to content

Commit

Permalink
Remove Admin Only tab logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pacodelaluna committed Jan 5, 2025
1 parent f2b8eeb commit ec546f5
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 91 deletions.
1 change: 0 additions & 1 deletion app/helpers/admin/enterprises_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def build_enterprise_side_menu_items(
)
[
{ 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 },
Expand Down
7 changes: 1 addition & 6 deletions app/views/admin/enterprises/_form.html.haml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 5 additions & 5 deletions app/views/admin/enterprises/_new_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 0 additions & 24 deletions app/views/admin/enterprises/form/_admin_only.html.haml

This file was deleted.

24 changes: 24 additions & 0 deletions app/views/admin/enterprises/form/_primary_details.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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'
30 changes: 0 additions & 30 deletions app/webpacker/controllers/admin_only_controller.js

This file was deleted.

12 changes: 10 additions & 2 deletions app/webpacker/controllers/primary_details_controller.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { Controller } from "stimulus";

export default class extends Controller {
static values = { primaryProducer: String };
static values = { primaryProducer: String, enterpriseSells: String };
static targets = ["spinner"];

primaryProducerChanged(event) {
this.primaryProducerValue = event.currentTarget.checked;
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" },
Expand Down
19 changes: 8 additions & 11 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1732,7 +1730,6 @@ en:
enterprise:
primary_details: "Primary Details"
address: "Address"
admin_only: "Admin Only"
contact: "Contact"
social: "Social"
about: "About"
Expand Down
8 changes: 0 additions & 8 deletions spec/helpers/admin/enterprises_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,5 @@
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
4 changes: 0 additions & 4 deletions spec/system/admin/enterprises_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@
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'
Expand Down

0 comments on commit ec546f5

Please sign in to comment.