Skip to content

Commit 72a3ffa

Browse files
committed
Update Admin to have firstname and lastname fields
Update the address handling logic in the admin components and tests to separate the 'firstname' and 'lastname' fields, instead of using a single 'name' field.
1 parent 4254d40 commit 72a3ffa

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

admin/app/components/solidus_admin/orders/index/component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def model_class
66
end
77

88
def search_key
9-
:number_or_shipments_number_or_bill_address_name_or_email_cont
9+
:number_or_shipments_number_or_bill_address_firstname_or_bill_address_lastname_cont_or_email_cont
1010
end
1111

1212
def search_url

admin/app/components/solidus_admin/ui/forms/address/component.html.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
<%= :disabled if @disabled %>
44
>
55
<div class="<%= stimulus_id %>--address-form flex flex-wrap gap-4 pb-4">
6-
<%= render component("ui/forms/field").text_field(@name, :name, object: @address) %>
6+
<%= render component("ui/forms/field").text_field(@name, :firstname, object: @address) %>
7+
<%= render component("ui/forms/field").text_field(@name, :lastname, object: @address) %>
8+
<% if Spree::Config[:company] %>
9+
<%= render component("ui/forms/field").text_field(@name, :company, object: @address) %>
10+
<% end %>
711
<%= render component("ui/forms/field").text_field(@name, :address1, object: @address) %>
812
<%= render component("ui/forms/field").text_field(@name, :address2, object: @address) %>
913
<div class="flex gap-4 w-full">

admin/spec/features/orders/show_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
expect(page).to have_css("dialog", wait: 5)
5252

5353
within("dialog") do
54-
fill_in "Name", with: "John Doe"
54+
fill_in "First Name", with: "John"
55+
fill_in "Last Name", with: "Doe"
5556
fill_in "Street Address", with: "1 John Doe Street"
5657
fill_in "Street Address (cont'd)", with: "Apartment 2"
5758
fill_in "City", with: "John Doe City"
@@ -77,7 +78,8 @@
7778
expect(page).to have_css("dialog", wait: 5)
7879

7980
within("dialog") do
80-
fill_in "Name", with: "Jane Doe"
81+
fill_in "First Name", with: "Jane"
82+
fill_in "Last Name", with: "Doe"
8183
fill_in "Street Address", with: "1 Jane Doe Street"
8284
fill_in "Street Address (cont'd)", with: "Apartment 3"
8385
fill_in "City", with: "Jane Doe City"

admin/spec/features/users_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,37 +128,37 @@
128128
it "allows editing of the existing address" do
129129
# Invalid submission
130130
within("form.ship_address") do
131-
fill_in "Name", with: ""
131+
fill_in "First Name", with: ""
132132
fill_in "Street Address", with: ""
133133
click_on "Update"
134134
end
135135
expect(page).to have_content("can't be blank").twice
136136

137137
# Valid submission
138138
within("form.bill_address") do
139-
fill_in "Name", with: "Galadriel"
139+
fill_in "First Name", with: "Galadriel"
140140
click_on "Update"
141141
end
142142
expect(page).to have_content("Billing Address has been successfully updated.")
143143

144144
# Valid submission
145145
within("form.ship_address") do
146-
fill_in "Name", with: "Elrond"
146+
fill_in "First Name", with: "Elrond"
147147
click_on "Update"
148148
end
149149
expect(page).to have_content("Shipping Address has been successfully updated.")
150150

151151
# Cancel submission
152152
within("form.bill_address") do
153-
fill_in "Name", with: "Smeagol"
153+
fill_in "First Name", with: "Smeagol"
154154
click_on "Cancel"
155155
end
156156
expect(page).to have_content("Users / customer@example.com / Addresses")
157157
expect(page).not_to have_content("Smeagol")
158158

159159
# The address forms weirdly only have values rather than actual text on the page.
160-
expect(page).to have_field("user[bill_address_attributes][name]", with: "Galadriel")
161-
expect(page).to have_field("user[ship_address_attributes][name]", with: "Elrond")
160+
expect(page).to have_field("user[bill_address_attributes][firstname]", with: "Galadriel")
161+
expect(page).to have_field("user[ship_address_attributes][firstname]", with: "Elrond")
162162
end
163163
end
164164

admin/spec/requests/solidus_admin/users_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
{
1212
user: {
1313
bill_address_attributes: {
14-
name: address.name,
14+
firstname: address.firstname,
15+
lastname: address.lastname,
1516
address1: address.address1,
1617
address2: address.address2,
1718
city: address.city,

0 commit comments

Comments
 (0)