diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index db7d78d5d5..67ed726282 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -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 }, diff --git a/app/views/admin/enterprises/_form.html.haml b/app/views/admin/enterprises/_form.html.haml index 0284abb32b..71a9b2378b 100644 --- a/app/views/admin/enterprises/_form.html.haml +++ b/app/views/admin/enterprises/_form.html.haml @@ -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 diff --git a/app/views/admin/enterprises/_new_form.html.haml b/app/views/admin/enterprises/_new_form.html.haml index a1d12ac492..6964c19032 100644 --- a/app/views/admin/enterprises/_new_form.html.haml +++ b/app/views/admin/enterprises/_new_form.html.haml @@ -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 diff --git a/app/views/admin/enterprises/form/_admin_only.html.haml b/app/views/admin/enterprises/form/_admin_only.html.haml deleted file mode 100644 index 275e106c09..0000000000 --- a/app/views/admin/enterprises/form/_admin_only.html.haml +++ /dev/null @@ -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') } diff --git a/app/views/admin/enterprises/form/_primary_details.html.haml b/app/views/admin/enterprises/form/_primary_details.html.haml index 297263f263..8f1ebb93df 100644 --- a/app/views/admin/enterprises/form/_primary_details.html.haml +++ b/app/views/admin/enterprises/form/_primary_details.html.haml @@ -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' diff --git a/app/webpacker/controllers/admin_only_controller.js b/app/webpacker/controllers/admin_only_controller.js deleted file mode 100644 index beb5eae2e4..0000000000 --- a/app/webpacker/controllers/admin_only_controller.js +++ /dev/null @@ -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"); - }); - } -} diff --git a/app/webpacker/controllers/primary_details_controller.js b/app/webpacker/controllers/primary_details_controller.js index 59443d2669..b4e72be4cf 100644 --- a/app/webpacker/controllers/primary_details_controller.js +++ b/app/webpacker/controllers/primary_details_controller.js @@ -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" }, diff --git a/config/locales/en.yml b/config/locales/en.yml index 6db44cbe9e..b2ab4fd807 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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.
Own - Enterprise sells own products to customers.
Any - Enterprise can sell own or other enterprises products.
" - 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.
Own - Enterprise sells own products to customers.
Any - Enterprise can sell own or other enterprises products.
" + 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
1. publicly visible, appearing on the OFN map and listings.
2. Hidden on maps and listings but referenced by other shops and linked in their profile.
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" diff --git a/spec/helpers/admin/enterprises_helper_spec.rb b/spec/helpers/admin/enterprises_helper_spec.rb index 36bd1b5085..aae01ab5ea 100644 --- a/spec/helpers/admin/enterprises_helper_spec.rb +++ b/spec/helpers/admin/enterprises_helper_spec.rb @@ -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 diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 2cd8b23e88..86d007a46b 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -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'