mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-11 03:40:20 +00:00
Handle order voucher responses with turbo_stream
This commit is contained in:
@@ -60,24 +60,19 @@ class VoucherAdjustmentsController < BaseController
|
||||
end
|
||||
|
||||
def update_payment_section
|
||||
render cable_ready: cable_car.replace(
|
||||
selector: "#checkout-payment-methods",
|
||||
html: render_to_string(partial: "checkout/payment", locals: { step: "payment" })
|
||||
)
|
||||
respond_to do |format|
|
||||
format.html { head :ok }
|
||||
format.turbo_stream { render :update_payment_section }
|
||||
end
|
||||
end
|
||||
|
||||
def render_error
|
||||
flash.now[:error] = @order.errors.full_messages.to_sentence
|
||||
|
||||
render status: :unprocessable_entity, cable_ready: cable_car.
|
||||
replace("#flashes", partial("shared/flashes", locals: { flashes: flash })).
|
||||
replace(
|
||||
"#voucher-section",
|
||||
partial(
|
||||
"checkout/voucher_section",
|
||||
locals: { order: @order, voucher_adjustment: @order.voucher_adjustments.first }
|
||||
)
|
||||
)
|
||||
respond_to do |format|
|
||||
format.html { head :unprocessable_entity }
|
||||
format.turbo_stream { render :render_error, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
|
||||
def voucher_params
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
.checkout-title
|
||||
= t("checkout.step2.voucher.apply_voucher")
|
||||
.checkout-input{"data-controller": "toggle-control"}
|
||||
= form_with url: voucher_adjustments_path, model: @order, method: :post, data: { remote: true } do |form|
|
||||
= form_with url: voucher_adjustments_path, model: @order, method: :post, data: { turbo: true } do |form|
|
||||
- if voucher_adjustment.present?
|
||||
.two-columns-inputs.voucher
|
||||
%span.button.voucher-added
|
||||
%i.ofn-i_051-check-big
|
||||
= t("checkout.step2.voucher.voucher", voucher_amount: voucher_adjustment.originator.display_value)
|
||||
= link_to t("checkout.step2.voucher.remove_code"), voucher_adjustment_path(id: voucher_adjustment.id), method: "delete", data: { confirm: t("checkout.step2.voucher.confirm_delete") }
|
||||
= link_to t("checkout.step2.voucher.remove_code"), voucher_adjustment_path(id: voucher_adjustment.id), data: { turbo_method: "delete", confirm: t("checkout.step2.voucher.confirm_delete") }
|
||||
|
||||
- # This might not be true, ie payment method including a fee which wouldn't be covered by voucher or tax implication raising total to be bigger than the voucher amount ?
|
||||
- if voucher_adjustment.originator.amount > order.pre_discount_total && voucher_adjustment.originator.is_a?(Vouchers::FlatRate)
|
||||
@@ -22,4 +22,4 @@
|
||||
= form.error_message_on :voucher_code
|
||||
|
||||
%div.checkout-input
|
||||
= form.submit t("checkout.step2.voucher.apply"), disabled: true, class: "button cancel voucher-button", "data-disable-with": false, data: { "toggle-control-target": "control" }
|
||||
= form.submit t("checkout.step2.voucher.apply"), disabled: true, class: "button cancel voucher-button", data: { "toggle-control-target": "control" }
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
= turbo_stream.replace 'flashes' do
|
||||
= render partial: "shared/flashes", locals: { flashes: flash }
|
||||
= turbo_stream.replace 'voucher-section' do
|
||||
= render partial: 'checkout/voucher_section', locals: { order: @order, voucher_adjustment: @order.voucher_adjustments.first }
|
||||
@@ -0,0 +1,2 @@
|
||||
= turbo_stream.replace 'checkout-payment-methods' do
|
||||
= render partial: "checkout/payment", locals: { step: "payment" }
|
||||
Reference in New Issue
Block a user