Skip to content

Commit

Permalink
[wip] Include "Select address" feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rainerdema committed Nov 8, 2023
1 parent 114759f commit 41adfce
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
<div class="<%= stimulus_id %>">
<div class="<%= stimulus_id %>" data-controller="<%= stimulus_id %>">
<%= render component("orders/show").new(order: @order) %>
<%= render component("ui/modal").new(title: t(".title.#{@type}"), close_path: solidus_admin.order_path(@order)) do |modal| %>
<%= form_for @order, url: solidus_admin.send("order_#{@type}_address_path", @order), html: { id: form_id } do |form| %>
<div class="w-full flex flex-col mb-4">
<h2 class="text-sm mb-4 font-semibold"><%= t(".subtitle.#{@type}") %></h2>
<div class="flex justify-between items-center mb-4">
<h2 class="text-sm font-semibold"><%= t(".subtitle.#{@type}") %></h2>

<div class="flex justify-between items-center">
<div class="relative">
<button type="button" data-action="<%= stimulus_id %>#toggle" class="text-sm w-full text-left flex items-center justify-between">
<%= t(".select_address") %>
<%= render component("ui/icon").new(name: 'arrow-down-s-fill', class: 'w-5 h-5') %>
</button>

<% addresses = Spree::Address.limit(5) %>
<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]">
<% addresses.each do |address| %>
<a href="#" class="block text-sm hover:bg-gray-50 px-4 py-3 w-auto mx-2 my-1 rounded">
<%= format_address(address) %>
</a>
<% end %>
</div>
</div>
</div>

</div>
<div class="w-full flex gap-4">
<%= form.fields_for :"#{@type}_address" do |address_form| %>
<%= render component('ui/forms/address').new(form: address_form, disabled: false) %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static targets = ["menu"]

toggle() {
this.menuTarget.classList.toggle('hidden')
}

close() {
this.menuTarget.classList.add('hidden')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ def use_attribute
end
end

def format_address(address)
return unless address
safe_join([
address.name,
tag.br,
address.address1,
tag.br,
address.address2,
address.city,
address.zipcode,
address.state&.name,
tag.br,
address.country.name,
tag.br,
address.phone,
], " ")
end

def validate_address_type(type)
VALID_TYPES.include?(type) ? type : raise(ArgumentError, "Invalid address type: #{type}")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ en:
save: Save
cancel: Cancel
back: Back
select_address: Select address
title:
ship: Edit Shipping Address
bill: Edit Billing Address
Expand Down

0 comments on commit 41adfce

Please sign in to comment.