docbrown/app/components/admin/users/tools/notes_component.html.erb
rhymes fc01a93326
Admin Member view: add Tools::HeaderComponent to reduce duplication (#14558)
* This does not work

* Revert "This does not work"

This reverts commit b2292e61fb10faa6051b009214e732a9927c7746.

* Tried with a partial, works

* Improved with component
2021-08-24 15:08:48 +02:00

47 lines
1.7 KiB
Text

<section
class="crayons-card p-3 js-component"
data-controller="users--tools--ajax"
data-action="ajax:success@document->users--tools--ajax#success ajax:error@document->users--tools--ajax#error">
<%= render Admin::Users::Tools::HeaderComponent.new(title: "Notes", user: @user) %>
<%# Create a new note %>
<%= form_with model: Note.new,
url: admin_user_tools_notes_path(@user),
method: :post,
remote: true,
class: "mt-2" do |f| %>
<div class="crayons-field form-group">
<%= f.label :content, "Add a new note", class: "crayons-field__label" %>
<%= f.text_area :content, required: true, class: "crayons-textfield" %>
</div>
<%= f.submit "Create Note", class: "crayons-btn", data: { disable_with: "Creating..." } %>
<% end -%>
<%# Notes history #%>
<% if @notes.any? %>
<article class="mt-5">
<details>
<summary class="fw-medium">Recent Notes (<%= @notes.size %>)</summary>
<ul class="list-none">
<% @notes.each_with_index do |note, index| %>
<li class="py-3 pl-3 <%= index == @notes.size - 1 ? "border-b-0" : "border-b-1" %> border-l-0 border-t-0 border-r-0 border-solid border-base-50">
<local-time datetime="<%= note.created_at.iso8601 %>">
<%= note.created_at.strftime("%d %B %Y %H:%M %Z") %>
</local-time>
by
<%= note.author&.username %>
<% if note.reason.present? %>
<strong><%= note.reason %></strong>:
<% end -%>
<%= note.content %>
</li>
<% end %>
</ul>
</details>
</article>
<% end %>
</section>