Skip to content

Commit

Permalink
Fix resend verification email logic
Browse files Browse the repository at this point in the history
There's a couple of states this partial can be in

* Verification email not sent to the provider
  - When the claim was flagged as a duplicate so we didn't send the
    email on claimant journey completion AND and admin is yet to
    manually send the verification email by clicking the button

* Initial verification email sent to the provider
  - The claim was not flagged as a duplicate so the initial email was
    sent when the claimant journey was completed

* Email sent by the admin
  - The claim was flagged as a duplicate but an admin has now clicked
    the send email button

To make the view a bit less confussing we've pulled out a partial for
the provider verification completed and uncompleted states.
  • Loading branch information
rjlynch committed Sep 16, 2024
1 parent f1b8f73 commit 8c0b3c5
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ def rows
end
end

def latest_email
def latest_admin_sent_email
claim.notes.by_label("provider_verification").order(created_at: :desc).first
end

def verification_email_sent?
!claim.eligibility.flagged_as_duplicate? || verification_email_sent_by_admin_team?
end

def verification_email_sent_by_admin_team?
latest_admin_sent_email.present?
end

private

def verification
Expand Down
38 changes: 38 additions & 0 deletions app/views/admin/tasks/_provider_verification_submitted.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<p class="govuk-body">
This task was verified by the provider
(<%= @tasks_presenter.provider_name %>).
</p>

<table class="govuk-table govuk-!-margin-bottom-9">
<caption class="govuk-table__caption govuk-visually-hidden">
<%= @current_task_name.humanize %>
</caption>
<thead>
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">
Eligibility check
</th>
<th scope="col" class="govuk-table__header">
Claimant submitted
</th>
<th scope="col" class="govuk-table__header">
Provider response
</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<% @tasks_presenter.provider_verification.rows.each do |row| %>
<tr class="govuk-table__row govuk-!-width-one-quarter">
<th scope="row" class="govuk-table__header">
<%= row.label %>
</th>
<td class="govuk-table__cell govuk-!-width-one-half">
<%= Array.wrap(row.claimant_answer).join("<br><br>").html_safe %>
</td>
<td class="govuk-table__cell govuk-!-width-one-quarter">
<%= row.provider_answer %>
</td>
</tr>
<% end %>
</tbody>
</table>
34 changes: 34 additions & 0 deletions app/views/admin/tasks/_provider_verification_unsubmitted.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<% if @tasks_presenter.provider_verification.verification_email_sent? %>
<% if @tasks_presenter.provider_verification.verification_email_sent_by_admin_team? %>
<% verification_email = @tasks_presenter.provider_verification.latest_admin_sent_email %>
<div class="govuk-inset-text">
<p>
The verification request was sent to the provider by
<%= user_details(verification_email.created_by) %> on <%= l(verification_email.created_at) %>
</p>
</div>
<% end %>

<%= govuk_button_to(
"Resend provider verification request",
admin_claim_further_education_payments_provider_verification_emails_path(@claim),
class: "govuk-!-margin-bottom-0"
) %>
<% else %>
<p class="govuk-body">
This task has not been sent to the provider yet.
</p>

<div class="govuk-inset-text">
<p>
You need to check the matching details and confirm if this is a
duplicate claim. If it isn't a duplicate claim, send the verification
request to the provider.
</p>
<%= govuk_button_to(
"Send provider verification request",
admin_claim_further_education_payments_provider_verification_emails_path(@claim),
class: "govuk-!-margin-bottom-0"
) %>
</div>
<% end %>
64 changes: 2 additions & 62 deletions app/views/admin/tasks/provider_verification.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,69 +10,9 @@
<h2 class="govuk-heading-xl"><%= @current_task_name.humanize %></h2>

<% if @tasks_presenter.provider_verification_submitted? %>
<p class="govuk-body">
This task was verified by the provider
(<%= @tasks_presenter.provider_name %>).
</p>

<table class="govuk-table govuk-!-margin-bottom-9">
<caption class="govuk-table__caption govuk-visually-hidden">
<%= @current_task_name.humanize %>
</caption>
<thead>
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">
Eligibility check
</th>
<th scope="col" class="govuk-table__header">
Claimant submitted
</th>
<th scope="col" class="govuk-table__header">
Provider response
</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<% @tasks_presenter.provider_verification.rows.each do |row| %>
<tr class="govuk-table__row govuk-!-width-one-quarter">
<th scope="row" class="govuk-table__header">
<%= row.label %>
</th>
<td class="govuk-table__cell govuk-!-width-one-half">
<%= Array.wrap(row.claimant_answer).join("<br><br>").html_safe %>
</td>
<td class="govuk-table__cell govuk-!-width-one-quarter">
<%= row.provider_answer %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= render "provider_verification_submitted" %>
<% else %>
<p class="govuk-body">
This task has not been sent to the provider yet.
</p>

<div class="govuk-inset-text">
<% if @tasks_presenter.provider_verification.latest_email.present? %>
<% verification_email = @tasks_presenter.provider_verification.latest_email %>
<p>
The verification request was sent to the provider by
<%= user_details(verification_email.created_by) %> on <%= l(verification_email.created_at) %>
</p>
<% else %>
<p>
You need to check the matching details and confirm if this is a
duplicate claim. If it isn't a duplicate claim, send the verification
request to the provider.
</p>
<% end %>
<%= govuk_button_to(
"Resend provider verification’",
admin_claim_further_education_payments_provider_verification_emails_path(@claim),
class: "govuk-!-margin-bottom-0"
) %>
</div>
<%= render "provider_verification_unsubmitted" %>
<% end %>
</div>

Expand Down
Loading

0 comments on commit 8c0b3c5

Please sign in to comment.