From ca4635922495467a173e17977ecbe0f6fb7523d8 Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Mon, 10 Jan 2022 16:23:54 +0100 Subject: [PATCH] More fixes --- app/controllers/admin/customers_controller.rb | 2 +- app/models/customer.rb | 4 ++-- app/views/admin/customers/index.html.haml | 15 ++++++++++----- config/locales/en_GB.yml | 2 ++ .../column_preference_defaults.rb | 3 ++- spec/system/admin/customers_spec.rb | 3 ++- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/customers_controller.rb b/app/controllers/admin/customers_controller.rb index 71cc8fc2c8..28fcf235ba 100644 --- a/app/controllers/admin/customers_controller.rb +++ b/app/controllers/admin/customers_controller.rb @@ -99,7 +99,7 @@ module Admin def customer_params params.require(:customer).permit( - :enterprise_id, :name, :email, :code, :tag_list, + :enterprise_id, :first_name, :last_name, :email, :code, :tag_list, ship_address_attributes: PermittedAttributes::Address.attributes, bill_address_attributes: PermittedAttributes::Address.attributes, ) diff --git a/app/models/customer.rb b/app/models/customer.rb index 3c9cf3715a..ec4d78235c 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -34,12 +34,12 @@ class Customer < ApplicationRecord attr_accessor :gateway_recurring_payment_client_secret, :gateway_shop_id - private - def full_name "#{first_name} #{last_name}".strip end + private + def downcase_email email&.downcase! end diff --git a/app/views/admin/customers/index.html.haml b/app/views/admin/customers/index.html.haml index e2bff1832f..18bf810ee8 100644 --- a/app/views/admin/customers/index.html.haml +++ b/app/views/admin/customers/index.html.haml @@ -50,7 +50,8 @@ %table.index#customers %col.email{ width: "20%", 'ng-show' => 'columns.email.visible' } - %col.name{ width: "20%", 'ng-show' => 'columns.name.visible' } + %col.first_name{ width: "20%", 'ng-show' => 'columns.first_name.visible' } + %col.last_name{ width: "20%", 'ng-show' => 'columns.last_name.visible' } %col.code{ width: "10%", 'ng-show' => 'columns.code.visible' } %col.tags{ width: "20%", 'ng-show' => 'columns.tags.visible' } %col.bill_address{ width: "10%", 'ng-show' => 'columns.bill_address.visible' } @@ -63,8 +64,10 @@ -# %input{ :type => "checkbox", :name => 'toggle_bulk', 'ng-click' => 'toggleAllCheckboxes()', 'ng-checked' => "allBoxesChecked()" } %th.email{ 'ng-show' => 'columns.email.visible' } %a{ :href => '', 'ng-click' => "sorting.toggle('email')" }=t('admin.email') - %th.name{ 'ng-show' => 'columns.name.visible' } - %a{ :href => '', 'ng-click' => "sorting.toggle('name')" }=t('admin.name') + %th.first_name{ 'ng-show' => 'columns.first_name.visible' } + %a{ :href => '', 'ng-click' => "sorting.toggle('first_name')" }=t('admin.first_name') + %th.last_name{ 'ng-show' => 'columns.last_name.visible' } + %a{ :href => '', 'ng-click' => "sorting.toggle('last_name')" }=t('admin.last_name') %th.code{ 'ng-show' => 'columns.code.visible' } %a{ :href => '', 'ng-click' => "sorting.toggle('code')" }=t('admin.customers.index.code') %th.tags{ 'ng-show' => 'columns.tags.visible' }=t('admin.tags') @@ -78,8 +81,10 @@ %td.email{ 'ng-show' => 'columns.email.visible'} %span{ 'ng-bind' => '::customer.email' } %span.guest-label{ 'ng-show' => 'customer.user_id == null' }= t('.guest_label') - %td.name{ 'ng-show' => 'columns.name.visible'} - %input{ type: 'text', name: 'name', ng: { model: 'customer.name' }, 'obj-for-update' => 'customer', 'attr-for-update' => 'name'} + %td.first_name{ 'ng-show' => 'columns.first_name.visible'} + %input{ type: 'text', name: 'first_name', ng: { model: 'customer.first_name' }, 'obj-for-update' => 'customer', 'attr-for-update' => 'name'} + %td.name{ 'ng-show' => 'columns.last_name.visible'} + %input{ type: 'text', name: 'last_name', ng: { model: 'customer.last_name' }, 'obj-for-update' => 'customer', 'attr-for-update' => 'name'} %td.code{ 'ng-show' => 'columns.code.visible' } %input{ type: 'text', name: 'code', ng: {model: 'customer.code', change: 'checkForDuplicateCodes()'}, "obj-for-update" => "customer", "attr-for-update" => "code" } %i.icon-warning-sign{ ng: {if: 'duplicate'} } diff --git a/config/locales/en_GB.yml b/config/locales/en_GB.yml index 2e36241b0f..1733e703d9 100644 --- a/config/locales/en_GB.yml +++ b/config/locales/en_GB.yml @@ -411,6 +411,8 @@ en_GB: ends_at: Ends At ends_on: Ends On name: Name + first_name: First name + last_name: Last name on_hand: In Stock on_demand: Unlimited on_demand?: Unlimited? diff --git a/lib/open_food_network/column_preference_defaults.rb b/lib/open_food_network/column_preference_defaults.rb index 3f135f6b61..4f3cc21f3f 100644 --- a/lib/open_food_network/column_preference_defaults.rb +++ b/lib/open_food_network/column_preference_defaults.rb @@ -30,7 +30,8 @@ module OpenFoodNetwork node = 'admin.customers.index' { email: { name: I18n.t("admin.email"), visible: true }, - name: { name: I18n.t("admin.name"), visible: true }, + first_name: { name: I18n.t("admin.first_name"), visible: true }, + last_name: { name: I18n.t("admin.last_name"), visible: true }, code: { name: I18n.t("#{node}.code"), visible: true }, tags: { name: I18n.t("admin.tags"), visible: true }, bill_address: { name: I18n.t("#{node}.bill_address"), visible: true }, diff --git a/spec/system/admin/customers_spec.rb b/spec/system/admin/customers_spec.rb index 3692d90bf4..b7e63e8e2c 100644 --- a/spec/system/admin/customers_spec.rb +++ b/spec/system/admin/customers_spec.rb @@ -177,7 +177,8 @@ describe 'Customers' do select2_select managed_distributor1.name, from: "shop_id" within "tr#c_#{customer1.id}" do - expect(find_field('name').value).to eq 'John Doe' + expect(find_field('first_name').value).to eq 'John' + expect(find_field('last_name').value).to eq 'Doe' fill_in "code", with: "new-customer-code" expect(page).to have_css "input[name=code].update-pending"