Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,10 @@ def account_numbers
end

def email
@message = Ahoy::Message.find(params[:message_id])
end

def email_html
@message_id = params[:message_id]

respond_to do |format|
Expand All @@ -1323,7 +1327,6 @@ def emails
@count = messages.count

@messages = messages.page(@page).per(@per).order(sent_at: :desc)

end

def unknown_merchants
Expand Down
14 changes: 14 additions & 0 deletions app/views/admin/email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%#
We're doing this crazy level of nesting to prevent excess web requests.

emails (index page) -> lazy turboframe with inside iframe -> email_html action

This is because just having iframes on the index page causes a huge number of
web requests from browser extensions, etc. So, we lazy load the iframes.

And, Rails has a hard time with the email HTML when passed through ERB, so we
respond with the email HTML directly in the controller action.
%>
<%= turbo_frame_tag dom_id(@message) do %>
<iframe loading="lazy" src="<%= url_for(controller: "admin", action: "email_html", message_id: @message.id) %>" class="w-full h-full absolute border-none -mt-8 -ml-8 pb-24">iframes are not supported</iframe>
<% end %>
16 changes: 10 additions & 6 deletions app/views/admin/emails.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<%= form_with local: true, url: emails_admin_index_path, method: :get do |form| %>
<%= form.text_field :q, value: params[:q], placeholder: "Search" %>
<%= form.text_field :to, value: params[:to], placeholder: "Email address (to)" %>

<%= form.collection_select(:user_id, User.all.order(Arel.sql("COALESCE(preferred_name, full_name, email) ASC")), :id, :admin_dropdown_description, { include_blank: "Select a user", selected: @user_id }, { width: 250, style: "max-width: 250px" }) %>
<%= form.text_field :user_id, value: params[:user_id], placeholder: "User ID" %>

<div>
<%= form.submit "Search" %>
Expand All @@ -29,10 +28,6 @@
</thead>
<tbody>
<% @messages.each do |msg| %>
<section class="modal bg-snow" style="height: 60vh;" data-behavior="modal" role="dialog" id="message_<%= msg.id %>">
<%= modal_header "Email to #{msg.user&.name || "unknown user"}" %>
<iframe loading="lazy" src="<%= url_for(controller: "admin", action: "email", message_id: msg.id) %>" class="w-full h-full absolute border-none -mt-8 -ml-8 pb-24">iframes are not supported</iframe>
</section>
<tr>
<td><%= msg.id %></td>
<td><%= msg.sent_at.strftime("%Y-%m-%d") %></td>
Expand All @@ -56,4 +51,13 @@
</tbody>
</table>

<% @messages.each do |msg| %>
<section class="modal bg-snow" style="height: 60vh;" data-behavior="modal" role="dialog" id="message_<%= msg.id %>">
<%= modal_header "Email to #{msg.user&.name || "unknown user"}" %>
<%= turbo_frame_tag dom_id(msg), src: url_for(controller: "admin", action: "email", message_id: msg.id), loading: "lazy" do %>
Loading...
<% end %>
</section>
<% end %>

<%= paginate @messages %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
get "employee_payments", to: "admin#employee_payments"
get "emails", to: "admin#emails"
get "email", to: "admin#email"
get "email_html", to: "admin#email_html"
get "merchant_memo_check", to: "admin#merchant_memo_check"
get "referral_programs", to: "admin#referral_programs"
post "referral_program_create", to: "admin#referral_program_create"
Expand Down