Skip to content

Commit 53f04d6

Browse files
maebealeclaude
andcommitted
Reach the invoice from submission pages; use the existing print pattern
Bulk-payment payers are emailed a link to their (public) submission page, so the invoice needs to be reachable from there — add a "View invoice" link on both the public bulk-payment show page and the admin form-submission page. A bulk-payment submission's invoice is now public (gated by FormSubmission show_invoice?), matching that the submission show page is already public by id; the blank template stays admin-only. Also drop the bespoke print Stimulus controller in favor of the inline onclick="window.print();" pattern already used by sibling event views (recipients, background, social share), and render the invoice on a neutral public background rather than the admin blue tint. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent ce60020 commit 53f04d6

12 files changed

Lines changed: 83 additions & 34 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ This codebase (Rails 8.1)
7171
| Directory | Purpose |
7272
|---|---|
7373
| `app/frontend/entrypoints/` | Vite entry points (application.js, application.css) |
74-
| `app/frontend/javascript/controllers/` | Stimulus controllers (71) |
74+
| `app/frontend/javascript/controllers/` | Stimulus controllers (70) |
7575
| `app/frontend/javascript/rhino/` | Rich text editor customizations (mentions, grid) |
7676
| `app/frontend/stylesheets/` | Tailwind CSS and component styles |
7777

@@ -281,7 +281,6 @@ end
281281
- `paginated_fields` — Client-side pagination of nested fields
282282
- `password_toggle` — Show/hide password fields
283283
- `prefetch_lazy` — Prefetch lazy-loaded content
284-
- `print` — Triggers the browser print dialog (used by the invoice "Download PDF" button)
285284
- `print_options` — Print options toggle for analytics
286285
- `remote_select` — AJAX-powered select dropdown
287286
- `reveal_section` — Expand a collapsible section and scroll to it when loaded via matching URL hash

app/controllers/events/invoices_controller.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ module Events
33
# event's content (line item + cost); when a `submission_id` is supplied it
44
# autofills the bill-to/attention from that bulk-payment submission.
55
class InvoicesController < ApplicationController
6+
# Bulk-payment payers have no account; authorization (below) gates access.
7+
skip_before_action :authenticate_user!, only: [ :show ]
68
before_action :set_event
79

810
def show
9-
authorize! @event, to: :invoice?
10-
1111
if params[:submission_id].present?
12+
# A bulk-payment submission's invoice is reachable by the payer (who has
13+
# no account), matching the public bulk-payment show page they're sent.
1214
@submission = FormSubmission.find(params[:submission_id])
15+
authorize! @submission, to: :show_invoice?
1316
@invoice = EventInvoice.from_bulk_payment(@submission)
1417
else
18+
# The blank template is an admin tool.
19+
authorize! @event, to: :invoice?
1520
@invoice = EventInvoice.from_event(@event)
1621
end
1722

app/frontend/javascript/controllers/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ application.register("search-type-select", SearchTypeSelectController)
117117
import PrefetchLazyController from "./prefetch_lazy_controller"
118118
application.register("prefetch-lazy", PrefetchLazyController)
119119

120-
import PrintController from "./print_controller"
121-
application.register("print", PrintController)
122-
123120
import PrintOptionsController from "./print_options_controller"
124121
application.register("print-options", PrintOptionsController)
125122

app/frontend/javascript/controllers/print_controller.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/policies/form_submission_policy.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@ class FormSubmissionPolicy < ApplicationPolicy
33
def show?
44
admin?
55
end
6+
7+
# Bulk-payment payers have no account but are emailed a link to their public
8+
# submission, so they can reach its invoice too. Other submission types stay
9+
# admin-only.
10+
def show_invoice?
11+
record.role == "bulk_payment" || admin?
12+
end
613
end

app/views/events/_bulk_payment_card.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
class: "inline-flex items-center gap-1.5 rounded-lg border border-gray-300 bg-white px-2.5 py-1 text-xs font-medium text-gray-600 shadow-sm hover:bg-gray-50 hover:text-gray-800 transition-colors whitespace-nowrap" do %>
4141
<i class="fa-solid fa-file-lines text-xs"></i> Submission
4242
<% end %>
43-
<%= link_to event_invoice_path(@event, submission_id: submission.id),
43+
<%= link_to event_invoice_path(@event, submission_id: submission.id, return_to: "bulk_payments"),
4444
title: "View invoice",
4545
class: "inline-flex items-center gap-1.5 rounded-lg border border-gray-300 bg-white px-2.5 py-1 text-xs font-medium text-gray-600 shadow-sm hover:bg-gray-50 hover:text-gray-800 transition-colors whitespace-nowrap" do %>
4646
<i class="fa-solid fa-file-invoice-dollar text-xs"></i> Invoice

app/views/events/bulk_payments/show.html.erb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@
4545
<% end %>
4646
<%= render "form_submissions/submission", submission: @submission %>
4747

48+
<div class="mt-6 flex justify-center">
49+
<%= link_to event_invoice_path(@event, submission_id: @submission.id, return_to: "bulk_payment_show"),
50+
class: "inline-flex items-center gap-2 rounded-lg border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-50 transition-colors" do %>
51+
<i class="fa-solid fa-file-invoice-dollar"></i> View invoice
52+
<% end %>
53+
</div>
54+
4855
<% if allowed_to?(:dashboard?, @event) %>
4956
<div class="admin-only mt-6 rounded-lg border border-blue-200 bg-blue-50/50 px-4 py-4 space-y-3">
5057
<div class="flex items-center justify-between gap-2">

app/views/events/invoices/_actions.html.erb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
<%= link_to back_path, class: "inline-flex items-center gap-1.5 text-sm text-gray-500 hover:text-gray-700 px-2 py-1" do %>
66
<i class="fa-solid fa-arrow-left text-xs"></i> <%= back_label %>
77
<% end %>
8-
<div class="ml-auto" data-controller="print">
9-
<button type="button" data-action="print#print"
10-
class="inline-flex items-center gap-2 rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-50 transition-colors">
11-
<i class="fa-solid fa-file-arrow-down"></i> Download PDF
12-
</button>
13-
</div>
8+
<button onclick="window.print();"
9+
class="ml-auto inline-flex items-center gap-2 rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-50 transition-colors">
10+
<i class="fa-solid fa-file-arrow-down"></i> Download PDF
11+
</button>
1412
</div>
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
<% content_for(:page_bg_class, "admin-only bg-blue-100") %>
1+
<% content_for(:page_bg_class, "public") %>
22
<% content_for(:page_title, "Invoice — #{@event.title}") %>
3-
<% if @submission %>
4-
<%= render "events/invoices/actions",
5-
back_path: bulk_payments_event_path(@event, expand: @submission.id, anchor: "payment-card-#{@submission.id}"),
6-
back_label: "Back to bulk payments" %>
7-
<% else %>
8-
<%= render "events/invoices/actions",
9-
back_path: dashboard_event_path(@event),
10-
back_label: "Back to event" %>
11-
<% end %>
3+
<%
4+
back_path, back_label =
5+
if @submission
6+
case params[:return_to]
7+
when "bulk_payment_show"
8+
[ event_bulk_payment_path(@event, submission_id: @submission.id), "Back to submission" ]
9+
when "form_submission"
10+
[ form_submission_path(@submission), "Back to submission" ]
11+
else
12+
[ bulk_payments_event_path(@event, expand: @submission.id, anchor: "payment-card-#{@submission.id}"), "Back to bulk payments" ]
13+
end
14+
else
15+
[ dashboard_event_path(@event), "Back to event" ]
16+
end
17+
%>
18+
<%= render "events/invoices/actions", back_path: back_path, back_label: back_label %>
1219
<div class="px-4 sm:px-8 py-6 print:p-0">
1320
<%= render "events/invoices/invoice", invoice: @invoice %>
1421
</div>

app/views/form_submissions/show.html.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
</div>
3030
<div class="px-6 sm:px-8 py-7">
3131
<%= render "form_submissions/submission", submission: @form_submission %>
32+
33+
<% if event && @form_submission.role == "bulk_payment" %>
34+
<div class="mt-6 flex justify-center">
35+
<%= link_to event_invoice_path(event, submission_id: @form_submission.id, return_to: "form_submission"),
36+
class: "inline-flex items-center gap-2 rounded-lg border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-50 transition-colors" do %>
37+
<i class="fa-solid fa-file-invoice-dollar"></i> View invoice
38+
<% end %>
39+
</div>
40+
<% end %>
3241
</div>
3342
</div>
3443
</div>

0 commit comments

Comments
 (0)