Skip to content
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

Update Support Claims page #451

Merged
merged 4 commits into from
Apr 8, 2024
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
1 change: 1 addition & 0 deletions app/assets/stylesheets/components/_all.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "claim/card";
@import "autocomplete";
@import "content_header";
@import "header";
Expand Down
46 changes: 46 additions & 0 deletions app/assets/stylesheets/components/claim/card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.claim-card {
display: flex;
flex-direction: column;
gap: govuk-spacing(1);
border-bottom: 1px solid $govuk-border-colour;
padding: govuk-spacing(2) 0;
margin-bottom: govuk-spacing(1);

.claim-card__header {
display: flex;
justify-content: space-between;
align-items: flex-start;
flex-wrap: wrap;

.claim-card__header__name {
display: flex;
gap: govuk-spacing(1);

&.govuk-heading-s {
margin-bottom: govuk-spacing(1);
}
}
}

.claim-card__body {
display: flex;
justify-content: space-between;
gap: govuk-spacing(2);

.claim-card__body__provider {
flex-grow: 1;
max-width: 66%;
}

.claim-card__body__right {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: flex-end;
}

.govuk-body-s {
margin-bottom: govuk-spacing(1);
}
}
}
20 changes: 20 additions & 0 deletions app/components/claim/card_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="claim-card">
<div class="claim-card__header">
<div class="claim-card__header__name govuk-heading-s">
<%= govuk_link_to claim.school.name, claims_support_claim_path(claim), no_visited_state: true %>
<span class="govuk-caption-m"><%= claim.reference %></span>
</div>
<div><%= render Claim::StatusTagComponent.new(claim:, classes: %w[govuk-body-s]) %></div>
</div>

<div class="claim-card__body">
<div class="claim-card__body__provider">
<div class="govuk-body-s"><%= claim.provider.name %></div>
</div>

<div class="claim-card__body__right">
<div class="govuk-body-s"><%= l(claim.created_at.to_date, format: :short) %></div>
<div class="govuk-body-s"><%= humanized_money_with_symbol(claim.amount) %></div>
</div>
</div>
</div>
9 changes: 9 additions & 0 deletions app/components/claim/card_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Claim::CardComponent < ApplicationComponent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a spec and a preview?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I'll add that. Nice catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a relatively basic spec for the component, along with a preview.

attr_reader :claim

def initialize(claim:, classes: [], html_attributes: {})
super(classes:, html_attributes:)

@claim = claim
end
end
16 changes: 10 additions & 6 deletions app/components/claim/status_tag_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ def initialize(claim:, classes: [], html_attributes: {})
end

def call
content_tag(:p, claim.status.humanize, class: "govuk-tag #{css_class}")
govuk_tag(text: claim.status.humanize, colour:)
end

private

def css_class
style_status_classes.fetch(claim.status)
def default_attributes
super.merge!(class: super.class)
end

def style_status_classes
def colour
status_colours.fetch(claim.status)
end

def status_colours
{
draft: "govuk-tag--grey",
submitted: "govuk-tag--blue",
draft: "grey",
submitted: "blue",
}.with_indifferent_access
end
end
1 change: 0 additions & 1 deletion app/controllers/claims/support/schools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class Claims::Support::SchoolsController < Claims::Support::ApplicationControlle

def index
@pagy, @schools = pagy(schools)
@search_param = params[:name_or_postcode]
end

def show; end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Placements::Support::OrganisationsController < Placements::Support::Applic
def index
@pagy, @organisations = pagy(organisations)
@filters = filters_param
@search_param = search_param
end

def new
Expand Down
7 changes: 7 additions & 0 deletions app/queries/claims/claims_query.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
class Claims::ClaimsQuery < ApplicationQuery
def call
scope = Claims::Claim.submitted
scope = search_condition(scope)
scope = school_condition(scope)
scope = provider_condition(scope)
scope.order_created_at_desc
end

private

def search_condition(scope)
return scope if params[:search].blank?

scope.where(Claims::Claim.arel_table[:reference].matches("%#{params[:search]}%"))
CatalinVoineag marked this conversation as resolved.
Show resolved Hide resolved
end

def school_condition(scope)
return scope if params[:school_ids].blank?

Expand Down
46 changes: 26 additions & 20 deletions app/views/claims/support/claims/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
<%= render "claims/support/primary_navigation", current: :claims %>
<%= content_for :page_title, t(".heading") %>
<%= content_for :page_title, t(".heading", count: @pagy.count) %>

<div class="govuk-width-container">
<h1 class="govuk-heading-l"><%= t(".heading", count: @pagy.count) %></h1>

<%= govuk_button_to(t(".download_csv"), download_csv_claims_support_claims_path, method: :get) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-one-third">
<div class="app-filter">
<div class="app-filter__header">
<div class="govuk-heading-m">Filter</div>
</div>
</div>
</div>

<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l"><%= t(".heading") %></h1>
<%= render partial: "shared/search_form", locals: {
url: claims_support_claims_path,
label: { text: t(".search_label"), size: "s" },
name: :search,
clear_search_url: claims_support_claims_path,
} %>

<% if @claims.any? %>
<%= govuk_button_to(t(".download_csv"), download_csv_claims_support_claims_path, method: :get) %>

<%= govuk_table do |table| %>
<% table.with_head do |head| %>
<% head.with_row do |row| %>
<% row.with_cell(header: true, text: Claims::Claim.human_attribute_name(:id)) %>
<% row.with_cell(header: true, text: Claims::Claim.human_attribute_name(:status)) %>
<% end %>
<% end %>
<div class="govuk-section-break govuk-section-break--m govuk-section-break--visible"></div>

<% table.with_body do |body| %>
<% @claims.each do |claim| %>
<% body.with_row do |row| %>
<% row.with_cell(text: govuk_link_to(claim.id, claims_support_claim_path(claim))) %>
<% row.with_cell(text: render(Claim::StatusTagComponent.new(claim:))) %>
<% end %>
<% end %>
<% if @claims.any? %>
<div class="govuk-!-margin-bottom-2">
<% @claims.each do |claim| %>
<%= render Claim::CardComponent.new(claim:) %>
<% end %>
<% end %>
</div>

<%= govuk_pagination(pagy: @pagy) %>

<p>
<%= t("pagination_info", from: @pagy.from, to: @pagy.to, count: @pagy.count) %>
</p>
Expand Down
5 changes: 3 additions & 2 deletions app/views/claims/support/schools/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

<%= render partial: "shared/search_form", locals: {
url: claims_support_schools_path,
search_param: @search_param,
label: { text: t(".search_label"), size: "m" },
name: :name_or_postcode,
clear_search_url: claims_support_schools_path,
} %>

Expand All @@ -30,7 +31,7 @@
</ul>
<% else %>
<p>
<%= t("no_results", for: @search_param) %>
<%= t("no_results", for: params[:name_or_postcode]) %>
</p>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
checked: filters.include?(org_type)) %>
<% end %>
<% end %>
<%= form.hidden_field :name_or_postcode, value: @search_param %>
<%= form.hidden_field :name_or_postcode, value: search_param %>
<% end %>
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions app/views/placements/support/organisations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
</div>
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-third">
<%= render partial: "filter", locals: { filters: @filters, search_param: @search_param } %>
<%= render partial: "filter", locals: { filters: @filters, search_param: params[:name_or_postcode] } %>
</div>
<div class="govuk-grid-column-two-thirds">
<%= render partial: "shared/search_form", locals: {
url: placements_support_organisations_path,
search_param: @search_param,
label: { text: t(".search_label"), size: "m" },
name: :name_or_postcode,
clear_search_url: placements_support_organisations_path(filters: @filters),
filters: @filters,
} %>
Expand All @@ -27,7 +28,7 @@
<%= govuk_pagination(pagy: @pagy) %>
<p><%= t("pagination_info", from: @pagy.from, to: @pagy.to, count: @pagy.count) %></p>
<% else %>
<p><%= no_results(@search_param, @filters) %></p>
<p><%= no_results(params[:name_or_postcode], @filters) %></p>
<% end %>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions app/views/shared/_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%# locals: (url:, search_param:, clear_search_url: "", filters: []) -%>
<%# locals: (url:, name:, value: params[name], clear_search_url: "", label:, filters: []) -%>

<div class="govuk-form-group">
<%= form_with(
Expand All @@ -7,8 +7,8 @@
class: "search-form",
data: { turbo: false },
) do |f| %>
<%= f.govuk_text_field :name_or_postcode, type: :search, value: search_param, label: { text: t(".search-header"), size: "m" } %>
<%= f.govuk_submit t(".search") %>
<%= f.govuk_text_field name, type: :search, value:, label: %>
<%= f.govuk_submit t(".submit") %>
<% if filters.present? %>
<% filters.each do |filter| %>
<%= f.hidden_field :filters, multiple: true, value: filter %>
Expand All @@ -17,8 +17,8 @@
<% end %>
</div>

<% unless search_param.blank? %>
<% unless value.blank? %>
<p class="clear-search">
<%= govuk_link_to t(".clear_search"), clear_search_url, no_visited_state: true %>
<%= govuk_link_to t(".clear"), clear_search_url, no_visited_state: true %>
</p>
<% end %>
2 changes: 1 addition & 1 deletion config/initializers/money.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
}
end

Money.locale_backend = nil
Money.locale_backend = :i18n
Money.rounding_mode = BigDecimal::ROUND_HALF_UP
3 changes: 2 additions & 1 deletion config/locales/en/claims/support/claims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ en:
support:
claims:
index:
heading: Claims
heading: Claims (%{count})
download_csv: Download claims
search_label: Search by claim reference
show:
heading: Claim
status: Status
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/claims/support/schools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ en:
index:
heading: Organisations (%{records})
add_organisation: Add organisation
search_label: Search by organisation name or postcode
new:
caption: Add organisation
cancel: Cancel
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/placements/support/organisations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ en:
lead_school: Lead partner
no_organisations: There are no onboarded organisations
organisation_type: Organisation type
search_label: Search by organisation name or postcode
5 changes: 2 additions & 3 deletions config/locales/en/shared/search_form.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
en:
shared:
search_form:
search-header: Search by organisation name or postcode
search: Search
clear_search: Clear search
submit: Search
clear: Clear search
27 changes: 27 additions & 0 deletions spec/components/claim/card_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "rails_helper"

RSpec.describe Claim::CardComponent, type: :component do
include Rails.application.routes.url_helpers

subject(:component) { described_class.new(claim:) }

let(:claim) do
create(:claim, :submitted, created_at: "2024/04/08", school:) do |claim|
claim.mentor_trainings << create(:mentor_training, hours_completed: 20)
end
end

let(:school) { create(:claims_school, region: regions(:inner_london)) }

it "renders a card with claim details" do
render_inline(component)

expect(page).to have_link(claim.school.name, href: claims_support_claim_path(claim))
expect(page).to have_content(claim.reference)
expect(page).to have_content("Submitted")

expect(page).to have_content(claim.provider.name)
expect(page).to have_content("08/04/2024")
expect(page).to have_content("£1,072")
end
end
11 changes: 11 additions & 0 deletions spec/components/previews/claim/card_component_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Claim::CardComponentPreview < ApplicationComponentPreview
def default
render Claim::CardComponent.new(claim:)
end

private

def claim
Claims::Claim.submitted.first
end
end
11 changes: 11 additions & 0 deletions spec/queries/claims/claims_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
expect(claims_query).to eq([submitted_claim])
end

context "when given a search query" do
let(:params) { { search: "1234" } }

it "filters the results by provided school ids" do
claim_with_partial_reference = create(:claim, :submitted, reference: "12345678")
_claim_without_partial_reference = create(:claim, :submitted, reference: "87654321")

expect(claims_query).to match_array([claim_with_partial_reference])
end
end

context "when given school ids" do
let(:school) { create(:claims_school) }
let(:params) { { school_ids: [school.id] } }
Expand Down
2 changes: 1 addition & 1 deletion spec/system/claims/schools/claims/create_claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def then_i_check_my_answers
within("dl.govuk-summary-list:nth(3)") do
within(".govuk-summary-list__row:nth(1)") do
expect(page).to have_content("Claim amount")
expect(page).to have_content("£1715.20")
expect(page).to have_content("£1,715.20")
end
end
end
Expand Down
Loading
Loading