Skip to content

Commit

Permalink
Add clawback wizard and functionality to change claim status
Browse files Browse the repository at this point in the history
  • Loading branch information
dp-daly committed Dec 18, 2024
1 parent bc92b53 commit e090085
Show file tree
Hide file tree
Showing 16 changed files with 420 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class Claims::Support::Claims::RequestClawbackController < Claims::ApplicationController
include WizardController
before_action :skip_authorization
before_action :set_claim
before_action :set_wizard

def new
@wizard.reset_state
redirect_to step_path(@wizard.first_step)
end

def edit; end

def update
if !@wizard.save_step
render "edit"
elsif @wizard.next_step.present?
redirect_to step_path(@wizard.next_step)
else
@wizard.update_status
@wizard.reset_state
redirect_to index_path, flash: {
heading: t(".success_heading"),
}
end
end

private

def set_claim
@claim = Claims::Claim.find(params[:claim_id])
end

def set_wizard
state = session[state_key] ||= {}
current_step = params[:step]&.to_sym
@wizard = Claims::RequestClawbackWizard.new(claim: @claim, params:, state:, current_step:)
end

def step_path(step)
request_clawback_claims_support_claims_clawbacks_path(state_key:, step:)
end

def index_path
claims_support_claims_clawbacks_path
end
end
6 changes: 4 additions & 2 deletions app/views/claims/support/claims/clawbacks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
<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>
<span class="govuk-caption-l"><%= t(".page_caption", reference: @claim.reference) %></span>
<h1 class="govuk-heading-l"><%= @claim.school_name %> <%= render Claim::StatusTagComponent.new(claim: @claim) %></h1>

<%= govuk_button_link_to("Request clawback", new_request_clawback_claims_support_claims_clawbacks_path(@claim)) %>

<% if @claim.submitted? %>
<p class="govuk-body"><%= t(".submitted_by", name: @claim.submitted_by.full_name, date: l(@claim.submitted_on, format: :long)) %></p>
Expand Down
14 changes: 14 additions & 0 deletions app/views/claims/support/claims/request_clawback/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= render "claims/support/primary_navigation", current: :claims %>
<%= content_for(:before_content) do %>
<%= govuk_back_link(href: back_link_path) %>
<% end %>

<div class="govuk-width-container">
<span class="govuk-caption-l"><%= t(".caption", reference: @claim.reference) %></span>

<%= render_wizard(@wizard) %>

<p class="govuk-body">
<%= govuk_link_to(t(".cancel"), claims_support_claims_clawbacks_path, no_visited_state: true) %>
</p>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<% content_for(:page_title) { sanitize t(".page_title", school_name: @claim.school_name, reference: @claim.reference) } %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_with(model: current_step, url: current_step_path, method: :put) do |f| %>
<%= f.govuk_error_summary %>

<h1 class="govuk-heading-l"><%= t(".title") %></h1>

<%= govuk_summary_list do |summary_list| %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: t(".hours")) %>
<% row.with_value %>
<% row.with_action(text: t(".change"),
href: step_path(:clawback),
visually_hidden_text: t(".hours"),
classes: ["govuk-link--no-visited-state"]) %>
<% end %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: t(".rate")) %>
<% row.with_value(text: humanized_money_with_symbol(@claim.school.region.funding_available_per_hour)) %>
<% end %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: t(".amount")) %>
<% row.with_value %>
<% end %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: t(".reason")) %>
<% row.with_value %>
<% row.with_action(text: t(".change"),
href: step_path(:clawback),
visually_hidden_text: t(".reason"),
classes: ["govuk-link--no-visited-state"]) %>
<% end %>
<% end %>

<div class="govuk-warning-text">
<span class="govuk-warning-text__icon" aria-hidden="true">!</span>
<strong class="govuk-warning-text__text"><%= t(".warning") %></strong>
</div>

<%= f.submit t(".submit"), class: "govuk-button" %>

</div>
</div>

<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<% content_for(:page_title) { sanitize t(".page_title", school_name: @claim.school_name, reference: @claim.reference) } %>

<%= form_with(model: current_step, url: current_step_path, method: :put) do |f| %>
<%= f.govuk_error_summary %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l"><%= t(".title") %></h1>

<div class="govuk-form-group">
<%= f.govuk_text_field :number_of_hours,
width: 2,
label: { text: t(".hours"), size: "s" },
hint: { text: t(".hours_hint") } %>
</div>

<div class="govuk-form-group">
<%= f.govuk_text_area :reason_for_clawback,
width: "govuk-text-area",
label: { text: t(".reason"), size: "s" },
hint: { text: t(".reason_hint") } %>
</div>

<%= f.govuk_submit t(".continue") %>
</div>
</div>
<% end %>
20 changes: 20 additions & 0 deletions app/wizards/claims/request_clawback_wizard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Claims
class RequestClawbackWizard < BaseWizard
attr_reader :claim

def initialize(claim:, params:, state:, current_step: nil)
@claim = claim
super(state:, params:, current_step:)
end

def define_steps
add_step(ClawbackStep)
add_step(CheckYourAnswersStep)
end

def update_status
@claim.status = :clawback_requested
@claim.save!
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Claims::RequestClawbackWizard::CheckYourAnswersStep < BaseStep
end
10 changes: 10 additions & 0 deletions app/wizards/claims/request_clawback_wizard/clawback_step.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Claims::RequestClawbackWizard::ClawbackStep < BaseStep
attribute :number_of_hours, :integer
attribute :reason_for_clawback

validates :number_of_hours, presence: true, numericality: { only_integer: true, less_than_or_equal_to: 40 }
validates :reason_for_clawback, presence: true

# TODO: Add methods for assigning attributes to relevant clawback fields on the claim model instance
# TODO: Add tailored error messages to activerecord yml file when attributes are in use
end
4 changes: 4 additions & 0 deletions config/locales/en/claims/support/claims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ en:
claims:
support:
claims:
request_clawback:
edit:
caption: Clawbacks - Claim %{reference}
cancel: Cancel
index:
heading: Claims
sub_heading: Claims (%{count})
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en/claims/support/claims/request_clawback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
en:
claims:
support:
claims:
request_clawback:
update:
success_heading: Clawback requested
23 changes: 23 additions & 0 deletions config/locales/en/wizards/claims/request_clawback_wizard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
en:
wizards:
claims:
request_clawback_wizard:
clawback_step:
page_title: Clawback details - %{school_name} - Claim %{reference}
title: Clawback details
hours: Number of hours to clawback
hours_hint: Enter whole numbers up to a maximum of 40 hours
reason: Reason for clawback
reason_hint: Explain why the clawback is being requested. For example, include details of which mentor has received a deduction.
continue: Continue
description: Personal details
check_your_answers_step:
page_title: Check your answers - %{school_name} - Claim %{reference}
title: Check your answers
hours: Number of hours
rate: Hourly rate
amount: Clawback amount
reason: Reason for clawback
submit: Request clawback
warning: We will show clawback details to the school.
change: Change
11 changes: 10 additions & 1 deletion config/routes/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@
end
end

resources :clawbacks, path: "clawbacks/claims", only: %i[index show]
resources :clawbacks, path: "clawbacks/claims", only: %i[index show] do
get :remove, on: :member

collection do
get "new/:claim_id", to: "request_clawback#new", as: :new_request_clawback
get "new/:claim_id/:step", to: "request_clawback#edit", as: :request_clawback
put "new/:claim_id/:step", to: "request_clawback#update"
end
end

resources :activity_logs, path: "activity", only: %i[index]
end

Expand Down
4 changes: 0 additions & 4 deletions spec/support/govuk_component_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@ def secondary_navigation
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 e090085

Please sign in to comment.