Skip to content

Commit 174839b

Browse files
Fix UI and accessibility and check and resolve all found errors
1 parent 5494b42 commit 174839b

2 files changed

Lines changed: 59 additions & 43 deletions

File tree

app/controllers/milestones_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ class MilestonesController < ApplicationController
33
before_action :set_milestone
44

55
def toggle_paid
6-
@milestone.update(paid: params[:paid] == "1")
6+
@milestone.update(paid: params[:paid] == '1')
77
respond_to do |format|
88
format.html { redirect_back fallback_location: product_path(@milestone.product), notice: "Milestone with status '#{@milestone.status&.name}' is now paid." }
9-
format.js # For remote: true handling
9+
format.js # For remote: true handling
1010
end
1111
end
1212

app/views/product/show.html.erb

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,68 @@
1717
<div class="gap-6 flex justify-between">
1818
<!-- First Column: List milestones -->
1919
<div class="px-16 grid grid-cols-1 gap-4 col-span-1 w-1/2">
20-
<h2 class="text-lg font-semibold text-gray-900 dark:text-white mb-2">Milestones</h2>
21-
<% if @product.milestones.any? %>
22-
<ul class="space-y-3">
23-
<% @product.milestones.each do |milestone| %>
24-
<li class="bg-gray-50 dark:bg-gray-700 p-4 rounded-md shadow-sm">
25-
<p class="text-sm text-gray-800 dark:text-white">
26-
<strong>Status:</strong> <%= milestone.status&.name || 'N/A' %>
27-
</p>
28-
<p class="text-sm text-gray-800 dark:text-white">
29-
<strong>Percentage:</strong> <%= milestone.percentage %>%
30-
</p>
31-
<% if @product.budget.present? %>
32-
<p class="text-sm text-gray-800 dark:text-white">
33-
<strong>Amount:</strong> KES <%= number_with_precision(@product.budget * milestone.percentage.to_f / 100, precision: 2) %>
34-
</p>
35-
<% end %>
20+
<h2 class="text-lg font-semibold text-gray-900 dark:text-white mb-2">Milestones</h2>
21+
<% if @product.milestones.any? %>
22+
<ul class="space-y-3">
23+
<% @product.milestones.each do |milestone| %>
24+
<li class="bg-gray-50 dark:bg-gray-700 p-4 rounded-md shadow-sm">
25+
<p class="text-sm text-gray-800 dark:text-white">
26+
<strong>Status:</strong> <%= milestone.status&.name || 'N/A' %>
27+
</p>
28+
<p class="text-sm text-gray-800 dark:text-white">
29+
<strong>Percentage:</strong> <%= milestone.percentage %>%
30+
</p>
31+
<% if @product.budget.present? %>
32+
<p class="text-sm text-gray-800 dark:text-white">
33+
<strong>Amount:</strong> KES <%= number_with_precision(@product.budget * milestone.percentage.to_f / 100, precision: 2) %>
34+
</p>
35+
<% end %>
3636

37-
<!-- Paid Toggle -->
38-
<div class="mt-2">
39-
<%= form_with url: toggle_paid_milestone_path(milestone), method: :patch, local: true, remote: true do |form| %>
40-
<div class="flex items-center">
41-
<label class="relative inline-block w-16 h-8">
42-
<%= form.check_box :paid,
43-
checked: milestone.paid,
44-
class: "hidden",
45-
disabled: milestone.paid?, # lock once paid
46-
onchange: milestone.paid? ? nil : 'this.form.submit()' %>
47-
48-
<span class="absolute cursor-pointer top-0 left-0 right-0 bottom-0 bg-gray-300 rounded-full transition duration-300"></span>
49-
<span class="absolute left-1 top-1 bg-white w-6 h-6 rounded-full transition duration-300 transform"></span>
50-
</label>
51-
<span class="ml-3 text-sm text-gray-800 dark:text-white">
52-
Paid
53-
</span>
37+
<!-- Paid Toggle -->
38+
<div class="mt-2">
39+
<%= form_with url: toggle_paid_milestone_path(milestone), method: :patch, local: true, remote: true do |form| %>
40+
<div class="flex items-center space-x-3">
41+
42+
<!-- Switch -->
43+
<label class="relative inline-block w-16 h-8">
44+
<%= form.check_box :paid,
45+
checked: milestone.paid,
46+
class: "hidden peer",
47+
disabled: milestone.paid?,
48+
onchange: milestone.paid? ? nil : 'this.form.submit()' %>
49+
50+
<!-- Background -->
51+
<span class="absolute top-0 left-0 right-0 bottom-0 bg-gray-300 rounded-full transition duration-300 peer-checked:bg-green-500"></span>
52+
53+
<!-- Knob -->
54+
<span class="absolute left-1 top-1 bg-white w-6 h-6 rounded-full transition duration-300 transform peer-checked:translate-x-8"></span>
55+
</label>
56+
57+
<!-- Label Text -->
58+
<span class="text-sm text-gray-800 dark:text-white">
59+
Paid
60+
<span class="text-xs text-gray-500 block">
61+
<% if milestone.paid? %>
62+
This milestone has been paid and cannot be changed.
63+
<% else %>
64+
Once marked as paid, it cannot be undone.
65+
<% end %>
66+
</span>
67+
</span>
68+
69+
</div>
70+
<% end %>
5471
</div>
55-
<% end %>
56-
</div>
5772

5873

59-
</li>
74+
75+
</li>
76+
<% end %>
77+
</ul>
78+
<% else %>
79+
<p class="text-gray-500 dark:text-gray-400">No milestones available for this product.</p>
6080
<% end %>
61-
</ul>
62-
<% else %>
63-
<p class="text-gray-500 dark:text-gray-400">No milestones available for this product.</p>
64-
<% end %>
65-
</div>
81+
</div>
6682

6783

6884
<!-- Fourth Column: Documents -->

0 commit comments

Comments
 (0)