Skip to content

Commit 0ed991b

Browse files
committed
feat: add orders section to shop page and fetch shop orders in controller
1 parent 88b80b5 commit 0ed991b

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

app/controllers/admin_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def users
6666
# GET /admin/shop
6767
def shop
6868
@shop_items = ShopItem.all.order(created_at: :desc)
69+
@shop_orders = ShopOrder.includes(:user, :shop_item).order(created_at: :desc)
6970
end
7071

7172
private

app/models/shop_order.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
class ShopOrder < ApplicationRecord
2-
belongs_to :user
3-
belongs_to :shop_item
1+
class ShopOrder < ApplicationRecord
2+
belongs_to :user
3+
belongs_to :shop_item
4+
5+
after_create :sync_to_airtable
6+
7+
private
8+
9+
def sync_to_airtable
10+
Airtable::ShopOrderSyncJob.perform_later
11+
end
412
end

app/views/admin/shop.html.erb

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<a href="/admin/shop" style="padding: 8px 16px; border-bottom: 2px solid #f25f2c; color: #f25f2c; text-decoration: none; font-weight: 600;">Shop</a>
1919
</div>
2020

21-
<h1 class="page-title">Shop Items</h1>
21+
<h1 class="page-title">Shop</h1>
2222

2323
<div class="card" style="padding: 2rem; margin-bottom: 2rem; max-width: 600px;">
2424
<h2 style="margin-top: 0; margin-bottom: 1.5rem;">Add New Item</h2>
@@ -83,10 +83,58 @@
8383
</div>
8484
</div>
8585
<% end %>
86-
</div>
87-
</main>
86+
</div>
87+
</div>
88+
89+
<h2 style="margin: 3rem 0 1rem;">Recent Orders (<%= @shop_orders.count %>)</h2>
90+
91+
<div class="card" style="overflow: hidden;">
92+
<table style="width: 100%; border-collapse: collapse;">
93+
<thead>
94+
<tr style="background: #f5f5f5; border-bottom: 1px solid #e0e0e0;">
95+
<th style="padding: 1rem; text-align: left; font-weight: 600; font-size: 0.9rem;">User</th>
96+
<th style="padding: 1rem; text-align: left; font-weight: 600; font-size: 0.9rem;">Order Name</th>
97+
<th style="padding: 1rem; text-align: left; font-weight: 600; font-size: 0.9rem;">Status</th>
98+
<th style="padding: 1rem; text-align: left; font-weight: 600; font-size: 0.9rem;">Date</th>
99+
</tr>
100+
</thead>
101+
<tbody>
102+
<% if @shop_orders.empty? %>
103+
<tr>
104+
<td colspan="4" style="padding: 2rem; text-align: center; color: #999;">No orders yet</td>
105+
</tr>
106+
<% else %>
107+
<% @shop_orders.each do |order| %>
108+
<tr style="border-bottom: 1px solid #e0e0e0;">
109+
<td style="padding: 1rem;">
110+
<span style="font-weight: 600;"><%= order.user.first_name %> <%= order.user.last_name %></span>
111+
<br>
112+
<span class="muted" style="font-size: 0.9rem;"><%= order.user.email %></span>
113+
</td>
114+
<td style="padding: 1rem;">
115+
<%= order.name %>
116+
</td>
117+
<td style="padding: 1rem;">
118+
<% status_color = case order.status
119+
when 'pending' then '#fff3cd'
120+
when 'completed' then '#d4edda'
121+
when 'cancelled' then '#f8d7da'
122+
else '#e2e3e5'
123+
end %>
124+
<span style="background: <%= status_color %>; padding: 4px 8px; border-radius: 4px; font-size: 0.85rem; font-weight: 600; text-transform: capitalize;"><%= order.status %></span>
125+
</td>
126+
<td style="padding: 1rem; color: #999; font-size: 0.9rem;">
127+
<%= order.created_at.strftime('%b %d, %Y') %>
128+
</td>
129+
</tr>
130+
<% end %>
131+
<% end %>
132+
</tbody>
133+
</table>
134+
</div>
135+
</main>
88136

89-
<script>
137+
<script>
90138
const addItemForm = document.getElementById('add-item-form');
91139
const addItemBtn = document.getElementById('add-item-btn');
92140

0 commit comments

Comments
 (0)