mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
fix: Generation d'une fiche d'élève avec le nouveau modèle PayementMode
et PayementPlans
This commit is contained in:
@ -64,6 +64,14 @@ export default function PaymentMethodSelector({
|
||||
setFormData((prev) => ({ ...prev, [field]: value }));
|
||||
};
|
||||
|
||||
// Fonction utilitaire pour trier selon paymentPlansOptions
|
||||
const sortPlansByOptions = (plans, options) => {
|
||||
const order = options.map((opt) => opt.id);
|
||||
return [...plans].sort(
|
||||
(a, b) => order.indexOf(a.plan_type) - order.indexOf(b.plan_type)
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Frais d'inscription */}
|
||||
@ -84,11 +92,21 @@ export default function PaymentMethodSelector({
|
||||
label="Mode de Paiement"
|
||||
placeHolder="Sélectionner un mode de paiement"
|
||||
selected={formData.registration_payment}
|
||||
callback={(e) =>
|
||||
onChange('registration_payment', parseInt(e.target.value, 10))
|
||||
}
|
||||
callback={(e) => {
|
||||
const selectedId = parseInt(e.target.value, 10);
|
||||
const selectedMode = registrationPaymentModes.find(
|
||||
(mode) => mode.id === selectedId
|
||||
);
|
||||
onChange('registration_payment', selectedId);
|
||||
// Ajoute ou retire isSepa selon le mode choisi
|
||||
if (selectedMode && selectedMode.mode === 1) {
|
||||
onChange('isSepa', 1);
|
||||
} else {
|
||||
onChange('isSepa', 0);
|
||||
}
|
||||
}}
|
||||
choices={registrationPaymentModes.map((mode) => ({
|
||||
value: mode.mode,
|
||||
value: mode.id, // <-- utiliser l'id du mode de paiement
|
||||
label:
|
||||
paymentModesOptions.find((option) => option.id === mode.mode)
|
||||
?.name || 'Mode inconnu',
|
||||
@ -102,26 +120,25 @@ export default function PaymentMethodSelector({
|
||||
<RadioList
|
||||
sectionLabel="Choisissez une option"
|
||||
required
|
||||
items={paymentPlansOptions
|
||||
.filter((option) =>
|
||||
registrationPaymentPlans.some(
|
||||
(plan) => plan.plan_type === option.id
|
||||
)
|
||||
)
|
||||
.map((option) => ({
|
||||
id: option.id,
|
||||
label: option.name,
|
||||
}))}
|
||||
items={sortPlansByOptions(
|
||||
registrationPaymentPlans,
|
||||
paymentPlansOptions
|
||||
).map((plan) => ({
|
||||
id: plan.id,
|
||||
label:
|
||||
paymentPlansOptions.find((opt) => opt.id === plan.plan_type)
|
||||
?.name || `Option ${plan.plan_type}`,
|
||||
}))}
|
||||
formData={{
|
||||
...formData,
|
||||
registration_payment_plan: parseInt(
|
||||
formData.registration_payment_plan,
|
||||
10
|
||||
), // S'assurer que la valeur est un entier
|
||||
),
|
||||
}}
|
||||
handleChange={(e) => {
|
||||
const value = parseInt(e.target.value, 10);
|
||||
onChange('registration_payment_plan', value); // Convertir la valeur en entier
|
||||
onChange('registration_payment_plan', value);
|
||||
}}
|
||||
fieldName="registration_payment_plan"
|
||||
className="mt-4"
|
||||
@ -147,11 +164,21 @@ export default function PaymentMethodSelector({
|
||||
label="Mode de Paiement"
|
||||
placeHolder="Sélectionner un mode de paiement"
|
||||
selected={formData.tuition_payment}
|
||||
callback={(e) =>
|
||||
onChange('tuition_payment', parseInt(e.target.value, 10))
|
||||
}
|
||||
callback={(e) => {
|
||||
const selectedId = parseInt(e.target.value, 10);
|
||||
const selectedMode = tuitionPaymentModes.find(
|
||||
(mode) => mode.id === selectedId
|
||||
);
|
||||
onChange('tuition_payment', selectedId);
|
||||
// Ajoute ou retire isSepa selon le mode choisi
|
||||
if (selectedMode && selectedMode.mode === 1) {
|
||||
onChange('isSepa', 1);
|
||||
} else {
|
||||
onChange('isSepa', 0);
|
||||
}
|
||||
}}
|
||||
choices={tuitionPaymentModes.map((mode) => ({
|
||||
value: mode.mode,
|
||||
value: mode.id,
|
||||
label:
|
||||
paymentModesOptions.find((option) => option.id === mode.mode)
|
||||
?.name || 'Mode inconnu',
|
||||
@ -165,18 +192,22 @@ export default function PaymentMethodSelector({
|
||||
<RadioList
|
||||
sectionLabel="Choisissez une option"
|
||||
required
|
||||
items={paymentPlansOptions
|
||||
.filter((option) =>
|
||||
tuitionPaymentPlans.some((plan) => plan.plan_type === option.id)
|
||||
)
|
||||
.map((option) => ({
|
||||
id: option.id,
|
||||
label: option.name,
|
||||
}))}
|
||||
formData={formData}
|
||||
items={sortPlansByOptions(
|
||||
tuitionPaymentPlans,
|
||||
paymentPlansOptions
|
||||
).map((plan) => ({
|
||||
id: plan.id,
|
||||
label:
|
||||
paymentPlansOptions.find((opt) => opt.id === plan.plan_type)
|
||||
?.name || `Option ${plan.plan_type}`,
|
||||
}))}
|
||||
formData={{
|
||||
...formData,
|
||||
tuition_payment_plan: parseInt(formData.tuition_payment_plan, 10),
|
||||
}}
|
||||
handleChange={(e) => {
|
||||
const value = parseInt(e.target.value, 10);
|
||||
onChange('tuition_payment_plan', value); // Convertir la valeur en entier
|
||||
const value = parseInt(e.target.value, 10); // valeur = id du plan
|
||||
onChange('tuition_payment_plan', value);
|
||||
}}
|
||||
fieldName="tuition_payment_plan"
|
||||
className="mt-4"
|
||||
|
||||
Reference in New Issue
Block a user