Allow editing the budget in budget creation wizard

When users created a budget and made a typo, they could use the link to
go back to edit a budget. However, after doing so, they were out of the
budget creation process.

So we're now letting users go back to edit the budget, fix any mistakes
they might have made, and then continue to groups.
This commit is contained in:
Javi Martín
2021-06-07 20:19:55 +02:00
parent f8008a4a6f
commit bdd5361f6a
12 changed files with 92 additions and 13 deletions

View File

@@ -37,7 +37,7 @@
<%= render "/admin/budgets/association", assignable_type: "valuators", assignables: valuators, form: f %>
</fieldset>
<% if budget.persisted? %>
<% unless wizard? %>
<fieldset>
<legend><%= t("admin.budgets.edit.info.phases_settings") %></legend>
<div class="small-12 medium-6 column">
@@ -52,10 +52,10 @@
<div class="small-12 column">
<div class="clear small-12 medium-4 large-3 inline-block">
<% if budget.persisted? %>
<%= f.submit nil, class: "button success" %>
<% else %>
<% if wizard? %>
<%= f.submit t("admin.budgets_wizard.budgets.continue"), class: "button success expanded" %>
<% else %>
<%= f.submit nil, class: "button success" %>
<% end %>
</div>

View File

@@ -3,14 +3,16 @@ class Admin::Budgets::FormComponent < ApplicationComponent
include GlobalizeHelper
include Admin::Namespace
attr_reader :budget
attr_reader :budget, :wizard
alias_method :wizard?, :wizard
delegate :display_calculate_winners_button?,
:calculate_winner_button_text,
:calculate_winners_admin_budget_path,
to: :helpers
def initialize(budget)
def initialize(budget, wizard: false)
@budget = budget
@wizard = wizard
end
def voting_styles_select_options

View File

@@ -0,0 +1,6 @@
<%= back_link_to admin_budgets_path %>
<%= header %>
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("budget") %>
<%= render Admin::Budgets::FormComponent.new(budget, wizard: true) %>

View File

@@ -0,0 +1,12 @@
class Admin::BudgetsWizard::Budgets::EditComponent < ApplicationComponent
include Header
attr_reader :budget
def initialize(budget)
@budget = budget
end
def title
t("admin.budgets.edit.title")
end
end

View File

@@ -3,4 +3,4 @@
<%= header %>
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("budget") %>
<%= render Admin::Budgets::FormComponent.new(budget) %>
<%= render Admin::Budgets::FormComponent.new(budget, wizard: true) %>

View File

@@ -1,4 +1,4 @@
<%= back_link_to admin_budget_path(budget), t("admin.budget_groups.index.back") %>
<%= back_link_to edit_admin_budgets_wizard_budget_path(budget), t("admin.budgets_wizard.groups.back") %>
<%= header %>

View File

@@ -8,16 +8,27 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BaseController
def new
end
def edit
end
def create
@budget.published = false
if @budget.save
redirect_to admin_budgets_wizard_budget_groups_path(@budget), notice: t("admin.budgets.create.notice")
redirect_to groups_index, notice: t("admin.budgets.create.notice")
else
render :new
end
end
def update
if @budget.update(budget_params)
redirect_to groups_index, notice: t("admin.budgets.update.notice")
else
render :edit
end
end
private
def budget_params
@@ -29,4 +40,8 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BaseController
valid_attributes + [translation_params(Budget)]
end
def groups_index
admin_budgets_wizard_budget_groups_path(@budget)
end
end

View File

@@ -0,0 +1 @@
<%= render Admin::BudgetsWizard::Budgets::EditComponent.new(@budget) %>

View File

@@ -306,6 +306,7 @@ en:
budgets:
continue: "Continue to groups"
groups:
back: "Go back to edit budget"
continue: "Continue to headings"
headings:
continue: "Continue to phases"

View File

@@ -306,6 +306,7 @@ es:
budgets:
continue: "Continuar a grupos"
groups:
back: "Volver a editar presupuesto"
continue: "Continuar a partidas"
headings:
continue: "Continuar a fases"

View File

@@ -73,7 +73,7 @@ namespace :admin do
end
namespace :budgets_wizard do
resources :budgets, only: [:create, :new] do
resources :budgets, only: [:create, :new, :edit, :update] do
resources :groups, only: [:index, :create, :edit, :update, :destroy] do
resources :headings, only: [:index, :create, :edit, :update, :destroy]
end

View File

@@ -11,7 +11,7 @@ describe "Budgets wizard, first step", :admin do
expect(page).to have_content "New participatory budget created successfully!"
click_link "Go back to budgets"
click_link "Go back to edit budget"
expect(page).to have_field "Name", with: "M30 - Summer campaign"
expect(page).to have_select "Final voting style", selected: "Knapsack"
@@ -29,7 +29,7 @@ describe "Budgets wizard, first step", :admin do
expect(page).to have_content "New participatory budget created successfully!"
click_link "Go back to budgets"
click_link "Go back to edit budget"
expect(page).to have_field "Name", with: "M30 - Summer campaign"
expect(page).to have_select "Final voting style", selected: "Approval"
@@ -81,11 +81,52 @@ describe "Budgets wizard, first step", :admin do
expect(page).to have_content "New participatory budget created successfully!"
click_link "Go back to budgets"
within("#side_menu") { click_link "Participatory budgets" }
within("tr", text: "M30 - Summer campaign") { click_link "Edit budget" }
expect(page).to have_content "This participatory budget is in draft mode"
expect(page).to have_link "Preview budget"
expect(page).to have_link "Publish budget"
end
end
describe "Edit" do
scenario "update budget" do
budget = create(:budget, name: "Budget wiht typo")
visit admin_budgets_wizard_budget_groups_path(budget)
click_link "Go back to edit budget"
expect(page).to have_content "Edit Participatory budget"
expect(page).to have_css ".creation-timeline"
expect(page).to have_field "Name", with: "Budget wiht typo"
fill_in "Name", with: "Budget without typos"
click_button "Continue to groups"
expect(page).to have_content "Participatory budget updated successfully"
expect(page).to have_content "Budget without typos"
expect(page).to have_css ".creation-timeline"
expect(page).to have_content "There are no groups"
end
scenario "submit the form with errors and then without errors" do
budget = create(:budget, name: "Budget wiht typo")
visit edit_admin_budgets_wizard_budget_path(budget)
fill_in "Name", with: ""
click_button "Continue to groups"
expect(page).to have_css "#error_explanation"
fill_in "Name", with: "Budget without typos"
click_button "Continue to groups"
expect(page).to have_content "Participatory budget updated successfully"
expect(page).to have_content "Budget without typos"
expect(page).to have_css ".creation-timeline"
expect(page).to have_content "There are no groups"
end
end
end