diff --git a/app/controllers/fee_change_validation_requests_controller.rb b/app/controllers/fee_change_validation_requests_controller.rb new file mode 100644 index 00000000..0a41463c --- /dev/null +++ b/app/controllers/fee_change_validation_requests_controller.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +class FeeChangeValidationRequestsController < ValidationRequestsController + before_action :set_validation_request + + def show + respond_to do |format| + if validation_request_is_closed? || validation_request_is_cancelled? + format.html + else + format.html { render_not_found } + end + end + end + + def edit + respond_to do |format| + if validation_request_is_open? + @fee_change_validation_request = build_validation_request + format.html + else + format.html { render_not_found } + end + end + end + + def update + @fee_change_validation_request = build_validation_request(fee_change_validation_request_params) + + respond_to do |format| + if @fee_change_validation_request.update + flash[:notice] = t("shared.response_updated.success") + format.html { validation_requests_redirect_url } + else + flash[:error] = error_message(@fee_change_validation_request) + format.html { render :edit } + end + end + end + + private + + def fee_change_validation_request_params + params.require(:fee_change_validation_request).permit(:response) + end +end diff --git a/app/helpers/validation_requests_helper.rb b/app/helpers/validation_requests_helper.rb index 86656201..1ed2e4f7 100644 --- a/app/helpers/validation_requests_helper.rb +++ b/app/helpers/validation_requests_helper.rb @@ -26,6 +26,7 @@ def flattened_validation_requests(validation_requests) validation_requests["data"]["description_change_validation_requests"] + validation_requests["data"]["replacement_document_validation_requests"] + validation_requests["data"]["other_change_validation_requests"] + + validation_requests["data"]["fee_change_validation_requests"] + validation_requests["data"]["red_line_boundary_change_validation_requests"] end @@ -42,6 +43,7 @@ def ordered_validation_requests replacement_document_validation_requests additional_document_validation_requests red_line_boundary_change_validation_requests + fee_change_validation_requests other_change_validation_requests] end diff --git a/app/models/bops/fee_change_validation_request.rb b/app/models/bops/fee_change_validation_request.rb new file mode 100644 index 00000000..67adc723 --- /dev/null +++ b/app/models/bops/fee_change_validation_request.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Bops + class FeeChangeValidationRequest + include ActiveModel::Model + + attr_accessor :response, :planning_application_id, :change_access_id, :id + + validates :response, presence: true + + class << self + def find(id, planning_application_id, change_access_id) + Apis::Bops::Client.get_fee_change_validation_request(id, planning_application_id, change_access_id) + end + + def respond(id, planning_application_id, change_access_id, response) + Apis::Bops::Client.patch_response_fee_change_request(id, planning_application_id, change_access_id, response) + end + end + + def update + return false unless valid? + + self.class.respond(id, planning_application_id, change_access_id, response) + end + end +end diff --git a/app/services/apis/bops/client.rb b/app/services/apis/bops/client.rb index fe60b7ac..5d44a6b6 100644 --- a/app/services/apis/bops/client.rb +++ b/app/services/apis/bops/client.rb @@ -78,6 +78,26 @@ def patch_rejected_description_change(id, planning_application_id, change_access ) end + # Fee change validation requests + def get_fee_change_validation_request(id, planning_application_id, change_access_id) + request( + http_method: :get, + endpoint: "planning_applications/#{planning_application_id}/fee_change_validation_requests/#{id}?change_access_id=#{change_access_id}" + ) + end + + def patch_response_fee_change_request(id, planning_application_id, change_access_id, response) + request( + http_method: :patch, + endpoint: "planning_applications/#{planning_application_id}/fee_change_validation_requests/#{id}?change_access_id=#{change_access_id}", + params: { + data: { + response: + } + }.to_json + ) + end + # Other change validation requests def get_other_change_validation_request(id, planning_application_id, change_access_id) request( diff --git a/app/views/fee_change_validation_requests/_form.html.erb b/app/views/fee_change_validation_requests/_form.html.erb new file mode 100644 index 00000000..2dfbab0e --- /dev/null +++ b/app/views/fee_change_validation_requests/_form.html.erb @@ -0,0 +1,30 @@ +<%= form_with scope: :fee_change_validation_request, + url: fee_change_validation_request_path(@validation_request["id"], planning_application_id: params["planning_application_id"], change_access_id: params["change_access_id"]), + method: :patch, + builder: GOVUKDesignSystemFormBuilder::FormBuilder do |form| %> + + <% if @fee_change_validation_request.errors.any? %> +
<%= t(".the_following_request") %>
+<%= t(".what_you_need") %>
+
+ <%= t(".officers_reason_for") %>
+ <%= render(FormattedContentComponent.new(text: @validation_request["reason"])) %>
+
+ <%= t(".how_you_can") %>
+ <%= render(FormattedContentComponent.new(text: @validation_request["suggestion"])) %>
+
+ Officer's reason for invalidating application
+
+ <%= render(FormattedContentComponent.new(text: @validation_request["reason"])) %> +
+
+ How you can make your application valid
+
+ <%= @validation_request["suggestion"] %> +
+
+ My response to this request
+
+ <%= render(FormattedContentComponent.new(text: @validation_request["response"])) %> +
+
<%= t(".officers_reason_for") %>
- <%= render(FormattedContentComponent.new(text: @validation_request["summary"])) %>
+ <%= render(FormattedContentComponent.new(text: @validation_request["reason"])) %>
- <%= render(FormattedContentComponent.new(text: @validation_request["summary"])) %> + <%= render(FormattedContentComponent.new(text: @validation_request["reason"])) %>
How you can make your application valid
diff --git a/app/views/validation_requests/_cancelled.html.erb b/app/views/validation_requests/_cancelled.html.erb
index 040b0232..31301344 100644
--- a/app/views/validation_requests/_cancelled.html.erb
+++ b/app/views/validation_requests/_cancelled.html.erb
@@ -4,9 +4,7 @@
The officer gave the following reason for cancelling this request:
- <%= render(FormattedContentComponent.new(text: validation_request["cancel_reason"])) %> -
+ <%= render(FormattedContentComponent.new(text: validation_request["cancel_reason"])) %><%= validation_request["cancelled_at"].to_time.to_formatted_s(:day_month_year) %>
diff --git a/app/views/validation_requests/_fee_change_validation_requests.html.erb b/app/views/validation_requests/_fee_change_validation_requests.html.erb new file mode 100644 index 00000000..5b309840 --- /dev/null +++ b/app/views/validation_requests/_fee_change_validation_requests.html.erb @@ -0,0 +1,19 @@ +