Skip to content

Commit

Permalink
Merge pull request #11885 from dacook/flash-messages
Browse files Browse the repository at this point in the history
 Fix mapping of flash messages on order cycle pages
  • Loading branch information
drummer83 committed Dec 6, 2023
2 parents 9790717 + 55d64e1 commit dc4b651
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions app/controllers/admin/order_cycles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def create
@order_cycle_form = OrderCycleForm.new(@order_cycle, order_cycle_params, spree_current_user)

if @order_cycle_form.save
flash[:notice] = I18n.t(:order_cycles_create_notice)
flash[:success] = t('.success')
render json: { success: true,
edit_path: main_app.admin_order_cycle_incoming_path(@order_cycle) }
else
Expand All @@ -66,7 +66,7 @@ def update
if @order_cycle_form.save
update_nil_subscription_line_items_price_estimate(@order_cycle)
respond_to do |format|
flash[:notice] = I18n.t(:order_cycles_update_notice) if params[:reloading] == '1'
flash[:success] = t('.success') if params[:reloading] == '1'
format.html { redirect_to_after_update_path }
format.json { render json: { success: true } }
end
Expand Down Expand Up @@ -118,15 +118,15 @@ def clone
@order_cycle = OrderCycle.find params[:id]
@order_cycle.clone!
redirect_to main_app.admin_order_cycles_path,
notice: I18n.t(:order_cycles_clone_notice, name: @order_cycle.name)
flash: { success: t('.success', name: @order_cycle.name) }
end

# Send notifications to all producers who are part of the order cycle
def notify_producers
OrderCycleNotificationJob.perform_later params[:id].to_i

redirect_to main_app.admin_order_cycles_path,
notice: I18n.t(:order_cycles_email_to_producers_notice)
flash: { success: t('.success') }
end

protected
Expand Down
18 changes: 11 additions & 7 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,14 @@ en:
create: "Create"
cancel: "Cancel"
back_to_list: "Back To List"
create:
success: 'Your order cycle has been created.'
update:
success: 'Your order cycle has been updated.'
clone:
success: "Your order cycle %{name} has been cloned."
notify_producers:
success: 'Emails to be sent to producers have been queued for sending.'
edit:
save: "Save"
save_and_next: "Save and Next"
Expand Down Expand Up @@ -1750,9 +1758,9 @@ en:
save: Save
voucher_code: Voucher Code
voucher_amount: Amount
voucher_type: Voucher Type
flat_rate: Flat
percentage_rate: Percentage (%)
voucher_type: Voucher Type
flat_rate: Flat
percentage_rate: Percentage (%)

# Admin controllers
controllers:
Expand Down Expand Up @@ -3208,11 +3216,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
enterprise_bulk_update_success_notice: "Enterprises updated successfully"
enterprise_bulk_update_error: 'Update failed'
enterprise_shop_show_error: "The shop you are looking for doesn't exist or is inactive on OFN. Please check other shops."
order_cycles_create_notice: 'Your order cycle has been created.'
order_cycles_update_notice: 'Your order cycle has been updated.'
order_cycles_bulk_update_notice: 'Order cycles have been updated.'
order_cycles_clone_notice: "Your order cycle %{name} has been cloned."
order_cycles_email_to_producers_notice: 'Emails to be sent to producers have been queued for sending.'
order_cycles_no_permission_to_coordinate_error: "None of your enterprises have permission to coordinate an order cycle"
order_cycles_no_permission_to_create_error: "You don't have permission to create an order cycle coordinated by that enterprise"
order_cycle_closed: "The order cycle you've selected has just closed. Please try again!"
Expand Down
8 changes: 5 additions & 3 deletions spec/controllers/admin/order_cycles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ def build_resource

it "sets flash message" do
spree_put :update, params
expect(flash[:notice]).to eq('Your order cycle has been updated.')
expect(flash[:success]).to eq('Your order cycle has been updated.')
end
end

context "when the page is not reloading" do
it "does not set flash message" do
spree_put :update, params
expect(flash[:notice]).to be nil
expect(flash[:success]).to be nil
end
end
end
Expand Down Expand Up @@ -445,7 +445,9 @@ def build_resource
it "redirects back to the order cycles path with a success message" do
spree_post :notify_producers, id: order_cycle.id
expect(response).to redirect_to admin_order_cycles_path
expect(flash[:notice]).to eq('Emails to be sent to producers have been queued for sending.')
expect(flash[:success]).to eq(
'Emails to be sent to producers have been queued for sending.'
)
end
end

Expand Down

0 comments on commit dc4b651

Please sign in to comment.