From 52301c4785c40b718b57f55ece85530c61a429bd Mon Sep 17 00:00:00 2001 From: JG Date: Fri, 16 Sep 2022 12:32:24 +0100 Subject: [PATCH] enough changes to go to the new sales log page as well --- app/controllers/logs_controller.rb | 2 +- app/controllers/sales_logs_controller.rb | 12 +++++++++++- app/views/logs/index.html.erb | 2 +- config/routes.rb | 5 +++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb index 91112a4fe..9bb913d70 100644 --- a/app/controllers/logs_controller.rb +++ b/app/controllers/logs_controller.rb @@ -15,7 +15,7 @@ private respond_to do |format| format.html do - redirect_to new_log_lettings_logs_path + redirect_to ( request.path.include?("sales") ? new_log_sales_logs_path : new_log_lettings_logs_path) end format.json do if log.save diff --git a/app/controllers/sales_logs_controller.rb b/app/controllers/sales_logs_controller.rb index 8a6c9937f..c8edfcfb5 100644 --- a/app/controllers/sales_logs_controller.rb +++ b/app/controllers/sales_logs_controller.rb @@ -28,7 +28,11 @@ class SalesLogsController < LogsController end def edit - @log = current_user.sales_logs.find_by(id: params[:id]) + @log = if new_log_request? + SalesLog.new + else + current_user.sales_logs.find_by(id: params[:id]) + end if @log render "logs/edit", locals: { current_user: } else @@ -43,4 +47,10 @@ class SalesLogsController < LogsController def permitted_log_params params.require(:sales_log).permit(SalesLog.editable_fields) end + +private + + def new_log_request? + request.path.include?("new") + end end diff --git a/app/views/logs/index.html.erb b/app/views/logs/index.html.erb index a6884ef96..fb0be69af 100644 --- a/app/views/logs/index.html.erb +++ b/app/views/logs/index.html.erb @@ -11,7 +11,7 @@ <%= govuk_button_to "Create a new lettings log", create_new_log_lettings_logs_path, method: :get %> <% end %> <% if FeatureToggle.sales_log_enabled? && current_page?(:controller => 'sales_logs', :action => 'index') %> - <%= govuk_button_to "Create a new sales log", sales_logs_path %> + <%= govuk_button_to "Create a new sales log", create_new_log_sales_logs_path, method: :get %> <% end %> <%#= govuk_link_to "Upload logs", bulk_upload_lettings_logs_path %> diff --git a/config/routes.rb b/config/routes.rb index 5ec1d7f9c..4d314525e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -106,6 +106,11 @@ Rails.application.routes.draw do end resources :sales_logs, path: "/sales-logs" do + collection do + get "create-new-log", to: "sales_logs#create" + get "new-log", to: "sales_logs#show" + end + FormHandler.instance.sales_forms.each do |_key, form| form.pages.map do |page| get page.id.to_s.dasherize, to: "form#show_page"