tweaks after rebase on clic-limit

This commit is contained in:
imperosol
2026-06-05 13:37:58 +02:00
parent 4c5149aec9
commit d73b7de903
2 changed files with 75 additions and 61 deletions
@@ -6,67 +6,71 @@ interface Basket {
timeout: Date; timeout: Date;
} }
document.addEventListener("alpine:init", () => { document.addEventListener("alpine:init", () => {
Alpine.data("etransaction", (initialData, basket: Basket) => ({ Alpine.data(
data: initialData, "etransaction",
isCbAvailable: Object.keys(initialData).length > 0, (initialData: Record<string, string>, basket: Basket) => ({
isSithAvailable: true, data: initialData,
isCbAvailable: Object.keys(initialData).length > 0,
isSithAvailable: true,
init() { init() {
const now = new Date(); const now = new Date();
const timeout = basket.timeout.getTime() - now.getTime(); const timeout = basket.timeout.getTime() - now.getTime();
if (timeout <= 0) { if (timeout > 0) {
// basket was already outdated at initial page load // if not going inside this condition, it means that
this.timeoutBasket(); // basket was already outdated at initial page load,
} else { // in which case disabling buttons and displaying
setTimeout(() => this.timeoutBasket(), timeout); // error message has been done at rendering time
} setTimeout(() => this.timeoutBasket(), timeout);
}, }
},
/** /**
* Make this basket into a timeout state. * Make this basket into a timeout state.
* All submission inputs are disabled, and an error message is displayed. * All submission inputs are disabled, and an error message is displayed.
*/ */
timeoutBasket() { timeoutBasket() {
this.isCbAvailable = false; this.isCbAvailable = false;
this.isSithAvailable = false; this.isSithAvailable = false;
const message = gettext("Basket expired"); const message = gettext("Basket expired");
const existingNotif: Notification | undefined = this.$notifications const existingNotif: Notification | undefined = this.$notifications
.getAll() .getAll()
.find( .find(
(n: Notification) => (n: Notification) =>
n.tag === NotificationLevel.Error && n.message === message, n.tag === NotificationLevel.Error && n.text === message,
); );
if (existingNotif === undefined) { if (existingNotif === undefined) {
this.$notifications.error(message); this.$notifications.error(message);
} }
}, },
/** /**
* Refresh the data used for etransaction. * Refresh the data used for etransaction.
* *
* Note: if this is called while the basket is expired, it will be a no-op * Note: if this is called while the basket is expired, it will be a no-op
*/ */
async fill() { async fill() {
if (new Date() > basket.timeout) { if (new Date() > basket.timeout) {
// refresh etransaction data only if the basket is still valid. // refresh etransaction data only if the basket is still valid.
this.timeoutBasket(); this.timeoutBasket();
return; return;
} }
this.isCbAvailable = false; this.isCbAvailable = false;
const res = await etransactioninfoFetchEtransactionData({ const res = await etransactioninfoFetchEtransactionData({
// biome-ignore lint/style/useNamingConvention: api is in snake_case // biome-ignore lint/style/useNamingConvention: api is in snake_case
path: { basket_id: basket.id }, path: { basket_id: basket.id },
}); });
if (res.response.ok) { if (res.response.ok) {
this.data = res.data; this.data = res.data as Record<string, string>;
this.isCbAvailable = true; this.isCbAvailable = true;
} else if (res.response.status === 410) { } else if (res.response.status === 410) {
// The basket is expired, so no payment method should be available at all. // The basket is expired, so no payment method should be available at all.
// This shouldn't happen, because we don't send the request // This shouldn't happen, because we don't send the request
// when the timeout is passed, but we are better safe than sorry // when the timeout is passed, but we are better safe than sorry
this.timeoutBasket(); this.timeoutBasket();
} }
}, },
})); }),
);
}); });
@@ -72,8 +72,18 @@
we have a third dummy form, containing only the cgv button, we have a third dummy form, containing only the cgv button,
which validation is triggered when one of the two other forms is submitted. which validation is triggered when one of the two other forms is submitted.
If the validation of this form fails, the submit event will be cancelled. #} If the validation of this form fails, the submit event will be cancelled. #}
<div class="form-group margin-bottom"> <div class="form-group">
<input type="checkbox" id="cgv-checkbox" name="cgv" required> <input
type="checkbox"
id="cgv-checkbox"
name="cgv"
required
{% if basket.is_expired %}
disabled="disabled"
{% else %}
:disabled="!isCbAvailable && !isSithAvailable"
{% endif %}
>
<label for="cgv-checkbox"> <label for="cgv-checkbox">
{% trans trimmed %}I have read and I accept{% endtrans %} {% trans trimmed %}I have read and I accept{% endtrans %}
<a href="{{ url('core:page', 'cgv') }}">{% trans %}the general terms and conditions{% endtrans%}</a> <a href="{{ url('core:page', 'cgv') }}">{% trans %}the general terms and conditions{% endtrans%}</a>