Skip to content

Commit

Permalink
COM-3872: fix update quantity with slotsToAdd
Browse files Browse the repository at this point in the history
  • Loading branch information
Aude committed Jan 7, 2025
1 parent bfd6151 commit 2f457f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
15 changes: 8 additions & 7 deletions src/core/components/courses/MultipleSlotCreationModal.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<template>
<ni-modal :model-value="modelValue" @update:model-value="input" @hide="hide">
<template #title>Ajouter des créneaux</template>
<ni-input in-modal caption="Nombre de créneaux à ajouter" type="number" required-field :model-value="slotsQuantity"
@update:model-value="update" :error="validations.$error" :error-message="quantityErrorMessage" />
<ni-input in-modal caption="Nombre de créneaux à ajouter" type="number" required-field
:model-value="slotsToAdd.quantity" @update:model-value="update($event, 'quantity')" :error="validations.$error"
:error-message="quantityErrorMessage" />
<template #footer>
<ni-button class="bg-primary full-width modal-btn" label="Ajouter les créneaux" icon="add" color="white"
:loading="loading" @click="submit" />
Expand All @@ -22,21 +23,21 @@ export default {
modelValue: { type: Boolean, default: false },
validations: { type: Object, default: () => ({}) },
loading: { type: Boolean, default: false },
slotsQuantity: { type: Number, required: true },
slotsToAdd: { type: Object, default: () => ({}) },
},
components: {
'ni-modal': Modal,
'ni-input': Input,
'ni-button': Button,
},
emits: ['hide', 'submit', 'update:slots-quantity', 'update:model-value'],
emits: ['hide', 'submit', 'update:slots-to-add', 'update:model-value'],
setup (props, { emit }) {
const { validations } = toRefs(props);
const { validations, slotsToAdd } = toRefs(props);
const quantityErrorMessage = computed(() => {
if (validations.value.strictPositiveNumber.$response === false ||
validations.value.integerNumber.$response === false) {
return 'Nombre non valide, doit être strictement positif.';
return 'Nombre non valide, doit être un entier strictement positif .';
}
return 'Nombre invalide.';
Expand All @@ -46,7 +47,7 @@ export default {
const submit = () => emit('submit');
const update = event => emit('update:slots-quantity', event);
const update = (event, prop) => emit('update:slots-to-add', { ...slotsToAdd.value, [prop]: event });
const input = event => emit('update:model-value', event);
Expand Down
23 changes: 9 additions & 14 deletions src/core/components/courses/SlotContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@
:is-vendor-interface="isVendorInterface" :is-only-slot="isOnlySlot" :is-planned-slot="isPlannedSlot"
@unplan-slot="unplanSlot" />

<multiple-slot-creation-modal v-model="multipleSlotCreationModal" :slots-quantity="slotsQuantity"
@hide="resetCreationModal" @submit="createCourseSlots" @update:slots-quantity="updateSlotsQuantity"
:validations="v$.slotsQuantity" :loading="slotCreationLoading" />
<multiple-slot-creation-modal v-model="multipleSlotCreationModal" v-model:slots-to-add="slotsToAdd"
@hide="resetCreationModal" @submit="createCourseSlots" :validations="v$.slotsToAdd.quantity"
:loading="slotCreationLoading" />
</div>
</template>
<script>
Expand Down Expand Up @@ -169,8 +169,6 @@ export default {
const course = computed(() => $store.state.course.course);
const slotsToAdd = ref({ course: course.value._id, step: '', quantity: 1 });
const slotsQuantity = computed(() => slotsToAdd.value.quantity);
const slotsDurationTitle = computed(() => {
if (!course.value || !course.value.slots) return '0h';
Expand Down Expand Up @@ -255,10 +253,10 @@ export default {
},
},
},
slotsQuantity: { required, strictPositiveNumber, integerNumber },
slotsToAdd: { quantity: { required, strictPositiveNumber, integerNumber } },
}));
const v$ = useVuelidate(rules, { editedCourseSlot, slotsQuantity });
const v$ = useVuelidate(rules, { editedCourseSlot, slotsToAdd });
const getSlotAddress = slot => get(slot, 'address.fullAddress') || 'Adresse non renseignée';
Expand Down Expand Up @@ -419,15 +417,16 @@ export default {
return NotifyWarning('Vous ne pouvez pas ajouter de créneaux à une formation archivée.');
}
v$.value.slotsQuantity.$touch();
if (v$.value.slotsQuantity.$error) return NotifyWarning('Champ invalide');
v$.value.slotsToAdd.$touch();
if (v$.value.slotsToAdd.$error) return NotifyWarning('Champ invalide');
slotCreationLoading.value = true;
await CourseSlots.create(slotsToAdd.value);
multipleSlotCreationModal.value = false;
NotifyPositive('Date à planifier ajoutée.');
slotCreationLoading.value = false;
emit('refresh');
} catch (e) {
console.error(e);
Expand All @@ -437,11 +436,9 @@ export default {
const resetCreationModal = () => {
slotsToAdd.value = { course: course.value._id, step: '', quantity: 1 };
v$.value.validations.slotsQuantity.$reset();
v$.value.slotsToAdd.$reset();
};
const updateSlotsQuantity = (value) => { set(slotsToAdd.value, 'quantity', Number(value)); };
const created = async () => {
if (!course.value) emit('refresh');
Expand Down Expand Up @@ -472,7 +469,6 @@ export default {
stepTypes,
courseSlotsByStepAndDate,
stepList,
slotsQuantity,
// Methods
get,
omit,
Expand All @@ -496,7 +492,6 @@ export default {
openMultipleSlotCreationModal,
resetCreationModal,
createCourseSlots,
updateSlotsQuantity,
};
},
};
Expand Down

0 comments on commit 2f457f8

Please sign in to comment.