Skip to content

Commit 41adfce

Browse files
committed
[wip] Include "Select address" feature
1 parent 114759f commit 41adfce

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

admin/app/components/solidus_admin/orders/show/address/component.html.erb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1-
<div class="<%= stimulus_id %>">
1+
<div class="<%= stimulus_id %>" data-controller="<%= stimulus_id %>">
22
<%= render component("orders/show").new(order: @order) %>
33
<%= render component("ui/modal").new(title: t(".title.#{@type}"), close_path: solidus_admin.order_path(@order)) do |modal| %>
44
<%= form_for @order, url: solidus_admin.send("order_#{@type}_address_path", @order), html: { id: form_id } do |form| %>
55
<div class="w-full flex flex-col mb-4">
6-
<h2 class="text-sm mb-4 font-semibold"><%= t(".subtitle.#{@type}") %></h2>
6+
<div class="flex justify-between items-center mb-4">
7+
<h2 class="text-sm font-semibold"><%= t(".subtitle.#{@type}") %></h2>
8+
9+
<div class="flex justify-between items-center">
10+
<div class="relative">
11+
<button type="button" data-action="<%= stimulus_id %>#toggle" class="text-sm w-full text-left flex items-center justify-between">
12+
<%= t(".select_address") %>
13+
<%= render component("ui/icon").new(name: 'arrow-down-s-fill', class: 'w-5 h-5') %>
14+
</button>
15+
16+
<% addresses = Spree::Address.limit(5) %>
17+
<div data-<%= stimulus_id %>-target="menu" class="absolute right-0 bg-white border border-gray-300 rounded mt-1 hidden shadow-lg z-10 w-full min-w-[16rem]">
18+
<% addresses.each do |address| %>
19+
<a href="#" class="block text-sm hover:bg-gray-50 px-4 py-3 w-auto mx-2 my-1 rounded">
20+
<%= format_address(address) %>
21+
</a>
22+
<% end %>
23+
</div>
24+
</div>
25+
</div>
26+
27+
</div>
728
<div class="w-full flex gap-4">
829
<%= form.fields_for :"#{@type}_address" do |address_form| %>
930
<%= render component('ui/forms/address').new(form: address_form, disabled: false) %>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Controller } from '@hotwired/stimulus'
2+
3+
export default class extends Controller {
4+
static targets = ["menu"]
5+
6+
toggle() {
7+
this.menuTarget.classList.toggle('hidden')
8+
}
9+
10+
close() {
11+
this.menuTarget.classList.add('hidden')
12+
}
13+
}

admin/app/components/solidus_admin/orders/show/address/component.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ def use_attribute
2323
end
2424
end
2525

26+
def format_address(address)
27+
return unless address
28+
safe_join([
29+
address.name,
30+
tag.br,
31+
address.address1,
32+
tag.br,
33+
address.address2,
34+
address.city,
35+
address.zipcode,
36+
address.state&.name,
37+
tag.br,
38+
address.country.name,
39+
tag.br,
40+
address.phone,
41+
], " ")
42+
end
43+
2644
def validate_address_type(type)
2745
VALID_TYPES.include?(type) ? type : raise(ArgumentError, "Invalid address type: #{type}")
2846
end

admin/app/components/solidus_admin/orders/show/address/component.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ en:
44
save: Save
55
cancel: Cancel
66
back: Back
7+
select_address: Select address
78
title:
89
ship: Edit Shipping Address
910
bill: Edit Billing Address

0 commit comments

Comments
 (0)