Skip to content

Commit

Permalink
add clawback index page and separate show page route and view
Browse files Browse the repository at this point in the history
  • Loading branch information
dp-daly committed Dec 10, 2024
1 parent de7895e commit 81f7589
Show file tree
Hide file tree
Showing 28 changed files with 1,672 additions and 53 deletions.
4 changes: 4 additions & 0 deletions app/components/claim/card_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<div class="claim-card__body__right">
<div class="govuk-body-s"><%= l(claim.submitted_at.to_date, format: :long) %></div>
<div class="govuk-body-s"><%= humanized_money_with_symbol(claim.amount) %></div>
<% if claim.status == "clawback_requested" %>
<div class="govuk-body-s govuk-!-font-weight-bold"><%= t(".clawback_amount") %></div>
<div class="govuk-body-s"><%#TODO: Display clawback amount when implemented %> £9.99</div>
<% end %>
</div>
</div>
</div>
30 changes: 13 additions & 17 deletions app/components/claims/claim/filter_form_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,24 @@
<% if filter_form.submitted_after.present? %>
<h3 class="govuk-heading-s govuk-!-margin-bottom-0"><%= t("claims.support.claims.index.submitted_after") %></h3>
<ul class="app-filter-tags">
<li>
<%= govuk_link_to(
helpers.safe_l(filter_form.submitted_after, format: :short),
filter_form.index_path_without_submitted_dates("submitted_after"),
class: "app-filter__tag",
no_visited_state: true,
) %>
</li>
<%= govuk_link_to(
helpers.safe_l(filter_form.submitted_after, format: :short),
filter_form.index_path_without_submitted_dates("submitted_after"),
class: "app-filter__tag",
no_visited_state: true,
) %>
</ul>
<% end %>

<% if filter_form.submitted_before.present? %>
<h3 class="govuk-heading-s govuk-!-margin-bottom-0"><%= t("claims.support.claims.index.submitted_before") %></h3>
<ul class="app-filter-tags">
<li>
<%= govuk_link_to(
helpers.safe_l(filter_form.submitted_before, format: :short),
filter_form.index_path_without_submitted_dates("submitted_before"),
class: "app-filter__tag",
no_visited_state: true,
) %>
</li>
<%= govuk_link_to(
helpers.safe_l(filter_form.submitted_before, format: :short),
filter_form.index_path_without_submitted_dates("submitted_before"),
class: "app-filter__tag",
no_visited_state: true,
) %>
</ul>
<% end %>
</div>
Expand Down Expand Up @@ -167,7 +163,7 @@
<%= form.govuk_check_box :statuses, status, label: { text: Claims::Claim.human_attribute_name("status.#{status}") } %>
<% end %>
<% end %>
<% end %>
</div>

<div class="app-filter__option" data-controller="filter-search">
<%= form.govuk_check_boxes_fieldset(
Expand Down
49 changes: 49 additions & 0 deletions app/controllers/claims/support/claims/clawbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
class Claims::Support::Claims::ClawbacksController < Claims::Support::ApplicationController
before_action :skip_authorization
before_action :set_filtered_claims, only: %i[index]
before_action :set_claim, only: %i[show]
helper_method :filter_form

def index
@pagy, @claims = pagy(
@filtered_claims.where(status: %i[clawback_requested clawback_in_progress sampling_not_approved]),
)
end

def show; end

private

def set_filtered_claims
@filtered_claims = Claims::ClaimsQuery.call(params: filter_form.query_params)
end

def filter_form
Claims::Support::Claims::FilterForm.new(filter_params)
end

def set_claim
@claim = Claims::Claim.find(params.require(:id))
end

def filter_params
params.fetch(:claims_support_claims_filter_form, {}).permit(
:search,
:search_school,
:search_provider,
"submitted_after(1i)",
"submitted_after(2i)",
"submitted_after(3i)",
"submitted_before(1i)",
"submitted_before(2i)",
"submitted_before(3i)",
:submitted_after,
:submitted_before,
provider_ids: [],
school_ids: [],
statuses: [],
academic_year_ids: [],
).with_defaults(index_path:)
end

def index_path
claims_support_claims_clawbacks_path
end
end
2 changes: 2 additions & 0 deletions app/models/claims/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Claims::Claim < ApplicationRecord
ACTIVE_STATUSES = %i[draft submitted].freeze
DRAFT_STATUSES = %i[internal_draft draft].freeze
PAYMENT_ACTIONABLE_STATUSES = %i[payment_information_requested payment_information_sent].freeze
SAMPLING_STATUSES = %w[sampling_in_progress sampling_provider_not_approved].freeze
CLAWBACK_STATUSES = %w[clawback_requested clawback_in_progress sampling_not_approved].freeze

scope :active, -> { where(status: ACTIVE_STATUSES) }
scope :order_created_at_desc, -> { order(created_at: :desc) }
Expand Down
19 changes: 18 additions & 1 deletion app/views/claims/support/claims/clawbacks/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,22 @@

<%= render "claims/support/claims/secondary_navigation", current: :clawbacks %>

<h2 class="govuk-heading-m"><%= t(".sub_heading") %></h2>
<% if @claims.any? %>
<h2 class="govuk-heading-m"><%= t(".sub_heading", count: @pagy.count) %></h2>

<%= render Claims::Claim::FilterFormComponent.new(filter_form:, statuses: Claims::Claim::CLAWBACK_STATUSES) do %>
<div class="govuk-!-margin-bottom-2">
<% @claims.each do |claim| %>
<%= render Claim::CardComponent.new(claim:, href: claims_support_claims_clawback_path(claim)) %>
<% end %>
</div>

<%= render PaginationComponent.new(pagy: @pagy) %>
<% end %>
<% else %>
<h2 class="govuk-heading-m"><%= t(".sub_heading_without_count") %></h2>
<p class="govuk-body">
<%= t(".no_claims") %>
</p>
<% end %>
</div>
21 changes: 21 additions & 0 deletions app/views/claims/support/claims/clawbacks/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%= render "claims/support/primary_navigation", current: :claims %>
<% content_for(:page_title) { sanitize t(".page_title", school_name: @claim.school.name, reference: @claim.reference) } %>

<% content_for(:before_content) do %>
<%= govuk_back_link href: claims_support_claims_path %>
<% end %>

<div class="govuk-width-container">
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<p class="govuk-caption-l"><%= t(".page_caption", reference: @claim.reference) %></p>
<h1 class="govuk-heading-l"><%= @claim.school.name %> <%= render Claim::StatusTagComponent.new(claim: @claim) %></h1>

<% if @claim.submitted? %>
<p class="govuk-body"><%= t(".submitted_by", name: @claim.submitted_by.full_name, date: l(@claim.submitted_on, format: :long)) %></p>
<% end %>

<%= render "claims/support/claims/details", claim: @claim %>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/claims/support/claims/samplings/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<% if @claims.any? %>
<h2 class="govuk-heading-m"><%= t(".sub_heading", count: @pagy.count) %></h2>

<%= render Claims::Claim::FilterFormComponent.new(filter_form:, statuses: %w[sampling_in_progress sampling_provider_not_approved]) do %>
<%= render Claims::Claim::FilterFormComponent.new(filter_form:, statuses: Claims::Claim::SAMPLING_STATUSES) do %>
<div class="govuk-!-margin-bottom-2">
<% @claims.each do |claim| %>
<%= render Claim::CardComponent.new(claim:, href: claims_support_claim_path(claim)) %>
<%= render Claim::CardComponent.new(claim:, href: claims_support_claims_sampling_path(claim)) %>
<% end %>
</div>

Expand Down
12 changes: 11 additions & 1 deletion config/locales/en/claims/support/claims/clawbacks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@ en:
clawbacks:
index:
heading: Claims
sub_heading: Clawbacks
sub_heading: Clawbacks (%{count})
sub_heading_without_count: Clawbacks
no_claims: There are no claims waiting to be processed.
show:
page_caption: Clawbacks - Claim %{reference}
page_title: "Clawbacks - %{school_name} - Claim %{reference}"
status: Status
provider: Accredited provider
mentor_with_index: Mentor %{index}
mentor: Mentor
submitted_by: Submitted by %{name} on %{date}.
1 change: 1 addition & 0 deletions config/locales/en/components/claim/card_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ en:
claim:
card_component:
claim_title: "%{reference} - %{school_name}"
clawback_amount: Clawback amount
4 changes: 2 additions & 2 deletions config/routes/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
end

resources :payments, only: %i[index]
resources :samplings, path: "sampling", only: %i[index]
resources :clawbacks, only: %i[index]
resources :samplings, path: "sampling", only: %i[index show]
resources :clawbacks, path: "clawbacks/claims", only: %i[index show]
resources :activity_logs, path: "activity", only: %i[index]
end

Expand Down
5 changes: 5 additions & 0 deletions spec/support/govuk_component_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ def secondary_navigation
right = body.find("div.claim-card__body__right")
right.find("div.govuk-body-s:nth-of-type(1)", text: expected_claim_details["submitted_date"])
right.find("div.govuk-body-s:nth-of-type(2)", text: expected_claim_details["amount"])

if expected_claim_details["status"] == "Clawback requested"
body.find("div.claim-card__body__right").find("div.govuk-body-s govuk-!-font-weight-bold", text: "Clawback requested")
# TODO: Correct clawback amount to be tested when implemented
end
true
rescue Capybara::ElementNotFound
false
Expand Down
Loading

0 comments on commit 81f7589

Please sign in to comment.