Browse Source

alter redirect after support user creates an organisation

pull/2389/head
Arthur Campbell 2 years ago
parent
commit
cc4ff102fd
  1. 11
      app/controllers/organisations_controller.rb
  2. 4
      app/views/organisations/new.html.erb
  3. 1
      config/locales/en.yml
  4. 3
      spec/requests/organisations_controller_spec.rb

11
app/controllers/organisations_controller.rb

@ -73,19 +73,20 @@ class OrganisationsController < ApplicationController
end end
def new def new
@resource = Organisation.new @organisation = Organisation.new
@rent_periods = helpers.rent_periods_with_checked_attr @rent_periods = helpers.rent_periods_with_checked_attr
render "new", layout: "application" render "new", layout: "application"
end end
def create def create
selected_rent_periods = params.require(:organisation).permit(rent_periods: [])[:rent_periods].compact_blank selected_rent_periods = params.require(:organisation).permit(rent_periods: [])[:rent_periods].compact_blank
@resource = Organisation.new(org_params) @organisation = Organisation.new(org_params)
if @resource.save if @organisation.save
OrganisationRentPeriod.transaction do OrganisationRentPeriod.transaction do
selected_rent_periods.each { |period| OrganisationRentPeriod.create!(organisation: @resource, rent_period: period) } selected_rent_periods.each { |period| OrganisationRentPeriod.create!(organisation: @organisation, rent_period: period) }
end end
redirect_to organisations_path flash[:notice] = I18n.t("organisation.created", organisation: @organisation.name)
redirect_to organisation_path @organisation
else else
@rent_periods = helpers.rent_periods_with_checked_attr(checked_periods: selected_rent_periods) @rent_periods = helpers.rent_periods_with_checked_attr(checked_periods: selected_rent_periods)
render :new, status: :unprocessable_entity render :new, status: :unprocessable_entity

4
app/views/organisations/new.html.erb

@ -4,7 +4,7 @@
<%= govuk_back_link(href: :back) %> <%= govuk_back_link(href: :back) %>
<% end %> <% end %>
<%= form_for(@resource, as: :organisation, html: { method: :post }) do |f| %> <%= form_for(@organisation, as: :organisation, html: { method: :post }) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
@ -48,7 +48,7 @@
:id, :id,
:name, :name,
label: { text: "Organisation type", size: "m" }, label: { text: "Organisation type", size: "m" },
options: { disabled: [""], selected: @resource.provider_type || "" } %> options: { disabled: [""], selected: @organisation.provider_type || "" } %>
<%= f.govuk_collection_radio_buttons :holds_own_stock, <%= f.govuk_collection_radio_buttons :holds_own_stock,
[OpenStruct.new(id: true, name: "Yes"), OpenStruct.new(id: false, name: "No")], [OpenStruct.new(id: true, name: "Yes"), OpenStruct.new(id: false, name: "No")],

1
config/locales/en.yml

@ -33,6 +33,7 @@ en:
service_name: "Submit social housing lettings and sales data (CORE)" service_name: "Submit social housing lettings and sales data (CORE)"
feedback_form: "https://forms.office.com/Pages/ResponsePage.aspx?id=EGg0v32c3kOociSi7zmVqC4YDsCJ3llAvEZelBFBLUBURFVUTzFDTUJPQlM4M0laTE5DTlNFSjJBQi4u" feedback_form: "https://forms.office.com/Pages/ResponsePage.aspx?id=EGg0v32c3kOociSi7zmVqC4YDsCJ3llAvEZelBFBLUBURFVUTzFDTUJPQlM4M0laTE5DTlNFSjJBQi4u"
organisation: organisation:
created: "%{organisation} was created"
updated: "Organisation details updated" updated: "Organisation details updated"
reactivated: "%{organisation} has been reactivated." reactivated: "%{organisation} has been reactivated."
deactivated: "%{organisation} has been deactivated." deactivated: "%{organisation} has been deactivated."

3
spec/requests/organisations_controller_spec.rb

@ -1569,7 +1569,8 @@ RSpec.describe OrganisationsController, type: :request do
it "redirects to the organisation list" do it "redirects to the organisation list" do
request request
expect(response).to redirect_to("/organisations") organisation = Organisation.find_by(housing_registration_no:)
expect(response).to redirect_to organisation_path(organisation)
end end
context "when required params are missing" do context "when required params are missing" do

Loading…
Cancel
Save