Skip to content

Commit

Permalink
Use common partial for redemption of tutor and speeaker vouchers
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterfarrell9 committed Aug 19, 2024
1 parent a3e99ed commit b71af1a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
13 changes: 13 additions & 0 deletions app/helpers/vouchers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,17 @@ def cancel_voucher_button
link_to(t("buttons.cancel"), cancel_voucher_path,
class: "btn btn-secondary ms-2", remote: true)
end

def claim_select_field(form, user, voucher)
field_name, options, prompt = if voucher.tutor?
[:tutorial_ids, tutorial_options(user, voucher), t("profile.select_tutorials")]
elsif voucher.speaker?
[:talk_ids, talk_options(user, voucher), t("profile.select_talks")]
end

form.select(field_name,
options_for_select(options),
{ prompt: prompt },
{ multiple: true, class: "selectize me-2 w-50" })
end
end
2 changes: 1 addition & 1 deletion app/views/vouchers/_redeem_speaker_voucher.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<% if voucher.lecture.talks_without_speaker(current_user).any? %>

<%= render partial: "vouchers/talks_form", locals: { voucher: voucher } %>
<%= render partial: "vouchers/voucher_form", locals: { voucher: voucher } %>

<% elsif voucher.lecture.talks.any? %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/vouchers/_redeem_tutor_voucher.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<% if voucher.lecture.tutorials_without_tutor(current_user).any? %>

<%= render partial: "vouchers/tutorials_form", locals: { voucher: voucher } %>
<%= render partial: "vouchers/voucher_form", locals: { voucher: voucher } %>

<% elsif voucher.lecture.tutorials.any? %>

Expand Down
14 changes: 0 additions & 14 deletions app/views/vouchers/_tutorials_form.html.erb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
remote: true,
method: :post,
html: { class: "form-inline" } do |f| %>

<%= f.hidden_field :secure_hash, value: voucher.secure_hash %>

<div class="form-group d-flex">
<%= f.select :talk_ids,
options_for_select(talk_options(current_user, voucher)),
{ prompt: t('profile.select_talks') },
{ multiple: true, class: 'selectize me-2 w-50' } %>

<%= claim_select_field(f, current_user, voucher) %>

<%= f.submit t('profile.redeem_voucher'), class: "btn btn-primary" %>
<%= cancel_voucher_button %>
</div>

<% end %>

0 comments on commit b71af1a

Please sign in to comment.