Merge pull request #1378 from ae-utbm/fix-subscriptions

Fix subscription form
This commit is contained in:
2026-05-10 14:13:37 +02:00
committed by GitHub
3 changed files with 62 additions and 54 deletions
@@ -1,38 +1,42 @@
import { userFetchUser } from "#openapi"; import { userFetchUser } from "#openapi";
document.addEventListener("alpine:init", () => { Alpine.data("existing_user_subscription_form", () => ({
Alpine.data("existing_user_subscription_form", () => ({ loading: false,
loading: false, selectedUser: "",
profileFragment: "" as string, profileFragment: "",
dateOfBirth: "",
dateOfBirthHidden: true,
async init() { init() {
const userSelect = document.getElementById("id_member") as HTMLSelectElement; this.$watch("selectedUser", async () => {
userSelect.addEventListener("change", async () => { await this.loadProfile(Number.parseInt(this.selectedUser, 10));
await this.loadProfile(Number.parseInt(userSelect.value, 10)); });
});
await this.loadProfile(Number.parseInt(userSelect.value, 10));
},
async loadProfile(userId: number) { this.$nextTick(() => {
const birthdayInput = document.getElementById("id_birthdate") as HTMLInputElement; // Force to detect the initial value
if (!Number.isInteger(userId)) { this.selectedUser = this.$refs.userSelect.widget.getValue();
this.profileFragment = ""; });
birthdayInput.hidden = true; },
return;
} async loadProfile(userId: number) {
this.loading = true; if (!Number.isInteger(userId)) {
const [miniProfile, userInfos] = await Promise.all([ this.profileFragment = "";
fetch(`/user/${userId}/mini/`), this.dateOfBirth = "";
// biome-ignore lint/style/useNamingConvention: api is snake_case this.dateOfBirthHidden = true;
userFetchUser({ path: { user_id: userId } }), return;
]); }
this.profileFragment = await miniProfile.text(); this.loading = true;
// If the user has no birthdate yet, show the form input const [miniProfile, userInfos] = await Promise.all([
// to fill this info. fetch(`/user/${userId}/mini/`),
// Else keep the input hidden and change its value to the user birthdate // biome-ignore lint/style/useNamingConvention: api is snake_case
birthdayInput.value = userInfos.data.date_of_birth; userFetchUser({ path: { user_id: userId } }),
birthdayInput.hidden = userInfos.data.date_of_birth !== null; ]);
this.loading = false; this.profileFragment = await miniProfile.text();
}, // If the user has no birthdate yet, show the form input
})); // to fill this info.
}); // Else keep the input hidden and change its value to the user birthdate
this.dateOfBirth = userInfos.data.date_of_birth;
this.dateOfBirthHidden = userInfos.data.date_of_birth !== null;
this.loading = false;
},
}));
@@ -5,7 +5,8 @@
margin-top: 0; margin-top: 0;
} }
fieldset p:first-of-type, & > p:first-of-type { fieldset p:first-of-type,
&>p:first-of-type {
margin-top: 0; margin-top: 0;
} }
@@ -24,7 +25,7 @@
fieldset { fieldset {
flex: 0 1 auto; flex: 0 1 auto;
p:has(input[hidden]) { .form-group:has(input[hidden]) {
// when the input is hidden, hide the whole label+input+help text group // when the input is hidden, hide the whole label+input+help text group
display: none; display: none;
} }
@@ -8,24 +8,27 @@
<div x-data="existing_user_subscription_form" class="form-content existing-user"> <div x-data="existing_user_subscription_form" class="form-content existing-user">
<fieldset> <fieldset>
{{ form.errors }} {{ form.non_field_errors() }}
{% for field in form %} <div class="form-group">
<div class="form-group"> {{ form.member.label_tag() }}
{{ field.label_tag() }} {{ form.member|add_attr("x-ref=userSelect,x-model=selectedUser") }}
{{ field }} </div>
{% if field.help_text %} <div class="form-group">
<span class="helptext">{{ field.help_text }}</span> {{ form.birthdate.label_tag() }}
{% endif %} {{ form.birthdate|add_attr(":value=dateOfBirth,:hidden=dateOfBirthHidden,:type=dateOfBirthHidden ? 'hidden' : 'date'") }}
{% if field.name == "payment_method" %} <span class="helptext">{{ form.birthdate.help_text }}</span>
<i> </div>
{% trans trimmed %} <div class="form-group">{{ form.subscription_type.as_field_group() }}</div>
If the subscription is done using the AE account, <div class="form-group">
you must also click it on the AE counter. {{ form.payment_method.as_field_group() }}
{% endtrans %} <i>
</i> {% trans trimmed %}
{% endif %} If the subscription is done using the AE account,
</div> you must also click it on the AE counter.
{% endfor %} {% endtrans %}
</i>
</div>
<div class="form-group">{{ form.location.as_field_group() }}</div>
</fieldset> </fieldset>
<div <div
id="subscription-form-user-mini-profile" id="subscription-form-user-mini-profile"