Skip to content

Commit 6412e3d

Browse files
etewiahclaude
andcommitted
Add admin UI for configuring display currencies
- Add available_currencies column to pwb_websites table - Add currency selection UI in Admin > Settings > General tab - Add COMMON_CURRENCIES constant with ECB-supported currencies - Allow admins to select which currencies visitors can view prices in - Update permitted params to include available_currencies When currencies are selected, visitors will see a currency selector and property prices will show conversions (e.g., "€250,000 (~$270,000 USD)"). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d7c4850 commit 6412e3d

File tree

8 files changed

+75
-2
lines changed

8 files changed

+75
-2
lines changed

app/controllers/site_admin/website/settings_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ def general_settings_params
223223
:analytics_id,
224224
:analytics_id_type,
225225
:external_image_mode,
226-
supported_locales: []
226+
supported_locales: [],
227+
available_currencies: []
227228
)
228229
end
229230

app/lib/pwb/config.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ module Config
6161
'NZD' => { label: 'New Zealand Dollar', symbol: 'NZ$' }
6262
}.freeze
6363

64+
# Common currencies for display conversion (subset of ECB-supported currencies)
65+
# These are shown in the admin UI for selecting additional display currencies
66+
COMMON_CURRENCIES = {
67+
'EUR' => 'Euro (€)',
68+
'USD' => 'US Dollar ($)',
69+
'GBP' => 'British Pound (£)',
70+
'CHF' => 'Swiss Franc (CHF)',
71+
'AUD' => 'Australian Dollar (A$)',
72+
'CAD' => 'Canadian Dollar (CA$)',
73+
'NZD' => 'New Zealand Dollar (NZ$)',
74+
'SEK' => 'Swedish Krona (kr)',
75+
'NOK' => 'Norwegian Krone (kr)',
76+
'DKK' => 'Danish Krone (kr)',
77+
'PLN' => 'Polish Zloty (zł)',
78+
'CZK' => 'Czech Koruna (Kč)',
79+
'HUF' => 'Hungarian Forint (Ft)'
80+
}.freeze
81+
6482
# ==========================================================================
6583
# AREA UNITS
6684
# ==========================================================================

app/models/pwb/website.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# id :integer not null, primary key
88
# admin_config :json
99
# analytics_id_type :integer
10+
# available_currencies :text default([]), is an Array
1011
# company_display_name :string
1112
# configuration :json
1213
# custom_domain :string

app/views/site_admin/website/settings/_general_tab.html.erb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,51 @@
7070
<p class="mt-1 text-sm text-gray-500">Currency used for property prices</p>
7171
</div>
7272

73+
<!-- Available Currencies for Display -->
74+
<div>
75+
<label class="block text-sm font-medium text-gray-700 mb-1">
76+
Additional Display Currencies
77+
</label>
78+
<p class="text-sm text-gray-500 mb-3">
79+
Select additional currencies visitors can view prices in. When selected, prices will show
80+
conversion alongside the original price (e.g., "€250,000 (~$270,000 USD)").
81+
</p>
82+
83+
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3">
84+
<%
85+
current_currencies = @website.available_currencies || []
86+
default_currency = @website.default_currency || 'EUR'
87+
%>
88+
<% Pwb::Config::COMMON_CURRENCIES.each do |currency_code, label| %>
89+
<% currency_str = currency_code.to_s %>
90+
<% is_default = currency_str == default_currency %>
91+
<label class="flex items-center p-2 border border-gray-200 rounded-lg hover:bg-gray-50 cursor-pointer <%= 'opacity-50' if is_default %>">
92+
<input type="checkbox"
93+
name="pwb_website[available_currencies][]"
94+
value="<%= currency_str %>"
95+
<%= 'checked disabled' if is_default %>
96+
<%= 'checked' if current_currencies.include?(currency_str) && !is_default %>
97+
class="h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500">
98+
<span class="ml-2 text-sm text-gray-700">
99+
<%= label %>
100+
<% if is_default %>
101+
<span class="text-xs text-gray-400">(default)</span>
102+
<% end %>
103+
</span>
104+
</label>
105+
<% end %>
106+
</div>
107+
108+
<!-- Hidden field to ensure empty array is submitted when no checkboxes selected -->
109+
<input type="hidden" name="pwb_website[available_currencies][]" value="">
110+
111+
<p class="mt-2 text-sm text-gray-500">
112+
<strong>Currency conversion:</strong>
113+
Exchange rates are updated daily from the European Central Bank.
114+
Conversions are approximate and for display purposes only.
115+
</p>
116+
</div>
117+
73118
<!-- Default Area Unit -->
74119
<div>
75120
<label for="default_area_unit" class="block text-sm font-medium text-gray-700 mb-1">
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddAvailableCurrenciesToPwbWebsites < ActiveRecord::Migration[8.1]
2+
def change
3+
add_column :pwb_websites, :available_currencies, :text, array: true, default: []
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.1].define(version: 2025_12_27_154344) do
13+
ActiveRecord::Schema[8.1].define(version: 2025_12_27_182239) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_catalog.plpgsql"
1616
enable_extension "pgcrypto"
@@ -837,6 +837,7 @@
837837
t.json "admin_config", default: {}
838838
t.string "analytics_id"
839839
t.integer "analytics_id_type"
840+
t.text "available_currencies", default: [], array: true
840841
t.string "company_display_name"
841842
t.json "configuration", default: {}
842843
t.integer "contact_address_id"

spec/factories/pwb_websites.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# id :integer not null, primary key
66
# admin_config :json
77
# analytics_id_type :integer
8+
# available_currencies :text default([]), is an Array
89
# company_display_name :string
910
# configuration :json
1011
# custom_domain :string

spec/models/pwb/website_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# id :integer not null, primary key
66
# admin_config :json
77
# analytics_id_type :integer
8+
# available_currencies :text default([]), is an Array
89
# company_display_name :string
910
# configuration :json
1011
# custom_domain :string

0 commit comments

Comments
 (0)