Skip to content

Commit 4add9dd

Browse files
committed
Move time zone control into a stimulus controller
1 parent 8700a1b commit 4add9dd

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Controller } from "stimulus"
2+
3+
export default class extends Controller {
4+
static targets = [ "select" ]
5+
6+
connect() {
7+
// Called when the controller is initialized and the element is in the DOM
8+
const userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
9+
10+
if (this.hasSelectTarget) {
11+
const options = this.selectTarget.options;
12+
for (let i = 0; i < options.length; i++) {
13+
if (options[i].value === userTimeZone) {
14+
this.selectTarget.selectedIndex = i;
15+
break;
16+
}
17+
}
18+
}
19+
}
20+
}

app/views/better_together/wizard_step_definitions/host_setup/platform_details.html.erb

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,19 @@
7474
</small>
7575
</div>
7676

77-
<div class="mb-3">
78-
<%= f.label :time_zone, class: 'form-label' %>
79-
<%= f.time_zone_select :time_zone, ActiveSupport::TimeZone.all, {}, { class: 'form-select', id: 'time_zone_select', required: true } %>
77+
<!-- Time Zone Section with Stimulus Controller -->
78+
<div class="mb-3" data-controller="better-together--time-zone">
79+
<%= f.label :time_zone, 'Which time zone should we use?', class: 'form-label' %>
80+
<%= f.time_zone_select :time_zone, ActiveSupport::TimeZone.all, {},
81+
{
82+
class: 'form-select',
83+
data: { 'better-together--time-zone-target': 'select' },
84+
id: 'time_zone_select',
85+
required: true
86+
}
87+
%>
8088
<small class="form-text text-muted">
81-
Set your platform's time zone for accurate scheduling.
89+
This helps keep events and notifications in sync for everyone.
8290
</small>
8391
</div>
8492

@@ -95,19 +103,3 @@
95103
</div>
96104
</div>
97105
</div>
98-
99-
<script>
100-
document.addEventListener('DOMContentLoaded', function() {
101-
var userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
102-
var timeZoneSelect = document.getElementById('time_zone_select');
103-
104-
if (timeZoneSelect) {
105-
for (var i = 0; i < timeZoneSelect.options.length; i++) {
106-
if (timeZoneSelect.options[i].value === userTimeZone) {
107-
timeZoneSelect.selectedIndex = i;
108-
break;
109-
}
110-
}
111-
}
112-
});
113-
</script>

0 commit comments

Comments
 (0)