-
Notifications
You must be signed in to change notification settings - Fork 24
HOLD: Add communications/notifications section to person edit #1864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
maebeale
wants to merge
1
commit into
main
Choose a base branch
from
maebeale/person-edit-notifications
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,10 @@ | |
| <% sender_users |= [ current_user ] if current_user %> | ||
| <% sender_options = sender_users.sort_by { |u| u.full_name.to_s.downcase }.map { |u| [ u.full_name, u.id ] } %> | ||
| <% channel_default = Notification::MANUAL_CHANNELS.include?(f.object.channel) ? f.object.channel : "email" %> | ||
| <% record = local_assigns[:event_registration] %> | ||
| <% record = local_assigns[:record] %> | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 From Claude: Renamed the |
||
| <div class="nested-fields rounded-md border border-amber-200 bg-amber-50 p-3"> | ||
| <%# Record this communication against the event registration (the "Record" | ||
| column in the notifications index). %> | ||
| <%# Record this communication against its parent (the "Record" column in the | ||
| notifications index) — e.g. an event registration or a person. %> | ||
| <% if record %> | ||
| <%= f.hidden_field :noticeable_type, value: record.class.name %> | ||
| <%= f.hidden_field :noticeable_id, value: record.id %> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| <%# ---- Notifications — communications addressed to this person, newest first. | ||
| Persisted entries are read-only and paginated like the comments box; new | ||
| manual log entries (email/phone/text/video) can be added inline and are | ||
| saved with the person form. Links open in a new tab so unsaved edits aren't | ||
| lost. Mirrors the registration edit notifications section. ---- %> | ||
| <% person = f.object %> | ||
| <% email = person.preferred_email %> | ||
| <% notifications = email.present? ? Notification.email(email).order(created_at: :desc) : Notification.none %> | ||
| <section class="overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm"> | ||
| <div class="flex items-center gap-3 border-b border-gray-100 px-4 py-3"> | ||
| <span class="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg <%= DomainTheme.bg_class_for(:users, intensity: 100) %> <%= DomainTheme.text_class_for(:users, intensity: 600) %>"> | ||
| <i class="fa-solid fa-bell"></i> | ||
| </span> | ||
| <h2 class="text-sm font-semibold text-gray-700">Communications</h2> | ||
| <% if email.present? %> | ||
| <%= link_to notifications_path(email: email), | ||
| class: "ml-auto inline-flex items-center gap-1.5 text-xs font-medium text-gray-500 hover:text-gray-700 hover:underline", | ||
| target: "_blank", rel: "noopener" do %> | ||
| View all | ||
| <i class="fa-solid fa-arrow-up-right-from-square text-[0.6rem]"></i> | ||
| <% end %> | ||
| <% end %> | ||
| </div> | ||
|
|
||
| <div class="space-y-3 p-4"> | ||
| <% if notifications.any? %> | ||
| <div data-controller="paginated-fields" data-paginated-fields-per-page-value="5" class="space-y-2"> | ||
| <% notifications.each do |notification| %> | ||
| <% subject = notification.email_subject.presence || notification.kind.to_s.humanize %> | ||
| <% body = notification.email_body_text.to_s %> | ||
| <div data-paginated-fields-target="item" class="flex items-baseline gap-x-2"> | ||
| <span class="shrink-0 whitespace-nowrap text-xs text-gray-400"><%= notification.created_at.strftime("%-m/%-d/%Y") %></span> | ||
| <span class="shrink-0 whitespace-nowrap text-xs font-medium text-gray-500"><%= notification.sender&.full_name.presence || "AWBW Portal" %></span> | ||
| <span class="min-w-0 flex-1 truncate text-sm" title="<%= [ subject, body.presence ].compact.join(" — ") %>"> | ||
| <span class="font-semibold text-gray-900"><%= subject %></span> | ||
| <% if body.present? %> | ||
| <span class="text-gray-500"><%= body %></span> | ||
| <% end %> | ||
| </span> | ||
| </div> | ||
| <% end %> | ||
| <div data-paginated-fields-target="nav"></div> | ||
| </div> | ||
| <% else %> | ||
| <p class="text-sm text-gray-400">No notifications for this person yet.</p> | ||
| <% end %> | ||
|
|
||
| <%# Inline add — manual log entries, saved with the person form. %> | ||
| <div class="space-y-2 border-t border-gray-100 pt-3"> | ||
| <%= f.simple_fields_for :notifications, person.notifications.select(&:new_record?) do |nf| %> | ||
| <%= render "notifications/notification_fields", f: nf, record: person %> | ||
| <% end %> | ||
| <%= link_to_add_association f, :notifications, | ||
| partial: "notifications/notification_fields", | ||
| render_options: { locals: { record: person } }, | ||
| class: "inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700 cursor-pointer" do %> | ||
| <i class="fa-solid fa-plus text-[0.6rem]"></i> | ||
| Add notification | ||
| <% end %> | ||
| </div> | ||
| </div> | ||
| </section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| require "rails_helper" | ||
|
|
||
| RSpec.describe "Person notifications", type: :request do | ||
| let(:admin) { create(:user, :admin) } | ||
| let(:person) { create(:person) } | ||
|
|
||
| before { sign_in admin } | ||
|
|
||
| describe "PATCH /people/:id logging a notification" do | ||
| it "creates a manual notification log from nested attributes" do | ||
| expect { | ||
| patch person_path(person), params: { | ||
| person: { | ||
| notifications_attributes: { "0" => { channel: "phone", email_subject: "Left a voicemail" } } | ||
| } | ||
| } | ||
| }.to change { person.notifications.count }.by(1) | ||
|
|
||
| notification = person.notifications.order(:created_at).last | ||
| expect(notification.channel).to eq("phone") | ||
| expect(notification.kind).to eq("manual_log") | ||
| expect(notification.email_subject).to eq("Left a voicemail") | ||
| expect(notification.recipient_email).to eq(person.preferred_email) | ||
| expect(notification.noticeable).to eq(person) | ||
| end | ||
|
|
||
| it "ignores a blank notification with no note" do | ||
| expect { | ||
| patch person_path(person), params: { | ||
| person: { | ||
| notifications_attributes: { "0" => { channel: "email", email_subject: "" } } | ||
| } | ||
| } | ||
| }.not_to change(Notification, :count) | ||
| end | ||
| end | ||
|
|
||
| describe "GET /people/:id/edit" do | ||
| it "lists past communications addressed to the person" do | ||
| person = create(:person, user: nil, email: "comms@example.com") | ||
| create(:notification, recipient_email: "comms@example.com", email_subject: "Welcome aboard", | ||
| kind: "manual_log", recipient_role: "person", notification_type: 0) | ||
|
|
||
| get edit_person_path(person) | ||
|
|
||
| expect(response.body).to include("Communications") | ||
| expect(response.body).to include("Welcome aboard") | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 From Claude: Falls back to "n/a" when the person has no email, mirroring the registration controller —
recipient_emailispresence-validated on Notification, so a manual log against an email-less person still saves.