From 1bfb05a0d313dae4a20e57414c39c361a48c4301 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 20 Oct 2022 16:11:03 +0100 Subject: [PATCH] feat: add housing provider page with details and button --- .../related_organisation_search_component.html.erb | 14 ++++++++++++++ .../related_organisation_search_component.rb | 2 ++ .../organisation_relationships_controller.rb | 13 +++++++++++++ .../add_housing_provider.html.erb | 11 +++++++++++ .../housing_providers.html.erb | 9 ++++----- config/routes.rb | 1 + 6 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 app/components/related_organisation_search_component.html.erb create mode 100644 app/components/related_organisation_search_component.rb create mode 100644 app/views/organisation_relationships/add_housing_provider.html.erb diff --git a/app/components/related_organisation_search_component.html.erb b/app/components/related_organisation_search_component.html.erb new file mode 100644 index 000000000..e77881bc9 --- /dev/null +++ b/app/components/related_organisation_search_component.html.erb @@ -0,0 +1,14 @@ +<%= form_with model: @user, url: path(current_user), method: "get", local: true do |f| %> + + <%= f.govuk_submit "Add" %> +<% end %> diff --git a/app/components/related_organisation_search_component.rb b/app/components/related_organisation_search_component.rb new file mode 100644 index 000000000..95ffe66cf --- /dev/null +++ b/app/components/related_organisation_search_component.rb @@ -0,0 +1,2 @@ +class RelatedOrganisationSearchComponent < SearchComponent +end diff --git a/app/controllers/organisation_relationships_controller.rb b/app/controllers/organisation_relationships_controller.rb index 98456ac7b..e228edef8 100644 --- a/app/controllers/organisation_relationships_controller.rb +++ b/app/controllers/organisation_relationships_controller.rb @@ -18,6 +18,19 @@ class OrganisationRelationshipsController < ApplicationController end end + def add_housing_provider + housing_providers = organisation.housing_providers + unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term) + respond_to do |format| + format.html do + @pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers) + @searched = search_term.presence + @total_count = housing_providers.size + render "organisation_relationships/add_housing_provider", layout: "application" + end + end + end + private def organisation diff --git a/app/views/organisation_relationships/add_housing_provider.html.erb b/app/views/organisation_relationships/add_housing_provider.html.erb new file mode 100644 index 000000000..2735591a4 --- /dev/null +++ b/app/views/organisation_relationships/add_housing_provider.html.erb @@ -0,0 +1,11 @@ +<%= render partial: "organisations/headings", locals: { main: "What is the name of your housing provider?", sub: nil } %> +<%= render RelatedOrganisationSearchComponent.new(current_user:, search_label: "Start typing to search for your housing provider", value: @searched) %> +<%= govuk_details(summary_text: "Can't find the housing provider you're looking for?") do %> + +<% end %> diff --git a/app/views/organisation_relationships/housing_providers.html.erb b/app/views/organisation_relationships/housing_providers.html.erb index 84f38cde6..31b4afb54 100644 --- a/app/views/organisation_relationships/housing_providers.html.erb +++ b/app/views/organisation_relationships/housing_providers.html.erb @@ -1,6 +1,4 @@ <% item_label = format_label(@pagy.count, "housing providers") %> -<% title = "Housing Providers" %> -<% content_for :title, title %> <% if current_user.support? %> <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> <%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> @@ -10,12 +8,13 @@ <%= render partial: "organisations/headings", locals: { main: "Your housing providers", sub: nil } %>

Your organisation can submit logs for its housing providers.

<% end %> - <% if @total_count == 0 %>

This organisation does not currently have any housing providers.

<% end %> -<% if current_user.data_coordinator? || current_user.support? %> - <%= govuk_button_link_to "Add a housing provider", housing_providers_organisation_path(organisation_id: @organisation.id), html: { method: :get } %> +<% if current_user.support? %> + <%= govuk_button_link_to "Add a housing provider", add_housing_provider_organisation_path(organisation_id: @organisation.id), html: { method: :get } %> + <% elsif current_user.data_coordinator? %> + <%= govuk_button_link_to "Add a housing provider", add_housing_provider_organisation_path, html: { method: :get } %> <% end %> <% if @total_count != 0 %> <%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %> diff --git a/config/routes.rb b/config/routes.rb index e703b853d..ef447b426 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -80,6 +80,7 @@ Rails.application.routes.draw do get "logs/csv-confirmation", to: "lettings_logs#csv_confirmation" get "schemes", to: "organisations#schemes" get "housing-providers", to: "organisation_relationships#housing_providers" + get "add-housing-provider", to: "organisation_relationships#add_housing_provider" end end