feat: fold purchase and promo voucher fields into one code field
This commit is contained in:
1 parent
93512b8345
commit
21d756a2e3
21 files changed
+801
-432
No files matched your search
@@ -684,19 +684,84 @@
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{# Voucher fields - available for all participants regardless of eligibility #}
|
||||
{% if form.purchaseVoucherCode is defined or form.promoVoucherCode is defined %}
|
||||
{# Voucher field - available for all participants regardless of eligibility #}
|
||||
{% if form.voucherCode is defined %}
|
||||
{% set voucherParticipant = form.vars.data.participant %}
|
||||
{% set voucherHx = {
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content',
|
||||
'hx-swap': 'innerHTML'
|
||||
} %}
|
||||
<h3 class="font-semibold text-lg mb-4">
|
||||
Gutscheine
|
||||
</h3>
|
||||
<div class="grid lg:grid-cols-2 lg:gap-x-4">
|
||||
{% if form.purchaseVoucherCode is defined %}
|
||||
{{ form_row(form.purchaseVoucherCode) }}
|
||||
<div class="mb-4">
|
||||
{{ form_label(form.voucherCode) }}
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="grow">
|
||||
{{ form_widget(form.voucherCode) }}
|
||||
</div>
|
||||
<button type="button" class="button button--secondary"
|
||||
{% for name, value in voucherHx %} {{ name }}="{{ value }}"{% endfor %}>
|
||||
Code einlösen
|
||||
</button>
|
||||
</div>
|
||||
{# A full submit carries the error as a violation; the htmx refresh rebuilds the form, so read it from the DTO #}
|
||||
{% if form.voucherCode.vars.errors|length > 0 %}
|
||||
{{ form_errors(form.voucherCode) }}
|
||||
{% elseif voucherParticipant.voucherCodeError %}
|
||||
<ul class="pb-2 px-2">
|
||||
<li class="text-red-500">{{ voucherParticipant.voucherCodeError }}</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% if form.promoVoucherCode is defined %}
|
||||
{{ form_row(form.promoVoucherCode) }}
|
||||
|
||||
{% set appliedVouchers = [] %}
|
||||
{% if voucherParticipant.purchaseVoucherCode %}
|
||||
{% set purchaseVoucher = voucherParticipant.validatedPurchaseVoucher %}
|
||||
{% set appliedVouchers = appliedVouchers|merge([{
|
||||
code: voucherParticipant.purchaseVoucherCode,
|
||||
label: purchaseVoucher and purchaseVoucher.goodwill ? 'Kulanzgutschein' : 'Kaufgutschein',
|
||||
value: purchaseVoucher ? purchaseVoucher.remainingBalance|format_currency('EUR') : null,
|
||||
error: null
|
||||
}]) %}
|
||||
{% endif %}
|
||||
{% if voucherParticipant.promoVoucherCode %}
|
||||
{% set promoVoucher = voucherParticipant.validatedPromoVoucher %}
|
||||
{% set appliedVouchers = appliedVouchers|merge([{
|
||||
code: voucherParticipant.promoVoucherCode,
|
||||
label: 'Aktionsgutschein',
|
||||
value: promoVoucher ? (promoVoucher.discountPercentage > 0 ? promoVoucher.discountPercentage ~ ' %' : promoVoucher.discountAmount|format_currency('EUR')) : null,
|
||||
error: voucherParticipant.promoVoucherError
|
||||
}]) %}
|
||||
{% endif %}
|
||||
|
||||
{% if appliedVouchers is not empty %}
|
||||
<ul class="flex flex-wrap gap-2 mt-2">
|
||||
{% for voucher in appliedVouchers %}
|
||||
<li class="{{ html_classes('flex items-center gap-2 border px-2 py-1', {
|
||||
'border-primary-bg': not voucher.error,
|
||||
'border-red-500': voucher.error
|
||||
}) }}">
|
||||
<span>
|
||||
{{ voucher.label }} {{ voucher.code }}{% if voucher.value %}: {{ voucher.value }}{% endif %}
|
||||
{% if voucher.error %}
|
||||
<span class="block text-sm text-red-500">{{ voucher.error }}</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
<button type="button" class="text-sm text-primary-light" aria-label="{{ voucher.code }} entfernen"
|
||||
hx-vals="{{ {(form.removeVoucherCode.vars.full_name): voucher.code}|json_encode }}"
|
||||
{% for name, value in voucherHx %} {{ name }}="{{ value }}"{% endfor %}>
|
||||
Entfernen
|
||||
</button>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
{# Submitted through the remove buttons' hx-vals, never as an input of its own #}
|
||||
{% if form.removeVoucherCode is defined %}
|
||||
{% do form.removeVoucherCode.setRendered() %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
Reference in new issue
Block a user