Skip to content

Commit

Permalink
COM-3872: add validations createCourseSlots
Browse files Browse the repository at this point in the history
  • Loading branch information
Aude committed Jan 6, 2025
1 parent 783b493 commit bfd6151
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions src/core/components/courses/SlotContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</div>
<div class="q-mt-sm" v-if="canEdit && isRofOrVendorAdmin && isVendorInterface" align="right">
<ni-button label="Ajouter des créneaux" color="primary" icon="add"
@click="openMultipleSlotCreationModal(step.key)" :disable="addDateToPlanLoading" />
@click="openMultipleSlotCreationModal(step.key)" :disable="slotCreationLoading" />
</div>
</div>
</div>
Expand All @@ -93,7 +93,7 @@

<multiple-slot-creation-modal v-model="multipleSlotCreationModal" :slots-quantity="slotsQuantity"
@hide="resetCreationModal" @submit="createCourseSlots" @update:slots-quantity="updateSlotsQuantity"
:validations="v$.slotsQuantity" />
:validations="v$.slotsQuantity" :loading="slotCreationLoading" />
</div>
</template>
<script>
Expand Down Expand Up @@ -152,7 +152,7 @@ export default {
const $store = useStore();
const addDateToPlanLoading = ref(false);
const slotCreationLoading = ref(false);
const modalLoading = ref(false);
const editedCourseSlot = ref({});
const editionModal = ref(false);
Expand Down Expand Up @@ -313,26 +313,6 @@ export default {
};
};
const addDateToPlan = async (stepId) => {
try {
if (course.value.archivedAt) {
return NotifyWarning('Vous ne pouvez pas ajouter un créneau à une formation archivée.');
}
addDateToPlanLoading.value = true;
await CourseSlots.create({ course: course.value._id, step: stepId });
NotifyPositive('Date à planifier ajoutée.');
emit('refresh');
} catch (e) {
console.error(e);
NotifyNegative('Erreur lors de l\'ajout de la date à planifier.');
} finally {
addDateToPlanLoading.value = false;
showSlotToPlan.value[stepId] = true;
}
};
const updateCourseSlot = async () => {
try {
v$.value.editedCourseSlot.$touch();
Expand Down Expand Up @@ -435,9 +415,14 @@ export default {
const createCourseSlots = async () => {
try {
if (course.value.archivedAt) {
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');
slotCreationLoading.value = true;
await CourseSlots.create(slotsToAdd.value);
multipleSlotCreationModal.value = false;
Expand Down Expand Up @@ -469,7 +454,7 @@ export default {
// Data
isVendorInterface,
ON_SITE,
addDateToPlanLoading,
slotCreationLoading,
modalLoading,
editedCourseSlot,
editionModal,
Expand All @@ -494,7 +479,6 @@ export default {
getSlotAddress,
openEditionModal,
resetEditionModal,
addDateToPlan,
updateCourseSlot,
deleteCourseSlot,
unplanSlot,
Expand Down

0 comments on commit bfd6151

Please sign in to comment.